new dbi API additions to support threading

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401101
This commit is contained in:
David Anderson
2007-07-13 19:19:30 +00:00
parent 41aa77314d
commit 93c9ffdf02
12 changed files with 202 additions and 20 deletions
+1 -1
View File
@@ -276,7 +276,7 @@ DBResult MyBasicResults::CopyBlob(unsigned int columnId, void *buffer, size_t ma
MyQuery::MyQuery(MyDatabase *db, MYSQL_RES *res)
: m_pParent(db), m_rs(res)
{
m_pParent->IncRefCount();
m_pParent->IncReferenceCount();
}
IResultSet *MyQuery::GetResultSet()
+31 -2
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_bPersistent(persistent)
: m_mysql(mysql), m_refcount(1), m_pFullLock(NULL), m_bPersistent(persistent)
{
m_Host.assign(info->host);
m_Database.assign(info->database);
@@ -78,7 +78,7 @@ MyDatabase::~MyDatabase()
m_mysql = NULL;
}
void MyDatabase::IncRefCount()
void MyDatabase::IncReferenceCount()
{
m_refcount++;
}
@@ -212,3 +212,32 @@ IPreparedQuery *MyDatabase::PrepareQuery(const char *query, char *error, size_t
return new MyStatement(this, stmt);
}
bool MyDatabase::LockForFullAtomicOperation()
{
if (!m_pFullLock)
{
m_pFullLock = threader->MakeMutex();
if (!m_pFullLock)
{
return false;
}
}
m_pFullLock->Lock();
return true;
}
void MyDatabase::UnlockFromFullAtomicOperation()
{
if (m_pFullLock)
{
m_pFullLock->Unlock();
}
}
IDBDriver *MyDatabase::GetDriver()
{
return &g_MyDriver;
}
+6 -1
View File
@@ -2,6 +2,7 @@
#define _INCLUDE_SM_MYSQL_DATABASE_H_
#include "MyDriver.h"
#include <IThreader.h>
class MyQuery;
class MyStatement;
@@ -22,12 +23,16 @@ public: //IDatabase
bool QuoteString(const char *str, char buffer[], size_t maxlen, size_t *newSize);
unsigned int GetAffectedRows();
unsigned int GetInsertID();
bool LockForFullAtomicOperation();
void UnlockFromFullAtomicOperation();
void IncReferenceCount();
IDBDriver *GetDriver();
public:
const DatabaseInfo &GetInfo();
void IncRefCount();
private:
MYSQL *m_mysql;
unsigned int m_refcount;
IMutex *m_pFullLock;
/* ---------- */
DatabaseInfo m_Info;
+16 -1
View File
@@ -121,7 +121,7 @@ IDatabase *MyDriver::Connect(const DatabaseInfo *info, bool persistent, char *er
&& CompareField(info->database, other.database)
&& (info->port == other.port))
{
db->IncRefCount();
db->IncReferenceCount();
return db;
}
}
@@ -151,6 +151,21 @@ void MyDriver::RemoveFromList(MyDatabase *pdb, bool persistent)
}
}
bool MyDriver::IsThreadSafe()
{
return (mysql_thread_safe() != 0);
}
bool MyDriver::InitializeThreadSafety()
{
return (mysql_thread_init() == 0);
}
void MyDriver::ShutdownThreadSafety()
{
mysql_thread_end();
}
unsigned int strncopy(char *dest, const char *src, size_t count)
{
if (!count)
+3
View File
@@ -29,6 +29,9 @@ public: //IDBDriver
const char *GetProductName();
Handle_t GetHandle();
IdentityToken_t *GetIdentity();
bool IsThreadSafe();
bool InitializeThreadSafety();
void ShutdownThreadSafety();
public:
void Shutdown();
void RemoveFromList(MyDatabase *pdb, bool persistent);
+1 -1
View File
@@ -17,7 +17,7 @@ MyStatement::MyStatement(MyDatabase *db, MYSQL_STMT *stmt)
m_bind = NULL;
}
m_pParent->IncRefCount();
m_pParent->IncReferenceCount();
m_pRes = mysql_stmt_result_metadata(stmt);
m_Results = false;