Skip to content
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 Question mark in value still misbehavior #22

Open
karakum opened this issue Jan 16, 2019 · 2 comments
Open

BUG Question mark in value still misbehavior #22

karakum opened this issue Jan 16, 2019 · 2 comments

Comments

@karakum
Copy link

karakum commented Jan 16, 2019

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
Copy link

n00bik commented Mar 26, 2019

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

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

@dbaida
Copy link

dbaida commented Jul 23, 2020

Got similar issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants