Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions clickhouse/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void Client::Impl::SendBlockData(const Block& block) {
if (compression_ == CompressionState::Enable) {
std::unique_ptr<OutputStream> compressed_output = std::make_unique<CompressedOutput>(output_.get(), options_.max_compression_chunk_size, options_.compression_method);
BufferedOutput buffered(std::move(compressed_output), options_.max_compression_chunk_size);

WriteBlock(block, buffered);
} else {
WriteBlock(block, *output_);
Expand Down Expand Up @@ -696,7 +696,7 @@ bool Client::Impl::ReadBlock(InputStream& input, Block* block) {
if (!WireFormat::ReadString(input, &type)) {
return false;
}

if (server_info_.revision >= DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION) {
uint8_t custom_format_len;
if (!WireFormat::ReadFixed(input, &custom_format_len)) {
Expand All @@ -705,7 +705,7 @@ bool Client::Impl::ReadBlock(InputStream& input, Block* block) {
if (custom_format_len > 0) {
throw UnimplementedError(std::string("unsupported custom serialization"));
}
}
}

if (ColumnRef col = CreateColumnByType(type, create_column_settings)) {
if (num_rows && !col->Load(&input, num_rows)) {
Expand Down Expand Up @@ -909,7 +909,7 @@ void Client::Impl::SendQuery(const Query& query, bool finalize) {
}
WireFormat::WriteString(*output_, std::string()); // empty string after last param
}

if (finalize) {
FinalizeQuery();
}
Expand Down Expand Up @@ -1101,6 +1101,9 @@ Client::Client(const ClientOptions& opts,
Client::~Client()
{ }

Client::Client(Client&&) = default;
Client& Client::operator=(Client&&) = default;

void Client::Execute(const Query& query) {
impl_->ExecuteQuery(query);
}
Expand Down
8 changes: 7 additions & 1 deletion clickhouse/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ class Client {
std::unique_ptr<SocketFactory> socket_factory);
~Client();

// movable only
Client(Client&&);
Client& operator=(Client&&);
Client(const Client&) = delete;
Client& operator=(const Client&) = delete;

/// Intends for execute arbitrary queries.
void Execute(const Query& query);

Expand Down Expand Up @@ -300,7 +306,7 @@ class Client {
static Version GetVersion();

private:
const ClientOptions options_;
ClientOptions options_;

class Impl;
std::unique_ptr<Impl> impl_;
Expand Down
7 changes: 6 additions & 1 deletion tests/simple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ inline void ParamExample(Client& client) {
Query query("insert into test_client values ({id: UInt64}, {name: String})");

query.SetParam("id", "1").SetParam("name", "NAME");
client.Execute(query);
client.Execute(query);

query.SetParam("id", "123").SetParam("name", "FromParam");
client.Execute(query);
Expand Down Expand Up @@ -589,6 +589,8 @@ int main() {
.SetPingBeforeQuery(true));
RunTests(client);
std::cout << "current endpoint : " << client.GetCurrentEndpoint().value().host << "\n";
Client client2 = std::move(client);
RunTests(client2);
}

{
Expand All @@ -603,3 +605,6 @@ int main() {

return 0;
}

static_assert( !std::is_copy_constructible_v<Client> );
static_assert( std::is_move_constructible_v<Client> );
Loading