| 593 | |
| 594 | void registerDatabaseMySQL(DatabaseFactory & factory); |
| 595 | void registerDatabaseMySQL(DatabaseFactory & factory) |
| 596 | { |
| 597 | auto create_fn = [](const DatabaseFactory::Arguments & args) |
| 598 | { |
| 599 | auto * engine_define = args.create_query.storage; |
| 600 | const ASTFunction * engine = engine_define->engine; |
| 601 | const String & engine_name = engine_define->engine->name; |
| 602 | if (!engine->arguments) |
| 603 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "Engine `{}` must have arguments", engine_name); |
| 604 | |
| 605 | StorageMySQL::Configuration configuration; |
| 606 | ASTs & arguments = engine->arguments->children; |
| 607 | auto mysql_settings = std::make_unique<MySQLSettings>(); |
| 608 | |
| 609 | if (auto named_collection = tryGetNamedCollectionWithOverrides(arguments, args.context)) |
| 610 | { |
| 611 | configuration = StorageMySQL::processNamedCollectionResult(*named_collection, *mysql_settings, args.context, false); |
| 612 | } |
| 613 | else |
| 614 | { |
| 615 | if (arguments.size() != 4) |
| 616 | throw Exception( |
| 617 | ErrorCodes::BAD_ARGUMENTS, |
| 618 | "MySQL database require mysql_hostname, mysql_database_name, mysql_username, mysql_password arguments."); |
| 619 | |
| 620 | |
| 621 | arguments[1] = evaluateConstantExpressionOrIdentifierAsLiteral(arguments[1], args.context); |
| 622 | const auto & host_port = safeGetLiteralValue<String>(arguments[0], engine_name); |
| 623 | |
| 624 | if (engine_name == "MySQL") |
| 625 | { |
| 626 | size_t max_addresses = args.context->getSettingsRef()[Setting::glob_expansion_max_elements]; |
| 627 | configuration.addresses = parseRemoteDescriptionForExternalDatabase(host_port, max_addresses, 3306); |
| 628 | } |
| 629 | else |
| 630 | { |
| 631 | const auto & [remote_host, remote_port] = parseAddress(host_port, 3306); |
| 632 | configuration.host = remote_host; |
| 633 | configuration.port = remote_port; |
| 634 | } |
| 635 | |
| 636 | configuration.database = safeGetLiteralValue<String>(arguments[1], engine_name); |
| 637 | configuration.username = safeGetLiteralValue<String>(arguments[2], engine_name); |
| 638 | configuration.password = safeGetLiteralValue<String>(arguments[3], engine_name); |
| 639 | } |
| 640 | mysql_settings->loadFromQueryContext(args.context, *engine_define); |
| 641 | if (engine_define->settings) |
| 642 | mysql_settings->loadFromQuery(*engine_define); |
| 643 | |
| 644 | auto mysql_pool = createMySQLPoolWithFailover(configuration, *mysql_settings); |
| 645 | |
| 646 | try |
| 647 | { |
| 648 | return make_shared<DatabaseMySQL>( |
| 649 | args.context, |
| 650 | args.database_name, |
| 651 | args.metadata_path, |
| 652 | engine_define, |
no test coverage detected