added SQL_CheckConfig() so sql admin plugins can default back
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401330
This commit is contained in:
parent
badeade4e9
commit
e2e6ec777b
@ -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},
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user