Cleanup and applying code style to some Database files.
--HG-- branch : trunk
This commit is contained in:
@@ -32,7 +32,6 @@ DBCFileLoader::DBCFileLoader()
|
|||||||
|
|
||||||
bool DBCFileLoader::Load(const char *filename, const char *fmt)
|
bool DBCFileLoader::Load(const char *filename, const char *fmt)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint32 header;
|
uint32 header;
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
@@ -41,12 +40,14 @@ bool DBCFileLoader::Load(const char *filename, const char *fmt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FILE * f = fopen(filename,"rb");
|
FILE * f = fopen(filename,"rb");
|
||||||
if(!f)return false;
|
if (!f)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (fread(&header,4,1,f)!=1) // Number of records
|
if (fread(&header,4,1,f)!=1) // Number of records
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
EndianConvert(header);
|
EndianConvert(header);
|
||||||
|
|
||||||
if (header!=0x43424457)
|
if (header!=0x43424457)
|
||||||
return false; //'WDBC'
|
return false; //'WDBC'
|
||||||
|
|
||||||
@@ -88,6 +89,7 @@ bool DBCFileLoader::Load(const char *filename, const char *fmt)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +97,7 @@ DBCFileLoader::~DBCFileLoader()
|
|||||||
{
|
{
|
||||||
if (data)
|
if (data)
|
||||||
delete [] data;
|
delete [] data;
|
||||||
|
|
||||||
if (fieldsOffset)
|
if (fieldsOffset)
|
||||||
delete [] fieldsOffset;
|
delete [] fieldsOffset;
|
||||||
}
|
}
|
||||||
@@ -110,6 +113,7 @@ uint32 DBCFileLoader::GetFormatRecordSize(const char * format,int32* index_pos)
|
|||||||
uint32 recordsize = 0;
|
uint32 recordsize = 0;
|
||||||
int32 i = -1;
|
int32 i = -1;
|
||||||
for (uint32 x=0; format[x]; ++x)
|
for (uint32 x=0; format[x]; ++x)
|
||||||
|
{
|
||||||
switch(format[x])
|
switch(format[x])
|
||||||
{
|
{
|
||||||
case FT_FLOAT:
|
case FT_FLOAT:
|
||||||
@@ -130,6 +134,7 @@ uint32 DBCFileLoader::GetFormatRecordSize(const char * format,int32* index_pos)
|
|||||||
recordsize += 1;
|
recordsize += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (index_pos)
|
if (index_pos)
|
||||||
*index_pos = i;
|
*index_pos = i;
|
||||||
@@ -190,9 +195,7 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
|||||||
for (uint32 y =0; y<recordCount; ++y)
|
for (uint32 y =0; y<recordCount; ++y)
|
||||||
{
|
{
|
||||||
if(i>=0)
|
if(i>=0)
|
||||||
{
|
|
||||||
indexTable[getRecord(y).getUInt(i)]=&dataTable[offset];
|
indexTable[getRecord(y).getUInt(i)]=&dataTable[offset];
|
||||||
}
|
|
||||||
else
|
else
|
||||||
indexTable[y]=&dataTable[offset];
|
indexTable[y]=&dataTable[offset];
|
||||||
|
|
||||||
@@ -220,6 +223,7 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlDataTable = dataTable + offset;
|
sqlDataTable = dataTable + offset;
|
||||||
|
|
||||||
return dataTable;
|
return dataTable;
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
Database::~Database()
|
Database::~Database()
|
||||||
{
|
{
|
||||||
/*Delete objects*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Database::Initialize(const char *)
|
bool Database::Initialize(const char *)
|
||||||
@@ -114,12 +113,12 @@ bool Database::PExecuteLog(const char * format,...)
|
|||||||
void Database::SetResultQueue(SqlResultQueue * queue)
|
void Database::SetResultQueue(SqlResultQueue * queue)
|
||||||
{
|
{
|
||||||
m_queryQueues[ACE_Based::Thread::current()] = queue;
|
m_queryQueues[ACE_Based::Thread::current()] = queue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryResult_AutoPtr Database::PQuery(const char *format,...)
|
QueryResult_AutoPtr Database::PQuery(const char *format,...)
|
||||||
{
|
{
|
||||||
if(!format) return QueryResult_AutoPtr(NULL);
|
if (!format)
|
||||||
|
return QueryResult_AutoPtr(NULL);
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char szQuery [MAX_QUERY_LEN];
|
char szQuery [MAX_QUERY_LEN];
|
||||||
@@ -138,7 +137,8 @@ QueryResult_AutoPtr Database::PQuery(const char *format,...)
|
|||||||
|
|
||||||
QueryNamedResult* Database::PQueryNamed(const char *format,...)
|
QueryNamedResult* Database::PQueryNamed(const char *format,...)
|
||||||
{
|
{
|
||||||
if(!format) return NULL;
|
if (!format)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char szQuery [MAX_QUERY_LEN];
|
char szQuery [MAX_QUERY_LEN];
|
||||||
|
|||||||
@@ -18,11 +18,14 @@
|
|||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "Database/Database.h"
|
#include "Database/Database.h"
|
||||||
#include "Database/SqlOperations.h"
|
#include "Database/SqlOperations.h"
|
||||||
|
|
||||||
|
|
||||||
/// Function body definitions for the template function members of the Database class
|
/// Function body definitions for the template function members of the Database class
|
||||||
|
|
||||||
|
|
||||||
#define ASYNC_QUERY_BODY(sql, queue_itr) \
|
#define ASYNC_QUERY_BODY(sql, queue_itr) \
|
||||||
if (!sql) return false; \
|
if (!sql) return false; \
|
||||||
\
|
\
|
||||||
@@ -34,6 +37,7 @@
|
|||||||
if (queue_itr == m_queryQueues.end()) return false; \
|
if (queue_itr == m_queryQueues.end()) return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define ASYNC_PQUERY_BODY(format, szQuery) \
|
#define ASYNC_PQUERY_BODY(format, szQuery) \
|
||||||
if(!format) return false; \
|
if(!format) return false; \
|
||||||
\
|
\
|
||||||
@@ -53,6 +57,7 @@
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define ASYNC_DELAYHOLDER_BODY(holder, queue_itr) \
|
#define ASYNC_DELAYHOLDER_BODY(holder, queue_itr) \
|
||||||
if (!holder) return false; \
|
if (!holder) return false; \
|
||||||
\
|
\
|
||||||
@@ -64,8 +69,10 @@
|
|||||||
if (queue_itr == m_queryQueues.end()) return false; \
|
if (queue_itr == m_queryQueues.end()) return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- Query / member --
|
// -- Query / member --
|
||||||
|
|
||||||
|
|
||||||
template<class Class>
|
template<class Class>
|
||||||
bool
|
bool
|
||||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *sql)
|
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *sql)
|
||||||
@@ -74,6 +81,7 @@ Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr),
|
|||||||
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class>(object, method), itr->second));
|
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class>(object, method), itr->second));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Class, typename ParamType1>
|
template<class Class, typename ParamType1>
|
||||||
bool
|
bool
|
||||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql)
|
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql)
|
||||||
@@ -82,6 +90,7 @@ Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, P
|
|||||||
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1>(object, method, (QueryResult_AutoPtr)NULL, param1), itr->second));
|
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1>(object, method, (QueryResult_AutoPtr)NULL, param1), itr->second));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Class, typename ParamType1, typename ParamType2>
|
template<class Class, typename ParamType1, typename ParamType2>
|
||||||
bool
|
bool
|
||||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
|
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
|
||||||
@@ -90,6 +99,7 @@ Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, P
|
|||||||
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult_AutoPtr)NULL, param1, param2), itr->second));
|
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult_AutoPtr)NULL, param1, param2), itr->second));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
||||||
bool
|
bool
|
||||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
|
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
|
||||||
@@ -98,8 +108,10 @@ Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, P
|
|||||||
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, (QueryResult_AutoPtr)NULL, param1, param2, param3), itr->second));
|
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, (QueryResult_AutoPtr)NULL, param1, param2, param3), itr->second));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- Query / static --
|
// -- Query / static --
|
||||||
|
|
||||||
|
|
||||||
template<typename ParamType1>
|
template<typename ParamType1>
|
||||||
bool
|
bool
|
||||||
Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql)
|
Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql)
|
||||||
@@ -108,6 +120,7 @@ Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1
|
|||||||
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1>(method, (QueryResult_AutoPtr)NULL, param1), itr->second));
|
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1>(method, (QueryResult_AutoPtr)NULL, param1), itr->second));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename ParamType1, typename ParamType2>
|
template<typename ParamType1, typename ParamType2>
|
||||||
bool
|
bool
|
||||||
Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
|
Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
|
||||||
@@ -116,6 +129,7 @@ Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2)
|
|||||||
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult_AutoPtr)NULL, param1, param2), itr->second));
|
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult_AutoPtr)NULL, param1, param2), itr->second));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
||||||
bool
|
bool
|
||||||
Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
|
Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
|
||||||
@@ -124,8 +138,10 @@ Database::AsyncQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2,
|
|||||||
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, (QueryResult_AutoPtr)NULL, param1, param2, param3), itr->second));
|
return m_threadBody->Delay(new SqlQuery(sql, new Trinity::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, (QueryResult_AutoPtr)NULL, param1, param2, param3), itr->second));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- PQuery / member --
|
// -- PQuery / member --
|
||||||
|
|
||||||
|
|
||||||
template<class Class>
|
template<class Class>
|
||||||
bool
|
bool
|
||||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *format,...)
|
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr), const char *format,...)
|
||||||
@@ -134,6 +150,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr),
|
|||||||
return AsyncQuery(object, method, szQuery);
|
return AsyncQuery(object, method, szQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Class, typename ParamType1>
|
template<class Class, typename ParamType1>
|
||||||
bool
|
bool
|
||||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...)
|
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...)
|
||||||
@@ -142,6 +159,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr,
|
|||||||
return AsyncQuery(object, method, param1, szQuery);
|
return AsyncQuery(object, method, param1, szQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Class, typename ParamType1, typename ParamType2>
|
template<class Class, typename ParamType1, typename ParamType2>
|
||||||
bool
|
bool
|
||||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
|
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
|
||||||
@@ -150,6 +168,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr,
|
|||||||
return AsyncQuery(object, method, param1, param2, szQuery);
|
return AsyncQuery(object, method, param1, param2, szQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
||||||
bool
|
bool
|
||||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
|
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
|
||||||
@@ -158,8 +177,10 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult_AutoPtr,
|
|||||||
return AsyncQuery(object, method, param1, param2, param3, szQuery);
|
return AsyncQuery(object, method, param1, param2, param3, szQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- PQuery / static --
|
// -- PQuery / static --
|
||||||
|
|
||||||
|
|
||||||
template<typename ParamType1>
|
template<typename ParamType1>
|
||||||
bool
|
bool
|
||||||
Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...)
|
Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...)
|
||||||
@@ -168,6 +189,7 @@ Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1), ParamType
|
|||||||
return AsyncQuery(method, param1, szQuery);
|
return AsyncQuery(method, param1, szQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename ParamType1, typename ParamType2>
|
template<typename ParamType1, typename ParamType2>
|
||||||
bool
|
bool
|
||||||
Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
|
Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
|
||||||
@@ -176,6 +198,7 @@ Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2
|
|||||||
return AsyncQuery(method, param1, param2, szQuery);
|
return AsyncQuery(method, param1, param2, szQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
||||||
bool
|
bool
|
||||||
Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
|
Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
|
||||||
@@ -184,8 +207,10 @@ Database::AsyncPQuery(void (*method)(QueryResult_AutoPtr, ParamType1, ParamType2
|
|||||||
return AsyncQuery(method, param1, param2, param3, szQuery);
|
return AsyncQuery(method, param1, param2, param3, szQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- QueryHolder --
|
// -- QueryHolder --
|
||||||
|
|
||||||
|
|
||||||
template<class Class>
|
template<class Class>
|
||||||
bool
|
bool
|
||||||
Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*), SqlQueryHolder *holder)
|
Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*), SqlQueryHolder *holder)
|
||||||
@@ -194,6 +219,7 @@ Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_Auto
|
|||||||
return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult_AutoPtr)NULL, holder), m_threadBody, itr->second);
|
return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult_AutoPtr)NULL, holder), m_threadBody, itr->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Class, typename ParamType1>
|
template<class Class, typename ParamType1>
|
||||||
bool
|
bool
|
||||||
Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1)
|
Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_AutoPtr, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1)
|
||||||
@@ -202,7 +228,7 @@ Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult_Auto
|
|||||||
return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult_AutoPtr)NULL, holder, param1), m_threadBody, itr->second);
|
return holder->Execute(new Trinity::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult_AutoPtr)NULL, holder, param1), m_threadBody, itr->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#undef ASYNC_QUERY_BODY
|
#undef ASYNC_QUERY_BODY
|
||||||
#undef ASYNC_PQUERY_BODY
|
#undef ASYNC_PQUERY_BODY
|
||||||
#undef ASYNC_DELAYHOLDER_BODY
|
#undef ASYNC_DELAYHOLDER_BODY
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ DatabaseMysql::~DatabaseMysql()
|
|||||||
|
|
||||||
bool DatabaseMysql::Initialize(const char *infoString)
|
bool DatabaseMysql::Initialize(const char *infoString)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!Database::Initialize(infoString))
|
if (!Database::Initialize(infoString))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -143,24 +142,14 @@ bool DatabaseMysql::Initialize(const char *infoString)
|
|||||||
|
|
||||||
if (mMysql)
|
if (mMysql)
|
||||||
{
|
{
|
||||||
sLog.outDetail( "Connected to MySQL database at %s",
|
sLog.outDetail("Connected to MySQL database at %s", host.c_str());
|
||||||
host.c_str());
|
|
||||||
sLog.outString("MySQL client library: %s", mysql_get_client_info());
|
sLog.outString("MySQL client library: %s", mysql_get_client_info());
|
||||||
sLog.outString("MySQL server ver: %s ", mysql_get_server_info( mMysql));
|
sLog.outString("MySQL server ver: %s ", mysql_get_server_info( mMysql));
|
||||||
|
|
||||||
/*----------SET AUTOCOMMIT ON---------*/
|
|
||||||
// It seems mysql 5.0.x have enabled this feature
|
|
||||||
// by default. In crash case you can lose data!!!
|
|
||||||
// So better to turn this off
|
|
||||||
// ---
|
|
||||||
// This is wrong since Trinity use transactions,
|
|
||||||
// autocommit is turned of during it.
|
|
||||||
// Setting it to on makes atomic updates work
|
|
||||||
if (!mysql_autocommit(mMysql, 1))
|
if (!mysql_autocommit(mMysql, 1))
|
||||||
sLog.outDetail("AUTOCOMMIT SUCCESSFULLY SET TO 1");
|
sLog.outDetail("AUTOCOMMIT SUCCESSFULLY SET TO 1");
|
||||||
else
|
else
|
||||||
sLog.outDetail("AUTOCOMMIT NOT SET TO 1");
|
sLog.outDetail("AUTOCOMMIT NOT SET TO 1");
|
||||||
/*-------------------------------------*/
|
|
||||||
|
|
||||||
// set connection properties to UTF8 to properly handle locales for different
|
// set connection properties to UTF8 to properly handle locales for different
|
||||||
// server configs - core sends data in UTF8, so MySQL must expect UTF8 too
|
// server configs - core sends data in UTF8, so MySQL must expect UTF8 too
|
||||||
@@ -170,13 +159,9 @@ bool DatabaseMysql::Initialize(const char *infoString)
|
|||||||
#if MYSQL_VERSION_ID >= 50003
|
#if MYSQL_VERSION_ID >= 50003
|
||||||
my_bool my_true = (my_bool)1;
|
my_bool my_true = (my_bool)1;
|
||||||
if (mysql_options(mMysql, MYSQL_OPT_RECONNECT, &my_true))
|
if (mysql_options(mMysql, MYSQL_OPT_RECONNECT, &my_true))
|
||||||
{
|
|
||||||
sLog.outDetail("Failed to turn on MYSQL_OPT_RECONNECT.");
|
sLog.outDetail("Failed to turn on MYSQL_OPT_RECONNECT.");
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
sLog.outDetail("Successfully turned on MYSQL_OPT_RECONNECT.");
|
sLog.outDetail("Successfully turned on MYSQL_OPT_RECONNECT.");
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
#warning "Your mySQL client lib version does not support reconnecting after a timeout.\nIf this causes you any trouble we advice you to upgrade your mySQL client libs to at least mySQL 5.0.13 to resolve this problem."
|
#warning "Your mySQL client lib version does not support reconnecting after a timeout.\nIf this causes you any trouble we advice you to upgrade your mySQL client libs to at least mySQL 5.0.13 to resolve this problem."
|
||||||
#endif
|
#endif
|
||||||
@@ -185,8 +170,7 @@ bool DatabaseMysql::Initialize(const char *infoString)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sLog.outError( "Could not connect to MySQL database at %s: %s\n",
|
sLog.outError("Could not connect to MySQL database at %s: %s\n", host.c_str(),mysql_error(mysqlInit));
|
||||||
host.c_str(),mysql_error(mysqlInit));
|
|
||||||
mysql_close(mysqlInit);
|
mysql_close(mysqlInit);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -219,7 +203,6 @@ bool DatabaseMysql::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **p
|
|||||||
*pResult = mysql_store_result(mMysql);
|
*pResult = mysql_store_result(mMysql);
|
||||||
*pRowCount = mysql_affected_rows(mMysql);
|
*pRowCount = mysql_affected_rows(mMysql);
|
||||||
*pFieldCount = mysql_field_count(mMysql);
|
*pFieldCount = mysql_field_count(mMysql);
|
||||||
// end guarded block
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*pResult )
|
if (!*pResult )
|
||||||
@@ -279,19 +262,15 @@ bool DatabaseMysql::Execute(const char *sql)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// don't use queued execution if it has not been initialized
|
// don't use queued execution if it has not been initialized
|
||||||
if (!m_threadBody) return DirectExecute(sql);
|
if (!m_threadBody)
|
||||||
|
return DirectExecute(sql);
|
||||||
|
|
||||||
tranThread = ACE_Based::Thread::current(); // owner of this transaction
|
tranThread = ACE_Based::Thread::current(); // owner of this transaction
|
||||||
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
|
TransactionQueues::iterator i = m_tranQueues.find(tranThread);
|
||||||
if (i != m_tranQueues.end() && i->second != NULL)
|
if (i != m_tranQueues.end() && i->second != NULL)
|
||||||
{ // Statement for transaction
|
i->second->DelayExecute(sql); // Statement for transaction
|
||||||
i->second->DelayExecute(sql);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
m_threadBody->Delay(new SqlStatement(sql)); // Simple sql statement
|
||||||
// Simple sql statement
|
|
||||||
m_threadBody->Delay(new SqlStatement(sql));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -320,7 +299,6 @@ bool DatabaseMysql::DirectExecute(const char* sql)
|
|||||||
sLog.outDebug("[%u ms] SQL: %s", getMSTimeDiff(_s,getMSTime()), sql);
|
sLog.outDebug("[%u ms] SQL: %s", getMSTimeDiff(_s,getMSTime()), sql);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// end guarded block
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -335,9 +313,8 @@ bool DatabaseMysql::_TransactionCmd(const char *sql)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
DEBUG_LOG("SQL: %s", sql);
|
DEBUG_LOG("SQL: %s", sql);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,6 +360,7 @@ bool DatabaseMysql::CommitTransaction()
|
|||||||
{
|
{
|
||||||
if (tranThread != ACE_Based::Thread::current())
|
if (tranThread != ACE_Based::Thread::current())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool _res = _TransactionCmd("COMMIT");
|
bool _res = _TransactionCmd("COMMIT");
|
||||||
tranThread = NULL;
|
tranThread = NULL;
|
||||||
mMutex.release();
|
mMutex.release();
|
||||||
@@ -411,6 +389,7 @@ bool DatabaseMysql::RollbackTransaction()
|
|||||||
{
|
{
|
||||||
if (tranThread != ACE_Based::Thread::current())
|
if (tranThread != ACE_Based::Thread::current())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool _res = _TransactionCmd("ROLLBACK");
|
bool _res = _TransactionCmd("ROLLBACK");
|
||||||
tranThread = NULL;
|
tranThread = NULL;
|
||||||
mMutex.release();
|
mMutex.release();
|
||||||
@@ -424,6 +403,7 @@ bool DatabaseMysql::RollbackTransaction()
|
|||||||
delete i->second;
|
delete i->second;
|
||||||
i->second = NULL;
|
i->second = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,7 +426,8 @@ void DatabaseMysql::InitDelayThread()
|
|||||||
|
|
||||||
void DatabaseMysql::HaltDelayThread()
|
void DatabaseMysql::HaltDelayThread()
|
||||||
{
|
{
|
||||||
if (!m_threadBody || !m_delayThread) return;
|
if (!m_threadBody || !m_delayThread)
|
||||||
|
return;
|
||||||
|
|
||||||
m_threadBody->Stop(); //Stop event
|
m_threadBody->Stop(); //Stop event
|
||||||
m_delayThread->wait(); //Wait for flush to DB
|
m_delayThread->wait(); //Wait for flush to DB
|
||||||
@@ -455,4 +436,3 @@ void DatabaseMysql::HaltDelayThread()
|
|||||||
m_threadBody = NULL;
|
m_threadBody = NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -50,12 +50,14 @@ mType(type)
|
|||||||
|
|
||||||
Field::~Field()
|
Field::~Field()
|
||||||
{
|
{
|
||||||
if(mValue) delete [] mValue;
|
if (mValue)
|
||||||
|
delete [] mValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Field::SetValue(const char *value)
|
void Field::SetValue(const char *value)
|
||||||
{
|
{
|
||||||
if(mValue) delete [] mValue;
|
if (mValue)
|
||||||
|
delete [] mValue;
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
@@ -65,4 +67,3 @@ void Field::SetValue(const char *value)
|
|||||||
else
|
else
|
||||||
mValue = NULL;
|
mValue = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,4 +105,3 @@ enum Field::DataTypes QueryResultMysql::ConvertNativeType(enum_field_types mysql
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -48,4 +48,3 @@ class QueryResultMysql : public QueryResult
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ void SqlDelayThread::run()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
SqlAsyncTask * s = NULL;
|
SqlAsyncTask * s = NULL;
|
||||||
// Lets wait for next async task no more than 2 secs
|
|
||||||
ACE_Time_Value _time(2);
|
ACE_Time_Value _time(2);
|
||||||
while (m_running)
|
while (m_running)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,4 +48,3 @@ class SqlDelayThread : public ACE_Based::Runnable
|
|||||||
virtual void run(); ///< Main Thread loop
|
virtual void run(); ///< Main Thread loop
|
||||||
};
|
};
|
||||||
#endif //__SQLDELAYTHREAD_H
|
#endif //__SQLDELAYTHREAD_H
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ void SqlTransaction::Execute(Database *db)
|
|||||||
|
|
||||||
free((void*)const_cast<char*>(sql));
|
free((void*)const_cast<char*>(sql));
|
||||||
}
|
}
|
||||||
|
|
||||||
db->DirectExecute("COMMIT");
|
db->DirectExecute("COMMIT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ void SqlQuery::Execute(Database *db)
|
|||||||
{
|
{
|
||||||
if (!m_callback || !m_queue)
|
if (!m_callback || !m_queue)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/// execute the query and store the result in the callback
|
/// execute the query and store the result in the callback
|
||||||
m_callback->SetResult(db->Query(m_sql));
|
m_callback->SetResult(db->Query(m_sql));
|
||||||
/// add the callback to the sql result queue of the thread it originated from
|
/// add the callback to the sql result queue of the thread it originated from
|
||||||
@@ -196,4 +198,3 @@ void SqlQueryHolderEx::Execute(Database *db)
|
|||||||
/// sync with the caller thread
|
/// sync with the caller thread
|
||||||
m_queue->add(m_callback);
|
m_queue->add(m_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user