From 096676a93053f2dd7eeb3ce496dc77d7b9e3168b Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 7 Jan 2025 14:39:23 +0700 Subject: [PATCH] Fixed an issue causing error when defining column options --- src/Manticoresearch/Endpoints/Indices/Create.php | 12 +++++++++++- .../Manticoresearch/Endpoints/Indices/CreateTest.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Manticoresearch/Endpoints/Indices/Create.php b/src/Manticoresearch/Endpoints/Indices/Create.php index 24a8d627..5ad241d9 100644 --- a/src/Manticoresearch/Endpoints/Indices/Create.php +++ b/src/Manticoresearch/Endpoints/Indices/Create.php @@ -23,6 +23,15 @@ class Create extends EmulateBySql */ protected $index; + protected function buildOptionsExpr($options) { + $exprParts = []; + foreach ($options as $k => $v) { + $exprParts[] = is_string($k) ? "$k='$v'" : $v; + } + + return ' ' . implode(' ', $exprParts); + } + public function setBody($params = null) { if (isset($this->index)) { $columns = []; @@ -30,7 +39,7 @@ public function setBody($params = null) { foreach ($params['columns'] as $name => $settings) { $column = '`' . $name . '` ' . $settings['type']; if (isset($settings['options']) && sizeof($settings['options']) > 0) { - $column .= ' ' . implode(' ', $settings['options']); + $column .= $this->buildOptionsExpr($settings['options']); } $columns[] = $column; } @@ -47,6 +56,7 @@ public function setBody($params = null) { } } } + return parent::setBody( ['query' => 'CREATE TABLE '. (isset($params['silent']) && $params['silent'] === true ? ' IF NOT EXISTS ' : ''). diff --git a/test/Manticoresearch/Endpoints/Indices/CreateTest.php b/test/Manticoresearch/Endpoints/Indices/CreateTest.php index e7d826af..e3b1bb49 100644 --- a/test/Manticoresearch/Endpoints/Indices/CreateTest.php +++ b/test/Manticoresearch/Endpoints/Indices/CreateTest.php @@ -26,7 +26,7 @@ public function testCreateTableWithOptions() { 'columns' => [ 'title' => [ 'type' => 'text', - 'options' => ['indexed', 'stored'], + 'options' => ['indexed', 'stored', 'engine' => 'columnar'], ], 'price' => [ 'type' => 'float',