@@ -144,34 +144,35 @@ public String parseSQL(String origin) throws SQLException {
144144 batcher .readIdentifier (chars , keywordStart , keywordLength );
145145
146146 // Detect RETURNING keyword
147- if (parenLevel == 0 && parseReturningKeyword (chars , keywordStart )) {
147+ if (parenLevel == 0 && parseReturningKeyword (chars , keywordStart , keywordLength )) {
148148 statement .setHasReturning (true );
149149 }
150150
151- if (parseOffsetKeyword (chars , keywordStart ) || parseLimitKeyword (chars , keywordStart )) {
151+ if (parseOffsetKeyword (chars , keywordStart , keywordLength )
152+ || parseLimitKeyword (chars , keywordStart , keywordLength )) {
152153 lastKeywordIsOffsetLimit = true ;
153154 }
154155 } else {
155156 boolean skipped = false ;
156157 if (isDetectQueryType ) {
157158 // Detect scan expression - starts with SCAN
158- if (parseScanKeyword (chars , keywordStart )) {
159+ if (parseScanKeyword (chars , keywordStart , keywordLength )) {
159160 type = QueryType .SCAN_QUERY ;
160161 // Skip SCAN prefix
161162 parsed .append (chars , fragmentStart , keywordStart - fragmentStart );
162163 fragmentStart = isInsideKeyword ? keywordEnd + 1 : keywordEnd ;
163164 skipped = true ;
164165 }
165166 // Detect explain expression - starts with EXPLAIN
166- if (parseExplainKeyword (chars , keywordStart )) {
167+ if (parseExplainKeyword (chars , keywordStart , keywordLength )) {
167168 type = QueryType .EXPLAIN_QUERY ;
168169 // Skip EXPLAIN prefix
169170 parsed .append (chars , fragmentStart , keywordStart - fragmentStart );
170171 fragmentStart = isInsideKeyword ? keywordEnd + 1 : keywordEnd ;
171172 skipped = true ;
172173 }
173174 // Detect bulk upsert expression - starts with BULK
174- if (parseBulkKeyword (chars , keywordStart )) {
175+ if (parseBulkKeyword (chars , keywordStart , keywordLength )) {
175176 type = QueryType .BULK_QUERY ;
176177 // Skip BULK prefix
177178 parsed .append (chars , fragmentStart , keywordStart - fragmentStart );
@@ -185,33 +186,33 @@ public String parseSQL(String origin) throws SQLException {
185186 statement = new QueryStatement (type , QueryType .UNKNOWN , QueryCmd .UNKNOWN );
186187 // Detect data query expression - starts with SELECT, , UPSERT, DELETE, REPLACE
187188 // starts with SELECT
188- if (parseSelectKeyword (chars , keywordStart )) {
189+ if (parseSelectKeyword (chars , keywordStart , keywordLength )) {
189190 statement = new QueryStatement (type , QueryType .DATA_QUERY , QueryCmd .SELECT );
190191 batcher .readIdentifier (chars , keywordStart , keywordLength );
191192 }
192193
193194 // starts with INSERT, UPSERT
194- if (parseInsertKeyword (chars , keywordStart )) {
195+ if (parseInsertKeyword (chars , keywordStart , keywordLength )) {
195196 statement = new QueryStatement (type , QueryType .DATA_QUERY , QueryCmd .INSERT_UPSERT );
196197 batcher .readInsert ();
197198 }
198- if (parseUpsertKeyword (chars , keywordStart )) {
199+ if (parseUpsertKeyword (chars , keywordStart , keywordLength )) {
199200 statement = new QueryStatement (type , QueryType .DATA_QUERY , QueryCmd .INSERT_UPSERT );
200201 batcher .readUpsert ();
201202 }
202203
203204 // starts with UPDATE, REPLACE, DELETE
204- if (parseUpdateKeyword (chars , keywordStart )
205- || parseDeleteKeyword (chars , keywordStart )
206- || parseReplaceKeyword (chars , keywordStart )) {
205+ if (parseUpdateKeyword (chars , keywordStart , keywordLength )
206+ || parseDeleteKeyword (chars , keywordStart , keywordLength )
207+ || parseReplaceKeyword (chars , keywordStart , keywordLength )) {
207208 statement = new QueryStatement (type , QueryType .DATA_QUERY , QueryCmd .UPDATE_REPLACE_DELETE );
208209 batcher .readIdentifier (chars , keywordStart , keywordLength );
209210 }
210211
211212 // Detect scheme expression - starts with ALTER, DROP, CREATE
212- if (parseAlterKeyword (chars , keywordStart )
213- || parseCreateKeyword (chars , keywordStart )
214- || parseDropKeyword (chars , keywordStart )) {
213+ if (parseAlterKeyword (chars , keywordStart , keywordLength )
214+ || parseCreateKeyword (chars , keywordStart , keywordLength )
215+ || parseDropKeyword (chars , keywordStart , keywordLength )) {
215216 statement = new QueryStatement (type , QueryType .SCHEME_QUERY , QueryCmd .CREATE_ALTER_DROP );
216217 batcher .readIdentifier (chars , keywordStart , keywordLength );
217218 }
@@ -349,8 +350,8 @@ private static int parseBlockComment(final char[] query, int offset) {
349350 return offset ;
350351 }
351352
352- private static boolean parseAlterKeyword (char [] query , int offset ) {
353- if (query . length < ( offset + 5 ) ) {
353+ private static boolean parseAlterKeyword (char [] query , int offset , int length ) {
354+ if (length != 5 ) {
354355 return false ;
355356 }
356357
@@ -361,8 +362,8 @@ private static boolean parseAlterKeyword(char[] query, int offset) {
361362 && (query [offset + 4 ] | 32 ) == 'r' ;
362363 }
363364
364- private static boolean parseCreateKeyword (char [] query , int offset ) {
365- if (query . length < ( offset + 6 ) ) {
365+ private static boolean parseCreateKeyword (char [] query , int offset , int length ) {
366+ if (length != 6 ) {
366367 return false ;
367368 }
368369
@@ -374,8 +375,8 @@ private static boolean parseCreateKeyword(char[] query, int offset) {
374375 && (query [offset + 5 ] | 32 ) == 'e' ;
375376 }
376377
377- private static boolean parseDropKeyword (char [] query , int offset ) {
378- if (query . length < ( offset + 4 ) ) {
378+ private static boolean parseDropKeyword (char [] query , int offset , int length ) {
379+ if (length != 4 ) {
379380 return false ;
380381 }
381382
@@ -385,8 +386,8 @@ private static boolean parseDropKeyword(char[] query, int offset) {
385386 && (query [offset + 3 ] | 32 ) == 'p' ;
386387 }
387388
388- private static boolean parseScanKeyword (char [] query , int offset ) {
389- if (query . length < ( offset + 4 ) ) {
389+ private static boolean parseScanKeyword (char [] query , int offset , int length ) {
390+ if (length != 4 ) {
390391 return false ;
391392 }
392393
@@ -396,8 +397,8 @@ private static boolean parseScanKeyword(char[] query, int offset) {
396397 && (query [offset + 3 ] | 32 ) == 'n' ;
397398 }
398399
399- private static boolean parseBulkKeyword (char [] query , int offset ) {
400- if (query . length < ( offset + 4 ) ) {
400+ private static boolean parseBulkKeyword (char [] query , int offset , int length ) {
401+ if (length != 4 ) {
401402 return false ;
402403 }
403404
@@ -407,8 +408,8 @@ private static boolean parseBulkKeyword(char[] query, int offset) {
407408 && (query [offset + 3 ] | 32 ) == 'k' ;
408409 }
409410
410- private static boolean parseExplainKeyword (char [] query , int offset ) {
411- if (query . length < ( offset + 7 ) ) {
411+ private static boolean parseExplainKeyword (char [] query , int offset , int length ) {
412+ if (length != 7 ) {
412413 return false ;
413414 }
414415
@@ -421,8 +422,8 @@ private static boolean parseExplainKeyword(char[] query, int offset) {
421422 && (query [offset + 6 ] | 32 ) == 'n' ;
422423 }
423424
424- private static boolean parseSelectKeyword (char [] query , int offset ) {
425- if (query . length < ( offset + 6 ) ) {
425+ private static boolean parseSelectKeyword (char [] query , int offset , int length ) {
426+ if (length != 6 ) {
426427 return false ;
427428 }
428429
@@ -434,8 +435,8 @@ private static boolean parseSelectKeyword(char[] query, int offset) {
434435 && (query [offset + 5 ] | 32 ) == 't' ;
435436 }
436437
437- private static boolean parseUpdateKeyword (char [] query , int offset ) {
438- if (query . length < ( offset + 6 ) ) {
438+ private static boolean parseUpdateKeyword (char [] query , int offset , int length ) {
439+ if (length != 6 ) {
439440 return false ;
440441 }
441442
@@ -447,8 +448,8 @@ private static boolean parseUpdateKeyword(char[] query, int offset) {
447448 && (query [offset + 5 ] | 32 ) == 'e' ;
448449 }
449450
450- private static boolean parseUpsertKeyword (char [] query , int offset ) {
451- if (query . length < ( offset + 6 ) ) {
451+ private static boolean parseUpsertKeyword (char [] query , int offset , int length ) {
452+ if (length != 6 ) {
452453 return false ;
453454 }
454455
@@ -460,8 +461,8 @@ private static boolean parseUpsertKeyword(char[] query, int offset) {
460461 && (query [offset + 5 ] | 32 ) == 't' ;
461462 }
462463
463- private static boolean parseInsertKeyword (char [] query , int offset ) {
464- if (query . length < ( offset + 6 ) ) {
464+ private static boolean parseInsertKeyword (char [] query , int offset , int length ) {
465+ if (length != 6 ) {
465466 return false ;
466467 }
467468
@@ -473,8 +474,8 @@ private static boolean parseInsertKeyword(char[] query, int offset) {
473474 && (query [offset + 5 ] | 32 ) == 't' ;
474475 }
475476
476- private static boolean parseDeleteKeyword (char [] query , int offset ) {
477- if (query . length < ( offset + 6 ) ) {
477+ private static boolean parseDeleteKeyword (char [] query , int offset , int length ) {
478+ if (length != 6 ) {
478479 return false ;
479480 }
480481
@@ -486,8 +487,8 @@ private static boolean parseDeleteKeyword(char[] query, int offset) {
486487 && (query [offset + 5 ] | 32 ) == 'e' ;
487488 }
488489
489- private static boolean parseReplaceKeyword (char [] query , int offset ) {
490- if (query . length < ( offset + 7 ) ) {
490+ private static boolean parseReplaceKeyword (char [] query , int offset , int length ) {
491+ if (length != 7 ) {
491492 return false ;
492493 }
493494
@@ -500,8 +501,8 @@ private static boolean parseReplaceKeyword(char[] query, int offset) {
500501 && (query [offset + 6 ] | 32 ) == 'e' ;
501502 }
502503
503- private static boolean parseReturningKeyword (char [] query , int offset ) {
504- if (query . length < ( offset + 9 ) ) {
504+ private static boolean parseReturningKeyword (char [] query , int offset , int length ) {
505+ if (length != 9 ) {
505506 return false ;
506507 }
507508
@@ -516,8 +517,8 @@ private static boolean parseReturningKeyword(char[] query, int offset) {
516517 && (query [offset + 8 ] | 32 ) == 'g' ;
517518 }
518519
519- private static boolean parseOffsetKeyword (char [] query , int offset ) {
520- if (query . length < ( offset + 6 ) ) {
520+ private static boolean parseOffsetKeyword (char [] query , int offset , int length ) {
521+ if (length != 6 ) {
521522 return false ;
522523 }
523524
@@ -529,8 +530,8 @@ private static boolean parseOffsetKeyword(char[] query, int offset) {
529530 && (query [offset + 5 ] | 32 ) == 't' ;
530531 }
531532
532- private static boolean parseLimitKeyword (char [] query , int offset ) {
533- if (query . length < ( offset + 5 ) ) {
533+ private static boolean parseLimitKeyword (char [] query , int offset , int length ) {
534+ if (length != 5 ) {
534535 return false ;
535536 }
536537
0 commit comments