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
14 changes: 13 additions & 1 deletion doc/native-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,24 @@ $db->selectWithParams(
['id' => UUID::fromString('6d38d288-5b13-4714-b6e4-faa59ffd49d8')]
);

// Array
// Array of integers
$db->selectWithParams(
'SELECT {arr:Array(UInt32)} as arr',
['arr' => [1, 2, 3]]
);

// Array of strings — encoded as ['val1','val2'] (single-quoted, not JSON double-quoted)
$db->selectWithParams(
'SELECT {arr:Array(String)} as arr',
['arr' => ['foo', 'bar', 'baz']]
);

// Nested arrays
$db->selectWithParams(
'SELECT {arr:Array(Array(UInt32))} as arr',
['arr' => [[1, 2], [3, 4]]]
);

// IPv4 / IPv6
$db->selectWithParams(
'SELECT {ip:IPv4} as ip',
Expand Down
14 changes: 13 additions & 1 deletion docs/native-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,24 @@ $db->selectWithParams(
['id' => UUID::fromString('6d38d288-5b13-4714-b6e4-faa59ffd49d8')]
);

// Array
// Array of integers
$db->selectWithParams(
'SELECT {arr:Array(UInt32)} as arr',
['arr' => [1, 2, 3]]
);

// Array of strings — encoded as ['val1','val2'] (single-quoted, not JSON double-quoted)
$db->selectWithParams(
'SELECT {arr:Array(String)} as arr',
['arr' => ['foo', 'bar', 'baz']]
);

// Nested arrays
$db->selectWithParams(
'SELECT {arr:Array(Array(UInt32))} as arr',
['arr' => [[1, 2], [3, 4]]]
);

// IPv4 / IPv6
$db->selectWithParams(
'SELECT {ip:IPv4} as ip',
Expand Down
10 changes: 9 additions & 1 deletion src/Transport/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,15 @@ private function convertParamValue(mixed $value): string
return $value ? '1' : '0';
}
if (is_array($value)) {
return json_encode($value);
$arrayValues = [];
foreach ($value as $val) {
if (is_string($val)) {
$arrayValues[] = sprintf("'%s'", $val);
continue;
}
$arrayValues[] = $this->convertParamValue($val);
}
return sprintf('[%s]', implode(',', $arrayValues));
}
if ($value === null) {
return '\\N';
Expand Down
30 changes: 30 additions & 0 deletions tests/NativeParamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,36 @@ public function testSelectWithNullableParam(): void
$this->assertNull($result->fetchOne('val'));
}

public function testSelectWithUInt32ArrayParam(): void
{
$result = $this->client->selectWithParams(
'SELECT {arr:Array(UInt32)} as arr',
['arr' => [1, 2, 3]]
);

$this->assertEquals([1, 2, 3], $result->fetchOne('arr'));
}

public function testSelectWithStringArrayParam(): void
{
$result = $this->client->selectWithParams(
'SELECT {arr:Array(String)} as arr',
['arr' => ['foo', 'bar', 'baz']]
);

$this->assertEquals(['foo', 'bar', 'baz'], $result->fetchOne('arr'));
}

public function testSelectWithEmptyArrayParam(): void
{
$result = $this->client->selectWithParams(
'SELECT {arr:Array(UInt32)} as arr',
['arr' => []]
);

$this->assertEquals([], $result->fetchOne('arr'));
}

public function testSelectWithPerQuerySettings(): void
{
$result = $this->client->selectWithParams(
Expand Down
Loading