Skip to content

Commit 4154548

Browse files
authored
Fix "Query expects 9223372036854775807-0 placeholders, but no values are given." (#629)
1 parent 70a0fe7 commit 4154548

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/QueryReflection/PlaceholderValidation.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public function checkQuery(Expr $queryExpr, Scope $scope, array $parameters): it
4646
}
4747
}
4848

49+
if ($minPlaceholderCount === PHP_INT_MAX) {
50+
$minPlaceholderCount = 0;
51+
}
52+
4953
yield from $this->validateUnnamedPlaceholders($parameters, $minPlaceholderCount, $maxPlaceholderCount);
5054
}
5155

tests/rules/PdoStatementExecuteMethodRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ public function testPlaceholderBug(): void
125125
'Query expects 2-3 placeholders, but 1-3 values are given.',
126126
42,
127127
],
128+
[
129+
'Query expects 2 placeholders, but no values are given.',
130+
48,
131+
],
128132
]);
129133
}
130134
}

tests/rules/data/placeholder-bug.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@ public function sometimesWrongNumberOfParameters(PDO $pdo, $vkFrom)
4141
$stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? OR adaid = ? ' . $fromCondition);
4242
$stmt->execute($values);
4343
}
44+
45+
public function wrongMinBound(PDO $pdo)
46+
{
47+
$stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? OR adaid = ? ');
48+
$stmt->execute([]);
49+
}
4450
}

0 commit comments

Comments
 (0)