diff --git a/src/Database/ValueBinder.php b/src/Database/ValueBinder.php index bf8816ef126..b2ac40eb85c 100644 --- a/src/Database/ValueBinder.php +++ b/src/Database/ValueBinder.php @@ -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++; diff --git a/tests/TestCase/Database/Log/QueryLoggerTest.php b/tests/TestCase/Database/Log/QueryLoggerTest.php index f66e8a0ddca..217401dc13f 100644 --- a/tests/TestCase/Database/Log/QueryLoggerTest.php +++ b/tests/TestCase/Database/Log/QueryLoggerTest.php @@ -72,7 +72,7 @@ public function testStringInterpolation() * * @return void */ - public function testStringInterpolation2() + public function testStringInterpolationNotNamed() { $logger = $this->getMockBuilder('\Cake\Database\Log\QueryLogger') ->setMethods(['_log']) @@ -92,7 +92,7 @@ public function testStringInterpolation2() * * @return void */ - public function testStringInterpolation3() + public function testStringInterpolationDuplicate() { $logger = $this->getMockBuilder('\Cake\Database\Log\QueryLogger') ->setMethods(['_log']) diff --git a/tests/TestCase/Database/QueryTest.php b/tests/TestCase/Database/QueryTest.php index 058e05a1e6c..4050439acee 100644 --- a/tests/TestCase/Database/QueryTest.php +++ b/tests/TestCase/Database/QueryTest.php @@ -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. *