Skip to content

Commit

Permalink
Fix "Query expects 9223372036854775807-0 placeholders, but no values …
Browse files Browse the repository at this point in the history
…are given." (#629)
  • Loading branch information
staabm committed Sep 29, 2023
1 parent 70a0fe7 commit 4154548
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/QueryReflection/PlaceholderValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function checkQuery(Expr $queryExpr, Scope $scope, array $parameters): it
}
}

if ($minPlaceholderCount === PHP_INT_MAX) {
$minPlaceholderCount = 0;
}

yield from $this->validateUnnamedPlaceholders($parameters, $minPlaceholderCount, $maxPlaceholderCount);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/rules/PdoStatementExecuteMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public function testPlaceholderBug(): void
'Query expects 2-3 placeholders, but 1-3 values are given.',
42,
],
[
'Query expects 2 placeholders, but no values are given.',
48,
],
]);
}
}
6 changes: 6 additions & 0 deletions tests/rules/data/placeholder-bug.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ public function sometimesWrongNumberOfParameters(PDO $pdo, $vkFrom)
$stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? OR adaid = ? ' . $fromCondition);
$stmt->execute($values);
}

public function wrongMinBound(PDO $pdo)
{
$stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? OR adaid = ? ');
$stmt->execute([]);
}
}

0 comments on commit 4154548

Please sign in to comment.