mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
Various Cleanups (shared/Database/)
This commit is contained in:
parent
9753625fd1
commit
c334cd5ea4
25 changed files with 508 additions and 508 deletions
|
|
@ -28,49 +28,49 @@ DBCFileLoader::DBCFileLoader()
|
|||
fieldsOffset = NULL;
|
||||
}
|
||||
|
||||
bool DBCFileLoader::Load(const char *filename, const char *fmt)
|
||||
bool DBCFileLoader::Load(const char* filename, const char* fmt)
|
||||
{
|
||||
|
||||
uint32 header;
|
||||
if(data)
|
||||
if (data)
|
||||
{
|
||||
delete [] data;
|
||||
data=NULL;
|
||||
}
|
||||
|
||||
FILE * f=fopen(filename,"rb");
|
||||
if(!f)return false;
|
||||
FILE* f=fopen(filename,"rb");
|
||||
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;
|
||||
|
||||
EndianConvert(header);
|
||||
if(header!=0x43424457)
|
||||
if (header!=0x43424457)
|
||||
return false; //'WDBC'
|
||||
|
||||
if(fread(&recordCount,4,1,f)!=1) // Number of records
|
||||
if (fread(&recordCount,4,1,f)!=1) // Number of records
|
||||
return false;
|
||||
|
||||
EndianConvert(recordCount);
|
||||
|
||||
if(fread(&fieldCount,4,1,f)!=1) // Number of fields
|
||||
if (fread(&fieldCount,4,1,f)!=1) // Number of fields
|
||||
return false;
|
||||
|
||||
EndianConvert(fieldCount);
|
||||
|
||||
if(fread(&recordSize,4,1,f)!=1) // Size of a record
|
||||
if (fread(&recordSize,4,1,f)!=1) // Size of a record
|
||||
return false;
|
||||
|
||||
EndianConvert(recordSize);
|
||||
|
||||
if(fread(&stringSize,4,1,f)!=1) // String size
|
||||
if (fread(&stringSize,4,1,f)!=1) // String size
|
||||
return false;
|
||||
|
||||
EndianConvert(stringSize);
|
||||
|
||||
fieldsOffset = new uint32[fieldCount];
|
||||
fieldsOffset[0] = 0;
|
||||
for(uint32 i = 1; i < fieldCount; i++)
|
||||
for (uint32 i = 1; i < fieldCount; i++)
|
||||
{
|
||||
fieldsOffset[i] = fieldsOffset[i - 1];
|
||||
if (fmt[i - 1] == 'b' || fmt[i - 1] == 'X') // byte fields
|
||||
|
|
@ -82,7 +82,7 @@ bool DBCFileLoader::Load(const char *filename, const char *fmt)
|
|||
data = new unsigned char[recordSize*recordCount+stringSize];
|
||||
stringTable = data + recordSize*recordCount;
|
||||
|
||||
if(fread(data,recordSize*recordCount+stringSize,1,f)!=1)
|
||||
if (fread(data,recordSize*recordCount+stringSize,1,f)!=1)
|
||||
return false;
|
||||
|
||||
fclose(f);
|
||||
|
|
@ -91,9 +91,9 @@ bool DBCFileLoader::Load(const char *filename, const char *fmt)
|
|||
|
||||
DBCFileLoader::~DBCFileLoader()
|
||||
{
|
||||
if(data)
|
||||
if (data)
|
||||
delete [] data;
|
||||
if(fieldsOffset)
|
||||
if (fieldsOffset)
|
||||
delete [] fieldsOffset;
|
||||
}
|
||||
|
||||
|
|
@ -103,13 +103,13 @@ DBCFileLoader::Record DBCFileLoader::getRecord(size_t id)
|
|||
return Record(*this, data + id*recordSize);
|
||||
}
|
||||
|
||||
uint32 DBCFileLoader::GetFormatRecordSize(const char * format,int32* index_pos)
|
||||
uint32 DBCFileLoader::GetFormatRecordSize(const char* format,int32* index_pos)
|
||||
{
|
||||
uint32 recordsize = 0;
|
||||
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:
|
||||
recordsize += sizeof(float);
|
||||
|
|
@ -161,22 +161,22 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
|||
this func will generate entry[rows] data;
|
||||
*/
|
||||
|
||||
typedef char * ptr;
|
||||
if(strlen(format)!=fieldCount)
|
||||
typedef char* ptr;
|
||||
if (strlen(format)!=fieldCount)
|
||||
return NULL;
|
||||
|
||||
//get struct size and index pos
|
||||
int32 i;
|
||||
uint32 recordsize=GetFormatRecordSize(format,&i);
|
||||
|
||||
if(i>=0)
|
||||
if (i>=0)
|
||||
{
|
||||
uint32 maxi=0;
|
||||
//find max index
|
||||
for(uint32 y=0;y<recordCount;y++)
|
||||
for (uint32 y=0; y<recordCount; y++)
|
||||
{
|
||||
uint32 ind=getRecord(y).getUInt (i);
|
||||
if(ind>maxi)maxi=ind;
|
||||
uint32 ind=getRecord(y).getUInt(i);
|
||||
if (ind>maxi)maxi=ind;
|
||||
}
|
||||
|
||||
++maxi;
|
||||
|
|
@ -194,7 +194,7 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
|||
|
||||
uint32 offset=0;
|
||||
|
||||
for(uint32 y =0; y < recordCount; ++y)
|
||||
for (uint32 y =0; y < recordCount; ++y)
|
||||
{
|
||||
if (i >= 0)
|
||||
{
|
||||
|
|
@ -203,9 +203,9 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
|||
else
|
||||
indexTable[y]=&dataTable[offset];
|
||||
|
||||
for(uint32 x = 0; x < fieldCount; ++x)
|
||||
for (uint32 x = 0; x < fieldCount; ++x)
|
||||
{
|
||||
switch(format[x])
|
||||
switch (format[x])
|
||||
{
|
||||
case FT_FLOAT:
|
||||
*((float*)(&dataTable[offset]))=getRecord(y).getFloat(x);
|
||||
|
|
@ -243,7 +243,7 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
|||
|
||||
char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
|
||||
{
|
||||
if(strlen(format)!=fieldCount)
|
||||
if (strlen(format)!=fieldCount)
|
||||
return NULL;
|
||||
|
||||
char* stringPool= new char[stringSize];
|
||||
|
|
@ -251,11 +251,11 @@ char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
|
|||
|
||||
uint32 offset=0;
|
||||
|
||||
for(uint32 y =0; y < recordCount; ++y)
|
||||
for (uint32 y =0; y < recordCount; ++y)
|
||||
{
|
||||
for(uint32 x = 0; x < fieldCount; ++x)
|
||||
for (uint32 x = 0; x < fieldCount; ++x)
|
||||
{
|
||||
switch(format[x])
|
||||
switch (format[x])
|
||||
{
|
||||
case FT_FLOAT:
|
||||
offset += sizeof(float);
|
||||
|
|
@ -271,9 +271,9 @@ char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
|
|||
{
|
||||
// fill only not filled entries
|
||||
char** slot = (char**)(&dataTable[offset]);
|
||||
if(!*slot || !**slot)
|
||||
if (!*slot || !** slot)
|
||||
{
|
||||
const char * st = getRecord(y).getString(x);
|
||||
const char* st = getRecord(y).getString(x);
|
||||
*slot=stringPool+(st-(const char*)stringTable);
|
||||
}
|
||||
offset += sizeof(char*);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class DBCFileLoader
|
|||
DBCFileLoader();
|
||||
~DBCFileLoader();
|
||||
|
||||
bool Load(const char *filename, const char *fmt);
|
||||
bool Load(const char* filename, const char* fmt);
|
||||
|
||||
class Record
|
||||
{
|
||||
|
|
@ -68,7 +68,7 @@ class DBCFileLoader
|
|||
return *reinterpret_cast<uint8*>(offset+file.GetOffset(field));
|
||||
}
|
||||
|
||||
const char *getString(size_t field) const
|
||||
const char* getString(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
size_t stringOffset = getUInt(field);
|
||||
|
|
@ -77,9 +77,9 @@ class DBCFileLoader
|
|||
}
|
||||
|
||||
private:
|
||||
Record(DBCFileLoader &file_, unsigned char *offset_): offset(offset_), file(file_) {}
|
||||
unsigned char *offset;
|
||||
DBCFileLoader &file;
|
||||
Record(DBCFileLoader& file_, unsigned char* offset_): offset(offset_), file(file_) {}
|
||||
unsigned char* offset;
|
||||
DBCFileLoader& file;
|
||||
|
||||
friend class DBCFileLoader;
|
||||
|
||||
|
|
@ -95,15 +95,15 @@ class DBCFileLoader
|
|||
bool IsLoaded() {return (data!=NULL);}
|
||||
char* AutoProduceData(const char* fmt, uint32& count, char**& indexTable);
|
||||
char* AutoProduceStrings(const char* fmt, char* dataTable);
|
||||
static uint32 GetFormatRecordSize(const char * format, int32 * index_pos = NULL);
|
||||
static uint32 GetFormatRecordSize(const char* format, int32* index_pos = NULL);
|
||||
private:
|
||||
|
||||
uint32 recordSize;
|
||||
uint32 recordCount;
|
||||
uint32 fieldCount;
|
||||
uint32 stringSize;
|
||||
uint32 *fieldsOffset;
|
||||
unsigned char *data;
|
||||
unsigned char *stringTable;
|
||||
uint32* fieldsOffset;
|
||||
unsigned char* data;
|
||||
unsigned char* stringTable;
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class DBCStorage
|
|||
{
|
||||
typedef std::list<char*> StringPoolList;
|
||||
public:
|
||||
explicit DBCStorage(const char *f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { }
|
||||
explicit DBCStorage(const char* f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { }
|
||||
~DBCStorage() { Clear(); }
|
||||
|
||||
T const* LookupEntry(uint32 id) const { return (id >= nCount) ? NULL : indexTable[id]; }
|
||||
|
|
@ -38,7 +38,7 @@ class DBCStorage
|
|||
{
|
||||
DBCFileLoader dbc;
|
||||
// Check if load was sucessful, only then continue
|
||||
if(!dbc.Load(fn, fmt))
|
||||
if (!dbc.Load(fn, fmt))
|
||||
return false;
|
||||
|
||||
fieldCount = dbc.GetCols();
|
||||
|
|
@ -56,12 +56,12 @@ class DBCStorage
|
|||
bool LoadStringsFrom(char const* fn)
|
||||
{
|
||||
// DBC must be already loaded using Load
|
||||
if(!indexTable)
|
||||
if (!indexTable)
|
||||
return false;
|
||||
|
||||
DBCFileLoader dbc;
|
||||
// Check if load was successful, only then continue
|
||||
if(!dbc.Load(fn, fmt))
|
||||
if (!dbc.Load(fn, fmt))
|
||||
return false;
|
||||
|
||||
// load strings from another locale dbc data
|
||||
|
|
@ -75,12 +75,12 @@ class DBCStorage
|
|||
if (!indexTable)
|
||||
return;
|
||||
|
||||
delete[] ((char*)indexTable);
|
||||
delete[]((char*)indexTable);
|
||||
indexTable = NULL;
|
||||
delete[] ((char*)m_dataTable);
|
||||
delete[]((char*)m_dataTable);
|
||||
m_dataTable = NULL;
|
||||
|
||||
while(!m_stringPoolList.empty())
|
||||
while (!m_stringPoolList.empty())
|
||||
{
|
||||
delete[] m_stringPoolList.front();
|
||||
m_stringPoolList.pop_front();
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
#define MAX_CONNECTION_POOL_SIZE 16
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
SqlPreparedStatement * SqlConnection::CreateStatement( const std::string& fmt )
|
||||
SqlPreparedStatement* SqlConnection::CreateStatement(const std::string& fmt)
|
||||
{
|
||||
return new SqlPlainPreparedStatement(fmt, *this);
|
||||
}
|
||||
|
|
@ -45,19 +45,19 @@ void SqlConnection::FreePreparedStatements()
|
|||
m_holder.clear();
|
||||
}
|
||||
|
||||
SqlPreparedStatement * SqlConnection::GetStmt( int nIndex )
|
||||
SqlPreparedStatement* SqlConnection::GetStmt(int nIndex)
|
||||
{
|
||||
if(nIndex < 0)
|
||||
if (nIndex < 0)
|
||||
return NULL;
|
||||
|
||||
//resize stmt container
|
||||
if(m_holder.size() <= nIndex)
|
||||
if (m_holder.size() <= nIndex)
|
||||
m_holder.resize(nIndex + 1, NULL);
|
||||
|
||||
SqlPreparedStatement * pStmt = NULL;
|
||||
SqlPreparedStatement* pStmt = NULL;
|
||||
|
||||
//create stmt if needed
|
||||
if(m_holder[nIndex] == NULL)
|
||||
if (m_holder[nIndex] == NULL)
|
||||
{
|
||||
//obtain SQL request string
|
||||
std::string fmt = m_db.GetStmtString(nIndex);
|
||||
|
|
@ -65,7 +65,7 @@ SqlPreparedStatement * SqlConnection::GetStmt( int nIndex )
|
|||
//allocate SQlPreparedStatement object
|
||||
pStmt = CreateStatement(fmt);
|
||||
//prepare statement
|
||||
if(!pStmt->prepare())
|
||||
if (!pStmt->prepare())
|
||||
{
|
||||
MANGOS_ASSERT(false && "Unable to prepare SQL statement");
|
||||
return NULL;
|
||||
|
|
@ -80,13 +80,13 @@ SqlPreparedStatement * SqlConnection::GetStmt( int nIndex )
|
|||
return pStmt;
|
||||
}
|
||||
|
||||
bool SqlConnection::ExecuteStmt(int nIndex, const SqlStmtParameters& id )
|
||||
bool SqlConnection::ExecuteStmt(int nIndex, const SqlStmtParameters& id)
|
||||
{
|
||||
if(nIndex == -1)
|
||||
if (nIndex == -1)
|
||||
return false;
|
||||
|
||||
//get prepared statement object
|
||||
SqlPreparedStatement * pStmt = GetStmt(nIndex);
|
||||
SqlPreparedStatement* pStmt = GetStmt(nIndex);
|
||||
//bind parameters
|
||||
pStmt->bind(id);
|
||||
//execute statement
|
||||
|
|
@ -99,26 +99,26 @@ Database::~Database()
|
|||
StopServer();
|
||||
}
|
||||
|
||||
bool Database::Initialize(const char * infoString, int nConns /*= 1*/)
|
||||
bool Database::Initialize(const char* infoString, int nConns /*= 1*/)
|
||||
{
|
||||
// Enable logging of SQL commands (usually only GM commands)
|
||||
// (See method: PExecuteLog)
|
||||
m_logSQL = sConfig.GetBoolDefault("LogSQL", false);
|
||||
m_logsDir = sConfig.GetStringDefault("LogsDir","");
|
||||
if(!m_logsDir.empty())
|
||||
if (!m_logsDir.empty())
|
||||
{
|
||||
if((m_logsDir.at(m_logsDir.length()-1)!='/') && (m_logsDir.at(m_logsDir.length()-1)!='\\'))
|
||||
if ((m_logsDir.at(m_logsDir.length()-1)!='/') && (m_logsDir.at(m_logsDir.length()-1)!='\\'))
|
||||
m_logsDir.append("/");
|
||||
}
|
||||
|
||||
m_pingIntervallms = sConfig.GetIntDefault ("MaxPingTime", 30) * (MINUTE * 1000);
|
||||
m_pingIntervallms = sConfig.GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000);
|
||||
|
||||
//create DB connections
|
||||
|
||||
//setup connection pool size
|
||||
if(nConns < MIN_CONNECTION_POOL_SIZE)
|
||||
if (nConns < MIN_CONNECTION_POOL_SIZE)
|
||||
m_nQueryConnPoolSize = MIN_CONNECTION_POOL_SIZE;
|
||||
else if(nConns > MAX_CONNECTION_POOL_SIZE)
|
||||
else if (nConns > MAX_CONNECTION_POOL_SIZE)
|
||||
m_nQueryConnPoolSize = MAX_CONNECTION_POOL_SIZE;
|
||||
else
|
||||
m_nQueryConnPoolSize = nConns;
|
||||
|
|
@ -126,8 +126,8 @@ bool Database::Initialize(const char * infoString, int nConns /*= 1*/)
|
|||
//create connection pool for sync requests
|
||||
for (int i = 0; i < m_nQueryConnPoolSize; ++i)
|
||||
{
|
||||
SqlConnection * pConn = CreateConnection();
|
||||
if(!pConn->Initialize(infoString))
|
||||
SqlConnection* pConn = CreateConnection();
|
||||
if (!pConn->Initialize(infoString))
|
||||
{
|
||||
delete pConn;
|
||||
return false;
|
||||
|
|
@ -138,7 +138,7 @@ bool Database::Initialize(const char * infoString, int nConns /*= 1*/)
|
|||
|
||||
//create and initialize connection for async requests
|
||||
m_pAsyncConn = CreateConnection();
|
||||
if(!m_pAsyncConn->Initialize(infoString))
|
||||
if (!m_pAsyncConn->Initialize(infoString))
|
||||
return false;
|
||||
|
||||
m_pResultQueue = new SqlResultQueue;
|
||||
|
|
@ -151,13 +151,13 @@ void Database::StopServer()
|
|||
{
|
||||
HaltDelayThread();
|
||||
/*Delete objects*/
|
||||
if(m_pResultQueue)
|
||||
if (m_pResultQueue)
|
||||
{
|
||||
delete m_pResultQueue;
|
||||
m_pResultQueue = NULL;
|
||||
}
|
||||
|
||||
if(m_pAsyncConn)
|
||||
if (m_pAsyncConn)
|
||||
{
|
||||
delete m_pAsyncConn;
|
||||
m_pAsyncConn = NULL;
|
||||
|
|
@ -170,7 +170,7 @@ void Database::StopServer()
|
|||
|
||||
}
|
||||
|
||||
SqlDelayThread * Database::CreateDelayThread()
|
||||
SqlDelayThread* Database::CreateDelayThread()
|
||||
{
|
||||
assert(m_pAsyncConn);
|
||||
return new SqlDelayThread(this, m_pAsyncConn);
|
||||
|
|
@ -206,13 +206,13 @@ void Database::ThreadEnd()
|
|||
|
||||
void Database::ProcessResultQueue()
|
||||
{
|
||||
if(m_pResultQueue)
|
||||
if (m_pResultQueue)
|
||||
m_pResultQueue->Update();
|
||||
}
|
||||
|
||||
void Database::escape_string(std::string& str)
|
||||
{
|
||||
if(str.empty())
|
||||
if (str.empty())
|
||||
return;
|
||||
|
||||
char* buf = new char[str.size()*2+1];
|
||||
|
|
@ -222,11 +222,11 @@ void Database::escape_string(std::string& str)
|
|||
delete[] buf;
|
||||
}
|
||||
|
||||
SqlConnection * Database::getQueryConnection()
|
||||
SqlConnection* Database::getQueryConnection()
|
||||
{
|
||||
int nCount = 0;
|
||||
|
||||
if(m_nQueryCounter == long(1 << 31))
|
||||
if (m_nQueryCounter == long(1 << 31))
|
||||
m_nQueryCounter = 0;
|
||||
else
|
||||
nCount = ++m_nQueryCounter;
|
||||
|
|
@ -236,7 +236,7 @@ SqlConnection * Database::getQueryConnection()
|
|||
|
||||
void Database::Ping()
|
||||
{
|
||||
const char * sql = "SELECT 1";
|
||||
const char* sql = "SELECT 1";
|
||||
|
||||
{
|
||||
SqlConnection::Lock guard(m_pAsyncConn);
|
||||
|
|
@ -250,7 +250,7 @@ void Database::Ping()
|
|||
}
|
||||
}
|
||||
|
||||
bool Database::PExecuteLog(const char * format,...)
|
||||
bool Database::PExecuteLog(const char* format,...)
|
||||
{
|
||||
if (!format)
|
||||
return false;
|
||||
|
|
@ -258,23 +258,23 @@ bool Database::PExecuteLog(const char * format,...)
|
|||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
if (res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return false;
|
||||
}
|
||||
|
||||
if( m_logSQL )
|
||||
if (m_logSQL)
|
||||
{
|
||||
time_t curr;
|
||||
tm local;
|
||||
time(&curr); // get current time_t value
|
||||
local=*(localtime(&curr)); // dereference and assign
|
||||
char fName[128];
|
||||
sprintf( fName, "%04d-%02d-%02d_logSQL.sql", local.tm_year+1900, local.tm_mon+1, local.tm_mday );
|
||||
sprintf(fName, "%04d-%02d-%02d_logSQL.sql", local.tm_year+1900, local.tm_mon+1, local.tm_mday);
|
||||
|
||||
FILE* log_file;
|
||||
std::string logsDir_fname = m_logsDir+fName;
|
||||
|
|
@ -294,17 +294,17 @@ bool Database::PExecuteLog(const char * format,...)
|
|||
return Execute(szQuery);
|
||||
}
|
||||
|
||||
QueryResult* Database::PQuery(const char *format,...)
|
||||
QueryResult* Database::PQuery(const char* format,...)
|
||||
{
|
||||
if(!format) return NULL;
|
||||
if (!format) return NULL;
|
||||
|
||||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
if (res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return NULL;
|
||||
|
|
@ -313,17 +313,17 @@ QueryResult* Database::PQuery(const char *format,...)
|
|||
return Query(szQuery);
|
||||
}
|
||||
|
||||
QueryNamedResult* Database::PQueryNamed(const char *format,...)
|
||||
QueryNamedResult* Database::PQueryNamed(const char* format,...)
|
||||
{
|
||||
if(!format) return NULL;
|
||||
if (!format) return NULL;
|
||||
|
||||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
if (res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return NULL;
|
||||
|
|
@ -332,13 +332,13 @@ QueryNamedResult* Database::PQueryNamed(const char *format,...)
|
|||
return QueryNamed(szQuery);
|
||||
}
|
||||
|
||||
bool Database::Execute(const char *sql)
|
||||
bool Database::Execute(const char* sql)
|
||||
{
|
||||
if (!m_pAsyncConn)
|
||||
return false;
|
||||
|
||||
SqlTransaction * pTrans = m_TransStorage->get();
|
||||
if(pTrans)
|
||||
SqlTransaction* pTrans = m_TransStorage->get();
|
||||
if (pTrans)
|
||||
{
|
||||
//add SQL request to trans queue
|
||||
pTrans->DelayExecute(new SqlPlainRequest(sql));
|
||||
|
|
@ -346,7 +346,7 @@ bool Database::Execute(const char *sql)
|
|||
else
|
||||
{
|
||||
//if async execution is not available
|
||||
if(!m_bAllowAsyncTransactions)
|
||||
if (!m_bAllowAsyncTransactions)
|
||||
return DirectExecute(sql);
|
||||
|
||||
// Simple sql statement
|
||||
|
|
@ -356,7 +356,7 @@ bool Database::Execute(const char *sql)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Database::PExecute(const char * format,...)
|
||||
bool Database::PExecute(const char* format,...)
|
||||
{
|
||||
if (!format)
|
||||
return false;
|
||||
|
|
@ -364,10 +364,10 @@ bool Database::PExecute(const char * format,...)
|
|||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
if (res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return false;
|
||||
|
|
@ -376,7 +376,7 @@ bool Database::PExecute(const char * format,...)
|
|||
return Execute(szQuery);
|
||||
}
|
||||
|
||||
bool Database::DirectPExecute(const char * format,...)
|
||||
bool Database::DirectPExecute(const char* format,...)
|
||||
{
|
||||
if (!format)
|
||||
return false;
|
||||
|
|
@ -384,10 +384,10 @@ bool Database::DirectPExecute(const char * format,...)
|
|||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
if (res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return false;
|
||||
|
|
@ -413,11 +413,11 @@ bool Database::CommitTransaction()
|
|||
return false;
|
||||
|
||||
//check if we have pending transaction
|
||||
if(!m_TransStorage->get())
|
||||
if (!m_TransStorage->get())
|
||||
return false;
|
||||
|
||||
//if async execution is not available
|
||||
if(!m_bAllowAsyncTransactions)
|
||||
if (!m_bAllowAsyncTransactions)
|
||||
return CommitTransactionDirect();
|
||||
|
||||
//add SqlTransaction to the async queue
|
||||
|
|
@ -431,11 +431,11 @@ bool Database::CommitTransactionDirect()
|
|||
return false;
|
||||
|
||||
//check if we have pending transaction
|
||||
if(!m_TransStorage->get())
|
||||
if (!m_TransStorage->get())
|
||||
return false;
|
||||
|
||||
//directly execute SqlTransaction
|
||||
SqlTransaction * pTrans = m_TransStorage->detach();
|
||||
SqlTransaction* pTrans = m_TransStorage->detach();
|
||||
pTrans->Execute(m_pAsyncConn);
|
||||
delete pTrans;
|
||||
|
||||
|
|
@ -447,7 +447,7 @@ bool Database::RollbackTransaction()
|
|||
if (!m_pAsyncConn)
|
||||
return false;
|
||||
|
||||
if(!m_TransStorage->get())
|
||||
if (!m_TransStorage->get())
|
||||
return false;
|
||||
|
||||
//remove scheduled transaction
|
||||
|
|
@ -456,11 +456,11 @@ bool Database::RollbackTransaction()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Database::CheckRequiredField( char const* table_name, char const* required_name )
|
||||
bool Database::CheckRequiredField(char const* table_name, char const* required_name)
|
||||
{
|
||||
// check required field
|
||||
QueryResult* result = PQuery("SELECT %s FROM %s LIMIT 1",required_name,table_name);
|
||||
if(result)
|
||||
if (result)
|
||||
{
|
||||
delete result;
|
||||
return true;
|
||||
|
|
@ -470,11 +470,11 @@ bool Database::CheckRequiredField( char const* table_name, char const* required_
|
|||
|
||||
// search current required_* field in DB
|
||||
const char* db_name;
|
||||
if(!strcmp(table_name, "db_version"))
|
||||
if (!strcmp(table_name, "db_version"))
|
||||
db_name = "WORLD";
|
||||
else if(!strcmp(table_name, "character_db_version"))
|
||||
else if (!strcmp(table_name, "character_db_version"))
|
||||
db_name = "CHARACTER";
|
||||
else if(!strcmp(table_name, "realmd_db_version"))
|
||||
else if (!strcmp(table_name, "realmd_db_version"))
|
||||
db_name = "REALMD";
|
||||
else
|
||||
db_name = "UNKNOWN";
|
||||
|
|
@ -482,13 +482,13 @@ bool Database::CheckRequiredField( char const* table_name, char const* required_
|
|||
char const* req_sql_update_name = required_name+strlen("required_");
|
||||
|
||||
QueryNamedResult* result2 = PQueryNamed("SELECT * FROM %s LIMIT 1",table_name);
|
||||
if(result2)
|
||||
if (result2)
|
||||
{
|
||||
QueryFieldNames const& namesMap = result2->GetFieldNames();
|
||||
std::string reqName;
|
||||
for(QueryFieldNames::const_iterator itr = namesMap.begin(); itr != namesMap.end(); ++itr)
|
||||
for (QueryFieldNames::const_iterator itr = namesMap.begin(); itr != namesMap.end(); ++itr)
|
||||
{
|
||||
if(itr->substr(0,9)=="required_")
|
||||
if (itr->substr(0,9)=="required_")
|
||||
{
|
||||
reqName = *itr;
|
||||
break;
|
||||
|
|
@ -499,7 +499,7 @@ bool Database::CheckRequiredField( char const* table_name, char const* required_
|
|||
|
||||
std::string cur_sql_update_name = reqName.substr(strlen("required_"),reqName.npos);
|
||||
|
||||
if(!reqName.empty())
|
||||
if (!reqName.empty())
|
||||
{
|
||||
sLog.outErrorDb("The table `%s` in your [%s] database indicates that this database is out of date!",table_name,db_name);
|
||||
sLog.outErrorDb();
|
||||
|
|
@ -520,7 +520,7 @@ bool Database::CheckRequiredField( char const* table_name, char const* required_
|
|||
sLog.outErrorDb("`%s.sql`",req_sql_update_name);
|
||||
sLog.outErrorDb();
|
||||
|
||||
if(!strcmp(db_name, "WORLD"))
|
||||
if (!strcmp(db_name, "WORLD"))
|
||||
sLog.outErrorDb("Post this error to your database provider forum or find a solution there.");
|
||||
else
|
||||
sLog.outErrorDb("Reinstall your [%s] database with the included sql file in the sql folder.",db_name);
|
||||
|
|
@ -535,7 +535,7 @@ bool Database::CheckRequiredField( char const* table_name, char const* required_
|
|||
sLog.outErrorDb("`%s.sql`",req_sql_update_name);
|
||||
sLog.outErrorDb();
|
||||
|
||||
if(!strcmp(db_name, "WORLD"))
|
||||
if (!strcmp(db_name, "WORLD"))
|
||||
sLog.outErrorDb("Post this error to your database provider forum or find a solution there.");
|
||||
else
|
||||
sLog.outErrorDb("Reinstall your [%s] database with the included sql file in the sql folder.",db_name);
|
||||
|
|
@ -544,13 +544,13 @@ bool Database::CheckRequiredField( char const* table_name, char const* required_
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Database::ExecuteStmt( const SqlStatementID& id, SqlStmtParameters * params )
|
||||
bool Database::ExecuteStmt(const SqlStatementID& id, SqlStmtParameters* params)
|
||||
{
|
||||
if (!m_pAsyncConn)
|
||||
return false;
|
||||
|
||||
SqlTransaction * pTrans = m_TransStorage->get();
|
||||
if(pTrans)
|
||||
SqlTransaction* pTrans = m_TransStorage->get();
|
||||
if (pTrans)
|
||||
{
|
||||
//add SQL request to trans queue
|
||||
pTrans->DelayExecute(new SqlPreparedRequest(id.ID(), params));
|
||||
|
|
@ -558,7 +558,7 @@ bool Database::ExecuteStmt( const SqlStatementID& id, SqlStmtParameters * params
|
|||
else
|
||||
{
|
||||
//if async execution is not available
|
||||
if(!m_bAllowAsyncTransactions)
|
||||
if (!m_bAllowAsyncTransactions)
|
||||
return DirectExecuteStmt(id, params);
|
||||
|
||||
// Simple sql statement
|
||||
|
|
@ -568,7 +568,7 @@ bool Database::ExecuteStmt( const SqlStatementID& id, SqlStmtParameters * params
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Database::DirectExecuteStmt( const SqlStatementID& id, SqlStmtParameters * params )
|
||||
bool Database::DirectExecuteStmt(const SqlStatementID& id, SqlStmtParameters* params)
|
||||
{
|
||||
MANGOS_ASSERT(params);
|
||||
std::auto_ptr<SqlStmtParameters> p(params);
|
||||
|
|
@ -577,11 +577,11 @@ bool Database::DirectExecuteStmt( const SqlStatementID& id, SqlStmtParameters *
|
|||
return _guard->ExecuteStmt(id.ID(), *params);
|
||||
}
|
||||
|
||||
SqlStatement Database::CreateStatement(SqlStatementID& index, const char * fmt )
|
||||
SqlStatement Database::CreateStatement(SqlStatementID& index, const char* fmt)
|
||||
{
|
||||
int nId = -1;
|
||||
//check if statement ID is initialized
|
||||
if(!index.initialized())
|
||||
if (!index.initialized())
|
||||
{
|
||||
//convert to lower register
|
||||
std::string szFmt(fmt);
|
||||
|
|
@ -590,7 +590,7 @@ SqlStatement Database::CreateStatement(SqlStatementID& index, const char * fmt )
|
|||
//find existing or add a new record in registry
|
||||
LOCK_GUARD _guard(m_stmtGuard);
|
||||
PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.find(szFmt);
|
||||
if(iter == m_stmtRegistry.end())
|
||||
if (iter == m_stmtRegistry.end())
|
||||
{
|
||||
nId = ++m_iStmtIndex;
|
||||
m_stmtRegistry[szFmt] = nId;
|
||||
|
|
@ -609,13 +609,13 @@ std::string Database::GetStmtString(const int stmtId) const
|
|||
{
|
||||
LOCK_GUARD _guard(m_stmtGuard);
|
||||
|
||||
if(stmtId == -1 || stmtId > m_iStmtIndex)
|
||||
if (stmtId == -1 || stmtId > m_iStmtIndex)
|
||||
return std::string();
|
||||
|
||||
PreparedStmtRegistry::const_iterator iter_last = m_stmtRegistry.end();
|
||||
for(PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.begin(); iter != iter_last; ++iter)
|
||||
for (PreparedStmtRegistry::const_iterator iter = m_stmtRegistry.begin(); iter != iter_last; ++iter)
|
||||
{
|
||||
if(iter->second == stmtId)
|
||||
if (iter->second == stmtId)
|
||||
return iter->first;
|
||||
}
|
||||
|
||||
|
|
@ -628,23 +628,23 @@ Database::TransHelper::~TransHelper()
|
|||
reset();
|
||||
}
|
||||
|
||||
SqlTransaction * Database::TransHelper::init()
|
||||
SqlTransaction* Database::TransHelper::init()
|
||||
{
|
||||
MANGOS_ASSERT(!m_pTrans); //if we will get a nested transaction request - we MUST fix code!!!
|
||||
m_pTrans = new SqlTransaction;
|
||||
return m_pTrans;
|
||||
}
|
||||
|
||||
SqlTransaction * Database::TransHelper::detach()
|
||||
SqlTransaction* Database::TransHelper::detach()
|
||||
{
|
||||
SqlTransaction * pRes = m_pTrans;
|
||||
SqlTransaction* pRes = m_pTrans;
|
||||
m_pTrans = NULL;
|
||||
return pRes;
|
||||
}
|
||||
|
||||
void Database::TransHelper::reset()
|
||||
{
|
||||
if(m_pTrans)
|
||||
if (m_pTrans)
|
||||
{
|
||||
delete m_pTrans;
|
||||
m_pTrans = NULL;
|
||||
|
|
|
|||
|
|
@ -44,16 +44,16 @@ class MANGOS_DLL_SPEC SqlConnection
|
|||
virtual ~SqlConnection() {}
|
||||
|
||||
//method for initializing DB connection
|
||||
virtual bool Initialize(const char *infoString) = 0;
|
||||
virtual bool Initialize(const char* infoString) = 0;
|
||||
//public methods for making queries
|
||||
virtual QueryResult* Query(const char *sql) = 0;
|
||||
virtual QueryNamedResult* QueryNamed(const char *sql) = 0;
|
||||
virtual QueryResult* Query(const char* sql) = 0;
|
||||
virtual QueryNamedResult* QueryNamed(const char* sql) = 0;
|
||||
|
||||
//public methods for making requests
|
||||
virtual bool Execute(const char *sql) = 0;
|
||||
virtual bool Execute(const char* sql) = 0;
|
||||
|
||||
//escape string generation
|
||||
virtual unsigned long escape_string(char *to, const char *from, unsigned long length) { strncpy(to,from,length); return length; }
|
||||
virtual unsigned long escape_string(char* to, const char* from, unsigned long length) { strncpy(to,from,length); return length; }
|
||||
|
||||
// nothing do if DB not support transactions
|
||||
virtual bool BeginTransaction() { return true; }
|
||||
|
|
@ -68,13 +68,13 @@ class MANGOS_DLL_SPEC SqlConnection
|
|||
class Lock
|
||||
{
|
||||
public:
|
||||
Lock(SqlConnection * conn) : m_pConn(conn) { m_pConn->m_mutex.acquire(); }
|
||||
Lock(SqlConnection* conn) : m_pConn(conn) { m_pConn->m_mutex.acquire(); }
|
||||
~Lock() { m_pConn->m_mutex.release(); }
|
||||
|
||||
SqlConnection * operator->() const { return m_pConn; }
|
||||
SqlConnection* operator->() const { return m_pConn; }
|
||||
|
||||
private:
|
||||
SqlConnection * const m_pConn;
|
||||
SqlConnection* const m_pConn;
|
||||
};
|
||||
|
||||
//get DB object
|
||||
|
|
@ -83,9 +83,9 @@ class MANGOS_DLL_SPEC SqlConnection
|
|||
protected:
|
||||
SqlConnection(Database& db) : m_db(db) {}
|
||||
|
||||
virtual SqlPreparedStatement * CreateStatement(const std::string& fmt);
|
||||
virtual SqlPreparedStatement* CreateStatement(const std::string& fmt);
|
||||
//allocate prepared statement and return statement ID
|
||||
SqlPreparedStatement * GetStmt(int nIndex);
|
||||
SqlPreparedStatement* GetStmt(int nIndex);
|
||||
|
||||
Database& m_db;
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ class MANGOS_DLL_SPEC SqlConnection
|
|||
typedef ACE_Recursive_Thread_Mutex LOCK_TYPE;
|
||||
LOCK_TYPE m_mutex;
|
||||
|
||||
typedef std::vector<SqlPreparedStatement * > StmtHolder;
|
||||
typedef std::vector<SqlPreparedStatement* > StmtHolder;
|
||||
StmtHolder m_holder;
|
||||
};
|
||||
|
||||
|
|
@ -105,84 +105,84 @@ class MANGOS_DLL_SPEC Database
|
|||
public:
|
||||
virtual ~Database();
|
||||
|
||||
virtual bool Initialize(const char *infoString, int nConns = 1);
|
||||
virtual bool Initialize(const char* infoString, int nConns = 1);
|
||||
//start worker thread for async DB request execution
|
||||
virtual void InitDelayThread();
|
||||
//stop worker thread
|
||||
virtual void HaltDelayThread();
|
||||
|
||||
/// Synchronous DB queries
|
||||
inline QueryResult* Query(const char *sql)
|
||||
inline QueryResult* Query(const char* sql)
|
||||
{
|
||||
SqlConnection::Lock guard(getQueryConnection());
|
||||
return guard->Query(sql);
|
||||
}
|
||||
|
||||
inline QueryNamedResult* QueryNamed(const char *sql)
|
||||
inline QueryNamedResult* QueryNamed(const char* sql)
|
||||
{
|
||||
SqlConnection::Lock guard(getQueryConnection());
|
||||
return guard->QueryNamed(sql);
|
||||
}
|
||||
|
||||
QueryResult* PQuery(const char *format,...) ATTR_PRINTF(2,3);
|
||||
QueryNamedResult* PQueryNamed(const char *format,...) ATTR_PRINTF(2,3);
|
||||
QueryResult* PQuery(const char* format,...) ATTR_PRINTF(2,3);
|
||||
QueryNamedResult* PQueryNamed(const char* format,...) ATTR_PRINTF(2,3);
|
||||
|
||||
inline bool DirectExecute(const char* sql)
|
||||
{
|
||||
if(!m_pAsyncConn)
|
||||
if (!m_pAsyncConn)
|
||||
return false;
|
||||
|
||||
SqlConnection::Lock guard(m_pAsyncConn);
|
||||
return guard->Execute(sql);
|
||||
}
|
||||
|
||||
bool DirectPExecute(const char *format,...) ATTR_PRINTF(2,3);
|
||||
bool DirectPExecute(const char* format,...) ATTR_PRINTF(2,3);
|
||||
|
||||
/// Async queries and query holders, implemented in DatabaseImpl.h
|
||||
|
||||
// Query / member
|
||||
template<class Class>
|
||||
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql);
|
||||
bool AsyncQuery(Class* object, void (Class::*method)(QueryResult*), const char* sql);
|
||||
template<class Class, typename ParamType1>
|
||||
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
|
||||
bool AsyncQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char* sql);
|
||||
template<class Class, typename ParamType1, typename ParamType2>
|
||||
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
|
||||
bool AsyncQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* sql);
|
||||
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
|
||||
bool AsyncQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* sql);
|
||||
// Query / static
|
||||
template<typename ParamType1>
|
||||
bool AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
|
||||
bool AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char* sql);
|
||||
template<typename ParamType1, typename ParamType2>
|
||||
bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
|
||||
bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* sql);
|
||||
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
|
||||
bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* sql);
|
||||
// PQuery / member
|
||||
template<class Class>
|
||||
bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) ATTR_PRINTF(4,5);
|
||||
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*), const char* format,...) ATTR_PRINTF(4,5);
|
||||
template<class Class, typename ParamType1>
|
||||
bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6);
|
||||
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format,...) ATTR_PRINTF(5,6);
|
||||
template<class Class, typename ParamType1, typename ParamType2>
|
||||
bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(6,7);
|
||||
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format,...) ATTR_PRINTF(6,7);
|
||||
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(7,8);
|
||||
bool AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format,...) ATTR_PRINTF(7,8);
|
||||
// PQuery / static
|
||||
template<typename ParamType1>
|
||||
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(4,5);
|
||||
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format,...) ATTR_PRINTF(4,5);
|
||||
template<typename ParamType1, typename ParamType2>
|
||||
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6);
|
||||
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format,...) ATTR_PRINTF(5,6);
|
||||
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(6,7);
|
||||
bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format,...) ATTR_PRINTF(6,7);
|
||||
template<class Class>
|
||||
// QueryHolder
|
||||
bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder);
|
||||
bool DelayQueryHolder(Class* object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder* holder);
|
||||
template<class Class, typename ParamType1>
|
||||
bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1);
|
||||
bool DelayQueryHolder(Class* object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder* holder, ParamType1 param1);
|
||||
|
||||
bool Execute(const char *sql);
|
||||
bool PExecute(const char *format,...) ATTR_PRINTF(2,3);
|
||||
bool Execute(const char* sql);
|
||||
bool PExecute(const char* format,...) ATTR_PRINTF(2,3);
|
||||
|
||||
// Writes SQL commands to a LOG file (see mangosd.conf "LogSQL")
|
||||
bool PExecuteLog(const char *format,...) ATTR_PRINTF(2,3);
|
||||
bool PExecuteLog(const char* format,...) ATTR_PRINTF(2,3);
|
||||
|
||||
bool BeginTransaction();
|
||||
bool CommitTransaction();
|
||||
|
|
@ -193,7 +193,7 @@ class MANGOS_DLL_SPEC Database
|
|||
//PREPARED STATEMENT API
|
||||
|
||||
//allocate index for prepared statement with SQL request 'fmt'
|
||||
SqlStatement CreateStatement(SqlStatementID& index, const char * fmt);
|
||||
SqlStatement CreateStatement(SqlStatementID& index, const char* fmt);
|
||||
//get prepared statement format string
|
||||
std::string GetStmtString(const int stmtId) const;
|
||||
|
||||
|
|
@ -231,9 +231,9 @@ class MANGOS_DLL_SPEC Database
|
|||
void StopServer();
|
||||
|
||||
//factory method to create SqlConnection objects
|
||||
virtual SqlConnection * CreateConnection() = 0;
|
||||
virtual SqlConnection* CreateConnection() = 0;
|
||||
//factory method to create SqlDelayThread objects
|
||||
virtual SqlDelayThread * CreateDelayThread();
|
||||
virtual SqlDelayThread* CreateDelayThread();
|
||||
|
||||
class MANGOS_DLL_SPEC TransHelper
|
||||
{
|
||||
|
|
@ -242,18 +242,18 @@ class MANGOS_DLL_SPEC Database
|
|||
~TransHelper();
|
||||
|
||||
//initializes new SqlTransaction object
|
||||
SqlTransaction * init();
|
||||
SqlTransaction* init();
|
||||
//gets pointer on current transaction object. Returns NULL if transaction was not initiated
|
||||
SqlTransaction * get() const { return m_pTrans; }
|
||||
SqlTransaction* get() const { return m_pTrans; }
|
||||
//detaches SqlTransaction object allocated by init() function
|
||||
//next call to get() function will return NULL!
|
||||
//do not forget to destroy obtained SqlTransaction object!
|
||||
SqlTransaction * detach();
|
||||
SqlTransaction* detach();
|
||||
//destroyes SqlTransaction allocated by init() function
|
||||
void reset();
|
||||
|
||||
private:
|
||||
SqlTransaction * m_pTrans;
|
||||
SqlTransaction* m_pTrans;
|
||||
};
|
||||
|
||||
//per-thread based storage for SqlTransaction object initialization - no locking is required
|
||||
|
|
@ -263,30 +263,30 @@ class MANGOS_DLL_SPEC Database
|
|||
///< DB connections
|
||||
|
||||
//round-robin connection selection
|
||||
SqlConnection * getQueryConnection();
|
||||
SqlConnection* getQueryConnection();
|
||||
//for now return one single connection for async requests
|
||||
SqlConnection * getAsyncConnection() const { return m_pAsyncConn; }
|
||||
SqlConnection* getAsyncConnection() const { return m_pAsyncConn; }
|
||||
|
||||
friend class SqlStatement;
|
||||
//PREPARED STATEMENT API
|
||||
//query function for prepared statements
|
||||
bool ExecuteStmt(const SqlStatementID& id, SqlStmtParameters * params);
|
||||
bool DirectExecuteStmt(const SqlStatementID& id, SqlStmtParameters * params);
|
||||
bool ExecuteStmt(const SqlStatementID& id, SqlStmtParameters* params);
|
||||
bool DirectExecuteStmt(const SqlStatementID& id, SqlStmtParameters* params);
|
||||
|
||||
//connection helper counters
|
||||
int m_nQueryConnPoolSize; //current size of query connection pool
|
||||
ACE_Atomic_Op<ACE_Thread_Mutex, long> m_nQueryCounter; //counter for connection selection
|
||||
|
||||
//lets use pool of connections for sync queries
|
||||
typedef std::vector< SqlConnection * > SqlConnectionContainer;
|
||||
typedef std::vector< SqlConnection* > SqlConnectionContainer;
|
||||
SqlConnectionContainer m_pQueryConnections;
|
||||
|
||||
//only one single DB connection for transactions
|
||||
SqlConnection * m_pAsyncConn;
|
||||
SqlConnection* m_pAsyncConn;
|
||||
|
||||
SqlResultQueue * m_pResultQueue; ///< Transaction queues from diff. threads
|
||||
SqlDelayThread * m_threadBody; ///< Pointer to delay sql executer (owned by m_delayThread)
|
||||
ACE_Based::Thread * m_delayThread; ///< Pointer to executer thread
|
||||
SqlResultQueue* m_pResultQueue; ///< Transaction queues from diff. threads
|
||||
SqlDelayThread* m_threadBody; ///< Pointer to delay sql executer (owned by m_delayThread)
|
||||
ACE_Based::Thread* m_delayThread; ///< Pointer to executer thread
|
||||
|
||||
bool m_bAllowAsyncTransactions; ///< flag which specifies if async transactions are enabled
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
|
||||
template<class Class>
|
||||
bool
|
||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql)
|
||||
Database::AsyncQuery(Class* object, void (Class::*method)(QueryResult*), const char* sql)
|
||||
{
|
||||
ASYNC_QUERY_BODY(sql)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class>(object, method), m_pResultQueue));
|
||||
|
|
@ -55,7 +55,7 @@ Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const c
|
|||
|
||||
template<class Class, typename ParamType1>
|
||||
bool
|
||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
|
||||
Database::AsyncQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char* sql)
|
||||
{
|
||||
ASYNC_QUERY_BODY(sql)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1>(object, method, (QueryResult*)NULL, param1), m_pResultQueue));
|
||||
|
|
@ -63,7 +63,7 @@ Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamTyp
|
|||
|
||||
template<class Class, typename ParamType1, typename ParamType2>
|
||||
bool
|
||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
|
||||
Database::AsyncQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* sql)
|
||||
{
|
||||
ASYNC_QUERY_BODY(sql)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult*)NULL, param1, param2), m_pResultQueue));
|
||||
|
|
@ -71,7 +71,7 @@ Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamTyp
|
|||
|
||||
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool
|
||||
Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
|
||||
Database::AsyncQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* sql)
|
||||
{
|
||||
ASYNC_QUERY_BODY(sql)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, (QueryResult*)NULL, param1, param2, param3), m_pResultQueue));
|
||||
|
|
@ -81,7 +81,7 @@ Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamTyp
|
|||
|
||||
template<typename ParamType1>
|
||||
bool
|
||||
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
|
||||
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char* sql)
|
||||
{
|
||||
ASYNC_QUERY_BODY(sql)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), m_pResultQueue));
|
||||
|
|
@ -89,7 +89,7 @@ Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1
|
|||
|
||||
template<typename ParamType1, typename ParamType2>
|
||||
bool
|
||||
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
|
||||
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* sql)
|
||||
{
|
||||
ASYNC_QUERY_BODY(sql)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult*)NULL, param1, param2), m_pResultQueue));
|
||||
|
|
@ -97,7 +97,7 @@ Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), Param
|
|||
|
||||
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool
|
||||
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
|
||||
Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* sql)
|
||||
{
|
||||
ASYNC_QUERY_BODY(sql)
|
||||
return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, (QueryResult*)NULL, param1, param2, param3), m_pResultQueue));
|
||||
|
|
@ -107,7 +107,7 @@ Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamT
|
|||
|
||||
template<class Class>
|
||||
bool
|
||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...)
|
||||
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*), const char* format,...)
|
||||
{
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(object, method, szQuery);
|
||||
|
|
@ -115,7 +115,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const
|
|||
|
||||
template<class Class, typename ParamType1>
|
||||
bool
|
||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
|
||||
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format,...)
|
||||
{
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(object, method, param1, szQuery);
|
||||
|
|
@ -123,7 +123,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamTy
|
|||
|
||||
template<class Class, typename ParamType1, typename ParamType2>
|
||||
bool
|
||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
|
||||
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format,...)
|
||||
{
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(object, method, param1, param2, szQuery);
|
||||
|
|
@ -131,7 +131,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamTy
|
|||
|
||||
template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool
|
||||
Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
|
||||
Database::AsyncPQuery(Class* object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format,...)
|
||||
{
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(object, method, param1, param2, param3, szQuery);
|
||||
|
|
@ -141,7 +141,7 @@ Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamTy
|
|||
|
||||
template<typename ParamType1>
|
||||
bool
|
||||
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
|
||||
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char* format,...)
|
||||
{
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(method, param1, szQuery);
|
||||
|
|
@ -149,7 +149,7 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param
|
|||
|
||||
template<typename ParamType1, typename ParamType2>
|
||||
bool
|
||||
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
|
||||
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char* format,...)
|
||||
{
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(method, param1, param2, szQuery);
|
||||
|
|
@ -157,7 +157,7 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), Para
|
|||
|
||||
template<typename ParamType1, typename ParamType2, typename ParamType3>
|
||||
bool
|
||||
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
|
||||
Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char* format,...)
|
||||
{
|
||||
ASYNC_PQUERY_BODY(format, szQuery)
|
||||
return AsyncQuery(method, param1, param2, param3, szQuery);
|
||||
|
|
@ -167,7 +167,7 @@ Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, Param
|
|||
|
||||
template<class Class>
|
||||
bool
|
||||
Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder)
|
||||
Database::DelayQueryHolder(Class* object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder* holder)
|
||||
{
|
||||
ASYNC_DELAYHOLDER_BODY(holder)
|
||||
return holder->Execute(new MaNGOS::QueryCallback<Class, SqlQueryHolder*>(object, method, (QueryResult*)NULL, holder), m_threadBody, m_pResultQueue);
|
||||
|
|
@ -175,7 +175,7 @@ Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, Sq
|
|||
|
||||
template<class Class, typename ParamType1>
|
||||
bool
|
||||
Database::DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder *holder, ParamType1 param1)
|
||||
Database::DelayQueryHolder(Class* object, void (Class::*method)(QueryResult*, SqlQueryHolder*, ParamType1), SqlQueryHolder* holder, ParamType1 param1)
|
||||
{
|
||||
ASYNC_DELAYHOLDER_BODY(holder)
|
||||
return holder->Execute(new MaNGOS::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, (QueryResult*)NULL, holder, param1), m_threadBody, m_pResultQueue);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ void DatabaseMysql::ThreadEnd()
|
|||
DatabaseMysql::DatabaseMysql()
|
||||
{
|
||||
// before first connection
|
||||
if( db_count++ == 0 )
|
||||
if (db_count++ == 0)
|
||||
{
|
||||
// Mysql Library Init
|
||||
mysql_library_init(-1, NULL, NULL);
|
||||
|
|
@ -59,11 +59,11 @@ DatabaseMysql::~DatabaseMysql()
|
|||
StopServer();
|
||||
|
||||
//Free Mysql library pointers for last ~DB
|
||||
if(--db_count == 0)
|
||||
if (--db_count == 0)
|
||||
mysql_library_end();
|
||||
}
|
||||
|
||||
SqlConnection * DatabaseMysql::CreateConnection()
|
||||
SqlConnection* DatabaseMysql::CreateConnection()
|
||||
{
|
||||
return new MySQLConnection(*this);
|
||||
}
|
||||
|
|
@ -74,12 +74,12 @@ MySQLConnection::~MySQLConnection()
|
|||
mysql_close(mMysql);
|
||||
}
|
||||
|
||||
bool MySQLConnection::Initialize(const char *infoString)
|
||||
bool MySQLConnection::Initialize(const char* infoString)
|
||||
{
|
||||
MYSQL * mysqlInit = mysql_init(NULL);
|
||||
MYSQL* mysqlInit = mysql_init(NULL);
|
||||
if (!mysqlInit)
|
||||
{
|
||||
sLog.outError( "Could not initialize Mysql connection" );
|
||||
sLog.outError("Could not initialize Mysql connection");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -93,20 +93,20 @@ bool MySQLConnection::Initialize(const char *infoString)
|
|||
|
||||
iter = tokens.begin();
|
||||
|
||||
if(iter != tokens.end())
|
||||
if (iter != tokens.end())
|
||||
host = *iter++;
|
||||
if(iter != tokens.end())
|
||||
if (iter != tokens.end())
|
||||
port_or_socket = *iter++;
|
||||
if(iter != tokens.end())
|
||||
if (iter != tokens.end())
|
||||
user = *iter++;
|
||||
if(iter != tokens.end())
|
||||
if (iter != tokens.end())
|
||||
password = *iter++;
|
||||
if(iter != tokens.end())
|
||||
if (iter != tokens.end())
|
||||
database = *iter++;
|
||||
|
||||
mysql_options(mysqlInit,MYSQL_SET_CHARSET_NAME,"utf8");
|
||||
#ifdef WIN32
|
||||
if(host==".") // named pipe use option (Windows)
|
||||
if (host==".") // named pipe use option (Windows)
|
||||
{
|
||||
unsigned int opt = MYSQL_PROTOCOL_PIPE;
|
||||
mysql_options(mysqlInit,MYSQL_OPT_PROTOCOL,(char const*)&opt);
|
||||
|
|
@ -119,7 +119,7 @@ bool MySQLConnection::Initialize(const char *infoString)
|
|||
unix_socket = 0;
|
||||
}
|
||||
#else
|
||||
if(host==".") // socket use option (Unix/Linux)
|
||||
if (host==".") // socket use option (Unix/Linux)
|
||||
{
|
||||
unsigned int opt = MYSQL_PROTOCOL_SOCKET;
|
||||
mysql_options(mysqlInit,MYSQL_OPT_PROTOCOL,(char const*)&opt);
|
||||
|
|
@ -139,7 +139,7 @@ bool MySQLConnection::Initialize(const char *infoString)
|
|||
|
||||
if (!mMysql)
|
||||
{
|
||||
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));
|
||||
mysql_close(mysqlInit);
|
||||
return false;
|
||||
|
|
@ -147,7 +147,7 @@ bool MySQLConnection::Initialize(const char *infoString)
|
|||
|
||||
DETAIL_LOG("Connected to MySQL database %s@%s:%s/%s", user.c_str(), host.c_str(), port_or_socket.c_str(), database.c_str());
|
||||
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
|
||||
|
|
@ -174,29 +174,29 @@ bool MySQLConnection::Initialize(const char *infoString)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MySQLConnection::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount)
|
||||
bool MySQLConnection::_Query(const char* sql, MYSQL_RES** pResult, MYSQL_FIELD** pFields, uint64* pRowCount, uint32* pFieldCount)
|
||||
{
|
||||
if (!mMysql)
|
||||
return 0;
|
||||
|
||||
uint32 _s = WorldTimer::getMSTime();
|
||||
|
||||
if(mysql_query(mMysql, sql))
|
||||
if (mysql_query(mMysql, sql))
|
||||
{
|
||||
sLog.outErrorDb( "SQL: %s", sql );
|
||||
sLog.outErrorDb("SQL: %s", sql);
|
||||
sLog.outErrorDb("query ERROR: %s", mysql_error(mMysql));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql );
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql);
|
||||
}
|
||||
|
||||
*pResult = mysql_store_result(mMysql);
|
||||
*pRowCount = mysql_affected_rows(mMysql);
|
||||
*pFieldCount = mysql_field_count(mMysql);
|
||||
|
||||
if (!*pResult )
|
||||
if (!*pResult)
|
||||
return false;
|
||||
|
||||
if (!*pRowCount)
|
||||
|
|
@ -209,37 +209,37 @@ bool MySQLConnection::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD *
|
|||
return true;
|
||||
}
|
||||
|
||||
QueryResult* MySQLConnection::Query(const char *sql)
|
||||
QueryResult* MySQLConnection::Query(const char* sql)
|
||||
{
|
||||
MYSQL_RES *result = NULL;
|
||||
MYSQL_FIELD *fields = NULL;
|
||||
MYSQL_RES* result = NULL;
|
||||
MYSQL_FIELD* fields = NULL;
|
||||
uint64 rowCount = 0;
|
||||
uint32 fieldCount = 0;
|
||||
|
||||
if(!_Query(sql,&result,&fields,&rowCount,&fieldCount))
|
||||
if (!_Query(sql,&result,&fields,&rowCount,&fieldCount))
|
||||
return NULL;
|
||||
|
||||
QueryResultMysql *queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount);
|
||||
QueryResultMysql* queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount);
|
||||
|
||||
queryResult->NextRow();
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
QueryNamedResult* MySQLConnection::QueryNamed(const char *sql)
|
||||
QueryNamedResult* MySQLConnection::QueryNamed(const char* sql)
|
||||
{
|
||||
MYSQL_RES *result = NULL;
|
||||
MYSQL_FIELD *fields = NULL;
|
||||
MYSQL_RES* result = NULL;
|
||||
MYSQL_FIELD* fields = NULL;
|
||||
uint64 rowCount = 0;
|
||||
uint32 fieldCount = 0;
|
||||
|
||||
if(!_Query(sql,&result,&fields,&rowCount,&fieldCount))
|
||||
if (!_Query(sql,&result,&fields,&rowCount,&fieldCount))
|
||||
return NULL;
|
||||
|
||||
QueryFieldNames names(fieldCount);
|
||||
for (uint32 i = 0; i < fieldCount; i++)
|
||||
names[i] = fields[i].name;
|
||||
|
||||
QueryResultMysql *queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount);
|
||||
QueryResultMysql* queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount);
|
||||
|
||||
queryResult->NextRow();
|
||||
return new QueryNamedResult(queryResult,names);
|
||||
|
|
@ -253,7 +253,7 @@ bool MySQLConnection::Execute(const char* sql)
|
|||
{
|
||||
uint32 _s = WorldTimer::getMSTime();
|
||||
|
||||
if(mysql_query(mMysql, sql))
|
||||
if (mysql_query(mMysql, sql))
|
||||
{
|
||||
sLog.outErrorDb("SQL: %s", sql);
|
||||
sLog.outErrorDb("SQL ERROR: %s", mysql_error(mMysql));
|
||||
|
|
@ -261,7 +261,7 @@ bool MySQLConnection::Execute(const char* sql)
|
|||
}
|
||||
else
|
||||
{
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql );
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql);
|
||||
}
|
||||
// end guarded block
|
||||
}
|
||||
|
|
@ -269,7 +269,7 @@ bool MySQLConnection::Execute(const char* sql)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MySQLConnection::_TransactionCmd(const char *sql)
|
||||
bool MySQLConnection::_TransactionCmd(const char* sql)
|
||||
{
|
||||
if (mysql_query(mMysql, sql))
|
||||
{
|
||||
|
|
@ -299,7 +299,7 @@ bool MySQLConnection::RollbackTransaction()
|
|||
return _TransactionCmd("ROLLBACK");
|
||||
}
|
||||
|
||||
unsigned long MySQLConnection::escape_string(char *to, const char *from, unsigned long length)
|
||||
unsigned long MySQLConnection::escape_string(char* to, const char* from, unsigned long length)
|
||||
{
|
||||
if (!mMysql || !to || !from || !length)
|
||||
return 0;
|
||||
|
|
@ -308,14 +308,14 @@ unsigned long MySQLConnection::escape_string(char *to, const char *from, unsigne
|
|||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
SqlPreparedStatement * MySQLConnection::CreateStatement( const std::string& fmt )
|
||||
SqlPreparedStatement* MySQLConnection::CreateStatement(const std::string& fmt)
|
||||
{
|
||||
return new MySqlPreparedStatement(fmt, *this, mMysql);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
MySqlPreparedStatement::MySqlPreparedStatement( const std::string& fmt, SqlConnection& conn, MYSQL * mysql ) : SqlPreparedStatement(fmt, conn),
|
||||
MySqlPreparedStatement::MySqlPreparedStatement(const std::string& fmt, SqlConnection& conn, MYSQL* mysql) : SqlPreparedStatement(fmt, conn),
|
||||
m_pMySQLConn(mysql), m_stmt(NULL), m_pInputArgs(NULL), m_pResult(NULL), m_pResultMetadata(NULL)
|
||||
{
|
||||
}
|
||||
|
|
@ -327,7 +327,7 @@ MySqlPreparedStatement::~MySqlPreparedStatement()
|
|||
|
||||
bool MySqlPreparedStatement::prepare()
|
||||
{
|
||||
if(isPrepared())
|
||||
if (isPrepared())
|
||||
return true;
|
||||
|
||||
//remove old binds
|
||||
|
|
@ -363,14 +363,14 @@ bool MySqlPreparedStatement::prepare()
|
|||
}
|
||||
|
||||
//bind input buffers
|
||||
if(m_nParams)
|
||||
if (m_nParams)
|
||||
{
|
||||
m_pInputArgs = new MYSQL_BIND[m_nParams];
|
||||
memset(m_pInputArgs, 0, sizeof(MYSQL_BIND) * m_nParams);
|
||||
}
|
||||
|
||||
//check if we have a statement which returns result sets
|
||||
if(m_pResultMetadata)
|
||||
if (m_pResultMetadata)
|
||||
{
|
||||
//our statement is query
|
||||
m_bIsQuery = true;
|
||||
|
|
@ -384,20 +384,20 @@ bool MySqlPreparedStatement::prepare()
|
|||
return true;
|
||||
}
|
||||
|
||||
void MySqlPreparedStatement::bind( const SqlStmtParameters& holder )
|
||||
void MySqlPreparedStatement::bind(const SqlStmtParameters& holder)
|
||||
{
|
||||
if(!isPrepared())
|
||||
if (!isPrepared())
|
||||
{
|
||||
MANGOS_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
//finalize adding params
|
||||
if(!m_pInputArgs)
|
||||
if (!m_pInputArgs)
|
||||
return;
|
||||
|
||||
//verify if we bound all needed input parameters
|
||||
if(m_nParams != holder.boundParams())
|
||||
if (m_nParams != holder.boundParams())
|
||||
{
|
||||
MANGOS_ASSERT(false);
|
||||
return;
|
||||
|
|
@ -414,14 +414,14 @@ void MySqlPreparedStatement::bind( const SqlStmtParameters& holder )
|
|||
}
|
||||
|
||||
//bind input arguments
|
||||
if(mysql_stmt_bind_param(m_stmt, m_pInputArgs))
|
||||
if (mysql_stmt_bind_param(m_stmt, m_pInputArgs))
|
||||
{
|
||||
sLog.outError("SQL ERROR: mysql_stmt_bind_param() failed\n");
|
||||
sLog.outError("SQL ERROR: %s", mysql_stmt_error(m_stmt));
|
||||
}
|
||||
}
|
||||
|
||||
void MySqlPreparedStatement::addParam( int nIndex, const SqlStmtFieldData& data )
|
||||
void MySqlPreparedStatement::addParam(int nIndex, const SqlStmtFieldData& data)
|
||||
{
|
||||
MANGOS_ASSERT(m_pInputArgs);
|
||||
MANGOS_ASSERT(nIndex < m_nParams);
|
||||
|
|
@ -441,7 +441,7 @@ void MySqlPreparedStatement::addParam( int nIndex, const SqlStmtFieldData& data
|
|||
|
||||
void MySqlPreparedStatement::RemoveBinds()
|
||||
{
|
||||
if(!m_stmt)
|
||||
if (!m_stmt)
|
||||
return;
|
||||
|
||||
delete [] m_pInputArgs;
|
||||
|
|
@ -460,10 +460,10 @@ void MySqlPreparedStatement::RemoveBinds()
|
|||
|
||||
bool MySqlPreparedStatement::execute()
|
||||
{
|
||||
if(!isPrepared())
|
||||
if (!isPrepared())
|
||||
return false;
|
||||
|
||||
if(mysql_stmt_execute(m_stmt))
|
||||
if (mysql_stmt_execute(m_stmt))
|
||||
{
|
||||
sLog.outError("SQL: cannot execute '%s'", m_szFmt.c_str());
|
||||
sLog.outError("SQL ERROR: %s", mysql_stmt_error(m_stmt));
|
||||
|
|
@ -473,7 +473,7 @@ bool MySqlPreparedStatement::execute()
|
|||
return true;
|
||||
}
|
||||
|
||||
enum_field_types MySqlPreparedStatement::ToMySQLType( const SqlStmtFieldData &data, my_bool &bUnsigned )
|
||||
enum_field_types MySqlPreparedStatement::ToMySQLType(const SqlStmtFieldData& data, my_bool& bUnsigned)
|
||||
{
|
||||
bUnsigned = 0;
|
||||
enum_field_types dataType = MYSQL_TYPE_NULL;
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@
|
|||
//MySQL prepared statement class
|
||||
class MANGOS_DLL_SPEC MySqlPreparedStatement : public SqlPreparedStatement
|
||||
{
|
||||
public:
|
||||
MySqlPreparedStatement(const std::string& fmt, SqlConnection& conn, MYSQL * mysql);
|
||||
public:
|
||||
MySqlPreparedStatement(const std::string& fmt, SqlConnection& conn, MYSQL* mysql);
|
||||
~MySqlPreparedStatement();
|
||||
|
||||
//prepare statement
|
||||
|
|
@ -50,20 +50,20 @@ public:
|
|||
//execute DML statement
|
||||
virtual bool execute();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
//bind parameters
|
||||
void addParam(int nIndex, const SqlStmtFieldData& data);
|
||||
|
||||
static enum_field_types ToMySQLType( const SqlStmtFieldData &data, my_bool &bUnsigned );
|
||||
static enum_field_types ToMySQLType(const SqlStmtFieldData& data, my_bool& bUnsigned);
|
||||
|
||||
private:
|
||||
private:
|
||||
void RemoveBinds();
|
||||
|
||||
MYSQL * m_pMySQLConn;
|
||||
MYSQL_STMT * m_stmt;
|
||||
MYSQL_BIND * m_pInputArgs;
|
||||
MYSQL_BIND * m_pResult;
|
||||
MYSQL_RES *m_pResultMetadata;
|
||||
MYSQL* m_pMySQLConn;
|
||||
MYSQL_STMT* m_stmt;
|
||||
MYSQL_BIND* m_pInputArgs;
|
||||
MYSQL_BIND* m_pResult;
|
||||
MYSQL_RES* m_pResultMetadata;
|
||||
};
|
||||
|
||||
class MANGOS_DLL_SPEC MySQLConnection : public SqlConnection
|
||||
|
|
@ -74,26 +74,26 @@ class MANGOS_DLL_SPEC MySQLConnection : public SqlConnection
|
|||
|
||||
//! Initializes Mysql and connects to a server.
|
||||
/*! infoString should be formated like hostname;username;password;database. */
|
||||
bool Initialize(const char *infoString);
|
||||
bool Initialize(const char* infoString);
|
||||
|
||||
QueryResult* Query(const char *sql);
|
||||
QueryNamedResult* QueryNamed(const char *sql);
|
||||
bool Execute(const char *sql);
|
||||
QueryResult* Query(const char* sql);
|
||||
QueryNamedResult* QueryNamed(const char* sql);
|
||||
bool Execute(const char* sql);
|
||||
|
||||
unsigned long escape_string(char *to, const char *from, unsigned long length);
|
||||
unsigned long escape_string(char* to, const char* from, unsigned long length);
|
||||
|
||||
bool BeginTransaction();
|
||||
bool CommitTransaction();
|
||||
bool RollbackTransaction();
|
||||
|
||||
protected:
|
||||
SqlPreparedStatement * CreateStatement(const std::string& fmt);
|
||||
SqlPreparedStatement* CreateStatement(const std::string& fmt);
|
||||
|
||||
private:
|
||||
bool _TransactionCmd(const char *sql);
|
||||
bool _Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount);
|
||||
bool _TransactionCmd(const char* sql);
|
||||
bool _Query(const char* sql, MYSQL_RES** pResult, MYSQL_FIELD** pFields, uint64* pRowCount, uint32* pFieldCount);
|
||||
|
||||
MYSQL *mMysql;
|
||||
MYSQL* mMysql;
|
||||
};
|
||||
|
||||
class MANGOS_DLL_SPEC DatabaseMysql : public Database
|
||||
|
|
@ -110,7 +110,7 @@ class MANGOS_DLL_SPEC DatabaseMysql : public Database
|
|||
void ThreadEnd();
|
||||
|
||||
protected:
|
||||
virtual SqlConnection * CreateConnection();
|
||||
virtual SqlConnection* CreateConnection();
|
||||
|
||||
private:
|
||||
static size_t db_count;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ size_t DatabasePostgre::db_count = 0;
|
|||
DatabasePostgre::DatabasePostgre()
|
||||
{
|
||||
// before first connection
|
||||
if( db_count++ == 0 )
|
||||
if (db_count++ == 0)
|
||||
{
|
||||
if (!PQisthreadsafe())
|
||||
{
|
||||
|
|
@ -46,7 +46,7 @@ DatabasePostgre::~DatabasePostgre()
|
|||
|
||||
}
|
||||
|
||||
SqlConnection * DatabasePostgre::CreateConnection()
|
||||
SqlConnection* DatabasePostgre::CreateConnection()
|
||||
{
|
||||
return new PostgreSQLConnection();
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ PostgreSQLConnection::~PostgreSQLConnection()
|
|||
PQfinish(mPGconn);
|
||||
}
|
||||
|
||||
bool PostgreSQLConnection::Initialize(const char *infoString)
|
||||
bool PostgreSQLConnection::Initialize(const char* infoString)
|
||||
{
|
||||
Tokens tokens = StrSplit(infoString, ";");
|
||||
|
||||
|
|
@ -66,15 +66,15 @@ bool PostgreSQLConnection::Initialize(const char *infoString)
|
|||
|
||||
iter = tokens.begin();
|
||||
|
||||
if(iter != tokens.end())
|
||||
if (iter != tokens.end())
|
||||
host = *iter++;
|
||||
if(iter != tokens.end())
|
||||
if (iter != tokens.end())
|
||||
port_or_socket_dir = *iter++;
|
||||
if(iter != tokens.end())
|
||||
if (iter != tokens.end())
|
||||
user = *iter++;
|
||||
if(iter != tokens.end())
|
||||
if (iter != tokens.end())
|
||||
password = *iter++;
|
||||
if(iter != tokens.end())
|
||||
if (iter != tokens.end())
|
||||
database = *iter++;
|
||||
|
||||
if (host == ".")
|
||||
|
|
@ -85,7 +85,7 @@ bool PostgreSQLConnection::Initialize(const char *infoString)
|
|||
/* check to see that the backend connection was successfully made */
|
||||
if (PQstatus(mPGconn) != CONNECTION_OK)
|
||||
{
|
||||
sLog.outError( "Could not connect to Postgre database at %s: %s",
|
||||
sLog.outError("Could not connect to Postgre database at %s: %s",
|
||||
host.c_str(), PQerrorMessage(mPGconn));
|
||||
PQfinish(mPGconn);
|
||||
mPGconn = NULL;
|
||||
|
|
@ -97,7 +97,7 @@ bool PostgreSQLConnection::Initialize(const char *infoString)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PostgreSQLConnection::_Query(const char *sql, PGresult** pResult, uint64* pRowCount, uint32* pFieldCount)
|
||||
bool PostgreSQLConnection::_Query(const char* sql, PGresult** pResult, uint64* pRowCount, uint32* pFieldCount)
|
||||
{
|
||||
if (!mPGconn)
|
||||
return false;
|
||||
|
|
@ -105,19 +105,19 @@ bool PostgreSQLConnection::_Query(const char *sql, PGresult** pResult, uint64* p
|
|||
uint32 _s = WorldTimer::getMSTime();
|
||||
// Send the query
|
||||
*pResult = PQexec(mPGconn, sql);
|
||||
if(!*pResult )
|
||||
if (!*pResult)
|
||||
return false;
|
||||
|
||||
if (PQresultStatus(*pResult) != PGRES_TUPLES_OK)
|
||||
{
|
||||
sLog.outErrorDb( "SQL : %s", sql );
|
||||
sLog.outErrorDb( "SQL %s", PQerrorMessage(mPGconn));
|
||||
sLog.outErrorDb("SQL : %s", sql);
|
||||
sLog.outErrorDb("SQL %s", PQerrorMessage(mPGconn));
|
||||
PQclear(*pResult);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql );
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql);
|
||||
}
|
||||
|
||||
*pRowCount = PQntuples(*pResult);
|
||||
|
|
@ -133,7 +133,7 @@ bool PostgreSQLConnection::_Query(const char *sql, PGresult** pResult, uint64* p
|
|||
return true;
|
||||
}
|
||||
|
||||
QueryResult* PostgreSQLConnection::Query(const char *sql)
|
||||
QueryResult* PostgreSQLConnection::Query(const char* sql)
|
||||
{
|
||||
if (!mPGconn)
|
||||
return NULL;
|
||||
|
|
@ -142,16 +142,16 @@ QueryResult* PostgreSQLConnection::Query(const char *sql)
|
|||
uint64 rowCount = 0;
|
||||
uint32 fieldCount = 0;
|
||||
|
||||
if(!_Query(sql,&result,&rowCount,&fieldCount))
|
||||
if (!_Query(sql,&result,&rowCount,&fieldCount))
|
||||
return NULL;
|
||||
|
||||
QueryResultPostgre * queryResult = new QueryResultPostgre(result, rowCount, fieldCount);
|
||||
QueryResultPostgre* queryResult = new QueryResultPostgre(result, rowCount, fieldCount);
|
||||
|
||||
queryResult->NextRow();
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
QueryNamedResult* PostgreSQLConnection::QueryNamed(const char *sql)
|
||||
QueryNamedResult* PostgreSQLConnection::QueryNamed(const char* sql)
|
||||
{
|
||||
if (!mPGconn)
|
||||
return NULL;
|
||||
|
|
@ -160,48 +160,48 @@ QueryNamedResult* PostgreSQLConnection::QueryNamed(const char *sql)
|
|||
uint64 rowCount = 0;
|
||||
uint32 fieldCount = 0;
|
||||
|
||||
if(!_Query(sql,&result,&rowCount,&fieldCount))
|
||||
if (!_Query(sql,&result,&rowCount,&fieldCount))
|
||||
return NULL;
|
||||
|
||||
QueryFieldNames names(fieldCount);
|
||||
for (uint32 i = 0; i < fieldCount; i++)
|
||||
names[i] = PQfname(result, i);
|
||||
|
||||
QueryResultPostgre * queryResult = new QueryResultPostgre(result, rowCount, fieldCount);
|
||||
QueryResultPostgre* queryResult = new QueryResultPostgre(result, rowCount, fieldCount);
|
||||
|
||||
queryResult->NextRow();
|
||||
return new QueryNamedResult(queryResult,names);
|
||||
}
|
||||
|
||||
bool PostgreSQLConnection::Execute(const char *sql)
|
||||
bool PostgreSQLConnection::Execute(const char* sql)
|
||||
{
|
||||
if (!mPGconn)
|
||||
return false;
|
||||
|
||||
uint32 _s = WorldTimer::getMSTime();
|
||||
|
||||
PGresult *res = PQexec(mPGconn, sql);
|
||||
PGresult* res = PQexec(mPGconn, sql);
|
||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
{
|
||||
sLog.outErrorDb( "SQL: %s", sql );
|
||||
sLog.outErrorDb( "SQL %s", PQerrorMessage(mPGconn) );
|
||||
sLog.outErrorDb("SQL: %s", sql);
|
||||
sLog.outErrorDb("SQL %s", PQerrorMessage(mPGconn));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql );
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_SQL_TEXT, "[%u ms] SQL: %s", WorldTimer::getMSTimeDiff(_s,WorldTimer::getMSTime()), sql);
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PostgreSQLConnection::_TransactionCmd(const char *sql)
|
||||
bool PostgreSQLConnection::_TransactionCmd(const char* sql)
|
||||
{
|
||||
if (!mPGconn)
|
||||
return false;
|
||||
|
||||
PGresult *res = PQexec(mPGconn, sql);
|
||||
PGresult* res = PQexec(mPGconn, sql);
|
||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
{
|
||||
sLog.outError("SQL: %s", sql);
|
||||
|
|
@ -230,7 +230,7 @@ bool PostgreSQLConnection::RollbackTransaction()
|
|||
return _TransactionCmd("ROLLBACK");
|
||||
}
|
||||
|
||||
unsigned long PostgreSQLConnection::escape_string(char *to, const char *from, unsigned long length)
|
||||
unsigned long PostgreSQLConnection::escape_string(char* to, const char* from, unsigned long length)
|
||||
{
|
||||
if (!mPGconn || !to || !from || !length)
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -40,23 +40,23 @@ class MANGOS_DLL_SPEC PostgreSQLConnection : public SqlConnection
|
|||
PostgreSQLConnection() : mPGconn(NULL) {}
|
||||
~PostgreSQLConnection();
|
||||
|
||||
bool Initialize(const char *infoString);
|
||||
bool Initialize(const char* infoString);
|
||||
|
||||
QueryResult* Query(const char *sql);
|
||||
QueryNamedResult* QueryNamed(const char *sql);
|
||||
bool Execute(const char *sql);
|
||||
QueryResult* Query(const char* sql);
|
||||
QueryNamedResult* QueryNamed(const char* sql);
|
||||
bool Execute(const char* sql);
|
||||
|
||||
unsigned long escape_string(char *to, const char *from, unsigned long length);
|
||||
unsigned long escape_string(char* to, const char* from, unsigned long length);
|
||||
|
||||
bool BeginTransaction();
|
||||
bool CommitTransaction();
|
||||
bool RollbackTransaction();
|
||||
|
||||
private:
|
||||
bool _TransactionCmd(const char *sql);
|
||||
bool _Query(const char *sql, PGresult **pResult, uint64* pRowCount, uint32* pFieldCount);
|
||||
bool _TransactionCmd(const char* sql);
|
||||
bool _Query(const char* sql, PGresult** pResult, uint64* pRowCount, uint32* pFieldCount);
|
||||
|
||||
PGconn *mPGconn;
|
||||
PGconn* mPGconn;
|
||||
};
|
||||
|
||||
class MANGOS_DLL_SPEC DatabasePostgre : public Database
|
||||
|
|
@ -71,7 +71,7 @@ class MANGOS_DLL_SPEC DatabasePostgre : public Database
|
|||
/*! infoString should be formated like hostname;username;password;database. */
|
||||
|
||||
protected:
|
||||
virtual SqlConnection * CreateConnection();
|
||||
virtual SqlConnection* CreateConnection();
|
||||
|
||||
private:
|
||||
static size_t db_count;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class Field
|
|||
enum DataTypes GetType() const { return mType; }
|
||||
bool IsNULL() const { return mValue == NULL; }
|
||||
|
||||
const char *GetString() const { return mValue; }
|
||||
const char* GetString() const { return mValue; }
|
||||
std::string GetCppString() const
|
||||
{
|
||||
return mValue ? mValue : ""; // std::string s = 0 have undefine result in C++
|
||||
|
|
@ -57,7 +57,7 @@ class Field
|
|||
uint64 GetUInt64() const
|
||||
{
|
||||
uint64 value = 0;
|
||||
if(!mValue || sscanf(mValue,UI64FMTD,&value) == -1)
|
||||
if (!mValue || sscanf(mValue,UI64FMTD,&value) == -1)
|
||||
return 0;
|
||||
|
||||
return value;
|
||||
|
|
|
|||
|
|
@ -33,15 +33,15 @@ class MANGOS_DLL_SPEC QueryResult
|
|||
|
||||
virtual bool NextRow() = 0;
|
||||
|
||||
Field *Fetch() const { return mCurrentRow; }
|
||||
Field* Fetch() const { return mCurrentRow; }
|
||||
|
||||
const Field & operator [] (int index) const { return mCurrentRow[index]; }
|
||||
const Field& operator [](int index) const { return mCurrentRow[index]; }
|
||||
|
||||
uint32 GetFieldCount() const { return mFieldCount; }
|
||||
uint64 GetRowCount() const { return mRowCount; }
|
||||
|
||||
protected:
|
||||
Field *mCurrentRow;
|
||||
Field* mCurrentRow;
|
||||
uint32 mFieldCount;
|
||||
uint64 mRowCount;
|
||||
};
|
||||
|
|
@ -56,20 +56,20 @@ class MANGOS_DLL_SPEC QueryNamedResult
|
|||
|
||||
// compatible interface with QueryResult
|
||||
bool NextRow() { return mQuery->NextRow(); }
|
||||
Field *Fetch() const { return mQuery->Fetch(); }
|
||||
Field* Fetch() const { return mQuery->Fetch(); }
|
||||
uint32 GetFieldCount() const { return mQuery->GetFieldCount(); }
|
||||
uint64 GetRowCount() const { return mQuery->GetRowCount(); }
|
||||
Field const& operator[] (int index) const { return (*mQuery)[index]; }
|
||||
Field const& operator[](int index) const { return (*mQuery)[index]; }
|
||||
|
||||
// named access
|
||||
Field const& operator[] (const std::string &name) const { return mQuery->Fetch()[GetField_idx(name)]; }
|
||||
Field const& operator[](const std::string& name) const { return mQuery->Fetch()[GetField_idx(name)]; }
|
||||
QueryFieldNames const& GetFieldNames() const { return mFieldNames; }
|
||||
|
||||
uint32 GetField_idx(const std::string &name) const
|
||||
uint32 GetField_idx(const std::string& name) const
|
||||
{
|
||||
for(size_t idx = 0; idx < mFieldNames.size(); ++idx)
|
||||
for (size_t idx = 0; idx < mFieldNames.size(); ++idx)
|
||||
{
|
||||
if(mFieldNames[idx] == name)
|
||||
if (mFieldNames[idx] == name)
|
||||
return idx;
|
||||
}
|
||||
MANGOS_ASSERT(false && "unknown field name");
|
||||
|
|
@ -77,7 +77,7 @@ class MANGOS_DLL_SPEC QueryNamedResult
|
|||
}
|
||||
|
||||
protected:
|
||||
QueryResult *mQuery;
|
||||
QueryResult* mQuery;
|
||||
QueryFieldNames mFieldNames;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#include "DatabaseEnv.h"
|
||||
#include "Errors.h"
|
||||
|
||||
QueryResultMysql::QueryResultMysql(MYSQL_RES *result, MYSQL_FIELD *fields, uint64 rowCount, uint32 fieldCount) :
|
||||
QueryResultMysql::QueryResultMysql(MYSQL_RES* result, MYSQL_FIELD* fields, uint64 rowCount, uint32 fieldCount) :
|
||||
QueryResult(rowCount, fieldCount), mResult(result)
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
class QueryResultMysql : public QueryResult
|
||||
{
|
||||
public:
|
||||
QueryResultMysql(MYSQL_RES *result, MYSQL_FIELD *fields, uint64 rowCount, uint32 fieldCount);
|
||||
QueryResultMysql(MYSQL_RES* result, MYSQL_FIELD* fields, uint64 rowCount, uint32 fieldCount);
|
||||
|
||||
~QueryResultMysql();
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ class QueryResultMysql : public QueryResult
|
|||
enum Field::DataTypes ConvertNativeType(enum_field_types mysqlType) const;
|
||||
void EndQuery();
|
||||
|
||||
MYSQL_RES *mResult;
|
||||
MYSQL_RES* mResult;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include "DatabaseEnv.h"
|
||||
|
||||
QueryResultPostgre::QueryResultPostgre(PGresult *result, uint64 rowCount, uint32 fieldCount) :
|
||||
QueryResultPostgre::QueryResultPostgre(PGresult* result, uint64 rowCount, uint32 fieldCount) :
|
||||
QueryResult(rowCount, fieldCount), mResult(result), mTableIndex(0)
|
||||
{
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ QueryResultPostgre::QueryResultPostgre(PGresult *result, uint64 rowCount, uint32
|
|||
MANGOS_ASSERT(mCurrentRow);
|
||||
|
||||
for (uint32 i = 0; i < mFieldCount; i++)
|
||||
mCurrentRow[i].SetType(ConvertNativeType(PQftype( result, i )));
|
||||
mCurrentRow[i].SetType(ConvertNativeType(PQftype(result, i)));
|
||||
}
|
||||
|
||||
QueryResultPostgre::~QueryResultPostgre()
|
||||
|
|
@ -51,7 +51,7 @@ bool QueryResultPostgre::NextRow()
|
|||
for (int j = 0; j < mFieldCount; j++)
|
||||
{
|
||||
pPQgetvalue = PQgetvalue(mResult, mTableIndex, j);
|
||||
if(pPQgetvalue && !(*pPQgetvalue))
|
||||
if (pPQgetvalue && !(*pPQgetvalue))
|
||||
pPQgetvalue = NULL;
|
||||
|
||||
mCurrentRow[j].SetValue(pPQgetvalue);
|
||||
|
|
@ -77,7 +77,7 @@ void QueryResultPostgre::EndQuery()
|
|||
}
|
||||
|
||||
// see types in #include <postgre/pg_type.h>
|
||||
enum Field::DataTypes QueryResultPostgre::ConvertNativeType(Oid pOid ) const
|
||||
enum Field::DataTypes QueryResultPostgre::ConvertNativeType(Oid pOid) const
|
||||
{
|
||||
switch (pOid)
|
||||
{
|
||||
|
|
@ -112,12 +112,12 @@ enum Field::DataTypes QueryResultPostgre::ConvertNativeType(Oid pOid ) const
|
|||
return Field::DB_TYPE_INTEGER;
|
||||
case BOOLOID:
|
||||
return Field::DB_TYPE_BOOL; // Bool
|
||||
/*
|
||||
/*
|
||||
case BOXOID: Rect;
|
||||
case LINEOID: Rect;
|
||||
case VARBITOID: BitArray;
|
||||
case BYTEAOID: ByteArray;
|
||||
*/
|
||||
*/
|
||||
case LSEGOID:
|
||||
case OIDVECTOROID:
|
||||
case PATHOID:
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@
|
|||
class QueryResultPostgre : public QueryResult
|
||||
{
|
||||
public:
|
||||
QueryResultPostgre(PGresult *result, uint64 rowCount, uint32 fieldCount);
|
||||
QueryResultPostgre(PGresult* result, uint64 rowCount, uint32 fieldCount);
|
||||
|
||||
~QueryResultPostgre();
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ class QueryResultPostgre : public QueryResult
|
|||
enum Field::DataTypes ConvertNativeType(Oid pOid) const;
|
||||
void EndQuery();
|
||||
|
||||
PGresult *mResult;
|
||||
PGresult* mResult;
|
||||
uint32 mTableIndex;
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ void SQLStorage::EraseEntry(uint32 id)
|
|||
uint32 offset = 0;
|
||||
for (uint32 x = 0; x < oNumFields; ++x)
|
||||
{
|
||||
switch(dst_format[x])
|
||||
switch (dst_format[x])
|
||||
{
|
||||
case FT_LOGIC:
|
||||
offset += sizeof(bool); break;
|
||||
|
|
@ -35,7 +35,7 @@ void SQLStorage::EraseEntry(uint32 id)
|
|||
offset += sizeof(float); break;
|
||||
case FT_STRING:
|
||||
{
|
||||
if(pIndex[id])
|
||||
if (pIndex[id])
|
||||
delete [] *(char**)((char*)(pIndex[id])+offset);
|
||||
|
||||
offset += sizeof(char*);
|
||||
|
|
@ -62,12 +62,12 @@ void SQLStorage::EraseEntry(uint32 id)
|
|||
pIndex[id] = NULL;
|
||||
}
|
||||
|
||||
void SQLStorage::Free ()
|
||||
void SQLStorage::Free()
|
||||
{
|
||||
uint32 offset = 0;
|
||||
for (uint32 x = 0; x < oNumFields; ++x)
|
||||
{
|
||||
switch(dst_format[x])
|
||||
switch (dst_format[x])
|
||||
{
|
||||
case FT_LOGIC:
|
||||
offset += sizeof(bool); break;
|
||||
|
|
@ -79,8 +79,8 @@ void SQLStorage::Free ()
|
|||
offset += sizeof(float); break;
|
||||
case FT_STRING:
|
||||
{
|
||||
for(uint32 y = 0; y < MaxEntry; ++y)
|
||||
if(pIndex[y])
|
||||
for (uint32 y = 0; y < MaxEntry; ++y)
|
||||
if (pIndex[y])
|
||||
delete [] *(char**)((char*)(pIndex[y])+offset);
|
||||
|
||||
offset += sizeof(char*);
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@
|
|||
|
||||
template<class T>
|
||||
template<class S, class D>
|
||||
void SQLStorageLoaderBase<T>::convert(uint32 /*field_pos*/, S src, D &dst)
|
||||
void SQLStorageLoaderBase<T>::convert(uint32 /*field_pos*/, S src, D& dst)
|
||||
{
|
||||
dst = D(src);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 /*field_pos*/, char const *src, char *&dst)
|
||||
void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 /*field_pos*/, char const* src, char*& dst)
|
||||
{
|
||||
if (!src)
|
||||
{
|
||||
|
|
@ -48,7 +48,7 @@ void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 /*field_pos*/, char cons
|
|||
|
||||
template<class T>
|
||||
template<class S>
|
||||
void SQLStorageLoaderBase<T>::convert_to_str(uint32 /*field_pos*/, S /*src*/, char * & dst)
|
||||
void SQLStorageLoaderBase<T>::convert_to_str(uint32 /*field_pos*/, S /*src*/, char*& dst)
|
||||
{
|
||||
dst = new char[1];
|
||||
*dst = 0;
|
||||
|
|
@ -63,13 +63,13 @@ void SQLStorageLoaderBase<T>::convert_from_str(uint32 /*field_pos*/, char const*
|
|||
|
||||
template<class T>
|
||||
template<class S, class D>
|
||||
void SQLStorageLoaderBase<T>::default_fill(uint32 /*field_pos*/, S src, D &dst)
|
||||
void SQLStorageLoaderBase<T>::default_fill(uint32 /*field_pos*/, S src, D& dst)
|
||||
{
|
||||
dst = D(src);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void SQLStorageLoaderBase<T>::default_fill_to_str(uint32 /*field_pos*/, char const* /*src*/, char * & dst)
|
||||
void SQLStorageLoaderBase<T>::default_fill_to_str(uint32 /*field_pos*/, char const* /*src*/, char*& dst)
|
||||
{
|
||||
dst = new char[1];
|
||||
*dst = 0;
|
||||
|
|
@ -77,41 +77,41 @@ void SQLStorageLoaderBase<T>::default_fill_to_str(uint32 /*field_pos*/, char con
|
|||
|
||||
template<class T>
|
||||
template<class V>
|
||||
void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage &store, char *p, uint32 x, uint32 &offset)
|
||||
void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage& store, char* p, uint32 x, uint32& offset)
|
||||
{
|
||||
T * subclass = (static_cast<T*>(this));
|
||||
switch(store.dst_format[x])
|
||||
T* subclass = (static_cast<T*>(this));
|
||||
switch (store.dst_format[x])
|
||||
{
|
||||
case FT_LOGIC:
|
||||
subclass->convert(x, value, *((bool*)(&p[offset])) );
|
||||
subclass->convert(x, value, *((bool*)(&p[offset])));
|
||||
offset+=sizeof(bool);
|
||||
break;
|
||||
case FT_BYTE:
|
||||
subclass->convert(x, value, *((char*)(&p[offset])) );
|
||||
subclass->convert(x, value, *((char*)(&p[offset])));
|
||||
offset+=sizeof(char);
|
||||
break;
|
||||
case FT_INT:
|
||||
subclass->convert(x, value, *((uint32*)(&p[offset])) );
|
||||
subclass->convert(x, value, *((uint32*)(&p[offset])));
|
||||
offset+=sizeof(uint32);
|
||||
break;
|
||||
case FT_FLOAT:
|
||||
subclass->convert(x, value, *((float*)(&p[offset])) );
|
||||
subclass->convert(x, value, *((float*)(&p[offset])));
|
||||
offset+=sizeof(float);
|
||||
break;
|
||||
case FT_STRING:
|
||||
subclass->convert_to_str(x, value, *((char**)(&p[offset])) );
|
||||
subclass->convert_to_str(x, value, *((char**)(&p[offset])));
|
||||
offset+=sizeof(char*);
|
||||
break;
|
||||
case FT_NA:
|
||||
subclass->default_fill(x, value, *((int32*)(&p[offset])) );
|
||||
subclass->default_fill(x, value, *((int32*)(&p[offset])));
|
||||
offset+=sizeof(uint32);
|
||||
break;
|
||||
case FT_NA_BYTE:
|
||||
subclass->default_fill(x, value, *((char*)(&p[offset])) );
|
||||
subclass->default_fill(x, value, *((char*)(&p[offset])));
|
||||
offset+=sizeof(char);
|
||||
break;
|
||||
case FT_NA_FLOAT:
|
||||
subclass->default_fill(x, value, *((float*)(&p[offset])) );
|
||||
subclass->default_fill(x, value, *((float*)(&p[offset])));
|
||||
offset+=sizeof(float);
|
||||
break;
|
||||
case FT_IND:
|
||||
|
|
@ -125,33 +125,33 @@ void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage &store, char *p, ui
|
|||
}
|
||||
|
||||
template<class T>
|
||||
void SQLStorageLoaderBase<T>::storeValue(char const* value, SQLStorage &store, char *p, uint32 x, uint32 &offset)
|
||||
void SQLStorageLoaderBase<T>::storeValue(char const* value, SQLStorage& store, char* p, uint32 x, uint32& offset)
|
||||
{
|
||||
T * subclass = (static_cast<T*>(this));
|
||||
switch(store.dst_format[x])
|
||||
T* subclass = (static_cast<T*>(this));
|
||||
switch (store.dst_format[x])
|
||||
{
|
||||
case FT_LOGIC:
|
||||
subclass->convert_from_str(x, value, *((bool*)(&p[offset])) );
|
||||
subclass->convert_from_str(x, value, *((bool*)(&p[offset])));
|
||||
offset+=sizeof(bool);
|
||||
break;
|
||||
case FT_BYTE:
|
||||
subclass->convert_from_str(x, value, *((char*)(&p[offset])) );
|
||||
subclass->convert_from_str(x, value, *((char*)(&p[offset])));
|
||||
offset += sizeof(char);
|
||||
break;
|
||||
case FT_INT:
|
||||
subclass->convert_from_str(x, value, *((uint32*)(&p[offset])) );
|
||||
subclass->convert_from_str(x, value, *((uint32*)(&p[offset])));
|
||||
offset += sizeof(uint32);
|
||||
break;
|
||||
case FT_FLOAT:
|
||||
subclass->convert_from_str(x, value, *((float*)(&p[offset])) );
|
||||
subclass->convert_from_str(x, value, *((float*)(&p[offset])));
|
||||
offset += sizeof(float);
|
||||
break;
|
||||
case FT_STRING:
|
||||
subclass->convert_str_to_str(x, value, *((char**)(&p[offset])) );
|
||||
subclass->convert_str_to_str(x, value, *((char**)(&p[offset])));
|
||||
offset += sizeof(char*);
|
||||
break;
|
||||
case FT_NA_POINTER:
|
||||
subclass->default_fill_to_str(x, value, *((char**)(&p[offset])) );
|
||||
subclass->default_fill_to_str(x, value, *((char**)(&p[offset])));
|
||||
offset += sizeof(char*);
|
||||
break;
|
||||
case FT_IND:
|
||||
|
|
@ -165,12 +165,12 @@ void SQLStorageLoaderBase<T>::storeValue(char const* value, SQLStorage &store, c
|
|||
}
|
||||
|
||||
template<class T>
|
||||
void SQLStorageLoaderBase<T>::Load(SQLStorage &store, bool error_at_empty /*= true*/)
|
||||
void SQLStorageLoaderBase<T>::Load(SQLStorage& store, bool error_at_empty /*= true*/)
|
||||
{
|
||||
uint32 maxi;
|
||||
Field *fields;
|
||||
QueryResult *result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table);
|
||||
if(!result)
|
||||
Field* fields;
|
||||
QueryResult* result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table);
|
||||
if (!result)
|
||||
{
|
||||
sLog.outError("Error loading %s table (not exist?)\n", store.table);
|
||||
Log::WaitBeforeContinueIfNeed();
|
||||
|
|
@ -181,7 +181,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store, bool error_at_empty /*= tr
|
|||
delete result;
|
||||
|
||||
result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table);
|
||||
if(result)
|
||||
if (result)
|
||||
{
|
||||
fields = result->Fetch();
|
||||
store.RecordCount = fields[0].GetUInt32();
|
||||
|
|
@ -192,7 +192,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store, bool error_at_empty /*= tr
|
|||
|
||||
result = WorldDatabase.PQuery("SELECT * FROM %s", store.table);
|
||||
|
||||
if(!result)
|
||||
if (!result)
|
||||
{
|
||||
if (error_at_empty)
|
||||
sLog.outError("%s table is empty!\n", store.table);
|
||||
|
|
@ -218,7 +218,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store, bool error_at_empty /*= tr
|
|||
// get struct size
|
||||
for (uint32 x = 0; x < store.oNumFields; ++x)
|
||||
{
|
||||
switch(store.dst_format[x])
|
||||
switch (store.dst_format[x])
|
||||
{
|
||||
case FT_LOGIC:
|
||||
recordsize += sizeof(bool); break;
|
||||
|
|
@ -279,7 +279,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store, bool error_at_empty /*= tr
|
|||
if (y >= store.iNumFields)
|
||||
assert(false && "SQL storage has too few columns!");
|
||||
|
||||
switch(store.src_format[y])
|
||||
switch (store.src_format[y])
|
||||
{
|
||||
case FT_LOGIC:
|
||||
storeValue((bool)(fields[y].GetUInt32() > 0), store, p, x, offset); break;
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ SqlDelayThread::~SqlDelayThread()
|
|||
|
||||
void SqlDelayThread::run()
|
||||
{
|
||||
#ifndef DO_POSTGRESQL
|
||||
#ifndef DO_POSTGRESQL
|
||||
mysql_thread_init();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
const uint32 loopSleepms = 10;
|
||||
|
||||
|
|
@ -49,16 +49,16 @@ void SqlDelayThread::run()
|
|||
|
||||
ProcessRequests();
|
||||
|
||||
if((loopCounter++) >= pingEveryLoop)
|
||||
if ((loopCounter++) >= pingEveryLoop)
|
||||
{
|
||||
loopCounter = 0;
|
||||
m_dbEngine->Ping();
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef DO_POSTGRESQL
|
||||
#ifndef DO_POSTGRESQL
|
||||
mysql_thread_end();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void SqlDelayThread::Stop()
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class SqlDelayThread : public ACE_Based::Runnable
|
|||
private:
|
||||
SqlQueue m_sqlQueue; ///< Queue of SQL statements
|
||||
Database* m_dbEngine; ///< Pointer to used Database engine
|
||||
SqlConnection * m_dbConnection; ///< Pointer to DB connection
|
||||
SqlConnection* m_dbConnection; ///< Pointer to DB connection
|
||||
volatile bool m_running;
|
||||
|
||||
//process all enqueued requests
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
/// ---- ASYNC STATEMENTS / TRANSACTIONS ----
|
||||
|
||||
bool SqlPlainRequest::Execute(SqlConnection *conn)
|
||||
bool SqlPlainRequest::Execute(SqlConnection* conn)
|
||||
{
|
||||
/// just do it
|
||||
LOCK_DB_CONN(conn);
|
||||
|
|
@ -34,16 +34,16 @@ bool SqlPlainRequest::Execute(SqlConnection *conn)
|
|||
|
||||
SqlTransaction::~SqlTransaction()
|
||||
{
|
||||
while(!m_queue.empty())
|
||||
while (!m_queue.empty())
|
||||
{
|
||||
delete m_queue.back();
|
||||
m_queue.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
bool SqlTransaction::Execute(SqlConnection *conn)
|
||||
bool SqlTransaction::Execute(SqlConnection* conn)
|
||||
{
|
||||
if(m_queue.empty())
|
||||
if (m_queue.empty())
|
||||
return true;
|
||||
|
||||
LOCK_DB_CONN(conn);
|
||||
|
|
@ -53,9 +53,9 @@ bool SqlTransaction::Execute(SqlConnection *conn)
|
|||
const int nItems = m_queue.size();
|
||||
for (int i = 0; i < nItems; ++i)
|
||||
{
|
||||
SqlOperation * pStmt = m_queue[i];
|
||||
SqlOperation* pStmt = m_queue[i];
|
||||
|
||||
if(!pStmt->Execute(conn))
|
||||
if (!pStmt->Execute(conn))
|
||||
{
|
||||
conn->RollbackTransaction();
|
||||
return false;
|
||||
|
|
@ -65,7 +65,7 @@ bool SqlTransaction::Execute(SqlConnection *conn)
|
|||
return conn->CommitTransaction();
|
||||
}
|
||||
|
||||
SqlPreparedRequest::SqlPreparedRequest(int nIndex, SqlStmtParameters * arg ) : m_nIndex(nIndex), m_param(arg)
|
||||
SqlPreparedRequest::SqlPreparedRequest(int nIndex, SqlStmtParameters* arg) : m_nIndex(nIndex), m_param(arg)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ SqlPreparedRequest::~SqlPreparedRequest()
|
|||
delete m_param;
|
||||
}
|
||||
|
||||
bool SqlPreparedRequest::Execute( SqlConnection *conn )
|
||||
bool SqlPreparedRequest::Execute(SqlConnection* conn)
|
||||
{
|
||||
LOCK_DB_CONN(conn);
|
||||
return conn->ExecuteStmt(m_nIndex, *m_param);
|
||||
|
|
@ -82,9 +82,9 @@ bool SqlPreparedRequest::Execute( SqlConnection *conn )
|
|||
|
||||
/// ---- ASYNC QUERIES ----
|
||||
|
||||
bool SqlQuery::Execute(SqlConnection *conn)
|
||||
bool SqlQuery::Execute(SqlConnection* conn)
|
||||
{
|
||||
if(!m_callback || !m_queue)
|
||||
if (!m_callback || !m_queue)
|
||||
return false;
|
||||
|
||||
LOCK_DB_CONN(conn);
|
||||
|
|
@ -107,27 +107,27 @@ void SqlResultQueue::Update()
|
|||
}
|
||||
}
|
||||
|
||||
bool SqlQueryHolder::Execute(MaNGOS::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue)
|
||||
bool SqlQueryHolder::Execute(MaNGOS::IQueryCallback* callback, SqlDelayThread* thread, SqlResultQueue* queue)
|
||||
{
|
||||
if(!callback || !thread || !queue)
|
||||
if (!callback || !thread || !queue)
|
||||
return false;
|
||||
|
||||
/// delay the execution of the queries, sync them with the delay thread
|
||||
/// which will in turn resync on execution (via the queue) and call back
|
||||
SqlQueryHolderEx *holderEx = new SqlQueryHolderEx(this, callback, queue);
|
||||
SqlQueryHolderEx* holderEx = new SqlQueryHolderEx(this, callback, queue);
|
||||
thread->Delay(holderEx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqlQueryHolder::SetQuery(size_t index, const char *sql)
|
||||
bool SqlQueryHolder::SetQuery(size_t index, const char* sql)
|
||||
{
|
||||
if(m_queries.size() <= index)
|
||||
if (m_queries.size() <= index)
|
||||
{
|
||||
sLog.outError("Query index (" SIZEFMTD ") out of range (size: " SIZEFMTD ") for query: %s", index, m_queries.size(), sql);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(m_queries[index].first != NULL)
|
||||
if (m_queries[index].first != NULL)
|
||||
{
|
||||
sLog.outError("Attempt assign query to holder index (" SIZEFMTD ") where other query stored (Old: [%s] New: [%s])",
|
||||
index,m_queries[index].first,sql);
|
||||
|
|
@ -139,9 +139,9 @@ bool SqlQueryHolder::SetQuery(size_t index, const char *sql)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SqlQueryHolder::SetPQuery(size_t index, const char *format, ...)
|
||||
bool SqlQueryHolder::SetPQuery(size_t index, const char* format, ...)
|
||||
{
|
||||
if(!format)
|
||||
if (!format)
|
||||
{
|
||||
sLog.outError("Query (index: " SIZEFMTD ") is empty.",index);
|
||||
return false;
|
||||
|
|
@ -150,10 +150,10 @@ bool SqlQueryHolder::SetPQuery(size_t index, const char *format, ...)
|
|||
va_list ap;
|
||||
char szQuery [MAX_QUERY_LEN];
|
||||
va_start(ap, format);
|
||||
int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap );
|
||||
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if(res==-1)
|
||||
if (res==-1)
|
||||
{
|
||||
sLog.outError("SQL Query truncated (and not execute) for format: %s",format);
|
||||
return false;
|
||||
|
|
@ -164,12 +164,12 @@ bool SqlQueryHolder::SetPQuery(size_t index, const char *format, ...)
|
|||
|
||||
QueryResult* SqlQueryHolder::GetResult(size_t index)
|
||||
{
|
||||
if(index < m_queries.size())
|
||||
if (index < m_queries.size())
|
||||
{
|
||||
/// the query strings are freed on the first GetResult or in the destructor
|
||||
if(m_queries[index].first != NULL)
|
||||
if (m_queries[index].first != NULL)
|
||||
{
|
||||
delete [] (const_cast<char*>(m_queries[index].first));
|
||||
delete [](const_cast<char*>(m_queries[index].first));
|
||||
m_queries[index].first = NULL;
|
||||
}
|
||||
/// when you get a result aways remember to delete it!
|
||||
|
|
@ -179,23 +179,23 @@ QueryResult* SqlQueryHolder::GetResult(size_t index)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void SqlQueryHolder::SetResult(size_t index, QueryResult *result)
|
||||
void SqlQueryHolder::SetResult(size_t index, QueryResult* result)
|
||||
{
|
||||
/// store the result in the holder
|
||||
if(index < m_queries.size())
|
||||
if (index < m_queries.size())
|
||||
m_queries[index].second = result;
|
||||
}
|
||||
|
||||
SqlQueryHolder::~SqlQueryHolder()
|
||||
{
|
||||
for(size_t i = 0; i < m_queries.size(); i++)
|
||||
for (size_t i = 0; i < m_queries.size(); i++)
|
||||
{
|
||||
/// if the result was never used, free the resources
|
||||
/// results used already (getresult called) are expected to be deleted
|
||||
if(m_queries[i].first != NULL)
|
||||
if (m_queries[i].first != NULL)
|
||||
{
|
||||
delete [] (const_cast<char*>(m_queries[i].first));
|
||||
if(m_queries[i].second)
|
||||
delete [](const_cast<char*>(m_queries[i].first));
|
||||
if (m_queries[i].second)
|
||||
delete m_queries[i].second;
|
||||
}
|
||||
}
|
||||
|
|
@ -207,19 +207,19 @@ void SqlQueryHolder::SetSize(size_t size)
|
|||
m_queries.resize(size);
|
||||
}
|
||||
|
||||
bool SqlQueryHolderEx::Execute(SqlConnection *conn)
|
||||
bool SqlQueryHolderEx::Execute(SqlConnection* conn)
|
||||
{
|
||||
if(!m_holder || !m_callback || !m_queue)
|
||||
if (!m_holder || !m_callback || !m_queue)
|
||||
return false;
|
||||
|
||||
LOCK_DB_CONN(conn);
|
||||
/// we can do this, we are friends
|
||||
std::vector<SqlQueryHolder::SqlResultPair> &queries = m_holder->m_queries;
|
||||
for(size_t i = 0; i < queries.size(); i++)
|
||||
std::vector<SqlQueryHolder::SqlResultPair>& queries = m_holder->m_queries;
|
||||
for (size_t i = 0; i < queries.size(); i++)
|
||||
{
|
||||
/// execute all queries in the holder and pass the results
|
||||
char const *sql = queries[i].first;
|
||||
if(sql) m_holder->SetResult(i, conn->Query(sql));
|
||||
char const* sql = queries[i].first;
|
||||
if (sql) m_holder->SetResult(i, conn->Query(sql));
|
||||
}
|
||||
|
||||
/// sync with the caller thread
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class SqlOperation
|
|||
{
|
||||
public:
|
||||
virtual void OnRemove() { delete this; }
|
||||
virtual bool Execute(SqlConnection *conn) = 0;
|
||||
virtual bool Execute(SqlConnection* conn) = 0;
|
||||
virtual ~SqlOperation() {}
|
||||
};
|
||||
|
||||
|
|
@ -46,38 +46,38 @@ class SqlOperation
|
|||
class SqlPlainRequest : public SqlOperation
|
||||
{
|
||||
private:
|
||||
const char *m_sql;
|
||||
const char* m_sql;
|
||||
public:
|
||||
SqlPlainRequest(const char *sql) : m_sql(mangos_strdup(sql)){}
|
||||
SqlPlainRequest(const char* sql) : m_sql(mangos_strdup(sql)) {}
|
||||
~SqlPlainRequest() { char* tofree = const_cast<char*>(m_sql); delete [] tofree; }
|
||||
bool Execute(SqlConnection *conn);
|
||||
bool Execute(SqlConnection* conn);
|
||||
};
|
||||
|
||||
class SqlTransaction : public SqlOperation
|
||||
{
|
||||
private:
|
||||
std::vector<SqlOperation * > m_queue;
|
||||
std::vector<SqlOperation* > m_queue;
|
||||
|
||||
public:
|
||||
SqlTransaction() {}
|
||||
~SqlTransaction();
|
||||
|
||||
void DelayExecute(SqlOperation * sql) { m_queue.push_back(sql); }
|
||||
void DelayExecute(SqlOperation* sql) { m_queue.push_back(sql); }
|
||||
|
||||
bool Execute(SqlConnection *conn);
|
||||
bool Execute(SqlConnection* conn);
|
||||
};
|
||||
|
||||
class SqlPreparedRequest : public SqlOperation
|
||||
{
|
||||
public:
|
||||
SqlPreparedRequest(int nIndex, SqlStmtParameters * arg);
|
||||
SqlPreparedRequest(int nIndex, SqlStmtParameters* arg);
|
||||
~SqlPreparedRequest();
|
||||
|
||||
bool Execute(SqlConnection *conn);
|
||||
bool Execute(SqlConnection* conn);
|
||||
|
||||
private:
|
||||
const int m_nIndex;
|
||||
SqlStmtParameters * m_param;
|
||||
SqlStmtParameters* m_param;
|
||||
};
|
||||
|
||||
/// ---- ASYNC QUERIES ----
|
||||
|
|
@ -98,14 +98,14 @@ class SqlResultQueue : public ACE_Based::LockedQueue<MaNGOS::IQueryCallback* , A
|
|||
class SqlQuery : public SqlOperation
|
||||
{
|
||||
private:
|
||||
const char *m_sql;
|
||||
MaNGOS::IQueryCallback * m_callback;
|
||||
SqlResultQueue * m_queue;
|
||||
const char* m_sql;
|
||||
MaNGOS::IQueryCallback* m_callback;
|
||||
SqlResultQueue* m_queue;
|
||||
public:
|
||||
SqlQuery(const char *sql, MaNGOS::IQueryCallback * callback, SqlResultQueue * queue)
|
||||
SqlQuery(const char* sql, MaNGOS::IQueryCallback* callback, SqlResultQueue* queue)
|
||||
: m_sql(mangos_strdup(sql)), m_callback(callback), m_queue(queue) {}
|
||||
~SqlQuery() { char* tofree = const_cast<char*>(m_sql); delete [] tofree; }
|
||||
bool Execute(SqlConnection *conn);
|
||||
bool Execute(SqlConnection* conn);
|
||||
};
|
||||
|
||||
class SqlQueryHolder
|
||||
|
|
@ -117,23 +117,23 @@ class SqlQueryHolder
|
|||
public:
|
||||
SqlQueryHolder() {}
|
||||
~SqlQueryHolder();
|
||||
bool SetQuery(size_t index, const char *sql);
|
||||
bool SetPQuery(size_t index, const char *format, ...) ATTR_PRINTF(3,4);
|
||||
bool SetQuery(size_t index, const char* sql);
|
||||
bool SetPQuery(size_t index, const char* format, ...) ATTR_PRINTF(3,4);
|
||||
void SetSize(size_t size);
|
||||
QueryResult* GetResult(size_t index);
|
||||
void SetResult(size_t index, QueryResult *result);
|
||||
bool Execute(MaNGOS::IQueryCallback * callback, SqlDelayThread *thread, SqlResultQueue *queue);
|
||||
void SetResult(size_t index, QueryResult* result);
|
||||
bool Execute(MaNGOS::IQueryCallback* callback, SqlDelayThread* thread, SqlResultQueue* queue);
|
||||
};
|
||||
|
||||
class SqlQueryHolderEx : public SqlOperation
|
||||
{
|
||||
private:
|
||||
SqlQueryHolder * m_holder;
|
||||
MaNGOS::IQueryCallback * m_callback;
|
||||
SqlResultQueue * m_queue;
|
||||
SqlQueryHolder* m_holder;
|
||||
MaNGOS::IQueryCallback* m_callback;
|
||||
SqlResultQueue* m_queue;
|
||||
public:
|
||||
SqlQueryHolderEx(SqlQueryHolder *holder, MaNGOS::IQueryCallback * callback, SqlResultQueue * queue)
|
||||
SqlQueryHolderEx(SqlQueryHolder* holder, MaNGOS::IQueryCallback* callback, SqlResultQueue* queue)
|
||||
: m_holder(holder), m_callback(callback), m_queue(queue) {}
|
||||
bool Execute(SqlConnection *conn);
|
||||
bool Execute(SqlConnection* conn);
|
||||
};
|
||||
#endif //__SQLOPERATIONS_H
|
||||
|
|
|
|||
|
|
@ -18,36 +18,36 @@
|
|||
|
||||
#include "DatabaseEnv.h"
|
||||
|
||||
SqlStmtParameters::SqlStmtParameters( int nParams )
|
||||
SqlStmtParameters::SqlStmtParameters(int nParams)
|
||||
{
|
||||
//reserve memory if needed
|
||||
if(nParams > 0)
|
||||
if (nParams > 0)
|
||||
m_params.reserve(nParams);
|
||||
}
|
||||
|
||||
void SqlStmtParameters::reset( const SqlStatement& stmt )
|
||||
void SqlStmtParameters::reset(const SqlStatement& stmt)
|
||||
{
|
||||
m_params.clear();
|
||||
//reserve memory if needed
|
||||
if(stmt.arguments() > 0)
|
||||
if (stmt.arguments() > 0)
|
||||
m_params.reserve(stmt.arguments());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
SqlStatement& SqlStatement::operator=( const SqlStatement& index )
|
||||
SqlStatement& SqlStatement::operator=(const SqlStatement& index)
|
||||
{
|
||||
if(this != &index)
|
||||
if (this != &index)
|
||||
{
|
||||
m_index = index.m_index;
|
||||
m_pDB = index.m_pDB;
|
||||
|
||||
if(m_pParams)
|
||||
if (m_pParams)
|
||||
{
|
||||
delete m_pParams;
|
||||
m_pParams = NULL;
|
||||
}
|
||||
|
||||
if(index.m_pParams)
|
||||
if (index.m_pParams)
|
||||
m_pParams = new SqlStmtParameters(*(index.m_pParams));
|
||||
}
|
||||
|
||||
|
|
@ -56,9 +56,9 @@ SqlStatement& SqlStatement::operator=( const SqlStatement& index )
|
|||
|
||||
bool SqlStatement::Execute()
|
||||
{
|
||||
SqlStmtParameters * args = detach();
|
||||
SqlStmtParameters* args = detach();
|
||||
//verify amount of bound parameters
|
||||
if(args->boundParams() != arguments())
|
||||
if (args->boundParams() != arguments())
|
||||
{
|
||||
sLog.outError("SQL ERROR: wrong amount of parameters (%i instead of %i)", args->boundParams(), arguments());
|
||||
sLog.outError("SQL ERROR: statement: %s", m_pDB->GetStmtString(ID()).c_str());
|
||||
|
|
@ -71,9 +71,9 @@ bool SqlStatement::Execute()
|
|||
|
||||
bool SqlStatement::DirectExecute()
|
||||
{
|
||||
SqlStmtParameters * args = detach();
|
||||
SqlStmtParameters* args = detach();
|
||||
//verify amount of bound parameters
|
||||
if(args->boundParams() != arguments())
|
||||
if (args->boundParams() != arguments())
|
||||
{
|
||||
sLog.outError("SQL ERROR: wrong amount of parameters (%i instead of %i)", args->boundParams(), arguments());
|
||||
sLog.outError("SQL ERROR: statement: %s", m_pDB->GetStmtString(ID()).c_str());
|
||||
|
|
@ -85,17 +85,17 @@ bool SqlStatement::DirectExecute()
|
|||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
SqlPlainPreparedStatement::SqlPlainPreparedStatement( const std::string& fmt, SqlConnection& conn ) : SqlPreparedStatement(fmt, conn)
|
||||
SqlPlainPreparedStatement::SqlPlainPreparedStatement(const std::string& fmt, SqlConnection& conn) : SqlPreparedStatement(fmt, conn)
|
||||
{
|
||||
m_bPrepared = true;
|
||||
m_nParams = std::count(m_szFmt.begin(), m_szFmt.end(), '?');
|
||||
m_bIsQuery = strnicmp(m_szFmt.c_str(), "select", 6) == 0;
|
||||
}
|
||||
|
||||
void SqlPlainPreparedStatement::bind( const SqlStmtParameters& holder )
|
||||
void SqlPlainPreparedStatement::bind(const SqlStmtParameters& holder)
|
||||
{
|
||||
//verify if we bound all needed input parameters
|
||||
if(m_nParams != holder.boundParams())
|
||||
if (m_nParams != holder.boundParams())
|
||||
{
|
||||
MANGOS_ASSERT(false);
|
||||
return;
|
||||
|
|
@ -117,7 +117,7 @@ void SqlPlainPreparedStatement::bind( const SqlStmtParameters& holder )
|
|||
DataToString(data, fmt);
|
||||
|
||||
nLastPos = m_szPlainRequest.find('?', nLastPos);
|
||||
if(nLastPos != std::string::npos)
|
||||
if (nLastPos != std::string::npos)
|
||||
{
|
||||
std::string tmp = fmt.str();
|
||||
m_szPlainRequest.replace(nLastPos, 1, tmp);
|
||||
|
|
@ -128,13 +128,13 @@ void SqlPlainPreparedStatement::bind( const SqlStmtParameters& holder )
|
|||
|
||||
bool SqlPlainPreparedStatement::execute()
|
||||
{
|
||||
if(m_szPlainRequest.empty())
|
||||
if (m_szPlainRequest.empty())
|
||||
return false;
|
||||
|
||||
return m_pConn.Execute(m_szPlainRequest.c_str());
|
||||
}
|
||||
|
||||
void SqlPlainPreparedStatement::DataToString( const SqlStmtFieldData& data, std::ostringstream& fmt )
|
||||
void SqlPlainPreparedStatement::DataToString(const SqlStmtFieldData& data, std::ostringstream& fmt)
|
||||
{
|
||||
switch (data.type())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -86,12 +86,12 @@ class MANGOS_DLL_SPEC SqlStmtFieldData
|
|||
int64 toInt64() const { MANGOS_ASSERT(m_type == FIELD_I64); return m_binaryData.i64; }
|
||||
float toFloat() const { MANGOS_ASSERT(m_type == FIELD_FLOAT); return m_binaryData.f; }
|
||||
double toDouble() const { MANGOS_ASSERT(m_type == FIELD_DOUBLE); return m_binaryData.d; }
|
||||
const char * toStr() const { MANGOS_ASSERT(m_type == FIELD_STRING); return m_szStringData.c_str(); }
|
||||
const char* toStr() const { MANGOS_ASSERT(m_type == FIELD_STRING); return m_szStringData.c_str(); }
|
||||
|
||||
//get type of data
|
||||
SqlStmtFieldType type() const { return m_type; }
|
||||
//get underlying buffer type
|
||||
void * buff() const { return m_type == FIELD_STRING ? (void * )m_szStringData.c_str() : (void *)&m_binaryData; }
|
||||
void* buff() const { return m_type == FIELD_STRING ? (void*)m_szStringData.c_str() : (void*)&m_binaryData; }
|
||||
|
||||
//get size of data
|
||||
size_t size() const
|
||||
|
|
@ -135,7 +135,7 @@ template<> inline void SqlStmtFieldData::set(uint64 val) { m_type = FIELD_UI64;
|
|||
template<> inline void SqlStmtFieldData::set(int64 val) { m_type = FIELD_I64; m_binaryData.i64 = val; }
|
||||
template<> inline void SqlStmtFieldData::set(float val) { m_type = FIELD_FLOAT; m_binaryData.f = val; }
|
||||
template<> inline void SqlStmtFieldData::set(double val) { m_type = FIELD_DOUBLE; m_binaryData.d = val; }
|
||||
template<> inline void SqlStmtFieldData::set(const char * val) { m_type = FIELD_STRING; m_szStringData = val; }
|
||||
template<> inline void SqlStmtFieldData::set(const char* val) { m_type = FIELD_STRING; m_szStringData = val; }
|
||||
|
||||
class SqlStatement;
|
||||
//prepared statement executor
|
||||
|
|
@ -195,7 +195,7 @@ class MANGOS_DLL_SPEC SqlStatement
|
|||
|
||||
SqlStatement(const SqlStatement& index) : m_index(index.m_index), m_pDB(index.m_pDB), m_pParams(NULL)
|
||||
{
|
||||
if(index.m_pParams)
|
||||
if (index.m_pParams)
|
||||
m_pParams = new SqlStmtParameters(*(index.m_pParams));
|
||||
}
|
||||
|
||||
|
|
@ -254,7 +254,7 @@ class MANGOS_DLL_SPEC SqlStatement
|
|||
void addInt64(int64 var) { arg(var); }
|
||||
void addFloat(float var) { arg(var); }
|
||||
void addDouble(double var) { arg(var); }
|
||||
void addString(const char * var) { arg(var); }
|
||||
void addString(const char* var) { arg(var); }
|
||||
void addString(const std::string& var) { arg(var.c_str()); }
|
||||
void addString(std::ostringstream& ss) { arg(ss.str().c_str()); ss.str(std::string()); }
|
||||
|
||||
|
|
@ -265,17 +265,17 @@ class MANGOS_DLL_SPEC SqlStatement
|
|||
|
||||
private:
|
||||
|
||||
SqlStmtParameters * get()
|
||||
SqlStmtParameters* get()
|
||||
{
|
||||
if(!m_pParams)
|
||||
if (!m_pParams)
|
||||
m_pParams = new SqlStmtParameters(arguments());
|
||||
|
||||
return m_pParams;
|
||||
}
|
||||
|
||||
SqlStmtParameters * detach()
|
||||
SqlStmtParameters* detach()
|
||||
{
|
||||
SqlStmtParameters * p = m_pParams ? m_pParams : new SqlStmtParameters(0);
|
||||
SqlStmtParameters* p = m_pParams ? m_pParams : new SqlStmtParameters(0);
|
||||
m_pParams = NULL;
|
||||
return p;
|
||||
}
|
||||
|
|
@ -285,13 +285,13 @@ class MANGOS_DLL_SPEC SqlStatement
|
|||
template<typename ParamType>
|
||||
void arg(ParamType val)
|
||||
{
|
||||
SqlStmtParameters * p = get();
|
||||
SqlStmtParameters* p = get();
|
||||
p->addParam(SqlStmtFieldData(val));
|
||||
}
|
||||
|
||||
SqlStatementID m_index;
|
||||
Database * m_pDB;
|
||||
SqlStmtParameters * m_pParams;
|
||||
Database* m_pDB;
|
||||
SqlStmtParameters* m_pParams;
|
||||
};
|
||||
|
||||
//base prepared statement class
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue