Skip to content

Commit 1ac330b

Browse files
committed
X-auth althernative added
1 parent b70b6aa commit 1ac330b

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/ClickHouseAPI.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,17 +432,17 @@ public function doQuery(
432432
}
433433
}
434434

435-
$h_parameters = \array_merge(
435+
$h_params = \array_merge(
436436
\compact('user', 'password', 'query'),
437437
$this->options
438438
);
439439

440-
if (isset($h_parameters['session_id']) && !$this->isSupported('session_id')) {
441-
unset($h_parameters['session_id']);
440+
if (isset($h_params['session_id']) && !$this->isSupported('session_id')) {
441+
unset($h_params['session_id']);
442442
}
443443

444444
$response_data = $this->doApiCall(
445-
$this->server_url, $h_parameters, $is_post, $post_data, $file, $put
445+
$this->server_url, $h_params, $is_post, $post_data, $file, $put
446446
);
447447

448448
// Restore old session if need
@@ -559,6 +559,12 @@ public function yiDoApiCall($api_url,
559559
\curl_setopt($curl_h, \CURLOPT_POST, true);
560560
\curl_setopt($curl_h, \CURLOPT_POSTFIELDS, $post_data);
561561
}
562+
// No Auth in $h_params ? Try alternative
563+
\curl_setopt($curl_h, \CURLOPT_HTTPHEADER, [
564+
'X-ClickHouse-User: ' . $this->user,
565+
'X-ClickHouse-Key: ' . $this->pass,
566+
]);
567+
}
562568
\curl_setopt_array($curl_h, $this->curl_options);
563569

564570
$response_arr = (yield $curl_h);

src/ClickHouseQuery.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ public function queryArr($sql, $numeric_keys = false, $sess = null)
481481
$this->names = $x;
482482
}
483483
} else {
484+
while(\count($x) < \count($keys)) $x[]='';
484485
$ret[] = \array_combine($keys, $x);
485486
}
486487
}

tests/src/ClickHouseAPITest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function testSetServerUrlException()
8181
public function testDoApiCall()
8282
{
8383
$ch = $this->object;
84+
$ch->debug = true;
8485

8586
// $ch->toSlot()->doApiCall - clear async-mode, than do..
8687

@@ -126,7 +127,7 @@ public function testYiDoApiCall()
126127

127128
$file_data = '';
128129
for ($t=1; $t<100; $t++) {
129-
$file_data .= $t . "\t2017-12-12\tAny string data\n";
130+
$file_data .= $t . "\t2019-12-12\tAny string data\n";
130131
}
131132

132133
$file_size = file_put_contents($file, $file_data);
@@ -143,14 +144,20 @@ public function testYiDoApiCall()
143144
"ENGINE = MergeTree(dt, (id, dt), 8192)");
144145

145146
$ch->is_windows = true;
146-
147147
$ans = $ch->doApiCall(false,
148148
['query' => "INSERT INTO $table $fields FORMAT TabSeparated"],
149149
true, [], $file, true);
150150

151-
$ch->query("SELECT * FROM $table");
152-
$this->assertEquals($file_data, $ch->results);
151+
if ($ans['code'] == 200) {
152+
153+
$ch->query("SELECT * FROM $table");
153154

155+
$this->assertEquals($file_data, $ch->results);
156+
157+
} else {
158+
echo "Error on try upload file:";
159+
echo $ans['code'] . ' ' . $ans['curl_error'] . "\n";
160+
}
154161
$ch->is_windows = false;
155162

156163
try {

0 commit comments

Comments
 (0)