@@ -63,13 +63,13 @@ WHITESPACE = [ \t\r\n]+
63
63
}
64
64
65
65
/* * @return text matched by current token without enclosing double quotes or backticks */
66
- private String readTableName () {
67
- String tableName = yytext();
68
- if (tableName != null && ((tableName . startsWith(" \" " ) && tableName . endsWith(" \" " ))
69
- || (tableName . startsWith(" `" ) && tableName . endsWith(" `" )))) {
70
- tableName = tableName . substring(1 , tableName . length() - 1 );
66
+ private String readIdentifierName () {
67
+ String IdentifierName = yytext();
68
+ if (IdentifierName != null && ((IdentifierName . startsWith(" \" " ) && IdentifierName . endsWith(" \" " ))
69
+ || (IdentifierName . startsWith(" `" ) && IdentifierName . endsWith(" `" )))) {
70
+ IdentifierName = IdentifierName . substring(1 , IdentifierName . length() - 1 );
71
71
}
72
- return tableName ;
72
+ return IdentifierName ;
73
73
}
74
74
75
75
// you can reference a table in the FROM clause in one of the following ways:
@@ -92,7 +92,7 @@ WHITESPACE = [ \t\r\n]+
92
92
}
93
93
94
94
private static abstract class Operation {
95
- String mainTable = null ;
95
+ String mainIdentifier = null ;
96
96
97
97
/* * @return true if all statement info is gathered */
98
98
boolean handleFrom () {
@@ -119,8 +119,13 @@ WHITESPACE = [ \t\r\n]+
119
119
return false ;
120
120
}
121
121
122
+ /* * @return true if all statement info is gathered */
123
+ boolean handleNext () {
124
+ return false ;
125
+ }
126
+
122
127
SqlStatementInfo getResult (String fullStatement ) {
123
- return SqlStatementInfo . create(fullStatement, getClass(). getSimpleName(). toUpperCase(java.util. Locale . ROOT ), mainTable );
128
+ return SqlStatementInfo . create(fullStatement, getClass(). getSimpleName(). toUpperCase(java.util. Locale . ROOT ), mainIdentifier );
124
129
}
125
130
}
126
131
@@ -152,13 +157,13 @@ WHITESPACE = [ \t\r\n]+
152
157
}
153
158
154
159
// subquery in WITH or SELECT clause, before main FROM clause; skipping
155
- mainTable = null ;
160
+ mainIdentifier = null ;
156
161
return true ;
157
162
}
158
163
159
164
boolean handleJoin () {
160
165
// for SELECT statements with joined tables there's no main table
161
- mainTable = null ;
166
+ mainIdentifier = null ;
162
167
return true ;
163
168
}
164
169
@@ -173,17 +178,17 @@ WHITESPACE = [ \t\r\n]+
173
178
174
179
// SELECT FROM (subquery) case
175
180
if (parenLevel != 0 ) {
176
- mainTable = null ;
181
+ mainIdentifier = null ;
177
182
return true ;
178
183
}
179
184
180
185
// whenever >1 table is used there is no main table (e.g. unions)
181
186
if (mainTableSetAlready) {
182
- mainTable = null ;
187
+ mainIdentifier = null ;
183
188
return true ;
184
189
}
185
190
186
- mainTable = readTableName ();
191
+ mainIdentifier = readIdentifierName ();
187
192
mainTableSetAlready = true ;
188
193
expectingTableName = false ;
189
194
// start counting identifiers after encountering main from clause
@@ -199,7 +204,7 @@ WHITESPACE = [ \t\r\n]+
199
204
// any other list that can appear later needs at least 4 idents)
200
205
if (identifiersAfterMainFromClause > 0
201
206
&& identifiersAfterMainFromClause <= FROM_TABLE_REF_MAX_IDENTIFIERS ) {
202
- mainTable = null ;
207
+ mainIdentifier = null ;
203
208
return true ;
204
209
}
205
210
return false ;
@@ -219,7 +224,7 @@ WHITESPACE = [ \t\r\n]+
219
224
return false ;
220
225
}
221
226
222
- mainTable = readTableName ();
227
+ mainIdentifier = readIdentifierName ();
223
228
return true ;
224
229
}
225
230
}
@@ -237,21 +242,33 @@ WHITESPACE = [ \t\r\n]+
237
242
return false ;
238
243
}
239
244
240
- mainTable = readTableName ();
245
+ mainIdentifier = readIdentifierName ();
241
246
return true ;
242
247
}
243
248
}
244
249
245
250
private class Update extends Operation {
246
251
boolean handleIdentifier () {
247
- mainTable = readTableName();
252
+ mainIdentifier = readIdentifierName();
253
+ return true ;
254
+ }
255
+ }
256
+
257
+ private class Call extends Operation {
258
+ boolean handleIdentifier () {
259
+ mainIdentifier = readIdentifierName();
260
+ return true ;
261
+ }
262
+
263
+ boolean handleNext () {
264
+ mainIdentifier = null ;
248
265
return true ;
249
266
}
250
267
}
251
268
252
269
private class Merge extends Operation {
253
270
boolean handleIdentifier () {
254
- mainTable = readTableName ();
271
+ mainIdentifier = readIdentifierName ();
255
272
return true ;
256
273
}
257
274
}
@@ -298,14 +315,21 @@ WHITESPACE = [ \t\r\n]+
298
315
appendCurrentFragment();
299
316
if (isOverLimit()) return YYEOF ;
300
317
}
318
+ "CALL" {
319
+ if (! insideComment) {
320
+ setOperation(new Call ());
321
+ }
322
+ operation. handleIdentifier();
323
+ appendCurrentFragment();
324
+ if (isOverLimit()) return YYEOF ;
325
+ }
301
326
"MERGE" {
302
327
if (! insideComment) {
303
328
setOperation(new Merge ());
304
329
}
305
330
appendCurrentFragment();
306
331
if (isOverLimit()) return YYEOF ;
307
332
}
308
-
309
333
"FROM" {
310
334
if (! insideComment && ! extractionDone) {
311
335
if (operation == NoOp . INSTANCE ) {
@@ -332,6 +356,13 @@ WHITESPACE = [ \t\r\n]+
332
356
appendCurrentFragment();
333
357
if (isOverLimit()) return YYEOF ;
334
358
}
359
+ "NEXT" {
360
+ if (! insideComment && ! extractionDone) {
361
+ extractionDone = operation. handleNext();
362
+ }
363
+ appendCurrentFragment();
364
+ if (isOverLimit()) return YYEOF ;
365
+ }
335
366
{COMMA} {
336
367
if (! insideComment && ! extractionDone) {
337
368
extractionDone = operation. handleComma();
@@ -407,4 +438,4 @@ WHITESPACE = [ \t\r\n]+
407
438
appendCurrentFragment();
408
439
if (isOverLimit()) return YYEOF ;
409
440
}
410
- }
441
+ }
0 commit comments