Skip to content

Commit

Permalink
Correctly generate IN clause placeholders.
Browse files Browse the repository at this point in the history
This fixes logged queries not having placeholders replaced for IN clause
placeholders.

Refs cakephp/debug_kit#445
  • Loading branch information
markstory committed Nov 25, 2016
1 parent a744f91 commit 3099d41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Database/ValueBinder.php
Expand Up @@ -90,7 +90,7 @@ public function generateManyNamed($values, $type = 'string')
$this->_bindings[$param] = [
'value' => $value,
'type' => $type,
'placeholder' => $param
'placeholder' => substr($param, 1),
];
$placeholders[$k] = $param;
$this->_bindingsCount++;
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Database/Log/QueryLoggerTest.php
Expand Up @@ -72,7 +72,7 @@ public function testStringInterpolation()
*
* @return void
*/
public function testStringInterpolation2()
public function testStringInterpolationNotNamed()
{
$logger = $this->getMockBuilder('\Cake\Database\Log\QueryLogger')
->setMethods(['_log'])
Expand All @@ -92,7 +92,7 @@ public function testStringInterpolation2()
*
* @return void
*/
public function testStringInterpolation3()
public function testStringInterpolationDuplicate()
{
$logger = $this->getMockBuilder('\Cake\Database\Log\QueryLogger')
->setMethods(['_log'])
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/Database/QueryTest.php
Expand Up @@ -1367,6 +1367,26 @@ public function testInValueCast2()
$result->closeCursor();
}

/**
* Tests that IN clauses generate correct placeholders
*
* @return void
*/
public function testInClausePlaceholderGeneration()
{
$this->loadFixtures('Comments');
$query = new Query($this->connection);
$query->select(['id'])
->from('comments')
->where(['id IN' => [1, 2]])
->sql();
$bindings = $query->valueBinder()->bindings();
$this->assertArrayHasKey(':c0', $bindings);
$this->assertEquals('c0', $bindings[':c0']['placeholder']);
$this->assertArrayHasKey(':c1', $bindings);
$this->assertEquals('c1', $bindings[':c1']['placeholder']);
}

/**
* Tests where() with callable types.
*
Expand Down

0 comments on commit 3099d41

Please sign in to comment.