Skip to content

Commit 983280f

Browse files
committed
update(database): Better check if database exists
1 parent 2aac497 commit 983280f

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/network/database/DatabaseManager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ std::map<std::string, std::string> DatabaseManager::GetDatabaseCredentials(std::
9494
return databases_credentials[name];
9595
}
9696

97+
bool DatabaseManager::DatabaseExists(std::string name)
98+
{
99+
return (databases.find(name) != databases.end());
100+
}
101+
97102
std::string DatabaseManager::GetDatabaseKind(std::string name)
98103
{
99104
if (databases.find(name) == databases.end()) return "unknown";

src/network/database/DatabaseManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class DatabaseManager
1818

1919
std::map<std::string, std::string> GetDatabaseCredentials(std::string name);
2020
std::string GetDatabaseKind(std::string name);
21+
bool DatabaseExists(std::string name);
2122
};
2223

2324
extern DatabaseManager g_dbManager;

src/scripting/network/database.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ LoadScriptingComponent(database, [](PluginObject plugin, EContext* ctx) -> void
3636
bool shouldSkipDefaultConnection = context->GetArgumentOr<bool>(1, false);
3737

3838
auto db = g_dbManager.GetDatabase(connection_name);
39-
if (!db && connection_name != "default_connection" && g_dbManager.GetDatabaseKind(connection_name) != "unknown") {
40-
PRINTF("Database connection \"%s\" doesn't exists inside the database configurations. Automatically falling back to \"default_connection\".\n", connection_name.c_str());
41-
if (!shouldSkipDefaultConnection) db = g_dbManager.GetDatabase("default_connection");
39+
if (!db && connection_name != "default_connection" && !g_dbManager.DatabaseExists(connection_name)) {
40+
if (!shouldSkipDefaultConnection) {
41+
PRINTF("Database connection \"%s\" doesn't exists inside the database configurations. Automatically falling back to \"default_connection\".\n", connection_name.c_str());
42+
db = g_dbManager.GetDatabase("default_connection");
43+
}
4244
}
4345

4446
if (db) {

src/scripting/sdk/schema.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ typedef void (*CAttributeList_SetOrAddAttributeValueByName_t)(void*, const char*
2222
typedef void (*CBaseModelEntity_SetBodygroup_t)(void*, const char*, ...);
2323
typedef void (*CBaseModelEntity_SetModel_t)(void*, const char*);
2424
typedef void (*CBaseEntity_TakeDamage)(void*, CTakeDamageInfo*);
25-
typedef SndOpEventGuid_t(*CBaseEntity_EmitSoundFilter)(IRecipientFilter& filter, CEntityIndex ent, const EmitSound_t& params);
26-
typedef void (*CBaseEntity_EmitSoundParams)(void*, const char*, int, float, float);
2725

2826
std::set<std::string> skipFunctions = {
2927
"__call",

0 commit comments

Comments
 (0)