Skip to content

Commit

Permalink
Merge pull request #2773 from musmanikram/2762-fix-questionmark-bind
Browse files Browse the repository at this point in the history
Fix ? bind with := bind
  • Loading branch information
MGatner authored Mar 31, 2020
2 parents 2a40c22 + d7a47da commit b67f186
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
19 changes: 19 additions & 0 deletions tests/system/Database/BaseQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,23 @@ public function testSetQueryBindsWithSetEscapeFalse()

$this->assertEquals($expected, $query->getQuery());
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/2762
*/
public function testSetQueryBinds()
{
$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());
}
}

0 comments on commit b67f186

Please sign in to comment.