Skip to content

Commit dbd459f

Browse files
committed
fixes
1 parent 6c61bbb commit dbd459f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/ClickHouseAPI.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public function doQuery(
334334
}
335335

336336
// If need session, check this feature
337-
if(!empty($this->options['session_id'])) {
337+
if (!empty($this->options['session_id'])) {
338338
if (isset($this->support_fe['session_id'])) {
339339
$sess_sup = $this->support_fe['session_id'];
340340
} else {
@@ -542,7 +542,7 @@ public function getVersion($re_check = false)
542542
$session_id = $this->getSession();
543543
$query = 'SELECT version()';
544544
$ans = $this->doApiCall($this->server_url, compact('query', 'session_id'));
545-
if($ans['code'] == 200) {
545+
if ($ans['code'] == 200) {
546546
$this->support_fe['session_id'] = true;
547547
} else {
548548
// if session_id unsupported send request again
@@ -551,7 +551,9 @@ public function getVersion($re_check = false)
551551
$ans = $this->doApiCall($this->server_url, compact('query'));
552552
}
553553
$ver = explode("\n", $ans['response']);
554-
$this->server_version = (count($ver) == 2) ? $ver[0] : "Unknown";
554+
$ver = (count($ver) == 2 && strlen($ver[0]) < 32) ? $ver[0] : "Unknown";
555+
$this->support_fe['query'] = \is_string($ver) && (\count(\explode(".", $ver)) > 2);
556+
$this->server_version = $ver;
555557
$this->setSession($old_sess);
556558
}
557559
return $this->server_version;

tests/src/ClickHouseAPITest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function testDoQuery()
135135
$this->assertEquals(\trim($ans['response']), 22);
136136

137137
$session_id = $ch->getSession();
138-
if($ch->isSupported('session_id')) {
138+
if ($ch->isSupported('session_id')) {
139139
$this->assertEquals(32, strlen($session_id));
140140
} else {
141141
$this->assertNull($session_id);
@@ -160,6 +160,13 @@ public function testDoQuery()
160160
// but last last_used_session_id must be sess_tmp
161161
$this->assertEquals($sess_tmp, $ch->last_used_session_id);
162162
}
163+
164+
// check query if not supported session
165+
$ch->support_fe['session_id'] = false;
166+
$ch->setOption('session_id', 'test');
167+
$ans = $ch->doQuery("SELECT 321");
168+
$this->assertEquals(\trim($ans['response']), 321);
169+
$this->assertNull($ch->getSession());
163170
}
164171

165172

0 commit comments

Comments
 (0)