aboutsummaryrefslogtreecommitdiff
path: root/src/shared/Database/Database.h
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:51:44 -0700
committermaximius <none@none>2009-10-17 15:51:44 -0700
commite585187b248f48b3c6e9247b49fa07c6565d65e5 (patch)
tree637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /src/shared/Database/Database.h
parent26b5e033ffde3d161382fc9addbfa99738379641 (diff)
*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
Diffstat (limited to 'src/shared/Database/Database.h')
-rw-r--r--src/shared/Database/Database.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/shared/Database/Database.h b/src/shared/Database/Database.h
index 34438d994dc..6172a61c5f9 100644
--- a/src/shared/Database/Database.h
+++ b/src/shared/Database/Database.h
@@ -17,35 +17,48 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#ifndef DATABASE_H
#define DATABASE_H
+
#include "Threading.h"
#include "Utilities/UnorderedMap.h"
#include "Database/SqlDelayThread.h"
+
class SqlTransaction;
class SqlResultQueue;
class SqlQueryHolder;
+
typedef UNORDERED_MAP<ACE_Based::Thread* , SqlTransaction*> TransactionQueues;
typedef UNORDERED_MAP<ACE_Based::Thread* , SqlResultQueue*> QueryQueues;
+
#define MAX_QUERY_LEN 32*1024
+
class TRINITY_DLL_SPEC Database
{
protected:
Database() : m_threadBody(NULL), m_delayThread(NULL) {};
+
TransactionQueues m_tranQueues; ///< Transaction queues from diff. threads
QueryQueues m_queryQueues; ///< Query 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
+
public:
+
virtual ~Database();
+
virtual bool Initialize(const char *infoString);
virtual void InitDelayThread() = 0;
virtual void HaltDelayThread() = 0;
+
virtual QueryResult* Query(const char *sql) = 0;
QueryResult* PQuery(const char *format,...) ATTR_PRINTF(2,3);
virtual QueryNamedResult* QueryNamed(const char *sql) = 0;
QueryNamedResult* PQueryNamed(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);
@@ -83,14 +96,18 @@ class TRINITY_DLL_SPEC Database
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);
+
virtual bool Execute(const char *sql) = 0;
bool PExecute(const char *format,...) ATTR_PRINTF(2,3);
virtual bool DirectExecute(const char* sql) = 0;
bool DirectPExecute(const char *format,...) ATTR_PRINTF(2,3);
+
bool _UpdateDataBlobValue(const uint32 guid, const uint32 field, const int32 value);
bool _SetDataBlobValue(const uint32 guid, const uint32 field, const uint32 value);
+
// Writes SQL commands to a LOG file (see Trinityd.conf "LogSQL")
bool PExecuteLog(const char *format,...) ATTR_PRINTF(2,3);
+
virtual bool BeginTransaction() // nothing do if DB not support transactions
{
return true;
@@ -103,15 +120,20 @@ class TRINITY_DLL_SPEC Database
{
return false;
}
+
virtual operator bool () const = 0;
+
virtual unsigned long escape_string(char *to, const char *from, unsigned long length) { strncpy(to,from,length); return length; }
void escape_string(std::string& str);
+
// must be called before first query in thread (one time for thread using one from existed Database objects)
virtual void ThreadStart();
// must be called before finish thread run (one time for thread using one from existed Database objects)
virtual void ThreadEnd();
+
// sets the result queue of the current thread, be careful what thread you call this from
void SetResultQueue(SqlResultQueue * queue);
+
bool CheckRequiredField(char const* table_name, char const* required_name);
private:
bool m_logSQL;