mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-19 08:55:32 +01:00
Core/DBLayer: Convert Execute() queries to prepared statements
This commit is contained in:
@@ -37,8 +37,16 @@ AccountOpResult CreateAccount(std::string username, std::string password)
|
||||
if (GetId(username))
|
||||
return AOR_NAME_ALREDY_EXIST; // username does already exist
|
||||
|
||||
LoginDatabase.PExecute("INSERT INTO account(username, sha_pass_hash, joindate) VALUES('%s', '%s', NOW())", username.c_str(), CalculateShaPassHash(username, password).c_str());
|
||||
LoginDatabase.Execute("INSERT INTO realmcharacters (realmid, acctid, numchars) SELECT realmlist.id, account.id, 0 FROM realmlist, account LEFT JOIN realmcharacters ON acctid=account.id WHERE acctid IS NULL");
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_ADD_ACCOUNT);
|
||||
|
||||
stmt->setString(0, username);
|
||||
stmt->setString(1, CalculateShaPassHash(username, password));
|
||||
|
||||
LoginDatabase.Execute(stmt);
|
||||
|
||||
stmt = LoginDatabase.GetPreparedStatement(LOGIN_ADD_REALM_CHARS);
|
||||
|
||||
LoginDatabase.Execute(stmt);
|
||||
|
||||
return AOR_OK; // everything's fine
|
||||
}
|
||||
|
||||
@@ -3280,7 +3280,8 @@ bool ChatHandler::HandleBanListCharacterCommand(const char *args)
|
||||
|
||||
bool ChatHandler::HandleBanListAccountCommand(const char *args)
|
||||
{
|
||||
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_OLD_BANS);
|
||||
LoginDatabase.Execute(stmt);
|
||||
|
||||
char* cFilter = strtok((char*)args, " ");
|
||||
std::string filter = cFilter ? cFilter : "";
|
||||
@@ -3385,7 +3386,8 @@ bool ChatHandler::HandleBanListHelper(QueryResult result)
|
||||
|
||||
bool ChatHandler::HandleBanListIPCommand(const char *args)
|
||||
{
|
||||
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_OLD_IP_BANS);
|
||||
LoginDatabase.Execute(stmt);
|
||||
|
||||
char* cFilter = strtok((char*)args, " ");
|
||||
std::string filter = cFilter ? cFilter : "";
|
||||
|
||||
@@ -2687,7 +2687,10 @@ void World::InitRandomBGResetTime()
|
||||
void World::ResetDailyQuests()
|
||||
{
|
||||
sLog->outDetail("Daily quests reset for all characters.");
|
||||
CharacterDatabase.Execute("DELETE FROM character_queststatus_daily");
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_QUEST_STATUS_DAILY);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
|
||||
if (itr->second->GetPlayer())
|
||||
itr->second->GetPlayer()->ResetDailyQuestStatus();
|
||||
|
||||
@@ -92,7 +92,7 @@ class DatabaseWorkerPool
|
||||
++m_connectionCount[IDX_SYNCH];
|
||||
}
|
||||
|
||||
sLog->outSQLDriver("Databasepool opened succesfuly. %u total connections running.", (m_connectionCount[IDX_SYNCH] + m_connectionCount[IDX_ASYNC]));
|
||||
sLog->outSQLDriver("Databasepool opened successfully. %u total connections running.", (m_connectionCount[IDX_SYNCH] + m_connectionCount[IDX_ASYNC]));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ void CharacterDatabaseConnection::DoPrepareStatements()
|
||||
PREPARE_STATEMENT(CHAR_GET_PET_SLOT_BY_ID, "SELECT slot, entry FROM character_pet WHERE owner = ? AND id = ?", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(CHAR_GET_FREE_NAME, "SELECT guid, name FROM characters WHERE guid = ? AND account = ? AND (at_login & ?) = ? AND NOT EXISTS (SELECT NULL FROM characters WHERE name = ?)", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(CHAR_GET_GUID_RACE_ACC_BY_NAME, "SELECT guid, race, account FROM characters WHERE name = ?", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(CHAR_DEL_QUEST_STATUS_DAILY, "DELETE FROM character_queststatus_daily", CONNECTION_ASYNC);
|
||||
|
||||
// Start LoginQueryHolder content
|
||||
PREPARE_STATEMENT(CHAR_LOAD_PLAYER, "SELECT guid, account, name, race, class, gender, level, xp, money, playerBytes, playerBytes2, playerFlags, "
|
||||
|
||||
@@ -64,6 +64,7 @@ enum CharacterDatabaseStatements
|
||||
CHAR_GET_PET_SLOT_BY_ID,
|
||||
CHAR_GET_FREE_NAME,
|
||||
CHAR_GET_GUID_RACE_ACC_BY_NAME,
|
||||
CHAR_DEL_QUEST_STATUS_DAILY,
|
||||
CHAR_LOAD_PLAYER,
|
||||
CHAR_LOAD_PLAYER_GROUP,
|
||||
CHAR_LOAD_PLAYER_BOUNDINSTANCES,
|
||||
|
||||
@@ -45,4 +45,8 @@ void LoginDatabaseConnection::DoPrepareStatements()
|
||||
PREPARE_STATEMENT(LOGIN_DEL_REALMCHARACTERS, "DELETE FROM realmcharacters WHERE acctid = ? AND realmid = ?", CONNECTION_ASYNC)
|
||||
PREPARE_STATEMENT(LOGIN_ADD_REALMCHARACTERS, "INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (?, ?, ?)", CONNECTION_ASYNC)
|
||||
PREPARE_STATEMENT(LOGIN_GET_SUM_REALMCHARS, "SELECT SUM(numchars) FROM realmcharacters WHERE acctid = ?", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(LOGIN_ADD_ACCOUNT, "INSERT INTO account(username, sha_pass_hash, joindate) VALUES(?, ?, NOW())", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(LOGIN_ADD_REALM_CHARS, "INSERT INTO realmcharacters (realmid, acctid, numchars) SELECT realmlist.id, account.id, 0 FROM realmlist, account LEFT JOIN realmcharacters ON acctid=account.id WHERE acctid IS NULL", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(LOGIN_DEL_OLD_BANS, "DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(LOGIN_DEL_OLD_IP_BANS, "DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate", CONNECTION_ASYNC);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,10 @@ enum LoginDatabaseStatements
|
||||
LOGIN_DEL_REALMCHARACTERS,
|
||||
LOGIN_ADD_REALMCHARACTERS,
|
||||
LOGIN_GET_SUM_REALMCHARS,
|
||||
LOGIN_ADD_ACCOUNT,
|
||||
LOGIN_ADD_REALM_CHARS,
|
||||
LOGIN_DEL_OLD_BANS,
|
||||
LOGIN_DEL_OLD_IP_BANS,
|
||||
|
||||
MAX_LOGINDATABASE_STATEMENTS,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user