Skip to content

Commit

Permalink
fix: [Postgres] reset binds when replace() method is called multiple …
Browse files Browse the repository at this point in the history
…times in the context (#6728)

* fix: reset binds when replace() method is called multiple times in the context with Postgre driver
* add a reference to the issue in the test [ci skip]
  • Loading branch information
michalsn authored Oct 22, 2022
1 parent a3d3d9c commit 9cbf480
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions system/Database/Postgre/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function replace(?array $set = null)

unset($builder);
$this->resetWrite();
$this->binds = [];

return $result;
}
Expand Down
32 changes: 32 additions & 0 deletions tests/system/Database/Live/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,38 @@ public function testReplaceWithMatchingData()
$this->assertSame('Cab Driver', $row->name);
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/6726
*/
public function testReplaceTwice()
{
$builder = $this->db->table('job');

$data = [
'id' => 1,
'name' => 'John Smith',
'description' => 'American',
];
$builder->replace($data);

$row = $this->db->table('job')
->getwhere(['id' => 1])
->getRow();
$this->assertSame('John Smith', $row->name);

$data = [
'id' => 2,
'name' => 'Hans Schmidt',
'description' => 'German',
];
$builder->replace($data);

$row = $this->db->table('job')
->getwhere(['id' => 2])
->getRow();
$this->assertSame('Hans Schmidt', $row->name);
}

public function testBug302()
{
$code = "my code \\'CodeIgniter\\Autoloader\\'";
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.2.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ Bugs Fixed
**********

- Fixed a bug when the ``CodeIgniter\HTTP\IncomingRequest::getPostGet()`` and ``CodeIgniter\HTTP\IncomingRequest::getGetPost()`` methods didn't return values from the other stream when ``index`` was set to ``null``.
- Fixed a bug when ``binds`` weren't cleaned properly when calling ``CodeIgniter\Database\Postgre::replace()`` multiple times in the context.

See the repo's `CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_ for a complete list of bugs fixed.

0 comments on commit 9cbf480

Please sign in to comment.