diff --git a/src/Param/ParamValueConverterRegistry.php b/src/Param/ParamValueConverterRegistry.php index baa4a5e..8acebe5 100644 --- a/src/Param/ParamValueConverterRegistry.php +++ b/src/Param/ParamValueConverterRegistry.php @@ -8,6 +8,7 @@ use DateTimeInterface; use Psr\Http\Message\StreamInterface; use SimPod\ClickHouseClient\Exception\UnsupportedParamType; +use SimPod\ClickHouseClient\Sql\Escaper; use SimPod\ClickHouseClient\Sql\Type; use function array_keys; @@ -20,7 +21,6 @@ use function is_string; use function json_encode; use function sprintf; -use function str_replace; use function strlen; use function strtolower; use function trim; @@ -95,8 +95,8 @@ public function __construct(array $registry = []) 'datetime' => self::dateTimeConverter(), 'datetime32' => self::dateTimeConverter(), 'datetime64' => static fn (DateTimeInterface|string|int|float $value) => $value instanceof DateTimeInterface - ? $value->format('U.u') - : $value, + ? $value->format('U.u') + : $value, 'Dynamic' => self::noopConverter(), 'Variant' => self::noopConverter(), @@ -246,7 +246,7 @@ private static function stringConverter(): Closure string $value, Type|string|null $type = null, bool $nested = false, - ) => $nested ? '\'' . str_replace("'", "\'", $value) . '\'' : $value; + ) => $nested ? "'" . Escaper::escape($value) . "'" : $value; } private static function noopConverter(): Closure diff --git a/tests/Param/ParamValueConverterRegistryTest.php b/tests/Param/ParamValueConverterRegistryTest.php index 2c93aa2..d7a7480 100644 --- a/tests/Param/ParamValueConverterRegistryTest.php +++ b/tests/Param/ParamValueConverterRegistryTest.php @@ -117,7 +117,7 @@ public static function providerConvert(): Generator { yield 'Array' => ['Array(String)', "['foo','bar']", "['foo','bar']"]; yield 'Array LC' => ['Array(LowCardinality(String))', "['foo','bar']", "['foo','bar']"]; - yield 'Array (array)' => ['Array(String)', ['foo', 'bar'], "['foo','bar']"]; + yield 'Array (array)' => ['Array(String)', ['foo', 'bar', "baz'"], "['foo','bar','baz\\'']"]; yield 'Array Tuple' => ['Array(Tuple(String, String))', [['foo', 'bar']], "[('foo','bar')]"]; yield 'Array Tuple Complex' => [ 'Array(Tuple(Tuple(UInt32, UUID), String))',