Skip to content
Open
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: 7 additions & 1 deletion src/Transport/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,15 @@ private function prepareWrite($sql, array $bindings = [], array $querySettings =

$query = $this->prepareQuery($sql, $bindings);

if (strpos($sql, 'ON CLUSTER') === false) {
// strpos acts as a fast filter (cheap substring check)
// preg_match is used only for strict SQL keyword validation (word-boundary safe)
if (
strpos($sql, 'ON CLUSTER') === false
|| !preg_match("/\\bON\\s+CLUSTER\\b/i", $sql)
) {
return $this->getRequestWrite($query, $querySettings);
}

if (
!str_starts_with($sql, 'CREATE')
&& !str_starts_with($sql, 'DROP')
Expand Down
18 changes: 18 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1096,4 +1096,22 @@ public function testStreamInsertFormatJSONEachRow()
$this->assertEquals(count(file($file_name)), $statement->count());
}

public function testInsertWithOnClusterInData()
{
$this->client->write('DROP TABLE IF EXISTS `test`');
$this->client->write('CREATE TABLE `test` (
place String
) ENGINE = TinyLog()');
$this->client->insert(
'test',
[
['REGION CLUSTER'],
],
['place']
);

$statement = $this->client->select('SELECT place FROM `test`');
$this->assertCount(1, $statement->rows());
$this->assertEquals('REGION CLUSTER', $statement->fetchOne('place'));
}
}