From 91babb027ee14c5026aa3028fa8b4078c6897d21 Mon Sep 17 00:00:00 2001 From: Denis Kuznetsov Date: Fri, 15 Mar 2024 02:15:31 +0300 Subject: [PATCH] fix write method format --- src/Transport/Http.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Transport/Http.php b/src/Transport/Http.php index 34b984e..53a70fc 100644 --- a/src/Transport/Http.php +++ b/src/Transport/Http.php @@ -618,7 +618,7 @@ private function prepareSelect($sql, $bindings, $whereInFile, $writeToFile = nul * @return CurlerRequest * @throws \ClickHouseDB\Exception\TransportException */ - private function prepareWrite($sql, $bindings = []): CurlerRequest + private function prepareWrite($sql, $bindings = [], ?string $forceResponseFormat = null): CurlerRequest { if ($sql instanceof Query) { return $this->getRequestWrite($sql); @@ -626,8 +626,8 @@ private function prepareWrite($sql, $bindings = []): CurlerRequest $query = $this->prepareQuery($sql, $bindings); - if (strpos($sql, 'CREATE') === 0 || strpos($sql, 'DROP') === 0 || strpos($sql, 'ALTER') === 0) { - $query->setFormat('JSON'); + if (null !== $forceResponseFormat) { + $query->setFormat($forceResponseFormat); } return $this->getRequestWrite($query); @@ -689,9 +689,9 @@ public function setProgressFunction(callable $callback) : void * @return Statement * @throws \ClickHouseDB\Exception\TransportException */ - public function write($sql, array $bindings = [], $exception = true): Statement + public function write($sql, array $bindings = [], $exception = true, ?string $forceResponseFormat = null): Statement { - $request = $this->prepareWrite($sql, $bindings); + $request = $this->prepareWrite($sql, $bindings, $forceResponseFormat); $this->_curler->execOne($request); $response = new Statement($request); if ($exception) {