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

Symbol ? in query's value #37

Open
roma293 opened this issue May 14, 2020 · 1 comment
Open

Symbol ? in query's value #37

roma293 opened this issue May 14, 2020 · 1 comment
Labels

Comments

@roma293
Copy link

roma293 commented May 14, 2020

php v7.4
friendsofdoctrine/dbal-clickhouse v1.5.3
clickhouse-server: yandex/clickhouse-server:20.3.8.53 (image from official yandex hub.docker.com)

Table schema:

CREATE TABLE new_table (
    `id` Int32, 
    `payload` String, 
    `date` DateTime
) 
ENGINE = MergeTree 
PARTITION BY toYYYYMMDD(date) 
ORDER BY (id, payload, date) 
SETTINGS index_granularity = 8192;

Code example:

/** @var \FOD\DBALClickHouse\Connection $connection */
$connection = $this->getDoctrine()->getConnection('clickhouse');
$connection->insert('new_table', [
    'id' => 2,
    'payload' => 'test?o',
    'date' => (new DateTime())->format('Y-m-d H:i:s'),
]);

Result:

An exception occurred while executing 'INSERT INTO new_table (id, payload, date) VALUES (?, ?, ?)' with params [2, "test?o", "2020-05-14 13:57:42"]:

Cannot parse expression of type String here: 'test'2020-05-14 13:57:42'o', ?)
IN:INSERT INTO new_table (id, payload, date) VALUES (2, 'test'2020-05-14 13:57:42'o', ?)

If change code to:

/** @var \FOD\DBALClickHouse\Connection $connection */
$connection = $this->getDoctrine()->getConnection('clickhouse');
$data = [
    'id' => 2,
    'payload' => 'test?o',
    'date' => (new DateTime())->format('Y-m-d H:i:s'),
];
$query = sprintf(
    'INSERT INTO new_table (%s) VALUES (%s)',
    implode(', ', array_keys($data)),
    substr(str_repeat('?, ', count($data)), 0, -2)
);
$statement = $connection->prepare($query);
$statement->execute(array_values($data));

Result: insert is successful

@roma293 roma293 changed the title Symbol ? in query value Symbol ? in query's value May 15, 2020
@LarexSetch
Copy link

The problem in https://github.com/FriendsOfDoctrine/dbal-clickhouse/blob/master/src/ClickHouseStatement.php#L293
When the loop replacing ? to string with ? on the next iteration first found symbol ? will be replaced

P.S. @roma293 thank you for solution!

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

No branches or pull requests

3 participants