databases now get separate handles for persistent connections
removed GetHandle from IDatabase simplified IDatabase::Close --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40881
This commit is contained in:
parent
3ed301e9af
commit
a3687d9258
@ -94,6 +94,13 @@ static cell_t SQL_Connect(IPluginContext *pContext, const cell_t *params)
|
||||
return BAD_HANDLE;
|
||||
}
|
||||
|
||||
Handle_t hndl = g_DBMan.CreateHandle(DBHandle_Database, db, pContext->GetIdentity());
|
||||
if (!hndl)
|
||||
{
|
||||
db->Close();
|
||||
return BAD_HANDLE;
|
||||
}
|
||||
|
||||
/* HACK! Add us to the dependency list */
|
||||
CExtension *pExt = g_Extensions.GetExtensionFromIdent(driver->GetIdentity());
|
||||
if (pExt)
|
||||
@ -101,7 +108,7 @@ static cell_t SQL_Connect(IPluginContext *pContext, const cell_t *params)
|
||||
g_Extensions.BindChildPlugin(pExt, g_PluginSys.FindPluginByContext(pContext->GetContext()));
|
||||
}
|
||||
|
||||
return db->GetHandle();
|
||||
return hndl;
|
||||
}
|
||||
|
||||
static cell_t SQL_ConnectEx(IPluginContext *pContext, const cell_t *params)
|
||||
@ -146,6 +153,13 @@ static cell_t SQL_ConnectEx(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
if (db)
|
||||
{
|
||||
Handle_t hndl = g_DBMan.CreateHandle(DBHandle_Database, db, pContext->GetIdentity());
|
||||
if (!hndl)
|
||||
{
|
||||
db->Close();
|
||||
return BAD_HANDLE;
|
||||
}
|
||||
|
||||
/* HACK! Add us to the dependency list */
|
||||
CExtension *pExt = g_Extensions.GetExtensionFromIdent(driver->GetIdentity());
|
||||
if (pExt)
|
||||
@ -153,7 +167,7 @@ static cell_t SQL_ConnectEx(IPluginContext *pContext, const cell_t *params)
|
||||
g_Extensions.BindChildPlugin(pExt, g_PluginSys.FindPluginByContext(pContext->GetContext()));
|
||||
}
|
||||
|
||||
return db->GetHandle();
|
||||
return hndl;
|
||||
}
|
||||
|
||||
return BAD_HANDLE;
|
||||
|
@ -56,7 +56,7 @@ DBType GetOurType(enum_field_types type)
|
||||
}
|
||||
|
||||
MyDatabase::MyDatabase(MYSQL *mysql, const DatabaseInfo *info, bool persistent)
|
||||
: m_mysql(mysql), m_refcount(1), m_handle(BAD_HANDLE), m_bPersistent(persistent)
|
||||
: m_mysql(mysql), m_refcount(1), m_bPersistent(persistent)
|
||||
{
|
||||
m_Host.assign(info->host);
|
||||
m_Database.assign(info->database);
|
||||
@ -83,7 +83,7 @@ void MyDatabase::IncRefCount()
|
||||
m_refcount++;
|
||||
}
|
||||
|
||||
bool MyDatabase::Close(bool fromHndlSys)
|
||||
bool MyDatabase::Close()
|
||||
{
|
||||
if (m_refcount > 1)
|
||||
{
|
||||
@ -91,48 +91,18 @@ bool MyDatabase::Close(bool fromHndlSys)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If we don't have a Handle and the Handle is
|
||||
* is from the Handle System, it means we need
|
||||
* to block a re-entrant call from our own
|
||||
* FreeHandle().
|
||||
*/
|
||||
if (fromHndlSys && (m_handle == BAD_HANDLE))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Remove us from the search list */
|
||||
if (m_bPersistent)
|
||||
{
|
||||
g_MyDriver.RemoveFromList(this, true);
|
||||
}
|
||||
|
||||
/* If we're not from the Handle system, and
|
||||
* we have a Handle, we need to free it first.
|
||||
*/
|
||||
if (!fromHndlSys && m_handle != BAD_HANDLE)
|
||||
{
|
||||
Handle_t hndl = m_handle;
|
||||
m_handle = BAD_HANDLE;
|
||||
dbi->ReleaseHandle(hndl, DBHandle_Database, myself->GetIdentity());
|
||||
}
|
||||
|
||||
/* Finally, free our resource(s) */
|
||||
delete this;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Handle_t MyDatabase::GetHandle()
|
||||
{
|
||||
if (m_handle == BAD_HANDLE)
|
||||
{
|
||||
m_handle = dbi->CreateHandle(DBHandle_Database, this, myself->GetIdentity());
|
||||
}
|
||||
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
const DatabaseInfo &MyDatabase::GetInfo()
|
||||
{
|
||||
return m_Info;
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
MyDatabase(MYSQL *mysql, const DatabaseInfo *info, bool persistent);
|
||||
~MyDatabase();
|
||||
public: //IDatabase
|
||||
bool Close(bool fromHndlSys=false);
|
||||
bool Close();
|
||||
const char *GetError(int *errorCode=NULL);
|
||||
bool DoSimpleQuery(const char *query);
|
||||
IQuery *DoQuery(const char *query);
|
||||
@ -22,14 +22,12 @@ public: //IDatabase
|
||||
bool QuoteString(const char *str, char buffer[], size_t maxlen, size_t *newSize);
|
||||
unsigned int GetAffectedRows();
|
||||
unsigned int GetInsertID();
|
||||
Handle_t GetHandle();
|
||||
public:
|
||||
const DatabaseInfo &GetInfo();
|
||||
void IncRefCount();
|
||||
private:
|
||||
MYSQL *m_mysql;
|
||||
unsigned int m_refcount;
|
||||
Handle_t m_handle;
|
||||
|
||||
/* ---------- */
|
||||
DatabaseInfo m_Info;
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#define SMINTERFACE_DBI_NAME "IDBI"
|
||||
#define SMINTERFACE_DBI_VERSION 2
|
||||
#define SMINTERFACE_DBI_VERSION 3
|
||||
|
||||
namespace SourceMod
|
||||
{
|
||||
@ -409,13 +409,11 @@ namespace SourceMod
|
||||
*
|
||||
* It is guaranteed that an IDatabase pointer won't be destroyed until
|
||||
* all open IQuery or IPreparedQuery pointers are closed.
|
||||
*
|
||||
* @param Only pass true if being called from an
|
||||
* IHandleTypeDispatch destructor.
|
||||
*
|
||||
* @return True if object was destroyed, false if
|
||||
* references are remaining.
|
||||
*/
|
||||
virtual bool Close(bool fromHndlSys=false) =0;
|
||||
virtual bool Close() =0;
|
||||
|
||||
/**
|
||||
* @brief Error code and string returned by the last operation on this
|
||||
@ -486,13 +484,6 @@ namespace SourceMod
|
||||
* @return Row insertion ID of the last execute, if any.
|
||||
*/
|
||||
virtual unsigned int GetInsertID() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns an IDatabase Handle to this IDatabase.
|
||||
*
|
||||
* @return Handle_t of type IDatabase.
|
||||
*/
|
||||
virtual Handle_t GetHandle() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user