From 04b8aa97536a56b9e808a129cb5d1979a6da6db8 Mon Sep 17 00:00:00 2001 From: Philip Date: Fri, 26 Jul 2019 15:37:39 +0300 Subject: [PATCH] Adding support for "Array" type fields --- ColumnSchema.php | 2 +- Command.php | 4 ++-- Schema.php | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ColumnSchema.php b/ColumnSchema.php index 8e71302..f2f694a 100644 --- a/ColumnSchema.php +++ b/ColumnSchema.php @@ -55,7 +55,7 @@ protected function typecast($value) switch ($this->phpType) { case 'resource': case 'string': - if (is_resource($value)) { + if (is_resource($value) || is_array($value)) { return $value; } if (is_float($value)) { diff --git a/Command.php b/Command.php index 1f453cf..595f73a 100644 --- a/Command.php +++ b/Command.php @@ -129,7 +129,7 @@ public function bindValues($values) foreach ($values as $name => $value) { if (is_array($value)) { $this->_pendingParams[$name] = $value; - $this->params[$name] = $value[0]; + $this->params[$name] = isset($value[0]) ? $value[0] : '[]'; } else { $this->params[$name] = $value; } @@ -248,7 +248,7 @@ protected function queryInternal($method, $fetchMode = null) } } } - + $token = $rawSql; try { Yii::beginProfile($token, 'kak\clickhouse\Command::query'); diff --git a/Schema.php b/Schema.php index f5b3fb4..da33fb0 100644 --- a/Schema.php +++ b/Schema.php @@ -66,7 +66,19 @@ class Schema extends \yii\db\Schema */ public function insert($table, $columns) { + + foreach($columns as &$column){ + + if(is_array($column)){ + + $column = json_encode($column); + } + } + + unset($column); + $columns = $this->hardTypeCastValue($table, $columns); + return parent::insert($table, $columns); }