@@ -57,11 +57,7 @@ public QueryType detectQueryType() throws SQLException {
57
57
58
58
@ SuppressWarnings ("MethodLength" )
59
59
public String parseSQL (String origin ) throws SQLException {
60
- this .statements .clear ();
61
- this .batcher .clear ();
62
-
63
60
int fragmentStart = 0 ;
64
-
65
61
boolean detectJdbcArgs = false ;
66
62
67
63
QueryStatement currStatement = null ;
@@ -78,6 +74,7 @@ public String parseSQL(String origin) throws SQLException {
78
74
for (int i = 0 ; i < chars .length ; ++i ) {
79
75
char ch = chars [i ];
80
76
boolean isInsideKeyword = false ;
77
+ int keywordEnd = i ; // parseSingleQuotes, parseDoubleQuotes, etc move index so we keep old value
81
78
switch (ch ) {
82
79
case '\'' : // single-quotes
83
80
int singleQuitesEnd = parseSingleQuotes (chars , i );
@@ -140,7 +137,7 @@ public String parseSQL(String origin) throws SQLException {
140
137
141
138
if (keywordStart >= 0 && (!isInsideKeyword || (i == chars .length - 1 ))) {
142
139
lastKeywordIsOffsetLimit = false ;
143
- int keywordLength = isInsideKeyword ? i - keywordStart - 1 : i - keywordStart ;
140
+ int keywordLength = ( isInsideKeyword ? i + 1 : keywordEnd ) - keywordStart ;
144
141
145
142
if (currStatement != null ) {
146
143
batcher .readIdentifier (chars , keywordStart , keywordLength );
@@ -192,14 +189,14 @@ public String parseSQL(String origin) throws SQLException {
192
189
currStatement = new QueryStatement (QueryType .SCAN_QUERY , QueryCmd .SELECT );
193
190
// Skip SCAN prefix
194
191
parsed .append (chars , fragmentStart , keywordStart - fragmentStart );
195
- fragmentStart = isInsideKeyword ? i + 1 : i ;
192
+ fragmentStart = isInsideKeyword ? keywordEnd + 1 : keywordEnd ;
196
193
}
197
194
// Detect explain expression - starts with EXPLAIN
198
195
if (parseExplainKeyword (chars , keywordStart )) {
199
196
currStatement = new QueryStatement (QueryType .EXPLAIN_QUERY , QueryCmd .SELECT );
200
197
// Skip EXPLAIN prefix
201
198
parsed .append (chars , fragmentStart , keywordStart - fragmentStart );
202
- fragmentStart = isInsideKeyword ? i + 1 : i ;
199
+ fragmentStart = isInsideKeyword ? keywordEnd + 1 : keywordEnd ;
203
200
}
204
201
}
205
202
@@ -334,21 +331,16 @@ private static int parseBlockComment(final char[] query, int offset) {
334
331
return offset ;
335
332
}
336
333
337
- private static boolean isSpace (char c ) {
338
- return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' ;
339
- }
340
-
341
334
private static boolean parseAlterKeyword (char [] query , int offset ) {
342
- if (query .length < (offset + 6 )) {
335
+ if (query .length < (offset + 5 )) {
343
336
return false ;
344
337
}
345
338
346
339
return (query [offset ] | 32 ) == 'a'
347
340
&& (query [offset + 1 ] | 32 ) == 'l'
348
341
&& (query [offset + 2 ] | 32 ) == 't'
349
342
&& (query [offset + 3 ] | 32 ) == 'e'
350
- && (query [offset + 4 ] | 32 ) == 'r'
351
- && isSpace (query [offset + 5 ]);
343
+ && (query [offset + 4 ] | 32 ) == 'r' ;
352
344
}
353
345
354
346
private static boolean parseCreateKeyword (char [] query , int offset ) {
0 commit comments