MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / executeQueryForSingleString

Method executeQueryForSingleString

src/Client/ClientBase.cpp:3483–3552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3481}
3482
3483std::string ClientBase::executeQueryForSingleString(const std::string & query)
3484{
3485 if (!connection)
3486 return "";
3487
3488 try
3489 {
3490 std::string result;
3491
3492 /// Send the query
3493 connection->sendQuery(
3494 connection_parameters.timeouts,
3495 query,
3496 {}, /// query_parameters
3497 "", /// query_id
3498 QueryProcessingStage::Complete,
3499 nullptr, /// settings
3500 nullptr, /// client_info
3501 false, /// with_pending_data
3502 {}, /// external_roles
3503 {} /// external_data
3504 );
3505
3506 /// Receive and process results
3507 while (true)
3508 {
3509 Packet packet = connection->receivePacket();
3510 switch (packet.type)
3511 {
3512 case Protocol::Server::Data:
3513 if (!packet.block.empty() && packet.block.rows() > 0)
3514 {
3515 /// Convert block to string representation
3516 /// For schema queries, we expect single column results
3517 const auto & column = packet.block.getByPosition(0).column;
3518 for (size_t i = 0; i < column->size(); ++i)
3519 {
3520 if (!result.empty())
3521 result += "\n";
3522 result.append(column->getDataAt(i));
3523 }
3524 }
3525 break;
3526
3527 case Protocol::Server::EndOfStream:
3528 return result;
3529
3530 case Protocol::Server::Exception:
3531 /// Return empty string on exception
3532 return "";
3533
3534 case Protocol::Server::Progress:
3535 case Protocol::Server::ProfileInfo:
3536 case Protocol::Server::Log:
3537 case Protocol::Server::ProfileEvents:
3538 case Protocol::Server::TimezoneUpdate:
3539 /// Ignore these packet types
3540 break;

Callers

nothing calls this directly

Calls 7

sendQueryMethod · 0.45
receivePacketMethod · 0.45
emptyMethod · 0.45
rowsMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45
getDataAtMethod · 0.45

Tested by

no test coverage detected