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();
|
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)
|
REGISTER_NATIVES(dbNatives)
|
||||||
{
|
{
|
||||||
{"SQL_BindParamInt", SQL_BindParamInt},
|
{"SQL_BindParamInt", SQL_BindParamInt},
|
||||||
{"SQL_BindParamFloat", SQL_BindParamFloat},
|
{"SQL_BindParamFloat", SQL_BindParamFloat},
|
||||||
{"SQL_BindParamString", SQL_BindParamString},
|
{"SQL_BindParamString", SQL_BindParamString},\
|
||||||
|
{"SQL_CheckConfig", SQL_CheckConfig},
|
||||||
{"SQL_Connect", SQL_Connect},
|
{"SQL_Connect", SQL_Connect},
|
||||||
{"SQL_ConnectEx", SQL_ConnectEx},
|
{"SQL_ConnectEx", SQL_ConnectEx},
|
||||||
{"SQL_Execute", SQL_Execute},
|
{"SQL_Execute", SQL_Execute},
|
||||||
|
@ -38,7 +38,15 @@ public OnRebuildAdminCache(AdminCachePart:part)
|
|||||||
{
|
{
|
||||||
/* First try to get a database connection */
|
/* First try to get a database connection */
|
||||||
decl String:error[255];
|
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)
|
if (db == INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
LogError("Could not connect to database \"default\": %s", error);
|
LogError("Could not connect to database \"default\": %s", error);
|
||||||
|
@ -144,8 +144,13 @@ public OnDatabaseConnect(Handle:owner, Handle:hndl, const String:error[], any:da
|
|||||||
RequestDatabaseConnection()
|
RequestDatabaseConnection()
|
||||||
{
|
{
|
||||||
ConnectLock = ++g_sequence;
|
ConnectLock = ++g_sequence;
|
||||||
|
if (SQL_CheckConfig("admins"))
|
||||||
|
{
|
||||||
|
SQL_TConnect(OnDatabaseConnect, "admins", ConnectLock);
|
||||||
|
} else {
|
||||||
SQL_TConnect(OnDatabaseConnect, "default", ConnectLock);
|
SQL_TConnect(OnDatabaseConnect, "default", ConnectLock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public OnRebuildAdminCache(AdminCachePart:part)
|
public OnRebuildAdminCache(AdminCachePart:part)
|
||||||
{
|
{
|
||||||
|
@ -132,6 +132,14 @@ native Handle:SQL_ConnectEx(Handle:driver,
|
|||||||
port=0,
|
port=0,
|
||||||
maxTimeout=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.
|
* Returns a driver Handle from a name string.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user