@@ -31,7 +31,7 @@ class BufferedQuery
3131 // Constants that describe the current status of the parser.
3232 const STATUS_STRING_SINGLE_QUOTES = 1 ;
3333 const STATUS_STRING_DOUBLE_QUOTES = 2 ;
34- const STATUS_STRING_BACKTICK = 3 ;
34+ const STATUS_STRING_BACKTICK = 3 ;
3535 const STATUS_COMMENT_BASH = 4 ;
3636 const STATUS_COMMENT_C = 5 ;
3737 const STATUS_COMMENT_SQL = 6 ;
@@ -268,7 +268,8 @@ public function extract($end = false)
268268 *
269269 * This optimization makes the code about 3 times faster.
270270 */
271- if ((($ this ->query [$ i ] === 'D ' ) || ($ this ->query [$ i ] === 'd ' ))
271+ if (($ i + 9 < $ len )
272+ && (($ this ->query [$ i ] === 'D ' ) || ($ this ->query [$ i ] === 'd ' ))
272273 && (($ this ->query [$ i + 1 ] === 'E ' ) || ($ this ->query [$ i + 1 ] === 'e ' ))
273274 && (($ this ->query [$ i + 2 ] === 'L ' ) || ($ this ->query [$ i + 2 ] === 'l ' ))
274275 && (($ this ->query [$ i + 3 ] === 'I ' ) || ($ this ->query [$ i + 3 ] === 'i ' ))
@@ -277,6 +278,7 @@ public function extract($end = false)
277278 && (($ this ->query [$ i + 6 ] === 'T ' ) || ($ this ->query [$ i + 6 ] === 't ' ))
278279 && (($ this ->query [$ i + 7 ] === 'E ' ) || ($ this ->query [$ i + 7 ] === 'e ' ))
279280 && (($ this ->query [$ i + 8 ] === 'R ' ) || ($ this ->query [$ i + 8 ] === 'r ' ))
281+ && (Context::isWhitespace ($ this ->query [$ i + 9 ]))
280282 ) {
281283
282284 // Saving the current index to be able to revert any parsing
@@ -289,22 +291,16 @@ public function extract($end = false)
289291 ++$ i ;
290292 }
291293
292- // Checking if any whitespace was found between keyword
293- // `DELIMITER` and the actual delimiter.
294- if ($ iBak + 9 === $ i ) {
295- $ i = $ iBak ;
296- return false ;
297- }
298-
299294 // Parsing the delimiter.
300295 $ delimiter = '' ;
301296 while (($ i < $ len ) && (!Context::isWhitespace ($ this ->query [$ i ]))) {
302297 $ delimiter .= $ this ->query [$ i ++];
303298 }
304299
305300 // Checking if the delimiter definition ended.
306- if ((($ i < $ len ) && (Context::isWhitespace ($ this ->query [$ i ])))
307- || (($ i === $ len ) && ($ end ))
301+ if (($ delimiter != '' )
302+ && ((($ i < $ len ) && (Context::isWhitespace ($ this ->query [$ i ])))
303+ || (($ i === $ len ) && ($ end )))
308304 ) {
309305
310306 // Saving the delimiter.
@@ -380,11 +376,19 @@ public function extract($end = false)
380376 if (($ end ) && ($ i === $ len )) {
381377 // If the end of the buffer was reached, the buffer is emptied and
382378 // the current statement that was extracted is returned.
379+ $ ret = $ this ->current ;
380+
381+ // Emptying the buffer.
383382 $ this ->query = '' ;
384383 $ i = 0 ;
385- return trim ($ this ->current );
384+
385+ // Resetting the current statement.
386+ $ this ->current = '' ;
387+
388+ // Returning the statement.
389+ return trim ($ ret );
386390 }
387391
388- return false ;
392+ return '' ;
389393 }
390394}
0 commit comments