Skip to content

Commit 60865d5

Browse files
staabmclxmstaab
andauthored
detect syntax error in conditional union (#128)
Co-authored-by: Markus Staab <[email protected]>
1 parent be7c18b commit 60865d5

File tree

4 files changed

+34
-124
lines changed

4 files changed

+34
-124
lines changed

.phpstan-dba.cache

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.phpunit-phpstan-dba.cache

Lines changed: 8 additions & 124 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/SyntaxErrorInQueryMethodRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function testSyntaxErrorInQueryRule(): void
6565
"Query error: Unknown column 'asdsa' in 'where clause' (1054).",
6666
103,
6767
],
68+
[
69+
"Query error: Unknown column 'xy' in 'group statement' (1054).",
70+
118,
71+
],
6872
]);
6973
}
7074
}

tests/data/syntax-error-in-query-method.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,14 @@ public function validPrepare(PDO $pdo)
107107
{
108108
$pdo->prepare('SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid=?');
109109
}
110+
111+
public function conditionalSyntaxErrorInQueryUnion(PDO $pdo)
112+
{
113+
$add = "WHERE email='my_other_table'";
114+
if (rand(0, 1)) {
115+
$add = 'GROUP BY xy';
116+
}
117+
118+
$pdo->query('SELECT email, adaid FROM ada '.$add.' LIMIT 1', PDO::FETCH_ASSOC);
119+
}
110120
}

0 commit comments

Comments
 (0)