Skip to content

Commit

Permalink
SqlPreprocessor: workaround for PDO bug #74996 when looking for ? i…
Browse files Browse the repository at this point in the history
…n prepared query [Closes #177]
  • Loading branch information
dg committed Jul 27, 2017
1 parent e04eb88 commit 9b16e3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Database/SqlPreprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function formatValue($value, $mode = null)
{
if (!$mode || $mode === 'auto') {
if (is_string($value)) {
if (strlen($value) > 20) {
if (strlen($value) > 20 || strpos($value, '\\') !== false) {
$this->remaining[] = $value;
return '?';

Expand Down
4 changes: 4 additions & 0 deletions tests/Database/SqlPreprocessor.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ test(function () use ($preprocessor) { // arg without placeholder
list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id =', '11']);
Assert::same("SELECT id FROM author WHERE id = '11'", $sql);
Assert::same([], $params);

list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id =', '1\\1']);
Assert::same('SELECT id FROM author WHERE id = ?', $sql);
Assert::same(['1\\1'], $params);
});


Expand Down

0 comments on commit 9b16e3e

Please sign in to comment.