OregonCore  revision 3611e8a-git
Your Favourite TBC server
Database Class Reference

#include <Database.h>

Public Member Functions

 Database ()
 
 ~Database ()
 
bool Initialize (const char *infoString)
 
bool IsConnected () const
 
void InitDelayThread ()
 
void HaltDelayThread ()
 
QueryResult_AutoPtr Query (const char *sql)
 
QueryResult_AutoPtr PQuery (const char *format,...) ATTR_PRINTF(2
 
QueryResult_AutoPtr bool ExecuteFile (const char *file)
 
template<class Class >
bool AsyncQuery (Class *object, void(Class::*method)(QueryResult_AutoPtr), const char *sql)
 
template<class Class , typename ParamType1 >
bool AsyncQuery (Class *object, void(Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql)
 
template<class Class , typename ParamType1 , typename ParamType2 >
bool AsyncQuery (Class *object, void(Class::*method)(QueryResult_AutoPtr, 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_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
 
template<typename ParamType1 >
bool AsyncQuery (void(*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *sql)
 
template<typename ParamType1 , typename ParamType2 >
bool AsyncQuery (void(*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
 
template<typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool AsyncQuery (void(*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
 
template<class Class >
bool AsyncPQuery (Class *object, void(Class::*method)(QueryResult_AutoPtr), const char *format,...) ATTR_PRINTF(4
 
template<class Class , typename ParamType1 >
bool bool AsyncPQuery (Class *object, void(Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5
 
template<class Class , typename ParamType1 , typename ParamType2 >
bool bool bool AsyncPQuery (Class *object, void(Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(6
 
template<class Class , typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool bool bool bool AsyncPQuery (Class *object, void(Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(7
 
template<typename ParamType1 >
bool bool bool bool bool AsyncPQuery (void(*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(4
 
template<typename ParamType1 , typename ParamType2 >
bool bool bool bool bool bool AsyncPQuery (void(*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5
 
template<typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool bool bool bool bool bool bool AsyncPQuery (void(*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(6
 
template<class Class >
bool bool bool bool bool bool bool bool DelayQueryHolder (Class *object, void(Class::*method)(QueryResult_AutoPtr, SqlQueryHolder *), SqlQueryHolder *holder)
 
template<class Class , typename ParamType1 >
bool DelayQueryHolder (Class *object, void(Class::*method)(QueryResult_AutoPtr, SqlQueryHolder *, ParamType1), SqlQueryHolder *holder, ParamType1 param1)
 
bool Execute (const char *sql)
 
bool PExecute (const char *format,...) ATTR_PRINTF(2
 
bool bool DirectExecute (const char *sql)
 
bool DirectPExecute (const char *format,...) ATTR_PRINTF(2
 
bool bool DirectExecute (PreparedStatement *stmt, PreparedValues &values, va_list *args)
 
bool PExecuteLog (const char *format,...) ATTR_PRINTF(2
 
bool bool PreparedExecuteLog (const char *sql, const char *format=NULL,...)
 
bool PreparedExecuteLog (const char *sql, PreparedValues &values)
 
bool BeginTransaction ()
 
bool CommitTransaction ()
 
bool RollbackTransaction ()
 
bool ExecuteTransaction (SqlTransaction *transaction)
 Atomically executed SqlTransaction. Don't call this directly, use BeginTransaction and CommitTransaction instead. More...
 
PreparedQueryResult_AutoPtr PreparedQuery (const char *sql, const char *format=NULL,...)
 Runs Query via Prepared Statements. If statement doesn't exist, it shall be created. This function blocks calling thread until query is done, if your query is result-less use PreparedExecute instead. More...
 
PreparedQueryResult_AutoPtr PreparedQuery (const char *sql, PreparedValues &values)
 
bool PreparedExecute (const char *sql, const char *format=NULL,...)
 Executes Query via Prepared Statements. More...
 
bool PreparedExecute (const char *sql, PreparedValues &values)
 Executes Query via Prepared Statements. More...
 
 operator bool () const
 
unsigned long escape_string (char *to, const char *from, unsigned long length)
 
void escape_string (std::string &str)
 
void ThreadStart ()
 
void ThreadEnd ()
 
void SetResultQueue (SqlResultQueue *queue)
 
template<class Class , typename ParamType1 >
bool AsyncPQuery (Class *object, void(Class::*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...)
 
template<class Class , typename ParamType1 , typename ParamType2 >
bool AsyncPQuery (Class *object, void(Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
 
template<class Class , typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool AsyncPQuery (Class *object, void(Class::*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
 
template<typename ParamType1 >
bool AsyncPQuery (void(*method)(QueryResult_AutoPtr, ParamType1), ParamType1 param1, const char *format,...)
 
template<typename ParamType1 , typename ParamType2 >
bool AsyncPQuery (void(*method)(QueryResult_AutoPtr, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
 
template<typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool AsyncPQuery (void(*method)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
 
template<class Class >
bool DelayQueryHolder (Class *object, void(Class::*method)(QueryResult_AutoPtr, SqlQueryHolder *), SqlQueryHolder *holder)
 

Protected Member Functions

bool DirectExecute (bool lock, const char *sql)
 

Protected Attributes

TransactionQueues m_tranQueues
 
QueryQueues m_queryQueues
 
SqlDelayThreadm_threadBody
 
ACE_Based::Threadm_delayThread
 

Private Types

typedef UNORDERED_MAP< std::string, PreparedStatement * > PreparedStatementsMap
 

Private Member Functions

bool _TransactionCmd (const char *sql)
 
bool _Query (const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64 *pRowCount, uint32 *pFieldCount)
 
PreparedStatement_GetOrMakePreparedStatement (const char *query, const char *format, PreparedValues *values)
 
bool _ExecutePreparedStatement (PreparedStatement *ps, PreparedValues *values, va_list *args, bool resultset)
 
void _ConvertValistToPreparedValues (va_list ap, PreparedValues &values, const char *fmt)
 

Private Attributes

bool m_logSQL
 
std::string m_logsDir
 
ACE_Thread_Mutex mMutex
 
ACE_Thread_Mutex nMutex
 
ACE_Thread_Mutex pMutex
 
ACE_Based::ThreadtranThread
 
MYSQL * mMysql
 
bool m_connected
 
PreparedStatementsMap m_preparedStatements
 

Static Private Attributes

static size_t db_count = 0
 

Detailed Description

Definition at line 46 of file Database.h.

Member Typedef Documentation

Definition at line 177 of file Database.h.

Constructor & Destructor Documentation

Database::Database ( )

Definition at line 43 of file Database.cpp.

References db_count, and sLog.

43  : mMysql(NULL), m_connected(false)
44 {
45  // before first connection
46  if (db_count++ == 0)
47  {
48  // Mysql Library Init
49  mysql_library_init(-1, NULL, NULL);
50 
51  if (!mysql_thread_safe())
52  sLog.outFatal("FATAL ERROR: Used MySQL library isn't thread-safe.");
53  }
54 }
bool m_connected
Definition: Database.h:166
MYSQL * mMysql
Definition: Database.h:165
#define sLog
Log class singleton.
Definition: Log.h:187
static size_t db_count
Definition: Database.h:168
Database::~Database ( )

Definition at line 56 of file Database.cpp.

References db_count, HaltDelayThread(), m_delayThread, m_preparedStatements, and mMysql.

57 {
58  if (m_delayThread)
60 
61  for (PreparedStatementsMap::iterator it = m_preparedStatements.begin(); it != m_preparedStatements.end(); ++it)
62  {
63  mysql_stmt_close(it->second->stmt);
64  delete it->second;
65  }
66 
67  if (mMysql)
68  mysql_close(mMysql);
69 
70  // Free Mysql library pointers for last ~DB
71  if (--db_count == 0)
72  mysql_library_end();
73 }
MYSQL * mMysql
Definition: Database.h:165
static size_t db_count
Definition: Database.h:168
void HaltDelayThread()
Definition: Database.cpp:645
PreparedStatementsMap m_preparedStatements
Definition: Database.h:178
ACE_Based::Thread * m_delayThread
Definition: Database.h:52

Member Function Documentation

void Database::_ConvertValistToPreparedValues ( va_list  ap,
PreparedValues values,
const char *  fmt 
)
private

Definition at line 964 of file Database.cpp.

References ARG_TYPE_BINARY, ARG_TYPE_BINARY_ALT, ARG_TYPE_DOUBLE, ARG_TYPE_FLOAT, ARG_TYPE_LARGE_NUMBER, ARG_TYPE_LARGE_NUMBER_ALT, ARG_TYPE_LARGE_UNSIGNED_NUMBER, ARG_TYPE_NUMBER, ARG_TYPE_NUMBER_ALT, ARG_TYPE_STRING, ARG_TYPE_STRING_ALT, and ARG_TYPE_UNSIGNED_NUMBER.

Referenced by _ExecutePreparedStatement(), PreparedExecute(), and PreparedExecuteLog().

965 {
966  for (const char* i = fmt; *i != '\0'; ++i)
967  {
968  switch (*i)
969  {
970  case ARG_TYPE_STRING:
971  case ARG_TYPE_STRING_ALT:
972  values << va_arg(args, const char*);
973  break;
974  case ARG_TYPE_BINARY:
975  case ARG_TYPE_BINARY_ALT:
976  {
977  size_t size = va_arg(args, size_t);
978  const void* data = va_arg(args, const void*);
979  values << std::pair<const void*, size_t>(data, size);
980  }
981  break;
983  values << va_arg(args, uint32);
984  break;
985  case ARG_TYPE_NUMBER:
986  case ARG_TYPE_NUMBER_ALT:
987  values << va_arg(args, int32);
988  break;
990  values << va_arg(args, uint64);
991  break;
994  values << va_arg(args, int64);
995  break;
996  case ARG_TYPE_FLOAT:
997  // passed floats are promoted to doubles
998  values << (float) va_arg(args, double);
999  break;
1000  case ARG_TYPE_DOUBLE:
1001  values << va_arg(args, double);
1002  break;
1003  }
1004  }
1005 }
char const*, can be NULL
ACE_INT32 int32
Definition: Define.h:67
64bit signed int
floating point
ACE_UINT64 uint64
Definition: Define.h:70
ACE_INT64 int64
Definition: Define.h:66
ACE_UINT32 uint32
Definition: Define.h:71
void const*, can be NULL
bool Database::_ExecutePreparedStatement ( PreparedStatement ps,
PreparedValues values,
va_list *  args,
bool  resultset 
)
private

Definition at line 826 of file Database.cpp.

References _ConvertValistToPreparedValues(), ARG_TYPE_BINARY, ARG_TYPE_BINARY_ALT, ARG_TYPE_DOUBLE, ARG_TYPE_FLOAT, ARG_TYPE_LARGE_NUMBER, ARG_TYPE_LARGE_NUMBER_ALT, ARG_TYPE_LARGE_UNSIGNED_NUMBER, ARG_TYPE_NUMBER, ARG_TYPE_NUMBER_ALT, ARG_TYPE_STRING, ARG_TYPE_STRING_ALT, ARG_TYPE_UNSIGNED_NUMBER, ASSERT, PreparedValues::m_values, sLog, PreparedStatement::stmt, and PreparedStatement::types.

Referenced by DirectExecute(), ExecuteTransaction(), and PreparedQuery().

827 {
828  size_t paramCount = mysql_stmt_param_count(ps->stmt);
829  MYSQL_BIND* binding = NULL;
830  bool myValues = false;
831 
832  if (paramCount)
833  {
834  if (args)
835  {
836  if (paramCount != ps->types.size())
837  {
838  sLog.outErrorDb("Count of parameters passed doesn't equal to count of parameters in prepared statement!");
839  delete[] binding;
840  return false;
841  }
842 
843  if (!values)
844  {
845  values = new PreparedValues(paramCount);
846  myValues = true;
847  }
848 
849  _ConvertValistToPreparedValues(*args, *values, ps->types.c_str());
850  }
851  else
852  {
853  ASSERT (values);
854 
855  if (paramCount != values->m_values.size())
856  {
857  sLog.outErrorDb("Count of parameters passed doesn't equal to count of parameters in prepared statement!");
858  delete[] binding;
859  return false;
860  }
861  }
862 
863  binding = new MYSQL_BIND[paramCount];
864  memset(binding, 0, sizeof(MYSQL_BIND)*paramCount);
865 
866  for (size_t i = 0; i < paramCount; ++i)
867  {
868  switch ((*values)[i].type)
869  {
870  case ARG_TYPE_STRING:
871  case ARG_TYPE_STRING_ALT:
872  binding[i].buffer_type = MYSQL_TYPE_STRING;
873  binding[i].buffer = const_cast<char*> ((*values)[i].data.string);
874  binding[i].buffer_length = (*values)[i].data.length;
875  break;
876  case ARG_TYPE_BINARY:
877  case ARG_TYPE_BINARY_ALT:
878  binding[i].buffer_type = MYSQL_TYPE_BLOB;
879  binding[i].buffer = const_cast<void*> ((*values)[i].data.binary);
880  binding[i].buffer_length = (*values)[i].data.length;
881  break;
883  binding[i].is_unsigned = my_true;
884  /* FALLTHROUGH */
885  case ARG_TYPE_NUMBER:
886  case ARG_TYPE_NUMBER_ALT:
887  binding[i].buffer_type = MYSQL_TYPE_LONG;
888  binding[i].buffer = &(*values)[i].data.number;
889  binding[i].buffer_length = sizeof((*values)[i].data.number);
890  break;
892  binding[i].is_unsigned = my_true;
893  /* FALLTHROUGH */
896  binding[i].buffer_type = MYSQL_TYPE_LONGLONG;
897  binding[i].buffer = &(*values)[i].data.largeNumber;
898  binding[i].buffer_length = sizeof(&(*values)[i].data.largeNumber);
899  break;
900  case ARG_TYPE_FLOAT:
901  binding[i].buffer_type = MYSQL_TYPE_FLOAT;
902  binding[i].buffer = &(*values)[i].data.float_;
903  binding[i].buffer_length = sizeof(&(*values)[i].data.float_);
904  break;
905  case ARG_TYPE_DOUBLE:
906  binding[i].buffer_type = MYSQL_TYPE_DOUBLE;
907  binding[i].buffer = &(*values)[i].data.double_;
908  binding[i].buffer_length = sizeof((*values)[i].data.double_);
909  break;
910  }
911  }
912 
913  if (mysql_stmt_bind_param(ps->stmt, binding))
914  {
915  sLog.outError("mysql_stmt_bind_param() failed: %s", mysql_stmt_error(ps->stmt));
916  delete[] binding;
917  if (myValues)
918  delete values;
919  return false;
920  }
921  }
922 
923  if (mysql_stmt_execute(ps->stmt))
924  {
925  sLog.outError("mysql_stmt_execute() failed: %s", mysql_stmt_error(ps->stmt));
926  delete[] binding;
927  if (myValues)
928  delete values;
929  return false;
930  }
931 
932  if (myValues)
933  delete values;
934 
935  // this is safe, even if there's no result
936  mysql_stmt_store_result(ps->stmt);
937 
938  if (resultset)
939  {
940  if (!mysql_stmt_field_count(ps->stmt))
941  {
942  delete[] binding;
943  return false;
944  }
945 
946  if (!mysql_stmt_num_rows(ps->stmt))
947  {
948  mysql_stmt_free_result(ps->stmt);
949  delete[] binding;
950  return false;
951  }
952  }
953  else
954  {
955  if (mysql_stmt_field_count(ps->stmt))
956  mysql_stmt_free_result(ps->stmt);
957  mysql_stmt_reset(ps->stmt);
958  }
959 
960  delete[] binding;
961  return true;
962 }
std::vector< Value > m_values
char const*, can be NULL
void _ConvertValistToPreparedValues(va_list ap, PreparedValues &values, const char *fmt)
Definition: Database.cpp:964
#define sLog
Log class singleton.
Definition: Log.h:187
64bit signed int
floating point
#define ASSERT
Definition: Errors.h:33
void const*, can be NULL
PreparedStatement * Database::_GetOrMakePreparedStatement ( const char *  query,
const char *  format,
PreparedValues values 
)
private

Definition at line 751 of file Database.cpp.

References ARG_TYPE_BINARY, ARG_TYPE_BINARY_ALT, ARG_TYPE_DOUBLE, ARG_TYPE_FLOAT, ARG_TYPE_LARGE_NUMBER, ARG_TYPE_LARGE_NUMBER_ALT, ARG_TYPE_LARGE_UNSIGNED_NUMBER, ARG_TYPE_NUMBER, ARG_TYPE_NUMBER_ALT, ARG_TYPE_STRING, ARG_TYPE_STRING_ALT, ARG_TYPE_UNSIGNED_NUMBER, m_preparedStatements, PreparedValues::m_values, mMysql, pMutex, sLog, PreparedStatement::stmt, and PreparedStatement::types.

Referenced by PreparedExecute(), and PreparedQuery().

752 {
753  ACE_Guard<ACE_Thread_Mutex> guardian(pMutex);
754  PreparedStatementsMap::iterator it = m_preparedStatements.find(query);
755 
756  if (it != m_preparedStatements.end())
757  return it->second; // found, ok
758 
759  MYSQL_STMT* stmt = mysql_stmt_init(mMysql);
760 
761  if (!stmt)
762  {
763  sLog.outError("mysql_stmt_init() failed: %s", mysql_error(mMysql));
764  return 0;
765  }
766 
767  {
768  // set prefetch rows to maximum, thus making results buffered
769  unsigned long rows = (unsigned long) -1;
770  if (mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, &rows))
771  sLog.outError("mysql_stmt_attr_set() failed.");
772 
773  if (mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &my_true))
774  sLog.outError("mysql_stmt_attr_set() failed.");
775  }
776 
777  PreparedStatement* prepStmt = new PreparedStatement;
778  prepStmt->stmt = stmt;
779 
780  if (format)
781  {
782  prepStmt->types = format;
783 
784  for (const char* it = format; *it != '\0'; ++it)
785  {
786  switch (*it)
787  {
788  case ARG_TYPE_STRING:
789  case ARG_TYPE_STRING_ALT:
790  case ARG_TYPE_NUMBER:
791  case ARG_TYPE_NUMBER_ALT:
796  case ARG_TYPE_FLOAT:
797  case ARG_TYPE_DOUBLE:
798  case ARG_TYPE_BINARY:
799  case ARG_TYPE_BINARY_ALT:
800  break;
801  default:
802  sLog.outError("Unknown format type '%c' for prepared statement (%s)", *it, query);
803  delete prepStmt;
804  return 0;
805  }
806  }
807  }
808  else if (values)
809  {
810  for (size_t i = 0; i < values->m_values.size(); ++i)
811  prepStmt->types.append(1, static_cast<char>(values->m_values[i].type));
812  }
813 
814  {
815  if (mysql_stmt_prepare(stmt, query, strlen(query)))
816  {
817  sLog.outErrorDb("mysql_stmt_prepare() failed: %s, sql: %s", mysql_stmt_error(stmt), query);
818  delete prepStmt;
819  return 0;
820  }
821  }
822 
823  return m_preparedStatements.insert(std::pair<std::string, PreparedStatement*>(query, prepStmt)).first->second;
824 }
std::vector< Value > m_values
char const*, can be NULL
MYSQL * mMysql
Definition: Database.h:165
#define sLog
Log class singleton.
Definition: Log.h:187
64bit signed int
floating point
ACE_Thread_Mutex pMutex
Definition: Database.h:161
PreparedStatementsMap m_preparedStatements
Definition: Database.h:178
void const*, can be NULL
bool Database::_Query ( const char *  sql,
MYSQL_RES **  pResult,
MYSQL_FIELD **  pFields,
uint64 pRowCount,
uint32 pFieldCount 
)
private

Definition at line 337 of file Database.cpp.

References getMSTime(), getMSTimeDiff(), LOG_TYPE_DEBUG, mMutex, mMysql, and sLog.

Referenced by Query().

338 {
339  if (!mMysql)
340  return 0;
341 
342  {
343  // guarded block for thread-safe mySQL request
344  ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex);
345  #ifdef OREGON_DEBUG
346  uint32 _s = getMSTime();
347  #endif
348  if (mysql_query(mMysql, sql))
349  {
350  sLog.outErrorDb("SQL: %s", sql);
351  sLog.outErrorDb("query ERROR: %s", mysql_error(mMysql));
352  return false;
353  }
354  else
355  {
356  #ifdef OREGON_DEBUG
357  // prevent recursive death
358  unsigned long oldMask = sLog.GetDBLogMask();
359  sLog.SetDBLogMask(oldMask & ~(1 << LOG_TYPE_DEBUG));
360  sLog.outDebug("[%u ms] SQL: %s", getMSTimeDiff(_s, getMSTime()), sql);
361  sLog.SetDBLogMask(oldMask);
362  #endif
363  }
364 
365  *pResult = mysql_store_result(mMysql);
366  *pRowCount = mysql_affected_rows(mMysql);
367  *pFieldCount = mysql_field_count(mMysql);
368  }
369 
370  if (!*pResult )
371  return false;
372 
373  if (!*pRowCount)
374  {
375  mysql_free_result(*pResult);
376  return false;
377  }
378 
379  *pFields = mysql_fetch_fields(*pResult);
380  return true;
381 }
MYSQL * mMysql
Definition: Database.h:165
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition: Timer.h:78
uint32 getMSTime()
Definition: Timer.h:32
#define sLog
Log class singleton.
Definition: Log.h:187
ACE_Thread_Mutex mMutex
Definition: Database.h:159
NULL LOG_TYPE_DEBUG
Definition: Log.cpp:536
ACE_UINT32 uint32
Definition: Define.h:71
bool Database::_TransactionCmd ( const char *  sql)
private

Definition at line 517 of file Database.cpp.

References DEBUG_LOG, mMysql, and sLog.

518 {
519  if (mysql_query(mMysql, sql))
520  {
521  sLog.outError("SQL: %s", sql);
522  sLog.outError("SQL ERROR: %s", mysql_error(mMysql));
523  return false;
524  }
525  #if OREGON_DEBUG
526  else
527  DEBUG_LOG("SQL: %s", sql);
528  #endif
529 
530  return true;
531 }
MYSQL * mMysql
Definition: Database.h:165
#define sLog
Log class singleton.
Definition: Log.h:187
#define DEBUG_LOG(...)
Definition: Log.h:194
template<class Class >
bool Database::AsyncPQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr method,
const char *  format,
  ... 
)

Definition at line 128 of file DatabaseImpl.h.

References ASYNC_PQUERY_BODY, and AsyncQuery().

Referenced by WorldSession::HandleAddFriendOpcode(), WorldSession::HandleAddIgnoreOpcode(), WorldSession::HandleChangePlayerNameOpcode(), WorldSession::HandleCharEnumOpcode(), IsConnected(), WorldSession::SendNameQueryOpcodeFromDB(), and World::UpdateRealmCharCount().

129 {
130  ASYNC_PQUERY_BODY(format, szQuery)
131  return AsyncQuery(object, method, szQuery);
132 }
bool AsyncQuery(Class *object, void(Class::*method)(QueryResult_AutoPtr), const char *sql)
Definition: DatabaseImpl.h:68
#define ASYNC_PQUERY_BODY(format, szQuery)
Definition: DatabaseImpl.h:34
template<class Class , typename ParamType1 >
bool bool Database::AsyncPQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, ParamType1)  method,
ParamType1  param1,
const char *  format,
  ... 
)
template<class Class , typename ParamType1 , typename ParamType2 >
bool bool bool Database::AsyncPQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, ParamType1, ParamType2)  method,
ParamType1  param1,
ParamType2  param2,
const char *  format,
  ... 
)
template<class Class , typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool bool bool bool Database::AsyncPQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3)  method,
ParamType1  param1,
ParamType2  param2,
ParamType3  param3,
const char *  format,
  ... 
)
template<typename ParamType1 >
bool bool bool bool bool Database::AsyncPQuery ( void(*)(QueryResult_AutoPtr, ParamType1)  method,
ParamType1  param1,
const char *  format,
  ... 
)
template<typename ParamType1 , typename ParamType2 >
bool bool bool bool bool bool Database::AsyncPQuery ( void(*)(QueryResult_AutoPtr, ParamType1, ParamType2)  method,
ParamType1  param1,
ParamType2  param2,
const char *  format,
  ... 
)
template<typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool bool bool bool bool bool bool Database::AsyncPQuery ( void(*)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3)  method,
ParamType1  param1,
ParamType2  param2,
ParamType3  param3,
const char *  format,
  ... 
)
template<class Class , typename ParamType1 >
bool Database::AsyncPQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, ParamType1)  method,
ParamType1  param1,
const char *  format,
  ... 
)

Definition at line 136 of file DatabaseImpl.h.

References ASYNC_PQUERY_BODY, and AsyncQuery().

137 {
138  ASYNC_PQUERY_BODY(format, szQuery)
139  return AsyncQuery(object, method, param1, szQuery);
140 }
bool AsyncQuery(Class *object, void(Class::*method)(QueryResult_AutoPtr), const char *sql)
Definition: DatabaseImpl.h:68
#define ASYNC_PQUERY_BODY(format, szQuery)
Definition: DatabaseImpl.h:34
template<class Class , typename ParamType1 , typename ParamType2 >
bool Database::AsyncPQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, ParamType1, ParamType2)  method,
ParamType1  param1,
ParamType2  param2,
const char *  format,
  ... 
)

Definition at line 144 of file DatabaseImpl.h.

References ASYNC_PQUERY_BODY, and AsyncQuery().

145 {
146  ASYNC_PQUERY_BODY(format, szQuery)
147  return AsyncQuery(object, method, param1, param2, szQuery);
148 }
bool AsyncQuery(Class *object, void(Class::*method)(QueryResult_AutoPtr), const char *sql)
Definition: DatabaseImpl.h:68
#define ASYNC_PQUERY_BODY(format, szQuery)
Definition: DatabaseImpl.h:34
template<class Class , typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool Database::AsyncPQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3)  method,
ParamType1  param1,
ParamType2  param2,
ParamType3  param3,
const char *  format,
  ... 
)

Definition at line 152 of file DatabaseImpl.h.

References ASYNC_PQUERY_BODY, and AsyncQuery().

153 {
154  ASYNC_PQUERY_BODY(format, szQuery)
155  return AsyncQuery(object, method, param1, param2, param3, szQuery);
156 }
bool AsyncQuery(Class *object, void(Class::*method)(QueryResult_AutoPtr), const char *sql)
Definition: DatabaseImpl.h:68
#define ASYNC_PQUERY_BODY(format, szQuery)
Definition: DatabaseImpl.h:34
template<typename ParamType1 >
bool Database::AsyncPQuery ( void(*)(QueryResult_AutoPtr, ParamType1)  method,
ParamType1  param1,
const char *  format,
  ... 
)

Definition at line 162 of file DatabaseImpl.h.

References ASYNC_PQUERY_BODY, and AsyncQuery().

163 {
164  ASYNC_PQUERY_BODY(format, szQuery)
165  return AsyncQuery(method, param1, szQuery);
166 }
bool AsyncQuery(Class *object, void(Class::*method)(QueryResult_AutoPtr), const char *sql)
Definition: DatabaseImpl.h:68
#define ASYNC_PQUERY_BODY(format, szQuery)
Definition: DatabaseImpl.h:34
template<typename ParamType1 , typename ParamType2 >
bool Database::AsyncPQuery ( void(*)(QueryResult_AutoPtr, ParamType1, ParamType2)  method,
ParamType1  param1,
ParamType2  param2,
const char *  format,
  ... 
)

Definition at line 170 of file DatabaseImpl.h.

References ASYNC_PQUERY_BODY, and AsyncQuery().

171 {
172  ASYNC_PQUERY_BODY(format, szQuery)
173  return AsyncQuery(method, param1, param2, szQuery);
174 }
bool AsyncQuery(Class *object, void(Class::*method)(QueryResult_AutoPtr), const char *sql)
Definition: DatabaseImpl.h:68
#define ASYNC_PQUERY_BODY(format, szQuery)
Definition: DatabaseImpl.h:34
template<typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool Database::AsyncPQuery ( void(*)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3)  method,
ParamType1  param1,
ParamType2  param2,
ParamType3  param3,
const char *  format,
  ... 
)

Definition at line 178 of file DatabaseImpl.h.

References ASYNC_PQUERY_BODY, and AsyncQuery().

179 {
180  ASYNC_PQUERY_BODY(format, szQuery)
181  return AsyncQuery(method, param1, param2, param3, szQuery);
182 }
bool AsyncQuery(Class *object, void(Class::*method)(QueryResult_AutoPtr), const char *sql)
Definition: DatabaseImpl.h:68
#define ASYNC_PQUERY_BODY(format, szQuery)
Definition: DatabaseImpl.h:34
template<class Class >
bool Database::AsyncQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr method,
const char *  sql 
)

Definition at line 68 of file DatabaseImpl.h.

References ASYNC_QUERY_BODY, SqlDelayThread::Delay(), and m_threadBody.

Referenced by AsyncPQuery(), and IsConnected().

69 {
70  ASYNC_QUERY_BODY(sql, itr)
71  return m_threadBody->Delay(new SqlQuery(sql, new Oregon::QueryCallback<Class>(object, method), itr->second));
72 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
#define ASYNC_QUERY_BODY(sql, queue_itr)
Definition: DatabaseImpl.h:23
template<class Class , typename ParamType1 >
bool Database::AsyncQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, ParamType1)  method,
ParamType1  param1,
const char *  sql 
)

Definition at line 76 of file DatabaseImpl.h.

References ASYNC_QUERY_BODY, SqlDelayThread::Delay(), and m_threadBody.

77 {
78  ASYNC_QUERY_BODY(sql, itr)
79  return m_threadBody->Delay(new SqlQuery(sql, new Oregon::QueryCallback<Class, ParamType1>(object, method, QueryResult_AutoPtr(NULL), param1), itr->second));
80 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
#define ASYNC_QUERY_BODY(sql, queue_itr)
Definition: DatabaseImpl.h:23
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
template<class Class , typename ParamType1 , typename ParamType2 >
bool Database::AsyncQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, ParamType1, ParamType2)  method,
ParamType1  param1,
ParamType2  param2,
const char *  sql 
)

Definition at line 84 of file DatabaseImpl.h.

References ASYNC_QUERY_BODY, SqlDelayThread::Delay(), and m_threadBody.

85 {
86  ASYNC_QUERY_BODY(sql, itr)
87  return m_threadBody->Delay(new SqlQuery(sql, new Oregon::QueryCallback<Class, ParamType1, ParamType2>(object, method, QueryResult_AutoPtr(NULL), param1, param2), itr->second));
88 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
#define ASYNC_QUERY_BODY(sql, queue_itr)
Definition: DatabaseImpl.h:23
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
template<class Class , typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool Database::AsyncQuery ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3)  method,
ParamType1  param1,
ParamType2  param2,
ParamType3  param3,
const char *  sql 
)

Definition at line 92 of file DatabaseImpl.h.

References ASYNC_QUERY_BODY, SqlDelayThread::Delay(), and m_threadBody.

93 {
94  ASYNC_QUERY_BODY(sql, itr)
95  return m_threadBody->Delay(new SqlQuery(sql, new Oregon::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, QueryResult_AutoPtr(NULL), param1, param2, param3), itr->second));
96 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
#define ASYNC_QUERY_BODY(sql, queue_itr)
Definition: DatabaseImpl.h:23
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
template<typename ParamType1 >
bool Database::AsyncQuery ( void(*)(QueryResult_AutoPtr, ParamType1)  method,
ParamType1  param1,
const char *  sql 
)

Definition at line 102 of file DatabaseImpl.h.

References ASYNC_QUERY_BODY, SqlDelayThread::Delay(), and m_threadBody.

103 {
104  ASYNC_QUERY_BODY(sql, itr)
105  return m_threadBody->Delay(new SqlQuery(sql, new Oregon::SQueryCallback<ParamType1>(method, QueryResult_AutoPtr(NULL), param1), itr->second));
106 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
#define ASYNC_QUERY_BODY(sql, queue_itr)
Definition: DatabaseImpl.h:23
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
template<typename ParamType1 , typename ParamType2 >
bool Database::AsyncQuery ( void(*)(QueryResult_AutoPtr, ParamType1, ParamType2)  method,
ParamType1  param1,
ParamType2  param2,
const char *  sql 
)

Definition at line 110 of file DatabaseImpl.h.

References ASYNC_QUERY_BODY, SqlDelayThread::Delay(), and m_threadBody.

111 {
112  ASYNC_QUERY_BODY(sql, itr)
113  return m_threadBody->Delay(new SqlQuery(sql, new Oregon::SQueryCallback<ParamType1, ParamType2>(method, QueryResult_AutoPtr(NULL), param1, param2), itr->second));
114 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
#define ASYNC_QUERY_BODY(sql, queue_itr)
Definition: DatabaseImpl.h:23
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
template<typename ParamType1 , typename ParamType2 , typename ParamType3 >
bool Database::AsyncQuery ( void(*)(QueryResult_AutoPtr, ParamType1, ParamType2, ParamType3)  method,
ParamType1  param1,
ParamType2  param2,
ParamType3  param3,
const char *  sql 
)

Definition at line 118 of file DatabaseImpl.h.

References ASYNC_QUERY_BODY, SqlDelayThread::Delay(), and m_threadBody.

119 {
120  ASYNC_QUERY_BODY(sql, itr)
121  return m_threadBody->Delay(new SqlQuery(sql, new Oregon::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, QueryResult_AutoPtr(NULL), param1, param2, param3), itr->second));
122 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
#define ASYNC_QUERY_BODY(sql, queue_itr)
Definition: DatabaseImpl.h:23
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
bool Database::BeginTransaction ( )

Definition at line 533 of file Database.cpp.

References ACE_Based::Thread::current(), m_tranQueues, mMysql, nMutex, and tranThread.

Referenced by InstanceSaveManager::_ResetOrWarnAll(), Group::_setLeader(), Player::AutoUnequipOffhandIfNeed(), AuctionHouseBot::Commands(), ArenaTeam::Create(), Group::Create(), Guild::Create(), Guild::CreateBankRightForTab(), Guild::CreateNewBankTab(), AccountMgr::DeleteAccount(), Creature::DeleteFromDB(), Player::DeleteFromDB(), InstanceSaveManager::DeleteInstanceFromDB(), DirectExecute(), ArenaTeam::Disband(), Group::Disband(), Guild::Disband(), WorldSession::HandleAcceptTradeOpcode(), WorldSession::HandleAuctionPlaceBid(), WorldSession::HandleAuctionRemoveItem(), WorldSession::HandleAuctionSellItem(), WorldSession::HandleDeclinedPlayerNameOpcode(), WorldSession::HandleGuildBankDeposit(), WorldSession::HandleGuildBankDepositItem(), WorldSession::HandleGuildBankWithdraw(), WorldSession::HandlePetitionBuyOpcode(), WorldSession::HandlePetRename(), GameEventMgr::HandleQuestComplete(), WorldSession::HandleReturnToSender(), WorldSession::HandleSendMail(), WorldSession::HandleTakeItem(), WorldSession::HandleTakeMoney(), WorldSession::HandleTurnInPetitionOpcode(), WorldSession::HandleWrapItemOpcode(), PlayerDumpReader::LoadDump(), Pet::LoadPetFromDB(), Guild::LoadRanksFromDB(), Player::RemovePetitionsAndSigns(), TicketMgr::SaveGMTicket(), Pet::SavePetToDB(), PoolMgr::SaveQuestsToDB(), Corpse::SaveToDB(), ArenaTeam::SaveToDB(), GameObject::SaveToDB(), Creature::SaveToDB(), Player::SaveToDB(), GameEventMgr::SaveWorldEventStateToDB(), MailDraft::SendMailTo(), MailDraft::SendReturnToSender(), GameEventMgr::StopEvent(), and AuctionHouseObject::Update().

534 {
535  if (!mMysql)
536  return false;
537 
538  nMutex.acquire();
539  tranThread = ACE_Based::Thread::current(); // owner of this transaction
540  TransactionQueues::iterator i = m_tranQueues.find(tranThread);
541  if (i != m_tranQueues.end() && i->second != NULL)
542  // If for thread exists queue and also contains transaction
543  // delete that transaction (not allow trans in trans)
544  delete i->second;
545 
547  nMutex.release();
548  return true;
549 }
static Thread * current()
Definition: Threading.cpp:212
MYSQL * mMysql
Definition: Database.h:165
ACE_Based::Thread * tranThread
Definition: Database.h:163
TransactionQueues m_tranQueues
Definition: Database.h:49
ACE_Thread_Mutex nMutex
Definition: Database.h:160
bool Database::CommitTransaction ( )

Definition at line 551 of file Database.cpp.

References ACE_Based::Thread::current(), SqlDelayThread::Delay(), m_threadBody, m_tranQueues, mMysql, nMutex, and tranThread.

Referenced by InstanceSaveManager::_ResetOrWarnAll(), Group::_setLeader(), Player::AutoUnequipOffhandIfNeed(), AuctionHouseBot::Commands(), ArenaTeam::Create(), Group::Create(), Guild::Create(), Guild::CreateBankRightForTab(), Guild::CreateNewBankTab(), AccountMgr::DeleteAccount(), Creature::DeleteFromDB(), Player::DeleteFromDB(), InstanceSaveManager::DeleteInstanceFromDB(), DirectExecute(), ArenaTeam::Disband(), Group::Disband(), Guild::Disband(), WorldSession::HandleAcceptTradeOpcode(), WorldSession::HandleAuctionPlaceBid(), WorldSession::HandleAuctionRemoveItem(), WorldSession::HandleAuctionSellItem(), WorldSession::HandleDeclinedPlayerNameOpcode(), WorldSession::HandleGuildBankDeposit(), WorldSession::HandleGuildBankDepositItem(), WorldSession::HandleGuildBankWithdraw(), WorldSession::HandlePetitionBuyOpcode(), WorldSession::HandlePetRename(), GameEventMgr::HandleQuestComplete(), WorldSession::HandleReturnToSender(), WorldSession::HandleSendMail(), WorldSession::HandleTakeItem(), WorldSession::HandleTakeMoney(), WorldSession::HandleTurnInPetitionOpcode(), WorldSession::HandleWrapItemOpcode(), PlayerDumpReader::LoadDump(), Pet::LoadPetFromDB(), Guild::LoadRanksFromDB(), Player::RemovePetitionsAndSigns(), TicketMgr::SaveGMTicket(), Pet::SavePetToDB(), PoolMgr::SaveQuestsToDB(), Corpse::SaveToDB(), ArenaTeam::SaveToDB(), GameObject::SaveToDB(), Creature::SaveToDB(), Player::SaveToDB(), GameEventMgr::SaveWorldEventStateToDB(), MailDraft::SendMailTo(), MailDraft::SendReturnToSender(), GameEventMgr::StopEvent(), and AuctionHouseObject::Update().

552 {
553  if (!mMysql)
554  return false;
555 
556  bool _res = false;
557 
558  nMutex.acquire();
560  TransactionQueues::iterator i = m_tranQueues.find(tranThread);
561  if (i != m_tranQueues.end() && i->second != NULL)
562  {
563  m_threadBody->Delay(i->second);
564  m_tranQueues.erase(i);
565  _res = true;
566  }
567  nMutex.release();
568  return _res;
569 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
static Thread * current()
Definition: Threading.cpp:212
MYSQL * mMysql
Definition: Database.h:165
ACE_Based::Thread * tranThread
Definition: Database.h:163
TransactionQueues m_tranQueues
Definition: Database.h:49
bool Delay(SqlOperation *sql)
ACE_Thread_Mutex nMutex
Definition: Database.h:160
template<class Class >
bool bool bool bool bool bool bool bool Database::DelayQueryHolder ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, SqlQueryHolder *)  method,
SqlQueryHolder holder 
)
template<class Class , typename ParamType1 >
bool Database::DelayQueryHolder ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, SqlQueryHolder *, ParamType1)  method,
SqlQueryHolder holder,
ParamType1  param1 
)

Definition at line 196 of file DatabaseImpl.h.

References ASYNC_DELAYHOLDER_BODY, SqlQueryHolder::Execute(), and m_threadBody.

197 {
198  ASYNC_DELAYHOLDER_BODY(holder, itr)
199  return holder->Execute(new Oregon::QueryCallback<Class, SqlQueryHolder*, ParamType1>(object, method, QueryResult_AutoPtr(NULL), holder, param1), m_threadBody, itr->second);
200 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
bool Execute(const char *sql)
Definition: Database.cpp:420
#define ASYNC_DELAYHOLDER_BODY(holder, queue_itr)
Definition: DatabaseImpl.h:53
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
template<class Class >
bool Database::DelayQueryHolder ( Class *  object,
void(Class::*)(QueryResult_AutoPtr, SqlQueryHolder *)  method,
SqlQueryHolder holder 
)

Definition at line 188 of file DatabaseImpl.h.

References ASYNC_DELAYHOLDER_BODY, SqlQueryHolder::Execute(), and m_threadBody.

189 {
190  ASYNC_DELAYHOLDER_BODY(holder, itr)
191  return holder->Execute(new Oregon::QueryCallback<Class, SqlQueryHolder*>(object, method, QueryResult_AutoPtr(NULL), holder), m_threadBody, itr->second);
192 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
bool Execute(const char *sql)
Definition: Database.cpp:420
#define ASYNC_DELAYHOLDER_BODY(holder, queue_itr)
Definition: DatabaseImpl.h:53
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
bool Database::DirectExecute ( PreparedStatement stmt,
PreparedValues values,
va_list *  args 
)

Definition at line 1060 of file Database.cpp.

References _ExecutePreparedStatement(), and mMutex.

1061 {
1062  ACE_Guard<ACE_Thread_Mutex> guardian(mMutex);
1063 
1064  return _ExecutePreparedStatement(stmt, &values, args, false);
1065 }
ACE_Thread_Mutex mMutex
Definition: Database.h:159
bool _ExecutePreparedStatement(PreparedStatement *ps, PreparedValues *values, va_list *args, bool resultset)
Definition: Database.cpp:826
bool Database::DirectExecute ( bool  lock,
const char *  sql 
)
protected

Definition at line 461 of file Database.cpp.

References getMSTime(), getMSTimeDiff(), LOG_TYPE_DEBUG, mMutex, mMysql, and sLog.

462 {
463  if (!mMysql)
464  return false;
465 
466  if (lock)
467  mMutex.acquire();
468 
469  #ifdef OREGON_DEBUG
470  uint32 _s = getMSTime();
471  #endif
472  if (mysql_query(mMysql, sql))
473  {
474  sLog.outErrorDb("SQL: %s", sql);
475  sLog.outErrorDb("SQL ERROR: %s", mysql_error(mMysql));
476  if (lock)
477  mMutex.release();
478  return false;
479  }
480  else
481  {
482  #ifdef OREGON_DEBUG
483  // prevent recursive death
484  unsigned long oldMask = sLog.GetDBLogMask();
485  sLog.SetDBLogMask(oldMask & ~(1 << LOG_TYPE_DEBUG));
486  sLog.outDebug("[%u ms] SQL: %s", getMSTimeDiff(_s, getMSTime()), sql);
487  sLog.SetDBLogMask(oldMask);
488  #endif
489  }
490 
491  if (lock)
492  mMutex.release();
493 
494  return true;
495 }
MYSQL * mMysql
Definition: Database.h:165
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition: Timer.h:78
uint32 getMSTime()
Definition: Timer.h:32
#define sLog
Log class singleton.
Definition: Log.h:187
ACE_Thread_Mutex mMutex
Definition: Database.h:159
NULL LOG_TYPE_DEBUG
Definition: Log.cpp:536
ACE_UINT32 uint32
Definition: Define.h:71
bool Database::DirectPExecute ( const char *  format,
  ... 
)

Definition at line 497 of file Database.cpp.

References DirectExecute(), MAX_QUERY_LEN, sLog, and vsnprintf.

Referenced by InstanceSaveManager::_DelHelper(), InstanceSaveManager::CleanupInstances(), DirectExecute(), InstanceSaveManager::LoadResetTimes(), and ObjectMgr::SetCreatureLinkedRespawn().

498 {
499  if (!format)
500  return false;
501 
502  va_list ap;
503  char szQuery [MAX_QUERY_LEN];
504  va_start(ap, format);
505  int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
506  va_end(ap);
507 
508  if (res == -1)
509  {
510  sLog.outError("SQL Query truncated (and not execute) for format: %s", format);
511  return false;
512  }
513 
514  return DirectExecute(szQuery);
515 }
bool bool DirectExecute(const char *sql)
Definition: Database.h:115
#define sLog
Log class singleton.
Definition: Log.h:187
#define vsnprintf
Definition: Common.h:131
#define MAX_QUERY_LEN
Definition: Database.h:44
unsigned long Database::escape_string ( char *  to,
const char *  from,
unsigned long  length 
)

Definition at line 212 of file Database.cpp.

References mMysql.

Referenced by InstanceSaveManager::_DelHelper(), AuthSocket::_HandleLogonChallenge(), AuthSocket::_HandleLogonProof(), AuthSocket::_HandleReconnectChallenge(), Guild::AddMember(), World::BanAccount(), AccountMgr::ChangePassword(), AccountMgr::ChangeUsername(), RASocket::check_access_level(), RASocket::check_password(), AccountMgr::CheckPassword(), ArenaTeam::Create(), Guild::Create(), AccountMgr::CreateAccount(), CreateDumpString(), ObjectMgr::CreateItemText(), Guild::CreateRank(), escape_string(), AccountMgr::GetId(), ObjectMgr::GetPlayerGUIDByName(), WorldSession::HandleAddFriendOpcode(), WorldSession::HandleAddIgnoreOpcode(), ChatHandler::HandleAddItemCommand(), WorldSocket::HandleAuthSession(), ChatHandler::HandleBanInfoIPCommand(), ChatHandler::HandleBanListAccountCommand(), ChatHandler::HandleBanListCharacterCommand(), ChatHandler::HandleBanListIPCommand(), WorldSession::HandleBugOpcode(), WorldSession::HandleChangePlayerNameOpcode(), WorldSession::HandleDeclinedPlayerNameOpcode(), WorldSession::HandleGMSurveySubmit(), ChatHandler::HandleGoCreatureCommand(), ChatHandler::HandleLookupPlayerAccountCommand(), ChatHandler::HandleLookupPlayerEmailCommand(), ChatHandler::HandleLookupPlayerIpCommand(), WorldSession::HandlePetitionBuyOpcode(), WorldSession::HandlePetitionRenameOpcode(), WorldSession::HandlePetRename(), ChatHandler::HandleTargetObjectCommand(), ChatHandler::HandleWpEventCommand(), ChatHandler::HandleWpModifyCommand(), PlayerDumpReader::LoadDump(), Guild::LoadRanksFromDB(), operator bool(), Log::outDB(), PreparedExecuteLog(), World::RemoveBanAccount(), Master::Run(), TicketMgr::SaveGMTicket(), Pet::SavePetToDB(), InstanceSave::SaveToDB(), InstanceData::SaveToDB(), Player::SaveToDB(), MailDraft::SendMailTo(), PlayerSocial::SetFriendNote(), Guild::SetGINFO(), Guild::SetGuildBankTabInfo(), Guild::SetGuildBankTabText(), Guild::SetMOTD(), Guild::SetOFFNOTE(), Guild::SetPNOTE(), and Guild::SetRankName().

213 {
214  if (!mMysql || !to || !from || !length)
215  return 0;
216 
217  return (mysql_real_escape_string(mMysql, to, from, length));
218 }
MYSQL * mMysql
Definition: Database.h:165
void Database::escape_string ( std::string &  str)

Definition at line 201 of file Database.cpp.

References escape_string().

202 {
203  if (str.empty())
204  return;
205 
206  char* buf = new char[str.size() * 2 + 1];
207  escape_string(buf, str.c_str(), str.size());
208  str = buf;
209  delete[] buf;
210 }
unsigned long escape_string(char *to, const char *from, unsigned long length)
Definition: Database.cpp:212
bool Database::Execute ( const char *  sql)

Definition at line 420 of file Database.cpp.

References ACE_Based::Thread::current(), SqlDelayThread::Delay(), DirectExecute(), m_threadBody, m_tranQueues, mMysql, nMutex, and tranThread.

Referenced by Master::clearOnlineAccounts(), AccountMgr::CreateAccount(), ObjectMgr::CreateItemText(), Player::GetZoneIdFromDB(), ChatHandler::HandleBanListAccountCommand(), ChatHandler::HandleBanListCharacterCommand(), ChatHandler::HandleBanListIPCommand(), Initialize(), IsConnected(), PlayerDumpReader::LoadDump(), Item::LoadFromDB(), main(), InstanceSaveManager::PackInstances(), PExecute(), PExecuteLog(), World::ResetDailyQuests(), Player::SaveDataFieldToDB(), TicketMgr::SaveGMTicket(), Pet::SavePetToDB(), Player::SavePositionInDB(), Corpse::SaveToDB(), Item::SaveToDB(), Player::SaveToDB(), Player::SaveValuesArrayInDB(), and World::SetInitialWorldSettings().

421 {
422  if (!mMysql)
423  return false;
424 
425  // don't use queued execution if it has not been initialized
426  if (!m_threadBody)
427  return DirectExecute(sql);
428 
429  nMutex.acquire();
430  tranThread = ACE_Based::Thread::current(); // owner of this transaction
431  TransactionQueues::iterator i = m_tranQueues.find(tranThread);
432  if (i != m_tranQueues.end() && i->second != NULL)
433  i->second->DelayExecute(sql); // Statement for transaction
434  else
435  m_threadBody->Delay(new SqlStatement(sql)); // Simple sql statement
436 
437  nMutex.release();
438  return true;
439 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
bool bool DirectExecute(const char *sql)
Definition: Database.h:115
static Thread * current()
Definition: Threading.cpp:212
MYSQL * mMysql
Definition: Database.h:165
ACE_Based::Thread * tranThread
Definition: Database.h:163
TransactionQueues m_tranQueues
Definition: Database.h:49
bool Delay(SqlOperation *sql)
ACE_Thread_Mutex nMutex
Definition: Database.h:160
bool Database::ExecuteFile ( const char *  file)

Definition at line 657 of file Database.cpp.

References fileno, mMysql, and sLog.

Referenced by IsConnected().

658 {
659  if (!mMysql)
660  return false;
661 
662  if (mysql_set_server_option(mMysql, MYSQL_OPTION_MULTI_STATEMENTS_ON))
663  {
664  sLog.outErrorDb("Cannot turn multi-statements on: %s", mysql_error(mMysql));
665  return false;
666  }
667 
668  mysql_autocommit(mMysql, 0);
669  if (mysql_real_query(mMysql, "START TRANSACTION", sizeof("START TRANSACTION")-1))
670  {
671  sLog.outErrorDb("Couldn't start transaction for db update file: %s", file);
672  return false;
673  }
674 
675  bool in_transaction = true;
676  bool success = false;
677 
678  if (FILE* fp = ACE_OS::fopen(file, "rb"))
679  {
680  #if PLATFORM == PLATFORM_UNIX
681  flock(fileno(fp), LOCK_SH);
682  #endif
683  //------
684 
685  struct stat info;
686  fstat(fileno(fp), &info);
687 
688  // if less than 1MB allocate on stack, else on heap
689  char* contents = (info.st_size > 1024*1024) ? new char[info.st_size] : (char*) alloca(info.st_size);
690 
691  if (ACE_OS::fread(contents, info.st_size, 1, fp) == 1)
692  {
693  if (mysql_real_query(mMysql, contents, info.st_size))
694  {
695  sLog.outErrorDb("Cannot execute file %s, size: %lu: %s", file, info.st_size, mysql_error(mMysql));
696  }
697  else
698  {
699  do
700  {
701  if (mysql_field_count(mMysql))
702  if (MYSQL_RES* result = mysql_use_result(mMysql))
703  mysql_free_result(result);
704  }
705  while (0 == mysql_next_result(mMysql));
706 
707  // check whether the last mysql_next_result ended with an error
708  if (*mysql_error(mMysql))
709  {
710  success = false;
711  sLog.outErrorDb("Cannot execute file %s, size: %lu: %s", file, info.st_size, mysql_error(mMysql));
712  if (mysql_rollback(mMysql))
713  sLog.outErrorDb("ExecuteFile(): Rollback ended with an error!");
714  else
715  in_transaction = false;
716  }
717  else
718  {
719  if (mysql_commit(mMysql))
720  sLog.outErrorDb("mysql_commit() failed. Update %s will not be applied!", file);
721  else
722  in_transaction = false;
723  success = true;
724  }
725  }
726  }
727  else
728  {
729  sLog.outErrorDb("Couldn't read file %s, size: %lu", file, info.st_size);
730  return false;
731  }
732 
733  // if allocated on heap, free memory
734  if (info.st_size > 1024*1024)
735  delete [] contents;
736 
737  //------
738  #if PLATFORM == PLATFORM_UNIX
739  flock(fileno(fp), LOCK_UN);
740  #endif
741  ACE_OS::fclose(fp);
742  }
743 
744  mysql_set_server_option(mMysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF);
745  mysql_autocommit(mMysql, 1);
746  if (in_transaction)
747  mysql_rollback(mMysql);
748  return success;
749 }
MYSQL * mMysql
Definition: Database.h:165
#define sLog
Log class singleton.
Definition: Log.h:187
#define fileno
Definition: Common.h:135
bool Database::ExecuteTransaction ( SqlTransaction transaction)

Atomically executed SqlTransaction. Don't call this directly, use BeginTransaction and CommitTransaction instead.

Definition at line 593 of file Database.cpp.

References _ExecutePreparedStatement(), DirectExecute(), SqlTransaction::QueuedItem::isStmt, mMutex, mMysql, SqlTransaction::mutex, SqlTransaction::queue, SqlTransaction::QueuedItem::sql, SqlTransaction::QueuedItem::stmt, and SqlTransaction::QueuedItem::values.

Referenced by DirectExecute(), and SqlTransaction::Execute().

594 {
596 
597  ACE_Guard<ACE_Thread_Mutex> connection_guard(mMutex);
598  ACE_Guard<ACE_Thread_Mutex> transaction_guard(transaction->mutex);
599 
600  if (transaction->queue.empty())
601  return true;
602 
603  if (mysql_autocommit(mMysql, 0))
604  return false;
605 
606  if (mysql_real_query(mMysql, "START TRANSACTION", sizeof("START TRANSACTION")-1))
607  return false;
608 
609  while (!transaction->queue.empty())
610  {
611  item = transaction->queue.front();
612 
613  bool ok = (item.isStmt) ? _ExecutePreparedStatement(item.stmt, item.values, NULL, false) : DirectExecute(false, item.sql);
614  if (!ok)
615  {
616  transaction->queue.pop();
617  mysql_rollback(mMysql);
618  mysql_autocommit(mMysql, 1);
619  return false;
620  }
621 
622  if (!item.isStmt)
623  free (item.sql);
624  else
625  delete item.values;
626  transaction->queue.pop();
627  }
628 
629  if (mysql_commit(mMysql))
630  return false;
631 
632  mysql_autocommit(mMysql, 1);
633  return true;
634 }
std::queue< QueuedItem > queue
Definition: SqlOperations.h:97
bool bool DirectExecute(const char *sql)
Definition: Database.h:115
MYSQL * mMysql
Definition: Database.h:165
ACE_Thread_Mutex mutex
Definition: SqlOperations.h:98
PreparedStatement * stmt
Definition: SqlOperations.h:89
PreparedValues * values
Definition: SqlOperations.h:90
ACE_Thread_Mutex mMutex
Definition: Database.h:159
bool _ExecutePreparedStatement(PreparedStatement *ps, PreparedValues *values, va_list *args, bool resultset)
Definition: Database.cpp:826
void Database::HaltDelayThread ( )

Definition at line 645 of file Database.cpp.

References m_delayThread, m_threadBody, SqlDelayThread::Stop(), and ACE_Based::Thread::wait().

Referenced by IsConnected(), main(), Master::Run(), and ~Database().

646 {
647  if (!m_threadBody || !m_delayThread)
648  return;
649 
650  m_threadBody->Stop(); //Stop event
651  m_delayThread->wait(); //Wait for flush to DB
652  delete m_delayThread; //This also deletes m_threadBody
653  m_delayThread = NULL;
654  m_threadBody = NULL;
655 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
ACE_Based::Thread * m_delayThread
Definition: Database.h:52
void Database::InitDelayThread ( )

Definition at line 636 of file Database.cpp.

References m_delayThread, and m_threadBody.

Referenced by Initialize(), and IsConnected().

637 {
638  assert(!m_delayThread);
639 
640  //New delay thread for delay execute
641  m_threadBody = new SqlDelayThread(this); // will deleted at m_delayThread delete
643 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
ACE_Based::Thread * m_delayThread
Definition: Database.h:52
bool Database::Initialize ( const char *  infoString)
Parameters
infoStringshould be formated like hostname;username;password;database.

Definition at line 75 of file Database.cpp.

References Execute(), InitDelayThread(), m_connected, m_logsDir, m_logSQL, mMysql, sConfig, sLog, StrSplit(), and tranThread.

Referenced by Master::_StartDB(), and StartDB().

76 {
77  // Enable logging of SQL commands (usally only GM commands)
78  // (See method: PExecuteLog)
79  m_logSQL = sConfig.GetBoolDefault("LogSQL", false);
80  m_logsDir = sConfig.GetStringDefault("LogsDir", "");
81  if (!m_logsDir.empty())
82  {
83  if ((m_logsDir.at(m_logsDir.length() - 1) != '/') && (m_logsDir.at(m_logsDir.length() - 1) != '\\'))
84  m_logsDir.append("/");
85  }
86 
87  tranThread = NULL;
88  MYSQL* mysqlInit;
89  mysqlInit = mysql_init(NULL);
90  if (!mysqlInit)
91  {
92  sLog.outError("Could not initialize Mysql connection");
93  return false;
94  }
95 
97 
98  Tokens tokens = StrSplit(infoString, ";");
99 
100  Tokens::iterator iter;
101 
102  std::string host, port_or_socket, user, password, database;
103  int port;
104  char const* unix_socket;
105 
106  iter = tokens.begin();
107 
108  if (iter != tokens.end())
109  host = *iter++;
110  if (iter != tokens.end())
111  port_or_socket = *iter++;
112  if (iter != tokens.end())
113  user = *iter++;
114  if (iter != tokens.end())
115  password = *iter++;
116  if (iter != tokens.end())
117  database = *iter++;
118 
119  mysql_options(mysqlInit, MYSQL_SET_CHARSET_NAME, "utf8");
120  #ifdef _WIN32
121  if (host == ".") // named pipe use option (Windows)
122  {
123  unsigned int opt = MYSQL_PROTOCOL_PIPE;
124  mysql_options(mysqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt);
125  port = 0;
126  unix_socket = 0;
127  }
128  else // generic case
129  {
130  port = atoi(port_or_socket.c_str());
131  unix_socket = 0;
132  }
133  #else
134  if (host == ".") // socket use option (Unix/Linux)
135  {
136  unsigned int opt = MYSQL_PROTOCOL_SOCKET;
137  mysql_options(mysqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt);
138  host = "localhost";
139  port = 0;
140  unix_socket = port_or_socket.c_str();
141  }
142  else // generic case
143  {
144  port = atoi(port_or_socket.c_str());
145  unix_socket = 0;
146  }
147  #endif
148 
149  mMysql = mysql_real_connect(mysqlInit, host.c_str(), user.c_str(),
150  password.c_str(), database.c_str(), port, unix_socket, 0);
151 
152  if (mMysql)
153  {
154  sLog.outDetail("Connected to MySQL database at %s", host.c_str());
155  sLog.outDebug("MySQL client library: %s", mysql_get_client_info());
156  sLog.outDebug("MySQL server ver: %s ", mysql_get_server_info( mMysql));
157 
158  if (!mysql_autocommit(mMysql, 1))
159  sLog.outDebug("AUTOCOMMIT SUCCESSFULLY SET TO 1");
160  else
161  sLog.outDebug("AUTOCOMMIT NOT SET TO 1");
162 
163  // set connection properties to UTF8 to properly handle locales for different
164  // server configs - core sends data in UTF8, so MySQL must expect UTF8 too
165  // mysql_set_character_set is just like SET NAMES, but also sets encoding in client library
166  // which enforces mysql_real_escape_string to be safe
167  mysql_set_character_set(mMysql, "utf8");
168  Execute("SET CHARACTER SET `utf8`");
169 
170  #if MYSQL_VERSION_ID >= 50003
171  my_bool my_true = (my_bool)1;
172  if (mysql_options(mMysql, MYSQL_OPT_RECONNECT, &my_true))
173  sLog.outDebug("Failed to turn on MYSQL_OPT_RECONNECT.");
174  else
175  sLog.outDebug("Successfully turned on MYSQL_OPT_RECONNECT.");
176  #else
177 #warning "Your mySQL client lib version does not support reconnecting after a timeout.\nIf this causes you any trouble we advice you to upgrade your mySQL client libs to at least mySQL 5.0.13 to resolve this problem."
178  #endif
179 
180  m_connected = true;
181  return true;
182  }
183  else
184  {
185  sLog.outError("Could not connect to MySQL database at %s: %s", host.c_str(), mysql_error(mysqlInit));
186  mysql_close(mysqlInit);
187  return false;
188  }
189 }
#define sConfig
Definition: Config.h:52
std::string m_logsDir
Definition: Database.h:158
std::vector< std::string > Tokens
Definition: Util.h:26
bool m_connected
Definition: Database.h:166
MYSQL * mMysql
Definition: Database.h:165
bool Execute(const char *sql)
Definition: Database.cpp:420
#define sLog
Log class singleton.
Definition: Log.h:187
Tokens StrSplit(const std::string &src, const std::string &sep)
Definition: Util.cpp:97
ACE_Based::Thread * tranThread
Definition: Database.h:163
bool m_logSQL
Definition: Database.h:157
void InitDelayThread()
Definition: Database.cpp:636
bool Database::IsConnected ( ) const
inline
Database::operator bool ( ) const
inline

Definition at line 141 of file Database.h.

References DirectExecute(), escape_string(), mMysql, SetResultQueue(), ThreadEnd(), and ThreadStart().

142  {
143  return mMysql != NULL;
144  }
MYSQL * mMysql
Definition: Database.h:165
bool Database::PExecute ( const char *  format,
  ... 
)

Definition at line 441 of file Database.cpp.

References Execute(), MAX_QUERY_LEN, sLog, and vsnprintf.

Referenced by Group::_addMember(), AuthSocket::_HandleLogonProof(), Player::_LoadBoundInstances(), Player::_LoadHomeBind(), Player::_LoadInventory(), Player::_LoadMailedItems(), Player::_LoadSkills(), Group::_removeMember(), InstanceSaveManager::_ResetOrWarnAll(), Player::_SaveActions(), Pet::_SaveAuras(), Player::_SaveAuras(), Player::_SaveBGData(), Player::_SaveDailyQuestStatus(), Player::_SaveInventory(), Player::_SaveMail(), Player::_SaveQuestStatus(), Player::_SaveSkills(), Pet::_SaveSpellCooldowns(), Player::_SaveSpellCooldowns(), Pet::_SaveSpells(), Player::_SaveSpells(), Player::_SaveTutorials(), Group::_setAssistantFlag(), Group::_setLeader(), Group::_setMainAssistant(), Group::_setMainTank(), Group::_setMembersGroup(), AuthSocket::_SetVSFields(), Master::_StartDB(), World::_UpdateRealmCharCount(), Guild::AddGBankItemToDB(), ArenaTeam::AddMember(), Guild::AddMember(), AuctionHouseBot::addNewAuctionBuyerBotBid(), World::AddSession_(), Pet::addSpell(), Player::AddSpell(), PlayerSocial::AddToSocialList(), World::BanAccount(), Group::BindToInstance(), Player::BindToInstance(), AccountMgr::ChangePassword(), Guild::ChangeRank(), AccountMgr::ChangeUsername(), Master::clearOnlineAccounts(), AuctionHouseBot::Commands(), Player::ConvertInstancesToGroup(), Group::ConvertToRaid(), ArenaTeam::Create(), Group::Create(), Guild::Create(), AccountMgr::CreateAccount(), Guild::CreateBankRightForTab(), Guild::CreateDefaultGuildRanks(), Guild::CreateNewBankTab(), Guild::CreateRank(), OPvPCapturePoint::DelCreature(), AccountMgr::DeleteAccount(), Corpse::DeleteFromDB(), AuctionEntry::DeleteFromDB(), Pet::DeleteFromDB(), Item::DeleteFromDB(), Player::DeleteFromDB(), Item::DeleteFromInventoryDB(), TicketMgr::DeleteGMTicketPermanently(), MailDraft::deleteIncludedItems(), InstanceSaveManager::DeleteInstanceFromDB(), ObjectMgr::DeleteRespawnTimeForInstance(), ArenaTeam::DelMember(), Guild::DelMember(), Guild::DelRank(), Player::DestroyItem(), ArenaTeam::Disband(), Group::Disband(), Guild::Disband(), BattlegroundMgr::DistributeArenaPoints(), Guild::GetMemberMoneyWithdrawRem(), Guild::GetMemberSlotWithdrawRem(), ChatHandler::HandleAccountLockCommand(), ChatHandler::HandleAccountSetAddonCommand(), ChatHandler::HandleAccountSetGmLevelCommand(), WorldSession::HandleAuctionPlaceBid(), WorldSocket::HandleAuthSession(), WorldSession::HandleBugOpcode(), WorldSession::HandleChangePlayerNameOpcodeCallBack(), ChatHandler::HandleCharacterDeletedRestoreHelper(), ChatHandler::HandleCharacterRenameCommand(), WorldSession::HandleCharCreateOpcode(), WorldSession::HandleDeclinedPlayerNameOpcode(), WorldSession::HandleGMSurveySubmit(), ChatHandler::HandleLevelUpCommand(), ChatHandler::HandleMuteCommand(), WorldSession::HandleOpenItemOpcode(), WorldSession::HandlePetitionBuyOpcode(), WorldSession::HandlePetitionRenameOpcode(), WorldSession::HandlePetitionSignOpcode(), WorldSession::HandlePetRename(), WorldSession::HandlePlayerLogin(), GameEventMgr::HandleQuestComplete(), ChatHandler::HandleResetAllCommand(), ChatHandler::HandleResetSpellsCommand(), ChatHandler::HandleResetTalentsCommand(), WorldSession::HandleReturnToSender(), WorldSession::HandleSendMail(), WorldSession::HandleTurnInPetitionOpcode(), ChatHandler::HandleUnmuteCommand(), ChatHandler::HandleWpEventCommand(), ChatHandler::HandleWpLoadPathCommand(), ChatHandler::HandleWpUnLoadPathCommand(), WorldSession::HandleWrapItemOpcode(), BattlegroundMgr::InitAutomaticArenaPointDistribution(), IsConnected(), ObjectMgr::LinkIntoRAF(), Guild::LoadBankRightsFromDB(), Player::LoadFromDB(), ObjectMgr::LoadGroups(), Guild::LoadGuildBankEventLogFromDB(), Guild::LoadGuildBankFromDB(), Guild::LoadGuildEventLogFromDB(), ArenaTeam::LoadMembersFromDB(), Guild::LoadMembersFromDB(), Pet::LoadPetFromDB(), Guild::LoadRanksFromDB(), Guild::LogBankEvent(), Guild::LogGuildEvent(), WorldSession::LogoutPlayer(), Guild::MemberItemWithdraw(), Guild::MemberMoneyWithdraw(), Player::ModifyArenaPoints(), Log::outDB(), InstanceSaveManager::PackInstances(), World::RemoveBanAccount(), PlayerSocial::RemoveFromSocialList(), ObjectMgr::RemoveGraveYardLink(), InstanceSaveManager::RemoveInstanceSave(), Guild::RemoveItem(), Player::RemovePetitionsAndSigns(), Guild::RenumBankLogs(), Guild::RenumGuildEventlog(), Group::ResetInstances(), Player::ResetSpells(), Player::ResetTalents(), ObjectMgr::ReturnOrDeleteOldMails(), Master::Run(), ObjectMgr::SaveCreatureRespawnTime(), Player::SaveGoldToDB(), ObjectMgr::SaveGORespawnTime(), Pet::SavePetToDB(), PoolMgr::SaveQuestsToDB(), ReputationMgr::SaveToDB(), AuctionEntry::SaveToDB(), InstanceSave::SaveToDB(), InstanceData::SaveToDB(), Item::SaveToDB(), ArenaTeam::SaveToDB(), GameEventMgr::SaveWorldEventStateToDB(), AuctionHouseMgr::SendAuctionWonMail(), WorldSession::SendExternalMails(), MailDraft::SendMailTo(), MailDraft::SendReturnToSender(), Guild::SetBankMoney(), Guild::SetBankMoneyPerDay(), Guild::SetBankRightsAndSlots(), ArenaTeam::SetCaptain(), Group::SetDifficulty(), ArenaTeam::SetEmblem(), Guild::SetEmblem(), PlayerSocial::SetFriendNote(), Guild::SetGINFO(), Guild::SetGuildBankTabInfo(), Guild::SetGuildBankTabText(), ObjectMgr::SetHighestGuids(), Player::SetHomebindToLocation(), World::SetInitialWorldSettings(), Guild::SetLeader(), Guild::SetMOTD(), Guild::SetOFFNOTE(), Guild::SetPNOTE(), Guild::SetRankName(), Guild::SetRankRights(), ArenaTeam::SetStats(), GameEventMgr::StopEvent(), Group::UnbindInstance(), Player::UnbindInstance(), ObjectMgr::UnlinkFromRAF(), BattlegroundMgr::Update(), World::Update(), WorldSession::WorldSession(), Battleground::~Battleground(), and WorldSession::~WorldSession().

442 {
443  if (!format)
444  return false;
445 
446  va_list ap;
447  char szQuery [MAX_QUERY_LEN];
448  va_start(ap, format);
449  int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
450  va_end(ap);
451 
452  if (res == -1)
453  {
454  sLog.outError("SQL Query truncated (and not execute) for format: %s", format);
455  return false;
456  }
457 
458  return Execute(szQuery);
459 }
bool Execute(const char *sql)
Definition: Database.cpp:420
#define sLog
Log class singleton.
Definition: Log.h:187
#define vsnprintf
Definition: Common.h:131
#define MAX_QUERY_LEN
Definition: Database.h:44
bool Database::PExecuteLog ( const char *  format,
  ... 
)

Definition at line 221 of file Database.cpp.

References Execute(), MAX_QUERY_LEN, sLog, and vsnprintf.

Referenced by ObjectMgr::AddGameTele(), ObjectMgr::AddGraveYardLink(), ObjectMgr::AddVendorItem(), GameObject::DeleteFromDB(), Creature::DeleteFromDB(), ObjectMgr::DeleteGameTele(), DirectExecute(), ChatHandler::HandleNpcFactionIdCommand(), ChatHandler::HandleNpcFlagCommand(), ChatHandler::HandleNpcMoveCommand(), ChatHandler::HandleNpcSpawnDistCommand(), ChatHandler::HandleNpcSpawnTimeCommand(), ChatHandler::HandleWpAddCommand(), ChatHandler::HandleWpEventCommand(), ChatHandler::HandleWpModifyCommand(), ChatHandler::HandleWpShowCommand(), ObjectMgr::RemoveVendorItem(), GameObject::SaveToDB(), and Creature::SaveToDB().

222 {
223  if (!format)
224  return false;
225 
226  va_list ap;
227  char szQuery [MAX_QUERY_LEN];
228  va_start(ap, format);
229  int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
230  va_end(ap);
231 
232  if (res == -1)
233  {
234  sLog.outError("SQL Query truncated (and not execute) for format: %s", format);
235  return false;
236  }
237 
238  sLog.outSQL("%s", szQuery);
239  return Execute(szQuery);
240 }
bool Execute(const char *sql)
Definition: Database.cpp:420
#define sLog
Log class singleton.
Definition: Log.h:187
#define vsnprintf
Definition: Common.h:131
#define MAX_QUERY_LEN
Definition: Database.h:44
QueryResult_AutoPtr Database::PQuery ( const char *  format,
  ... 
)

Definition at line 400 of file Database.cpp.

References MAX_QUERY_LEN, Query(), sLog, and vsnprintf.

Referenced by InstanceSaveManager::_DelHelper(), AuthSocket::_HandleLogonChallenge(), AuthSocket::_HandleLogonProof(), AuthSocket::_HandleRealmList(), AuthSocket::_HandleReconnectChallenge(), Pet::_LoadAuras(), Player::_LoadMail(), Player::_LoadMailedItems(), Pet::_LoadSpellCooldowns(), Pet::_LoadSpells(), Player::_SaveTutorials(), ArenaTeam::AddMember(), AuctionHouseBot::addNewAuctionBuyerBotBid(), World::BanAccount(), AccountMgr::ChangePassword(), AccountMgr::ChangeUsername(), RASocket::check_access_level(), RASocket::check_password(), AccountMgr::CheckPassword(), AccountMgr::CreateAccount(), InstanceMap::CreateInstanceData(), AccountMgr::DeleteAccount(), Player::DeleteFromDB(), Player::DeleteOldCharacters(), PlayerDumpWriter::DumpTable(), Guild::FillPlayerData(), Player::GetArenaTeamIdFromDB(), AccountMgr::GetCharactersCount(), ChatHandler::GetDeletedCharacterInfoList(), AccountMgr::GetId(), Player::GetLevelFromDB(), AccountMgr::GetName(), ObjectMgr::GetPlayerAccountIdByGUID(), ObjectMgr::GetPlayerAccountIdByPlayerName(), ObjectMgr::GetPlayerGUIDByName(), ObjectMgr::GetPlayerNameByGUID(), ObjectMgr::GetPlayerTeamByGUID(), AccountMgr::GetSecurity(), ChatHandler::HandleAccountOnlineListCommand(), ChatHandler::HandleAddItemCommand(), WorldSocket::HandleAuthSession(), ChatHandler::HandleBanInfoHelper(), ChatHandler::HandleBanInfoIPCommand(), ChatHandler::HandleBanListAccountCommand(), ChatHandler::HandleBanListCharacterCommand(), ChatHandler::HandleBanListHelper(), ChatHandler::HandleBanListIPCommand(), WorldSession::HandleCharCreateOpcode(), WorldSession::HandleCharDeleteOpcode(), ChatHandler::HandleGoCreatureCommand(), ChatHandler::HandleLearnAllMySpellsCommand(), ChatHandler::HandleListCreatureCommand(), ChatHandler::HandleListItemCommand(), ChatHandler::HandleListObjectCommand(), ChatHandler::HandleLookupPlayerAccountCommand(), ChatHandler::HandleLookupPlayerEmailCommand(), ChatHandler::HandleLookupPlayerIpCommand(), ChatHandler::HandleNearObjectCommand(), WorldSession::HandleOfferPetitionOpcode(), WorldSession::HandleOpenItemOpcode(), WorldSession::HandlePetitionBuyOpcode(), WorldSession::HandlePetitionDeclineOpcode(), WorldSession::HandlePetitionRenameOpcode(), WorldSession::HandlePetitionShowSignOpcode(), WorldSession::HandlePetitionSignOpcode(), ChatHandler::HandlePInfoCommand(), WorldSession::HandlePlayerLoginOpcode(), WorldSession::HandleSendMail(), WorldSession::HandleStablePet(), WorldSession::HandleStableSwapPet(), ChatHandler::HandleTargetObjectCommand(), WorldSession::HandleTurnInPetitionOpcode(), ChatHandler::HandleUnFreezeCommand(), WorldSession::HandleUnstablePet(), WorldSession::HandleWhoisOpcode(), ChatHandler::HandleWpAddCommand(), ChatHandler::HandleWpEventCommand(), ChatHandler::HandleWpLoadPathCommand(), ChatHandler::HandleWpModifyCommand(), ChatHandler::HandleWpShowCommand(), AuctionHouseBot::Initialize(), IsConnected(), SQLStorageLoaderBase< T >::Load(), PlayerDumpReader::LoadDump(), Group::LoadGroupFromDB(), Guild::LoadGuildBankEventLogFromDB(), Guild::LoadGuildBankFromDB(), Guild::LoadGuildEventLogFromDB(), LootStore::LoadLootTable(), ObjectMgr::LoadOregonStrings(), Player::LoadPet(), Pet::LoadPetFromDB(), Player::LoadPositionFromDB(), ObjectMgr::LoadQuestRelationsHelper(), AuthSocket::LoadRealmlist(), ObjectMgr::LoadScripts(), SpellMgr::LoadSpellDummyCondition(), AuctionHouseBot::LoadValues(), Player::LoadValuesArrayFromDB(), ObjectMgr::LoadWaypointScripts(), ChatHandler::LookupPlayerSearchCommand(), WaypointMgr::ReloadPath(), Player::RemovePetitionsAndSigns(), Guild::RenumBankLogs(), Guild::RenumGuildEventlog(), ObjectMgr::ReturnOrDeleteOldMails(), WorldSession::SendPetitionQueryOpcode(), WorldSession::SendStablePet(), PoolGroup< Quest >::SpawnObject(), AuctionHouseObject::Update(), and World::UpdateAllowedSecurity().

401 {
402  if (!format)
403  return QueryResult_AutoPtr(NULL);
404 
405  va_list ap;
406  char szQuery [MAX_QUERY_LEN];
407  va_start(ap, format);
408  int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
409  va_end(ap);
410 
411  if (res == -1)
412  {
413  sLog.outError("SQL Query truncated (and not execute) for format: %s", format);
414  return QueryResult_AutoPtr(NULL);
415  }
416 
417  return Query(szQuery);
418 }
#define sLog
Log class singleton.
Definition: Log.h:187
QueryResult_AutoPtr Query(const char *sql)
Definition: Database.cpp:383
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
#define vsnprintf
Definition: Common.h:131
#define MAX_QUERY_LEN
Definition: Database.h:44
bool Database::PreparedExecute ( const char *  sql,
const char *  format = NULL,
  ... 
)

Executes Query via Prepared Statements.

Definition at line 1071 of file Database.cpp.

References _ConvertValistToPreparedValues(), _GetOrMakePreparedStatement(), ACE_Based::Thread::current(), SqlDelayThread::Delay(), DirectExecute(), m_threadBody, m_tranQueues, mMysql, nMutex, and tranThread.

Referenced by DirectExecute(), and PreparedExecuteLog().

1072 {
1073  if (!mMysql)
1074  return false;
1075 
1076  PreparedValues values(strlen(format));
1077 
1078  va_list args;
1079  va_start(args, format);
1080  _ConvertValistToPreparedValues(args, values, format);
1081  va_end(args);
1082 
1083  PreparedStatement* stmt = _GetOrMakePreparedStatement(sql, NULL, &values);
1084 
1085  // don't use queued execution if it has not been initialized
1086  if (!m_threadBody)
1087  return DirectExecute(stmt, values, NULL);
1088 
1089  nMutex.acquire();
1090  tranThread = ACE_Based::Thread::current(); // owner of this transaction
1091  TransactionQueues::iterator i = m_tranQueues.find(tranThread);
1092  if (i != m_tranQueues.end() && i->second != NULL)
1093  i->second->DelayExecute(stmt, values); // Statement for transaction
1094  else
1095  m_threadBody->Delay(new SqlPreparedStatement(stmt, values)); // Simple sql statement
1096 
1097  nMutex.release();
1098  return true;
1099 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
bool bool DirectExecute(const char *sql)
Definition: Database.h:115
void _ConvertValistToPreparedValues(va_list ap, PreparedValues &values, const char *fmt)
Definition: Database.cpp:964
static Thread * current()
Definition: Threading.cpp:212
MYSQL * mMysql
Definition: Database.h:165
ACE_Based::Thread * tranThread
Definition: Database.h:163
TransactionQueues m_tranQueues
Definition: Database.h:49
bool Delay(SqlOperation *sql)
ACE_Thread_Mutex nMutex
Definition: Database.h:160
PreparedStatement * _GetOrMakePreparedStatement(const char *query, const char *format, PreparedValues *values)
Definition: Database.cpp:751
bool Database::PreparedExecute ( const char *  sql,
PreparedValues values 
)

Executes Query via Prepared Statements.

Definition at line 1104 of file Database.cpp.

References _GetOrMakePreparedStatement(), ACE_Based::Thread::current(), SqlDelayThread::Delay(), DirectExecute(), m_threadBody, m_tranQueues, mMysql, nMutex, and tranThread.

1105 {
1106  if (!mMysql)
1107  return false;
1108 
1109  PreparedStatement* stmt = _GetOrMakePreparedStatement(sql, NULL, &values);
1110 
1111  // don't use queued execution if it has not been initialized
1112  if (!m_threadBody)
1113  return DirectExecute(stmt, values, NULL);
1114 
1115  nMutex.acquire();
1116  tranThread = ACE_Based::Thread::current(); // owner of this transaction
1117  TransactionQueues::iterator i = m_tranQueues.find(tranThread);
1118  if (i != m_tranQueues.end() && i->second != NULL)
1119  i->second->DelayExecute(stmt, values); // Statement for transaction
1120  else
1121  m_threadBody->Delay(new SqlPreparedStatement(stmt, values)); // Simple sql statement
1122 
1123  nMutex.release();
1124  return true;
1125 }
SqlDelayThread * m_threadBody
Definition: Database.h:51
bool bool DirectExecute(const char *sql)
Definition: Database.h:115
static Thread * current()
Definition: Threading.cpp:212
MYSQL * mMysql
Definition: Database.h:165
ACE_Based::Thread * tranThread
Definition: Database.h:163
TransactionQueues m_tranQueues
Definition: Database.h:49
bool Delay(SqlOperation *sql)
ACE_Thread_Mutex nMutex
Definition: Database.h:160
PreparedStatement * _GetOrMakePreparedStatement(const char *query, const char *format, PreparedValues *values)
Definition: Database.cpp:751
bool Database::PreparedExecuteLog ( const char *  sql,
const char *  format = NULL,
  ... 
)

Definition at line 242 of file Database.cpp.

References _ConvertValistToPreparedValues().

Referenced by DirectExecute().

243 {
244  if (format)
245  {
246  PreparedValues values(strlen(format));
247 
248  va_list ap;
249  va_start(ap, format);
250  _ConvertValistToPreparedValues(ap, values, format);
251  va_end(ap);
252 
253  return PreparedExecuteLog(sql, values);
254  }
255 
256  PreparedValues values(0);
257  return PreparedExecuteLog(sql, values);
258 }
void _ConvertValistToPreparedValues(va_list ap, PreparedValues &values, const char *fmt)
Definition: Database.cpp:964
bool bool PreparedExecuteLog(const char *sql, const char *format=NULL,...)
Definition: Database.cpp:242
bool Database::PreparedExecuteLog ( const char *  sql,
PreparedValues values 
)

Definition at line 260 of file Database.cpp.

References ARG_TYPE_BINARY, ARG_TYPE_BINARY_ALT, ARG_TYPE_DOUBLE, ARG_TYPE_FLOAT, ARG_TYPE_LARGE_NUMBER, ARG_TYPE_LARGE_NUMBER_ALT, ARG_TYPE_LARGE_UNSIGNED_NUMBER, ARG_TYPE_NUMBER, ARG_TYPE_NUMBER_ALT, ARG_TYPE_STRING, ARG_TYPE_STRING_ALT, ARG_TYPE_UNSIGNED_NUMBER, escape_string(), PreparedExecute(), PreparedValues::size(), and sLog.

261 {
262  std::string query(sql);
263  std::stringstream ss;
264  size_t pos = 0, i = 0;
265 
266  while ((pos = query.find("?", pos)) != std::string::npos)
267  {
268  switch (values[i].type)
269  {
270  case ARG_TYPE_STRING:
271  case ARG_TYPE_STRING_ALT:
272  {
273  std::string safeStr(values[i].data.string);
274  escape_string(safeStr);
275  safeStr += '\'';
276  safeStr.insert(0, "'");
277  query.replace(pos, 1, safeStr);
278  }
279  break;
280  case ARG_TYPE_BINARY:
281  case ARG_TYPE_BINARY_ALT:
282  ss << "0x" << std::hex;
283  for (size_t j = 0; j < values[i].data.length; ++j)
284  ss << *reinterpret_cast<const char*>(values[i].data.binary);
285  ss.clear();
286  break;
287  case ARG_TYPE_FLOAT:
288  ss << values[i].data.float_;
289  query.replace(pos, 1, ss.str());
290  ss.clear();
291  break;
292  case ARG_TYPE_DOUBLE:
293  ss << values[i].data.double_;
294  query.replace(pos, 1, ss.str());
295  ss.clear();
296  break;
297  case ARG_TYPE_NUMBER:
298  case ARG_TYPE_NUMBER_ALT:
299  ss << values[i].data.number;
300  query.replace(pos, 1, ss.str());
301  ss.clear();
302  break;
304  ss << values[i].data.unsignedNumber;
305  query.replace(pos, 1, ss.str());
306  ss.clear();
307  break;
310  ss << values[i].data.largeNumber;
311  query.replace(pos, 1, ss.str());
312  ss.clear();
313  break;
315  ss << values[i].data.unsignedLargeNumber;
316  query.replace(pos, 1, ss.str());
317  ss.clear();
318  break;
319  }
320 
321  ++i;
322  }
323 
324  sLog.outSQL("%s", query.c_str());
325 
326  if (values.size())
327  return PreparedExecute(sql, values);
328  else
329  return PreparedExecute(sql);
330 }
char const*, can be NULL
#define sLog
Log class singleton.
Definition: Log.h:187
unsigned long escape_string(char *to, const char *from, unsigned long length)
Definition: Database.cpp:212
size_t size() const
bool PreparedExecute(const char *sql, const char *format=NULL,...)
Executes Query via Prepared Statements.
Definition: Database.cpp:1071
64bit signed int
floating point
void const*, can be NULL
PreparedQueryResult_AutoPtr Database::PreparedQuery ( const char *  sql,
const char *  format = NULL,
  ... 
)

Runs Query via Prepared Statements. If statement doesn't exist, it shall be created. This function blocks calling thread until query is done, if your query is result-less use PreparedExecute instead.

Parameters
sqlThe sql to execute in template form
formatTypes of bound variables/values - see PreparedArgType
Returns
Result with compatible interface to QueryResult.
Note
For compatiblity reasons, if query result failed or contains no rows, the result will be NULL and may cause a crash if you don't count with it.
See also
Database::Query, Database::PQuery, Database::PreparedExecute Example:
...PreparedQuery("SELECT 1, 2, 3 FROM table WHERE id = ? AND name = ?", "is", 20, "john")

Definition at line 1024 of file Database.cpp.

References _ExecutePreparedStatement(), _GetOrMakePreparedStatement(), mMutex, and PreparedStatement::stmt.

Referenced by DirectExecute().

1025 {
1026  ACE_Guard<ACE_Thread_Mutex> guardian(mMutex);
1027  PreparedStatement* stmt = _GetOrMakePreparedStatement(sql, format, NULL);
1028 
1029  if (!stmt)
1030  return PreparedQueryResult_AutoPtr(NULL);
1031 
1032  va_list ap;
1033  va_start(ap, format);
1034 
1035  if (!_ExecutePreparedStatement(stmt, NULL, &ap, true))
1036  {
1037  va_end(ap);
1038  return PreparedQueryResult_AutoPtr(NULL);
1039  }
1040 
1041  va_end(ap);
1042 
1044 }
ACE_Refcounted_Auto_Ptr< PreparedQueryResult, ACE_Null_Mutex > PreparedQueryResult_AutoPtr
Definition: QueryResult.h:114
ACE_Thread_Mutex mMutex
Definition: Database.h:159
bool _ExecutePreparedStatement(PreparedStatement *ps, PreparedValues *values, va_list *args, bool resultset)
Definition: Database.cpp:826
PreparedStatement * _GetOrMakePreparedStatement(const char *query, const char *format, PreparedValues *values)
Definition: Database.cpp:751
PreparedQueryResult_AutoPtr Database::PreparedQuery ( const char *  sql,
PreparedValues values 
)

Definition at line 1046 of file Database.cpp.

References _ExecutePreparedStatement(), _GetOrMakePreparedStatement(), mMutex, and PreparedStatement::stmt.

1047 {
1048  ACE_Guard<ACE_Thread_Mutex> guardian(mMutex);
1049  PreparedStatement* stmt = _GetOrMakePreparedStatement(sql, NULL, &values);
1050 
1051  if (!stmt)
1052  return PreparedQueryResult_AutoPtr(NULL);
1053 
1054  if (!_ExecutePreparedStatement(stmt, &values, NULL, true))
1055  return PreparedQueryResult_AutoPtr(NULL);
1056 
1058 }
ACE_Refcounted_Auto_Ptr< PreparedQueryResult, ACE_Null_Mutex > PreparedQueryResult_AutoPtr
Definition: QueryResult.h:114
ACE_Thread_Mutex mMutex
Definition: Database.h:159
bool _ExecutePreparedStatement(PreparedStatement *ps, PreparedValues *values, va_list *args, bool resultset)
Definition: Database.cpp:826
PreparedStatement * _GetOrMakePreparedStatement(const char *query, const char *format, PreparedValues *values)
Definition: Database.cpp:751
QueryResult_AutoPtr Database::Query ( const char *  sql)

Definition at line 383 of file Database.cpp.

References _Query(), and QueryResult::NextRow().

Referenced by InstanceSaveManager::CleanupInstances(), BattlegroundMgr::CreateInitialBattlegrounds(), SqlQuery::Execute(), SqlQueryHolderEx::Execute(), ChatHandler::getCommandTable(), ChatHandler::GetDeletedCharacterInfoList(), Player::GetGuildIdFromDB(), Player::GetRankFromDB(), Player::GetZoneIdFromDB(), ChatHandler::HandleAccountOnlineListCommand(), ChatHandler::HandleBanListAccountCommand(), ChatHandler::HandleBanListIPCommand(), ChatHandler::HandleGMListFullCommand(), ChatHandler::HandleListFreezeCommand(), ChatHandler::HandleWpAddCommand(), ChatHandler::HandleWpEventCommand(), BattlegroundMgr::InitAutomaticArenaPointDistribution(), World::InitDailyQuestResetTime(), PoolMgr::Initialize(), AuctionHouseBot::Initialize(), MapManager::InitMaxInstanceId(), TicketMgr::InitTicketID(), IsConnected(), WaypointMgr::Load(), ObjectMgr::LoadAccessRequirements(), ObjectMgr::LoadAreaTriggerScripts(), ObjectMgr::LoadAreaTriggerTeleports(), ObjectMgr::LoadArenaTeams(), AuctionHouseMgr::LoadAuctionItems(), AuctionHouseMgr::LoadAuctions(), World::LoadAutobroadcasts(), ObjectMgr::LoadBattleMastersEntry(), ConditionMgr::LoadConditions(), ObjectMgr::LoadCorpses(), ObjectMgr::LoadCreatureClassLevelStats(), CreatureEventAIMgr::LoadCreatureEventAI_Scripts(), CreatureEventAIMgr::LoadCreatureEventAI_Summons(), CreatureEventAIMgr::LoadCreatureEventAI_Texts(), FormationMgr::LoadCreatureFormations(), ObjectMgr::LoadCreatureLinkedRespawn(), ObjectMgr::LoadCreatureLocales(), ObjectMgr::LoadCreatureRespawnTimes(), ObjectMgr::LoadCreatures(), CreatureTextMgr::LoadCreatureTextLocales(), CreatureTextMgr::LoadCreatureTexts(), World::LoadDBVersion(), DisableMgr::LoadDisables(), ObjectMgr::LoadExplorationBaseXP(), ObjectMgr::LoadFishingBaseSkillLevel(), GameEventMgr::LoadFromDB(), PoolMgr::LoadFromDB(), SmartWaypointMgr::LoadFromDB(), ObjectMgr::LoadGameObjectLocales(), ObjectMgr::LoadGameobjectRespawnTimes(), ObjectMgr::LoadGameobjects(), ObjectMgr::LoadGameTele(), TicketMgr::LoadGMSurveys(), TicketMgr::LoadGMTickets(), ObjectMgr::LoadGossipMenu(), ObjectMgr::LoadGossipMenuItems(), ObjectMgr::LoadGossipMenuItemsLocales(), ObjectMgr::LoadGossipText(), ObjectMgr::LoadGraveyardZones(), ObjectMgr::LoadGroups(), ObjectMgr::LoadGuilds(), World::LoadIp2nation(), ObjectMgr::LoadItemLocales(), ObjectMgr::LoadItemTexts(), ObjectMgr::LoadNpcTextId(), ObjectMgr::LoadNpcTextLocales(), World::LoadOpcodeProtection(), ObjectMgr::LoadPageTextLocales(), ObjectMgr::LoadPetCreateSpells(), ObjectMgr::LoadPetLevelInfo(), ObjectMgr::LoadPetNames(), ObjectMgr::LoadPetNumber(), ObjectMgr::LoadPlayerInfo(), ObjectMgr::LoadQuestAreaTriggers(), ObjectMgr::LoadQuestLocales(), PoolMgr::LoadQuestPools(), ObjectMgr::LoadQuests(), LoadRandomEnchantmentsTable(), ObjectMgr::LoadReferredFriends(), ObjectMgr::LoadReputationOnKill(), ObjectMgr::LoadReputationSpilloverTemplate(), ObjectMgr::LoadReservedPlayersNames(), InstanceSaveManager::LoadResetTimes(), ObjectMgr::LoadScriptNames(), SystemMgr::LoadScriptTexts(), SystemMgr::LoadScriptTextsCustom(), SystemMgr::LoadScriptWaypoints(), LoadSkillDiscoveryTable(), LoadSkillExtraItemTable(), SmartAIMgr::LoadSmartAIFromDB(), SpellMgr::LoadSpellAffects(), SpellMgr::LoadSpellCustomCooldowns(), SpellMgr::LoadSpellEnchantProcData(), SpellMgr::LoadSpellGroups(), SpellMgr::LoadSpellGroupStackRules(), SpellMgr::LoadSpellLearnSpells(), SpellMgr::LoadSpellLinked(), SpellMgr::LoadSpellPetAuras(), SpellMgr::LoadSpellProcEvents(), SpellMgr::LoadSpellRequired(), SpellMgr::LoadSpellTargetPositions(), SpellMgr::LoadSpellThreats(), ObjectMgr::LoadTavernAreaTriggers(), ObjectMgr::LoadTempSummons(), ObjectMgr::LoadTrainerSpell(), ObjectMgr::LoadTransportEvents(), MapManager::LoadTransports(), ObjectMgr::LoadVendors(), SystemMgr::LoadVersion(), CWardenDataStorage::LoadWardenDataResult(), ObjectMgr::LoadWeatherZoneChances(), main(), InstanceSaveManager::PackInstances(), PQuery(), WorldSession::SendExternalMails(), ObjectMgr::SetHighestGuids(), and RealmList::UpdateRealms().

384 {
385  MYSQL_RES* result = NULL;
386  MYSQL_FIELD* fields = NULL;
387  uint64 rowCount = 0;
388  uint32 fieldCount = 0;
389 
390  if (!_Query(sql, &result, &fields, &rowCount, &fieldCount))
391  return QueryResult_AutoPtr(NULL);
392 
393  QueryResult* queryResult = new QueryResult(result, fields, rowCount, fieldCount);
394 
395  queryResult->NextRow();
396 
397  return QueryResult_AutoPtr(queryResult);
398 }
bool _Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64 *pRowCount, uint32 *pFieldCount)
Definition: Database.cpp:337
ACE_UINT64 uint64
Definition: Define.h:70
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
ACE_UINT32 uint32
Definition: Define.h:71
bool NextRow()
bool Database::RollbackTransaction ( )

Definition at line 571 of file Database.cpp.

References ACE_Based::Thread::current(), m_tranQueues, mMysql, nMutex, and tranThread.

Referenced by DirectExecute(), and WorldSession::HandleGuildBankWithdraw().

572 {
573  if (!mMysql)
574  return false;
575 
576  nMutex.acquire();
578  TransactionQueues::iterator i = m_tranQueues.find(tranThread);
579  if (i != m_tranQueues.end() && i->second != NULL)
580  {
581  delete i->second;
582  i->second = NULL;
583  m_tranQueues.erase(i);
584  }
585  nMutex.release();
586  return true;
587 }
static Thread * current()
Definition: Threading.cpp:212
MYSQL * mMysql
Definition: Database.h:165
ACE_Based::Thread * tranThread
Definition: Database.h:163
TransactionQueues m_tranQueues
Definition: Database.h:49
ACE_Thread_Mutex nMutex
Definition: Database.h:160
void Database::SetResultQueue ( SqlResultQueue queue)

Definition at line 332 of file Database.cpp.

References ACE_Based::Thread::current(), and m_queryQueues.

Referenced by World::InitResultQueue(), and operator bool().

333 {
335 }
static Thread * current()
Definition: Threading.cpp:212
QueryQueues m_queryQueues
Definition: Database.h:50
void Database::ThreadEnd ( )

Definition at line 196 of file Database.cpp.

Referenced by WDBThreadEndReq1::call(), operator bool(), Master::Run(), and ReactorRunnable::svc().

197 {
198  mysql_thread_end();
199 }
void Database::ThreadStart ( )

Definition at line 191 of file Database.cpp.

Referenced by WDBThreadStartReq1::call(), operator bool(), Master::Run(), and ReactorRunnable::svc().

192 {
193  mysql_thread_init();
194 }

Member Data Documentation

size_t Database::db_count = 0
staticprivate

Definition at line 168 of file Database.h.

Referenced by Database(), and ~Database().

bool Database::m_connected
private

Definition at line 166 of file Database.h.

Referenced by Initialize(), and IsConnected().

ACE_Based::Thread* Database::m_delayThread
protected

Definition at line 52 of file Database.h.

Referenced by HaltDelayThread(), InitDelayThread(), and ~Database().

std::string Database::m_logsDir
private

Definition at line 158 of file Database.h.

Referenced by Initialize().

bool Database::m_logSQL
private

Definition at line 157 of file Database.h.

Referenced by Initialize().

PreparedStatementsMap Database::m_preparedStatements
private

Definition at line 178 of file Database.h.

Referenced by _GetOrMakePreparedStatement(), and ~Database().

QueryQueues Database::m_queryQueues
protected

Definition at line 50 of file Database.h.

Referenced by SetResultQueue().

SqlDelayThread* Database::m_threadBody
protected
TransactionQueues Database::m_tranQueues
protected
ACE_Thread_Mutex Database::mMutex
private

Definition at line 159 of file Database.h.

Referenced by _Query(), DirectExecute(), ExecuteTransaction(), and PreparedQuery().

ACE_Thread_Mutex Database::nMutex
private
ACE_Thread_Mutex Database::pMutex
private

Definition at line 161 of file Database.h.

Referenced by _GetOrMakePreparedStatement().

ACE_Based::Thread* Database::tranThread
private

The documentation for this class was generated from the following files: