Skip to content

Commit 32cd6d0

Browse files
committed
Fix query flags for lower-case functions
Signed-off-by: Maximilian Krög <[email protected]>
1 parent f136374 commit 32cd6d0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Utils/Query.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use function count;
3737
use function in_array;
3838
use function is_string;
39+
use function strtoupper;
3940
use function trim;
4041

4142
/**
@@ -317,9 +318,10 @@ private static function getFlagsSelect($statement, $flags)
317318

318319
foreach ($expressions as $expr) {
319320
if (! empty($expr->function)) {
320-
if ($expr->function === 'COUNT') {
321+
$function = strtoupper($expr->function);
322+
if ($function === 'COUNT') {
321323
$flags['is_count'] = true;
322-
} elseif (in_array($expr->function, static::$FUNCTIONS)) {
324+
} elseif (in_array($function, static::$FUNCTIONS, true)) {
323325
$flags['is_func'] = true;
324326
}
325327
}

tests/Utils/QueryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,24 @@ public function getFlagsProvider(): array
181181
'querytype' => 'SELECT',
182182
],
183183
],
184+
[
185+
'SELECT count(*) FROM tbl',
186+
[
187+
'is_count' => true,
188+
'is_select' => true,
189+
'select_from' => true,
190+
'querytype' => 'SELECT',
191+
],
192+
],
193+
[
194+
'SELECT sum(*) FROM tbl',
195+
[
196+
'is_func' => true,
197+
'is_select' => true,
198+
'select_from' => true,
199+
'querytype' => 'SELECT',
200+
],
201+
],
184202
[
185203
'SELECT (SELECT "foo")',
186204
[

0 commit comments

Comments
 (0)