From e8c7cf3c7272d019ab67671d606d28436803666a Mon Sep 17 00:00:00 2001 From: antao Date: Thu, 10 Jan 2019 13:24:03 +0800 Subject: [PATCH] Modify the createDbClient() method --- lib/src/ConfigLoader.cc | 5 ++++- lib/src/HttpAppFrameworkImpl.cc | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/src/ConfigLoader.cc b/lib/src/ConfigLoader.cc index 07b85622..5bcbd105 100644 --- a/lib/src/ConfigLoader.cc +++ b/lib/src/ConfigLoader.cc @@ -231,9 +231,9 @@ static void loadApp(const Json::Value &app) } static void loadDbClients(const Json::Value &dbClients) { -#if USE_ORM if (!dbClients) return; +#if USE_ORM for (auto &client : dbClients) { auto type = client.get("rdbms", "postgresql").asString(); @@ -252,6 +252,9 @@ static void loadDbClients(const Json::Value &dbClients) auto filename = client.get("filename", "").asString(); drogon::app().createDbClient(type, host, (u_short)port, dbname, user, password, connNum, filename, name); } +#else + std::cout << "No database is supported by drogon, please install the database development library first." << std::endl; + exit(1); #endif } static void loadListeners(const Json::Value &listeners) diff --git a/lib/src/HttpAppFrameworkImpl.cc b/lib/src/HttpAppFrameworkImpl.cc index 9029ba3b..c4f11202 100755 --- a/lib/src/HttpAppFrameworkImpl.cc +++ b/lib/src/HttpAppFrameworkImpl.cc @@ -1277,6 +1277,9 @@ void HttpAppFrameworkImpl::createDbClient(const std::string &dbType, #if USE_POSTGRESQL auto client = drogon::orm::DbClient::newPgClient(connStr, connectionNum); _dbClientsMap[name] = client; +#else + std::cout << "The PostgreSQL is not supported by drogon, please install the development library first." << std::endl; + exit(1); #endif } else if (type == "mysql") @@ -1284,6 +1287,9 @@ void HttpAppFrameworkImpl::createDbClient(const std::string &dbType, #if USE_MYSQL auto client = drogon::orm::DbClient::newMysqlClient(connStr, connectionNum); _dbClientsMap[name] = client; +#else + std::cout << "The Mysql is not supported by drogon, please install the development library first." << std::endl; + exit(1); #endif } else if (type == "sqlite3") @@ -1292,6 +1298,9 @@ void HttpAppFrameworkImpl::createDbClient(const std::string &dbType, std::string sqlite3ConnStr = "filename=" + filename; auto client = drogon::orm::DbClient::newSqlite3Client(sqlite3ConnStr, connectionNum); _dbClientsMap[name] = client; +#else + std::cout << "The Sqlite3 is not supported by drogon, please install the development library first." << std::endl; + exit(1); #endif } }