From 2a1bdb8be31cfdcc57afba4065b4575fabb97f93 Mon Sep 17 00:00:00 2001 From: Alexey Arno Date: Thu, 18 Dec 2014 15:11:08 +0300 Subject: [PATCH] Merge --- dbms/src/Client/Client.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/dbms/src/Client/Client.cpp b/dbms/src/Client/Client.cpp index d9a8a55bea2..e951a88c3e9 100644 --- a/dbms/src/Client/Client.cpp +++ b/dbms/src/Client/Client.cpp @@ -576,11 +576,15 @@ private: connection->sendQuery(query_without_data, "", QueryProcessingStage::Complete, &context.getSettingsRef(), true); sendExternalTables(); - /// Получим структуру таблицы - Block sample = receiveSampleBlock(); - - sendData(sample); - receivePacket(); + /// Получаем структуру таблицы. + Block sample; + if (receiveSampleBlock(sample)) + { + /// Если была получена структура, т.е. сервер не выкинул исключения, + /// отправляем эту структуру вместе с данными. + sendData(sample); + receivePacket(); + } } @@ -762,15 +766,21 @@ private: /** Получить блок - пример структуры таблицы, в которую будут вставляться данные. */ - Block receiveSampleBlock() + bool receiveSampleBlock(Block & out) { Connection::Packet packet = connection->receivePacket(); switch (packet.type) { case Protocol::Server::Data: - return packet.block; + out = packet.block; + return true; + case Protocol::Server::Exception: + onException(*packet.exception); + last_exception = packet.exception; + return false; + default: throw Exception("Unexpected packet from server (expected Data, got " + String(Protocol::Server::toString(packet.type)) + ")", ErrorCodes::UNEXPECTED_PACKET_FROM_SERVER);