Core/DBLayer:
- Example implementation of prepared statement in ObjectMgr::SaveCreatureRespawntime - #include "MYSQLThreading.h" -> #include "MySQLThreading.h" (*really* fixes Linux build) --HG-- branch : trunk
This commit is contained in:
@@ -7221,9 +7221,19 @@ void ObjectMgr::SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t
|
||||
mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)] = t;
|
||||
}
|
||||
|
||||
WorldDatabase.PExecute("DELETE FROM creature_respawn WHERE guid = '%u' AND instance = '%u'", loguid, instance);
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CRESPAWNTIME);
|
||||
stmt->setUInt32(0, loguid);
|
||||
stmt->setUInt32(1, instance);
|
||||
WorldDatabase.Execute(stmt);
|
||||
|
||||
if (t)
|
||||
WorldDatabase.PExecute("INSERT INTO creature_respawn VALUES ('%u', '" UI64FMTD "', '%u')", loguid, uint64(t), instance);
|
||||
{
|
||||
stmt = WorldDatabase.GetPreparedStatement(WORLD_ADD_CRESPAWNTIME);
|
||||
stmt->setUInt32(0, loguid);
|
||||
stmt->setUInt64(1, uint64(t));
|
||||
stmt->setUInt32(2, instance);
|
||||
WorldDatabase.Execute(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectMgr::DeleteCreatureData(uint32 guid)
|
||||
|
||||
@@ -20,11 +20,18 @@
|
||||
|
||||
bool WorldDatabaseConnection::Open(const std::string& infoString)
|
||||
{
|
||||
if (!MySQLConnection::Open(infoString))
|
||||
return false;
|
||||
|
||||
m_stmts.resize(MAX_WORLDDATABASE_STATEMENTS);
|
||||
|
||||
/*
|
||||
##################################
|
||||
LOAD YOUR PREPARED STATEMENTS HERE
|
||||
##################################
|
||||
*/
|
||||
PrepareStatement(WORLD_DEL_CRESPAWNTIME, "DELETE FROM creature_respawn WHERE guid = ? AND instance = ?");
|
||||
PrepareStatement(WORLD_ADD_CRESPAWNTIME, "INSERT INTO creature_respawn VALUES (?, ?, ?)");
|
||||
|
||||
return MySQLConnection::Open(infoString);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ typedef DatabaseWorkerPool<WorldDatabaseConnection> WorldDatabaseWorkerPool;
|
||||
|
||||
enum WorldDatabaseStatements
|
||||
{
|
||||
WORLD_DEL_CRESPAWNTIME,
|
||||
WORLD_ADD_CRESPAWNTIME,
|
||||
MAX_WORLDDATABASE_STATEMENTS,
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <mysql.h>
|
||||
|
||||
#include "MySQLConnection.h"
|
||||
#include "MYSQLThreading.h"
|
||||
#include "MySQLThreading.h"
|
||||
#include "QueryResult.h"
|
||||
#include "SQLOperation.h"
|
||||
#include "PreparedStatement.h"
|
||||
|
||||
@@ -50,13 +50,13 @@ class MySQLConnection
|
||||
MYSQL* GetHandle() { return m_Mysql; }
|
||||
MySQLPreparedStatement* GetPreparedStatement(uint32 index);
|
||||
void PrepareStatement(uint32 index, const char* sql);
|
||||
std::vector<MySQLPreparedStatement*> m_stmts; //! PreparedStatements storage
|
||||
|
||||
private:
|
||||
ACE_Activation_Queue* m_queue; //! Queue shared with other asynchroneous connections.
|
||||
DatabaseWorker* m_worker; //! Core worker task.
|
||||
MYSQL * m_Mysql; //! MySQL Handle.
|
||||
ACE_Thread_Mutex m_Mutex;
|
||||
std::vector<MySQLPreparedStatement*> m_stmts; //! PreparedStatements storage
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user