Skip to content

BUG Question mark in value still misbehavior #22

@karakum

Description

@karakum

Although #11 has closed, there are still bugs present.

There is simple test from repo, just some modified tests/InsertTest.php - copy method testInsertViaQueryBuilder() and change order of calling setValue/setParameter:

    public function testInsertViaQueryBuilder2()
    {
        $qb = $this->connection->createQueryBuilder();

        $qb
            ->insert('test_insert_table')
            ->setValue('payload', ':payload')
            ->setValue('id', ':id')
            ->setParameter('payload', 'Is this string a question?')
            ->setParameter('id', 11, \PDO::PARAM_INT)
            ->execute();

        $this->assertEquals([
            [
                'payload' => 'Is this string a question?',
                'id' => 11,
            ],
        ], $this->connection->fetchAll("SELECT payload, id from test_insert_table ORDER BY id"));
    }

assertEquals also modified.

Test results:

There was 1 failure:

1) FOD\DBALClickHouse\Tests\InsertTest::testInsertViaQueryBuilder2
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => Array (
-        'payload' => 'Is this string a question?'
-        'id' => 11
+        'payload' => 'Is this string a question11'
+        'id' => 15
     )
 )

It happened because there are consecutive replacement of question mark in query 4b7dbe2:

            foreach (array_keys($this->values) as $key) {
                $sql = preg_replace(
                    '/(' . (is_int($key) ? '\?' : ':' . $key) . ')/i',
                    $this->getTypedParam($key),
                    $sql,
                    1
                );
            }

and question mark in string value replaced with next parameter value.
Real SQL executed:

INSERT INTO test_insert_table (payload, id) VALUES('Is this string a question11', ?)

Seriously, guys?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions