@@ -205,6 +205,81 @@ class Query
205
205
'union ' => false ,
206
206
);
207
207
208
+ /**
209
+ * Gets an array with flags select statement has.
210
+ *
211
+ * @param Statement|null $statement the statement to be processed
212
+ * @param array $flagsi flags set so far
213
+ *
214
+ * @return array
215
+ */
216
+ private static function _getFlagsSelect ($ statement , $ flags )
217
+ {
218
+ $ flags ['querytype ' ] = 'SELECT ' ;
219
+ $ flags ['is_select ' ] = true ;
220
+
221
+ if (!empty ($ statement ->from )) {
222
+ $ flags ['select_from ' ] = true ;
223
+ }
224
+
225
+ if ($ statement ->options ->has ('DISTINCT ' )) {
226
+ $ flags ['distinct ' ] = true ;
227
+ }
228
+
229
+ if ((!empty ($ statement ->group )) || (!empty ($ statement ->having ))) {
230
+ $ flags ['is_group ' ] = true ;
231
+ }
232
+
233
+ if ((!empty ($ statement ->into ))
234
+ && ($ statement ->into ->type === 'OUTFILE ' )
235
+ ) {
236
+ $ flags ['is_export ' ] = true ;
237
+ }
238
+
239
+ $ expressions = $ statement ->expr ;
240
+ if (!empty ($ statement ->join )) {
241
+ foreach ($ statement ->join as $ join ) {
242
+ $ expressions [] = $ join ->expr ;
243
+ }
244
+ }
245
+
246
+ foreach ($ expressions as $ expr ) {
247
+ if (!empty ($ expr ->function )) {
248
+ if ($ expr ->function === 'COUNT ' ) {
249
+ $ flags ['is_count ' ] = true ;
250
+ } elseif (in_array ($ expr ->function , static ::$ FUNCTIONS )) {
251
+ $ flags ['is_func ' ] = true ;
252
+ }
253
+ }
254
+ if (!empty ($ expr ->subquery )) {
255
+ $ flags ['is_subquery ' ] = true ;
256
+ }
257
+ }
258
+
259
+ if ((!empty ($ statement ->procedure ))
260
+ && ($ statement ->procedure ->name === 'ANALYSE ' )
261
+ ) {
262
+ $ flags ['is_analyse ' ] = true ;
263
+ }
264
+
265
+ if (!empty ($ statement ->group )) {
266
+ $ flags ['group ' ] = true ;
267
+ }
268
+
269
+ if (!empty ($ statement ->having )) {
270
+ $ flags ['having ' ] = true ;
271
+ }
272
+
273
+ if (!empty ($ statement ->union )) {
274
+ $ flags ['union ' ] = true ;
275
+ }
276
+
277
+ if (!empty ($ statement ->join )) {
278
+ $ flags ['join ' ] = true ;
279
+ }
280
+ return $ flags ;
281
+ }
282
+
208
283
/**
209
284
* Gets an array with flags this statement has.
210
285
*
@@ -270,68 +345,7 @@ public static function getFlags($statement, $all = false)
270
345
$ flags ['is_replace ' ] = true ;
271
346
$ flags ['is_insert ' ] = true ;
272
347
} elseif ($ statement instanceof SelectStatement) {
273
- $ flags ['querytype ' ] = 'SELECT ' ;
274
- $ flags ['is_select ' ] = true ;
275
-
276
- if (!empty ($ statement ->from )) {
277
- $ flags ['select_from ' ] = true ;
278
- }
279
-
280
- if ($ statement ->options ->has ('DISTINCT ' )) {
281
- $ flags ['distinct ' ] = true ;
282
- }
283
-
284
- if ((!empty ($ statement ->group )) || (!empty ($ statement ->having ))) {
285
- $ flags ['is_group ' ] = true ;
286
- }
287
-
288
- if ((!empty ($ statement ->into ))
289
- && ($ statement ->into ->type === 'OUTFILE ' )
290
- ) {
291
- $ flags ['is_export ' ] = true ;
292
- }
293
-
294
- $ expressions = $ statement ->expr ;
295
- if (!empty ($ statement ->join )) {
296
- foreach ($ statement ->join as $ join ) {
297
- $ expressions [] = $ join ->expr ;
298
- }
299
- }
300
-
301
- foreach ($ expressions as $ expr ) {
302
- if (!empty ($ expr ->function )) {
303
- if ($ expr ->function === 'COUNT ' ) {
304
- $ flags ['is_count ' ] = true ;
305
- } elseif (in_array ($ expr ->function , static ::$ FUNCTIONS )) {
306
- $ flags ['is_func ' ] = true ;
307
- }
308
- }
309
- if (!empty ($ expr ->subquery )) {
310
- $ flags ['is_subquery ' ] = true ;
311
- }
312
- }
313
-
314
- if ((!empty ($ statement ->procedure ))
315
- && ($ statement ->procedure ->name === 'ANALYSE ' )
316
- ) {
317
- $ flags ['is_analyse ' ] = true ;
318
- }
319
-
320
- if (!empty ($ statement ->group )) {
321
- $ flags ['group ' ] = true ;
322
- }
323
-
324
- if (!empty ($ statement ->having )) {
325
- $ flags ['having ' ] = true ;
326
- }
327
-
328
- if (!empty ($ statement ->union )) {
329
- $ flags ['union ' ] = true ;
330
- }
331
-
332
- if (!empty ($ statement ->join )) {
333
- $ flags ['join ' ] = true ;
334
- }
348
+ $ flags = self ::_getFlagsSelect ($ statement , $ flags );
335
349
} elseif ($ statement instanceof ShowStatement) {
336
350
$ flags ['querytype ' ] = 'SHOW ' ;
337
351
$ flags ['is_show ' ] = true ;
0 commit comments