Skip to content

Commit

Permalink
Fix #91 ,Does not work inserting with the database name in the table
Browse files Browse the repository at this point in the history
  • Loading branch information
isublimity committed Sep 11, 2018
1 parent afce370 commit 5f7fa65
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,10 @@ public function getCountPendingQueue()
*/
public function insert($table, $values, $columns = [])
{
$sql = 'INSERT INTO `' . $table . "`";
if (stripos($table,'`')===false && stripos($table,'.')===false) {
$table = '`' . $table . "`"; //quote table name for dot names
}
$sql = 'INSERT INTO ' . $table;

if (0 !== count($columns)) {
$sql .= ' (`' . implode('`,`', $columns) . '`) ';
Expand Down
39 changes: 38 additions & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public function tearDown()
*/
private function insert_data_table_summing_url_views()
{
$databaseName = getenv('CLICKHOUSE_DATABASE');
return $this->client->insert(
'summing_url_views',

$databaseName.'.summing_url_views',
[
[strtotime('2010-10-10 00:00:00'), 'HASH1', 2345, 22, 20, 2],
[strtotime('2010-10-11 01:00:00'), 'HASH2', 2345, 12, 9, 3],
Expand Down Expand Up @@ -226,6 +228,41 @@ public function testSqlDisableConditions()



public function testInsertDotTable()
{
$databaseName = getenv('CLICKHOUSE_DATABASE');

$this->client->write("DROP TABLE IF EXISTS `tsts.test`");
$this->client->write('CREATE TABLE `tsts.test` (
event_date Date DEFAULT toDate(event_time),
event_time DateTime,
url_hash String,
site_id Int32,
views Int32,
v_00 Int32,
v_55 Int32
) ENGINE = TinyLog()');
$this->client->insert(
'`tsts.test`',
[
[strtotime('2010-10-10 00:00:00'), 'Хеш', 2345, 22, 20, 2],
],
['event_time', 'url_hash', 'site_id', 'views', 'v_00', 'v_55']
);

$this->client->insert(
$databaseName.'.`tsts.test`',
[
[strtotime('2010-10-10 00:00:00'), 'Хеш', 2345, 22, 20, 2],
],
['event_time', 'url_hash', 'site_id', 'views', 'v_00', 'v_55']
);

// $this->client->verbose();
$st=$this->client->select('SELECT url_hash FROM `tsts.test` WHERE like(url_hash,\'%Хеш%\') ');
$this->assertEquals('Хеш', $st->fetchOne('url_hash'));

}
public function testSearchWithCyrillic()
{
$this->create_table_summing_url_views();
Expand Down

1 comment on commit 5f7fa65

@simPod
Copy link
Contributor

@simPod simPod commented on 5f7fa65 Sep 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.