| 29 | } |
| 30 | |
| 31 | void AttachDatabase::executeInternal(ExecutionContext* context) { |
| 32 | auto client = context->clientContext; |
| 33 | auto databaseManager = main::DatabaseManager::Get(*client); |
| 34 | auto memoryManager = storage::MemoryManager::Get(*client); |
| 35 | if (common::StringUtils::getUpper(attachInfo.dbType) == common::ATTACHED_LBUG_DB_TYPE) { |
| 36 | auto db = std::make_unique<main::AttachedLbugDatabase>(attachInfo.dbPath, |
| 37 | attachInfo.dbAlias, common::ATTACHED_LBUG_DB_TYPE, client); |
| 38 | client->setDefaultDatabase(db.get()); |
| 39 | databaseManager->registerAttachedDatabase(std::move(db)); |
| 40 | client->addDBDirToFileSearchPath(attachInfo.dbPath); |
| 41 | appendMessage(attachMessage(), memoryManager); |
| 42 | return; |
| 43 | } |
| 44 | for (auto& storageExtension : client->getDatabase()->getStorageExtensions()) { |
| 45 | if (storageExtension->canHandleDB(attachInfo.dbType)) { |
| 46 | auto db = storageExtension->attach(attachInfo.dbAlias, attachInfo.dbPath, client, |
| 47 | attachInfo.options); |
| 48 | databaseManager->registerAttachedDatabase(std::move(db)); |
| 49 | client->addDBDirToFileSearchPath(attachInfo.dbPath); |
| 50 | appendMessage(attachMessage(), memoryManager); |
| 51 | return; |
| 52 | } |
| 53 | } |
| 54 | auto errMsg = |
| 55 | std::format("No loaded extension can handle database type: {}.", attachInfo.dbType); |
| 56 | auto dbType = common::StringUtils::getLower(attachInfo.dbType); |
| 57 | if (dbType == "adbc" || dbType == "duckdb" || dbType == "postgres" || dbType == "sqlite") { |
| 58 | errMsg += std::format("\nDid you forget to load {} extension?\nYou can load it by: load " |
| 59 | "extension {};", |
| 60 | dbType, dbType); |
| 61 | } |
| 62 | throw common::RuntimeException{errMsg}; |
| 63 | } |
| 64 | |
| 65 | } // namespace processor |
| 66 | } // namespace lbug |
nothing calls this directly
no test coverage detected