Skip to content

Commit 9cbf480

Browse files
authored
fix: [Postgres] reset binds when replace() method is called multiple 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]
1 parent a3d3d9c commit 9cbf480

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

system/Database/Postgre/Builder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public function replace(?array $set = null)
179179

180180
unset($builder);
181181
$this->resetWrite();
182+
$this->binds = [];
182183

183184
return $result;
184185
}

tests/system/Database/Live/InsertTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,38 @@ public function testReplaceWithMatchingData()
9292
$this->assertSame('Cab Driver', $row->name);
9393
}
9494

95+
/**
96+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/6726
97+
*/
98+
public function testReplaceTwice()
99+
{
100+
$builder = $this->db->table('job');
101+
102+
$data = [
103+
'id' => 1,
104+
'name' => 'John Smith',
105+
'description' => 'American',
106+
];
107+
$builder->replace($data);
108+
109+
$row = $this->db->table('job')
110+
->getwhere(['id' => 1])
111+
->getRow();
112+
$this->assertSame('John Smith', $row->name);
113+
114+
$data = [
115+
'id' => 2,
116+
'name' => 'Hans Schmidt',
117+
'description' => 'German',
118+
];
119+
$builder->replace($data);
120+
121+
$row = $this->db->table('job')
122+
->getwhere(['id' => 2])
123+
->getRow();
124+
$this->assertSame('Hans Schmidt', $row->name);
125+
}
126+
95127
public function testBug302()
96128
{
97129
$code = "my code \\'CodeIgniter\\Autoloader\\'";

user_guide_src/source/changelogs/v4.2.8.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ Bugs Fixed
3737
**********
3838

3939
- 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``.
40+
- Fixed a bug when ``binds`` weren't cleaned properly when calling ``CodeIgniter\Database\Postgre::replace()`` multiple times in the context.
4041

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

0 commit comments

Comments
 (0)