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

Incorrect escaping of single quote in ClickHouseStatement::resolveType #64

Open
constantin-gordienko-quarks-tech opened this issue Apr 17, 2024 · 0 comments

Comments

@constantin-gordienko-quarks-tech
Copy link

constantin-gordienko-quarks-tech commented Apr 17, 2024

I'm using version 2.0.0, and when I'm using prepared statement and making insert, I have a problem with inccorect escaping of single quote. Example:

/** @var FOD\DBALClickHouse\ClickHouseConnection $connection */
$stmt = $connection->prepare("INSERT INTO my_table (some_val) VALUES (?)");
$stmt->execute(["some ' value"]);

// HttpCode:400 ;  ;Code: 62, e.displayText() = DB::Exception: Cannot parse expression of type String() here: 'some \'' value'

The problem as I see it lays inside class \FOD\DBALClickHouse\ClickHousePlatform.

public function quoteStringLiteral($str): string
{
    return parent::quoteStringLiteral(addslashes($str));
}

It adds slashes before single/double quote etc. But inside parent method of \Doctrine\DBAL\Platforms\AbstractPlatform, there is different type of escaping as I see (doubling of quote).

public function quoteStringLiteral($str)
{
    $c = $this->getStringLiteralQuoteCharacter();

    return $c . str_replace($c, $c . $c, $str) . $c;
}

So eventually in such conditions, my value becomes some \'' value. This leads to an error of query execution at ClickHouse server. Previosly, this quoteStringLiteral method was looking like this:

public function quoteStringLiteral($str) : string
{
    $c = $this->getStringLiteralQuoteCharacter();

    return $c . addslashes($str) . $c;
}

I think additional addslashes is redundant in current (v2.0.0) implementation. But I'm open to discuss this in order to find best working solutions with this problem.

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

1 participant