ClickHouse fix select-like queries format postfix

This commit is contained in:
sartor 2018-10-20 19:37:44 +03:00 committed by Jakub Vrana
parent b327a76fc0
commit c8e41ee649

View file

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