Skip to content

Commit

Permalink
Merge pull request #174 from YaroslavMolchan/3.x
Browse files Browse the repository at this point in the history
Fix bug with null value.
  • Loading branch information
pmjones committed Jun 7, 2018
2 parents 82ecb90 + 0a8beed commit dc31f3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Parser/AbstractParser.php
Expand Up @@ -210,7 +210,11 @@ protected function prepareNumberedPlaceholder($sub)
}

$expanded = [];
foreach ((array) $this->values[$this->num] as $value) {
$values = (array) $this->values[$this->num];
if (is_null($this->values[$this->num])) {
$values[] = null;
}
foreach ($values as $value) {
$count = ++ $this->count['__'];
$name = "__{$count}";
$expanded[] = ":{$name}";
Expand Down
8 changes: 4 additions & 4 deletions tests/Parser/AbstractParserTest.php
Expand Up @@ -24,11 +24,11 @@ public function testReplaceMultipleUsesOfNamedParameter()

public function testReplaceNumberedParameter()
{
$parameters = ['bar', 'baz'];
$sql = "SELECT ? AS a, ? AS b";
$parameters = ['bar', 'baz', null];
$sql = "SELECT ? AS a, ? AS b FROM table WHERE id = ?";
list ($statement, $values) = $this->rebuild($sql, $parameters);
$expectedStatement = "SELECT :__1 AS a, :__2 AS b";
$expectedValues = ['__1' => 'bar', '__2' => 'baz'];
$expectedStatement = "SELECT :__1 AS a, :__2 AS b FROM table WHERE id = :__3";
$expectedValues = ['__1' => 'bar', '__2' => 'baz', '__3' => null];
$this->assertEquals($expectedStatement, $statement);
$this->assertEquals($expectedValues, $values);
}
Expand Down

0 comments on commit dc31f3b

Please sign in to comment.