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

Method connect

programs/client/Client.cpp:513–700  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

511#endif
512
513void Client::connect()
514{
515 String server_name;
516 UInt64 server_version_major = 0;
517 UInt64 server_version_minor = 0;
518 UInt64 server_version_patch = 0;
519
520 if (hosts_and_ports.empty())
521 {
522 String host = config().getString("host", "localhost");
523 UInt16 port = ConnectionParameters::getPortFromConfig(config(), host);
524 hosts_and_ports.emplace_back(HostAndPort{host, port});
525 }
526
527 for (size_t attempted_address_index = 0; attempted_address_index < hosts_and_ports.size(); ++attempted_address_index)
528 {
529 try
530 {
531 const auto host = ConnectionParameters::Host{hosts_and_ports[attempted_address_index].host};
532 const auto database = ConnectionParameters::Database{default_database};
533
534 connection_parameters = ConnectionParameters(
535 config(), host, database, hosts_and_ports[attempted_address_index].port);
536
537#if USE_JWT_CPP && USE_SSL
538 connection_parameters.jwt_provider = jwt_provider;
539#endif
540
541 if (is_interactive)
542 output_stream << "Connecting to "
543 << (!connection_parameters.default_database.empty()
544 ? "database " + connection_parameters.default_database + " at "
545 : "")
546 << connection_parameters.host << ":" << connection_parameters.port
547 << (!connection_parameters.user.empty() ? " as user " + connection_parameters.user : "") << "." << std::endl;
548
549 connection = Connection::createConnection(connection_parameters, client_context);
550
551 if (max_client_network_bandwidth)
552 {
553 ThrottlerPtr throttler = std::make_shared<Throttler>(max_client_network_bandwidth, 0, "");
554 connection->setThrottler(throttler);
555 }
556
557 connection->getServerVersion(
558 connection_parameters.timeouts,
559 server_name,
560 server_version_major,
561 server_version_minor,
562 server_version_patch,
563 server_revision);
564 config().setString("host", connection_parameters.host);
565 config().setInt("port", connection_parameters.port);
566
567 settings_from_server = assert_cast<Connection &>(*connection).settingsFromServer();
568
569 break;
570 }

Callers 1

Calls 15

readEscapedStringFunction · 0.85
keysMethod · 0.80
toStringFunction · 0.50
emptyMethod · 0.45
getStringMethod · 0.45
emplace_backMethod · 0.45
sizeMethod · 0.45
setThrottlerMethod · 0.45
getServerVersionMethod · 0.45

Tested by

no test coverage detected