Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Param/ParamValueConverterRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/Param/ParamValueConverterRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))',
Expand Down
Loading