-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: [Postgres] Can't use $builder->replace() multiple times in a method #6726
Comments
Why can't? What exactly happened? |
I get
|
I've confirmed this bug on PostgreSQL:
--- a/tests/system/Database/Live/InsertTest.php
+++ b/tests/system/Database/Live/InsertTest.php
@@ -92,6 +92,35 @@ final class InsertTest extends CIUnitTestCase
$this->assertSame('Cab Driver', $row->name);
}
+ 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\\'"; |
@nalakapws Workaround: $this->db->table('records')->replace($rows[0]);
$this->db->table('records')->replace($rows[1]); |
Thanks, @kenjis appreciate it! |
@codeigniter4/database-team If someone who are using Postgres, please check this and send a PR if you please. --- a/system/Database/Postgre/Builder.php
+++ b/system/Database/Postgre/Builder.php
@@ -179,6 +179,7 @@ class Builder extends BaseBuilder
unset($builder);
$this->resetWrite();
+ $this->binds = [];
return $result;
} |
PHP Version
8.1
CodeIgniter4 Version
4.2.6
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
PostgreSQL
What happened?
Can't use
$builder->replace();
statement multiple times in a method. I don't know if that is by design. But in CI3 we can use replace statement multiple times, like in a loop.Thanks.
Steps to Reproduce
Just kind of this type method,
Expected Output
Replace multiple records at once.
Anything else?
No response
The text was updated successfully, but these errors were encountered: