From 57634d09645368295ddb4667dabd4b54b30a1e08 Mon Sep 17 00:00:00 2001 From: Usman Ikram Date: Sun, 29 Mar 2020 21:50:24 +0200 Subject: [PATCH 1/3] Fix ? bind with := bind --- system/Database/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Database/Query.php b/system/Database/Query.php index 650a7da93193..dae2eeb11849 100644 --- a/system/Database/Query.php +++ b/system/Database/Query.php @@ -368,7 +368,7 @@ protected function compileBinds() { $sql = $this->finalQueryString; - $hasNamedBinds = strpos($sql, ':') !== false; + $hasNamedBinds = strpos($sql, ':') !== false && strpos($sql, ':=') === false; if (empty($this->binds) || empty($this->bindMarker) || (strpos($sql, $this->bindMarker) === false && From 9302744d70e532ac2330ec57e789c457448e7ae6 Mon Sep 17 00:00:00 2001 From: Usman Ikram Date: Sun, 29 Mar 2020 21:52:33 +0200 Subject: [PATCH 2/3] Add a unit test --- tests/system/Database/BaseQueryTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/system/Database/BaseQueryTest.php b/tests/system/Database/BaseQueryTest.php index 7a92467c3618..738979b0e5d2 100644 --- a/tests/system/Database/BaseQueryTest.php +++ b/tests/system/Database/BaseQueryTest.php @@ -316,4 +316,23 @@ public function testSetQueryBindsWithSetEscapeFalse() $this->assertEquals($expected, $query->getQuery()); } + + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/2762 + */ + public function testSetQueryBindsWithSetEscapeFalse2() + { + $query = new Query($this->db); + + $binds = [ + 1, + 2, + ]; + + $query->setQuery('SELECT @factorA := ?, @factorB := ?', $binds); + + $expected = 'SELECT @factorA := 1, @factorB := 2'; + + $this->assertEquals($expected, $query->getQuery()); + } } From d7a47da0efb0187641a960816c094e28d8b036b0 Mon Sep 17 00:00:00 2001 From: Usman Ikram Date: Sun, 29 Mar 2020 22:43:47 +0200 Subject: [PATCH 3/3] Changed test name --- tests/system/Database/BaseQueryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Database/BaseQueryTest.php b/tests/system/Database/BaseQueryTest.php index 738979b0e5d2..4e09d49ccc24 100644 --- a/tests/system/Database/BaseQueryTest.php +++ b/tests/system/Database/BaseQueryTest.php @@ -320,7 +320,7 @@ public function testSetQueryBindsWithSetEscapeFalse() /** * @see https://github.com/codeigniter4/CodeIgniter4/issues/2762 */ - public function testSetQueryBindsWithSetEscapeFalse2() + public function testSetQueryBinds() { $query = new Query($this->db);