]> git.joonet.de Git - adminer.git/commitdiff
ClickHouse fix select-like queries format postfix
authorsartor <sartorua@gmail.com>
Sat, 20 Oct 2018 16:37:44 +0000 (19:37 +0300)
committerJakub Vrana <jakub@vrana.cz>
Sat, 27 Oct 2018 17:30:33 +0000 (19:30 +0200)
adminer/drivers/clickhouse.inc.php

index edfa5f37538885ff2f34741c639a65f0f150ec1a..5f39c8bace7e071eed86ce615a0d8dcb7701261c 100644 (file)
@@ -12,12 +12,12 @@ if (isset($_GET["clickhouse"])) {
                        @ini_set('track_errors', 1); // @ - may be disabled
                        $file = @file_get_contents("$this->_url/?database=$db", false, stream_context_create(array('http' => array(
                                'method' => 'POST',
-                               'content' => stripos($query, 'insert') === 0 ? $query : "$query FORMAT JSONCompact",
+                'content' => $this->is_query_select_like($query) ? ($query.' FORMAT JSONCompact') : $query,
                                'header' => 'Content-type: application/x-www-form-urlencoded',
                                'ignore_errors' => 1, // available since PHP 5.2.10
                        ))));
 
-                       if (!$file) {
+                       if ($file === false) {
                                $this->error = $php_errormsg;
                                return $file;
                        }
@@ -43,6 +43,10 @@ if (isset($_GET["clickhouse"])) {
                        return new Min_Result($return);
                }
 
+        function is_query_select_like($query) {
+            return (bool) preg_match('~^(select|show)~i', $query);
+        }
+
                function query($query) {
                        return $this->rootQuery($this->_db, $query);
                }