Skip to content

Commit ff4eac0

Browse files
hembergerstaabm
andauthored
Allow placeholder validation for write queries (staabm#506)
Co-authored-by: Markus Staab <[email protected]>
1 parent bc1127e commit ff4eac0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/QueryReflection/PlaceholderValidation.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ public function checkQuery(Expr $queryExpr, Scope $scope, array $parameters): it
3232
*/
3333
private function checkErrors(string $queryString, array $parameters): iterable
3434
{
35-
if ('SELECT' !== QueryReflection::getQueryType($queryString)) {
36-
return;
37-
}
38-
3935
$queryReflection = new QueryReflection();
4036
if ($queryReflection->containsNamedPlaceholders($queryString, $parameters)) {
4137
yield from $this->validateNamedPlaceholders($queryString, $parameters);

tests/rules/SyntaxErrorInPreparedStatementMethodRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public function testSyntaxErrorInQueryRule(): void
8282
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'gesperrt freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",
8383
319,
8484
],
85+
[
86+
'Query expects placeholder :freigabe1u1, but it is missing from values given.',
87+
325,
88+
],
8589
];
8690
} elseif (PdoPgSqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
8791
$expectedErrors = [
@@ -157,6 +161,10 @@ public function testSyntaxErrorInQueryRule(): void
157161
^ (42601).',
158162
319,
159163
],
164+
[
165+
'Query expects placeholder :freigabe1u1, but it is missing from values given.',
166+
325,
167+
],
160168
];
161169
} elseif (PdoMysqlQueryReflector::NAME === getenv('DBA_REFLECTOR')) {
162170
$expectedErrors = [
@@ -208,6 +216,10 @@ public function testSyntaxErrorInQueryRule(): void
208216
"Query error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'gesperrt freigabe1u1 FROM ada LIMIT 0' at line 1 (42000).",
209217
319,
210218
],
219+
[
220+
'Query expects placeholder :freigabe1u1, but it is missing from values given.',
221+
325,
222+
],
211223
];
212224
} else {
213225
throw new \RuntimeException('Unsupported DBA_REFLECTOR '.getenv('DBA_REFLECTOR'));

0 commit comments

Comments
 (0)