Skip to content

Commit

Permalink
Merge pull request ClickHouse#34357 from kssenii/fix-clickhouse-local…
Browse files Browse the repository at this point in the history
…-use-db

Fix USE database for clickhouse-local
  • Loading branch information
alexey-milovidov authored Feb 6, 2022
2 parents 60cc5ff + e41a895 commit 4b1e131
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Client/LocalConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ void LocalConnection::sendQuery(
query_context->setProgressCallback([this] (const Progress & value) { return this->updateProgress(value); });
query_context->setFileProgressCallback([this](const FileProgress & value) { this->updateProgress(Progress(value)); });
}
if (!current_database.empty())
query_context->setCurrentDatabase(current_database);

CurrentThread::QueryScope query_scope_holder(query_context);

Expand Down Expand Up @@ -427,9 +429,9 @@ void LocalConnection::getServerVersion(
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not implemented");
}

void LocalConnection::setDefaultDatabase(const String &)
void LocalConnection::setDefaultDatabase(const String & database)
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Not implemented");
current_database = database;
}

UInt64 LocalConnection::getServerRevision(const ConnectionTimeouts &)
Expand Down
2 changes: 2 additions & 0 deletions src/Client/LocalConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,7 @@ class LocalConnection : public IServerConnection, WithContext

/// Last "server" packet.
std::optional<UInt64> next_packet_type;

String current_database;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SHOW TABLES;
CREATE DATABASE test1;
CREATE TABLE test1.table1 (a Int32) ENGINE=Memory;
USE test1;
SHOW TABLES;
table1
CREATE DATABASE test2;
USE test2;
SHOW TABLES;
USE test1;
SHOW TABLES;
table1
19 changes: 19 additions & 0 deletions tests/queries/0_stateless/02206_clickhouse_local_use_database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh


$CLICKHOUSE_LOCAL --echo --multiline --multiquery -q """
SHOW TABLES;
CREATE DATABASE test1;
CREATE TABLE test1.table1 (a Int32) ENGINE=Memory;
USE test1;
SHOW TABLES;
CREATE DATABASE test2;
USE test2;
SHOW TABLES;
USE test1;
SHOW TABLES;
"""

0 comments on commit 4b1e131

Please sign in to comment.