Skip to content

Commit 897a34b

Browse files
authored
Merge pull request #99 from simPod/improve-insert
Do not allow to execute insert with empty values
2 parents 66ee9c6 + 0b597ac commit 897a34b

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/Client.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,15 @@ public function getCountPendingQueue()
461461
}
462462

463463
/**
464-
* Insert Array
465-
*
466464
* @param mixed[][] $values
467465
* @param string[] $columns
468-
* @return Statement
469-
* @throws Exception\TransportException
470466
*/
471-
public function insert(string $table, $values, $columns = [])
467+
public function insert(string $table, array $values, array $columns = []) : Statement
472468
{
469+
if (empty($values)) {
470+
throw QueryException::cannotInsertEmptyValues();
471+
}
472+
473473
if (stripos($table, '`') === false && stripos($table, '.') === false) {
474474
$table = '`' . $table . '`'; //quote table name for dot names
475475
}

src/Exception/QueryException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88

99
class QueryException extends LogicException implements ClickHouseException
1010
{
11+
public static function cannotInsertEmptyValues() : self
12+
{
13+
return new self('Inserting empty values array is not supported in ClickHouse');
14+
}
1115
}

tests/ClientTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,14 @@ public function testExceptionInsert()
788788
], ['s_key', 's_arr']);
789789
}
790790

791+
public function testExceptionInsertNoData() : void
792+
{
793+
$this->expectException(QueryException::class);
794+
$this->expectExceptionMessage('Inserting empty values array is not supported in ClickHouse');
795+
796+
$this->client->insert('bla_bla', []);
797+
}
798+
791799
public function testExceptionSelect()
792800
{
793801
$this->expectException(DatabaseException::class);

0 commit comments

Comments
 (0)