@@ -417,6 +417,39 @@ void Client::Impl::Insert(const std::string& table_name, const std::string& quer
417417 throw ProtocolError (" fail to receive data packet" );
418418}
419419
420+ Block Client::Impl::BeginInsert (Query query) {
421+ if (inserting_) {
422+ throw ValidationError (" cannot execute query while inserting" );
423+ }
424+
425+ EnsureNull en (static_cast <QueryEvents*>(&query), &events_);
426+
427+ if (options_.ping_before_query ) {
428+ RetryGuard ([this ]() { Ping (); });
429+ }
430+
431+ inserting_ = true ;
432+
433+ // Create a callback to extract the block with the proper query columns.
434+ Block block;
435+ query.OnData ([&block](const Block& b) {
436+ block = std::move (b);
437+ return true ;
438+ });
439+
440+ SendQuery (query.GetText ());
441+
442+ // Wait for a data packet and return
443+ uint64_t server_packet = 0 ;
444+ while (ReceivePacket (&server_packet)) {
445+ if (server_packet == ServerCodes::Data) {
446+ return block;
447+ }
448+ }
449+
450+ throw ProtocolError (" fail to receive data packet" );
451+ }
452+
420453void Client::Impl::SendInsertBlock (const Block& block) {
421454 if (!inserting_) {
422455 throw ValidationError (" illegal call to InsertData without first calling BeginInsert" );
@@ -1121,39 +1154,6 @@ void Client::Impl::RetryGuard(std::function<void()> func) {
11211154 }
11221155}
11231156
1124- Block Client::Impl::BeginInsert (Query query) {
1125- if (inserting_) {
1126- throw ValidationError (" cannot execute query while inserting" );
1127- }
1128-
1129- EnsureNull en (static_cast <QueryEvents*>(&query), &events_);
1130-
1131- if (options_.ping_before_query ) {
1132- RetryGuard ([this ]() { Ping (); });
1133- }
1134-
1135- inserting_ = true ;
1136-
1137- // Create a callback to extract the block with the proper query columns.
1138- Block block;
1139- query.OnData ([&block](const Block& b) {
1140- block = std::move (b);
1141- return true ;
1142- });
1143-
1144- SendQuery (query.GetText ());
1145-
1146- // Wait for a data packet and return
1147- uint64_t server_packet = 0 ;
1148- while (ReceivePacket (&server_packet)) {
1149- if (server_packet == ServerCodes::Data) {
1150- return block;
1151- }
1152- }
1153-
1154- throw ProtocolError (" fail to receive data packet" );
1155- }
1156-
11571157Client::Client (const ClientOptions& opts)
11581158 : options_(opts)
11591159 , impl_(new Impl(opts))
0 commit comments