FriendsOfDoctrine / dbal-clickhouse

Doctrine DBAL driver for ClickHouse database
GNU General Public License v3.0
98 stars 80 forks source link

BUG Question mark in value still misbehavior #22

Open karakum opened 5 years ago

karakum commented 5 years ago

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?

n00bik commented 5 years ago

I have the same error, when try to insert "?" into string column

$conn->insert($tbl, [ 'subsite' => '?' ] );

dbaida commented 4 years ago

Got similar issue.