From e2e6ec777b912be5127d4f3fe4eeca95f90d542e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 14 Aug 2007 01:00:42 +0000 Subject: [PATCH] added SQL_CheckConfig() so sql admin plugins can default back --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401330 --- core/smn_database.cpp | 11 ++++++++++- plugins/admin-sql-prefetch.sp | 10 +++++++++- plugins/admin-sql-threaded.sp | 7 ++++++- plugins/include/dbi.inc | 8 ++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/core/smn_database.cpp b/core/smn_database.cpp index 059e5b48..dffcd89b 100644 --- a/core/smn_database.cpp +++ b/core/smn_database.cpp @@ -1256,11 +1256,20 @@ static cell_t SQL_ReadDriver(IPluginContext *pContext, const cell_t *params) return driver->GetHandle(); } +static cell_t SQL_CheckConfig(IPluginContext *pContext, const cell_t *params) +{ + char *name; + pContext->LocalToString(params[1], &name); + + return (g_DBMan.FindDatabaseConf(name) != NULL) ? 1 : 0; +} + REGISTER_NATIVES(dbNatives) { {"SQL_BindParamInt", SQL_BindParamInt}, {"SQL_BindParamFloat", SQL_BindParamFloat}, - {"SQL_BindParamString", SQL_BindParamString}, + {"SQL_BindParamString", SQL_BindParamString},\ + {"SQL_CheckConfig", SQL_CheckConfig}, {"SQL_Connect", SQL_Connect}, {"SQL_ConnectEx", SQL_ConnectEx}, {"SQL_Execute", SQL_Execute}, diff --git a/plugins/admin-sql-prefetch.sp b/plugins/admin-sql-prefetch.sp index 9e823952..4f2ad902 100644 --- a/plugins/admin-sql-prefetch.sp +++ b/plugins/admin-sql-prefetch.sp @@ -38,7 +38,15 @@ public OnRebuildAdminCache(AdminCachePart:part) { /* First try to get a database connection */ decl String:error[255]; - new Handle:db = SQL_Connect("default", true, error, sizeof(error)); + new Handle:db; + + if (SQL_CheckConfig("admins")) + { + db = SQL_Connect("admins", true, error, sizeof(error)); + } else { + db = SQL_Connect("default", true, error, sizeof(error)); + } + if (db == INVALID_HANDLE) { LogError("Could not connect to database \"default\": %s", error); diff --git a/plugins/admin-sql-threaded.sp b/plugins/admin-sql-threaded.sp index 84cc4df2..0b7ff19c 100644 --- a/plugins/admin-sql-threaded.sp +++ b/plugins/admin-sql-threaded.sp @@ -144,7 +144,12 @@ public OnDatabaseConnect(Handle:owner, Handle:hndl, const String:error[], any:da RequestDatabaseConnection() { ConnectLock = ++g_sequence; - SQL_TConnect(OnDatabaseConnect, "default", ConnectLock); + if (SQL_CheckConfig("admins")) + { + SQL_TConnect(OnDatabaseConnect, "admins", ConnectLock); + } else { + SQL_TConnect(OnDatabaseConnect, "default", ConnectLock); + } } public OnRebuildAdminCache(AdminCachePart:part) diff --git a/plugins/include/dbi.inc b/plugins/include/dbi.inc index 37a3d075..bce9ba40 100644 --- a/plugins/include/dbi.inc +++ b/plugins/include/dbi.inc @@ -131,6 +131,14 @@ native Handle:SQL_ConnectEx(Handle:driver, bool:persistent=true, port=0, maxTimeout=0); + +/** + * Returns if a named configuration is present in databases.cfg. + * + * @param name Configuration name. + * @return True if it exists, false otherwise. + */ +native bool:SQL_CheckConfig(const String:name[]); /** * Returns a driver Handle from a name string.