23 #ifndef _MYSQLCONNECTION_H
24 #define _MYSQLCONNECTION_H
33 CONNECTION_ASYNC = 0x1,
34 CONNECTION_SYNCH = 0x2,
35 CONNECTION_BOTH = CONNECTION_ASYNC | CONNECTION_SYNCH
40 explicit MySQLConnectionInfo(std::string
const& infoString)
44 if (tokens.size() != 5)
49 host.assign(tokens[i++]);
50 port_or_socket.assign(tokens[i++]);
51 user.assign(tokens[i++]);
52 password.assign(tokens[i++]);
53 database.assign(tokens[i++]);
60 std::string port_or_socket;
63 typedef std::map<
uint32 , std::pair<std::string , ConnectionFlags > > PreparedStatementMap;
71 MySQLConnection(MySQLConnectionInfo& connInfo);
73 virtual ~MySQLConnection();
75 virtual uint32 Open();
78 bool PrepareStatements();
85 bool _Query(
const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields,
uint64* pRowCount, uint32* pFieldCount);
88 void BeginTransaction();
89 void RollbackTransaction();
90 void CommitTransaction();
93 operator bool ()
const {
return m_Mysql !=
NULL; }
94 void Ping() { mysql_ping(m_Mysql); }
103 return m_Mutex.try_lock();
112 MYSQL* GetHandle() {
return m_Mysql; }
114 void PrepareStatement(uint32 index,
const char* sql, ConnectionFlags
flags);
116 virtual void DoPrepareStatements() = 0;
119 std::vector<std::unique_ptr<MySQLPreparedStatement>> m_stmts;
120 PreparedStatementMap m_queries;
125 bool _HandleMySQLErrno(uint32 errNo,
uint8 attempts = 5);
129 std::unique_ptr<DatabaseWorker> m_worker;
131 MySQLConnectionInfo& m_connectionInfo;
132 ConnectionFlags m_connectionFlags;
135 MySQLConnection(MySQLConnection
const& right) =
delete;
136 MySQLConnection&
operator=(MySQLConnection
const& right) =
delete;
#define TC_DATABASE_API
Definition: Define.h:122
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: PreparedStatement.h:74
Definition: QueryResult.h:30
#define bool
Definition: CascPort.h:16
Vector2int16 & operator=(const Any &a)
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
Definition: PreparedStatement.h:114
bool Execute() override
Operation for idle delaythreads.
Definition: DatabaseWorkerPool.h:40
Definition: DatabaseWorker.h:27
int GetLastError()
Definition: Common.cpp:70
Definition: DatabaseWorkerPool.h:37
uint8_t uint8
Definition: Define.h:152
uint8 flags
Definition: DisableMgr.cpp:44
Definition: QueryResult.h:63
Definition: DatabaseWorkerPool.h:48
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58