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:
David Anderson
2007-06-01 21:26:52 +00:00
parent 3ed301e9af
commit a3687d9258
4 changed files with 22 additions and 49 deletions
+2 -32
View File
@@ -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;
+1 -3
View File
@@ -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;