Skip to content

Dev: upsert()/setData() and binds #6688

@kenjis

Description

@kenjis

See #6600 (comment)

The following test (MySQL) fails now. Should upsert() also use binds?

    public function testUpsertArrayAndCheckBinds()
    {
        $builder  = $this->db->table('user');
        $userData = [
            'email'   => '[email protected]',
            'name'    => 'Upsert One',
            'country' => 'US',
        ];
        $builder->testMode()->set($userData);

        $expectedSQL = <<<'SQL'
            INSERT INTO `db_user` (`country`, `email`, `name`) VALUES ('US','[email protected]','Upsert One') ON DUPLICATE KEY UPDATE `db_user`.`country` = VALUES(`country`), `db_user`.`email` = VALUES(`email`), `db_user`.`name` = VALUES(`name`)
            SQL;
        $this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledUpsert()));

        $expectedBinds = [
            'email' => [
                '[email protected]',
                true,
            ],
            'name' => [
                'Upsert One',
                true,
            ],
            'country' => [
                'US',
                true,
            ],
        ];
        $this->assertSame($expectedBinds, $builder->getBinds());
    }
1) CodeIgniter\Database\Live\UpsertTest::testUpsertArrayAndCheckBinds
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
-Array &0 (
-    'email' => Array &1 (
-        0 => '[email protected]'
-        1 => true
-    )
-    'name' => Array &2 (
-        0 => 'Upsert One'
-        1 => true
-    )
-    'country' => Array &3 (
-        0 => 'US'
-        1 => true
-    )
-)
+Array &0 ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    databaseIssues or pull requests that affect the database layer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions