mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-17 13:39:46 -04:00
Core/DBLayer: Convert PQuery() queries to prepared statements
This commit is contained in:
@@ -91,7 +91,10 @@ public:
|
||||
pathid = target->GetWaypointPath();
|
||||
else
|
||||
{
|
||||
QueryResult result = WorldDatabase.Query("SELECT MAX(id) FROM waypoint_data");
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_MAX_ID);
|
||||
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
uint32 maxpathid = result->Fetch()->GetInt32();
|
||||
pathid = maxpathid+1;
|
||||
handler->PSendSysMessage("%s%s|r", "|cff00ff00", "New path started.");
|
||||
@@ -109,7 +112,9 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT MAX(point) FROM waypoint_data WHERE id = '%u'", pathid);
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_MAX_POINT);
|
||||
stmt->setUInt32(0, pathid);
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (result)
|
||||
point = (*result)[0].GetUInt32();
|
||||
@@ -117,7 +122,7 @@ public:
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
//Map* map = player->GetMap();
|
||||
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_WAYPOINT_DATA);
|
||||
stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_WAYPOINT_DATA);
|
||||
|
||||
stmt->setUInt32(0, pathid);
|
||||
stmt->setUInt32(1, point + 1);
|
||||
@@ -173,9 +178,12 @@ public:
|
||||
}
|
||||
|
||||
guidLow = target->GetDBTableGUIDLow();
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT guid FROM creature_addon WHERE guid = '%u'", guidLow);
|
||||
|
||||
PreparedStatement* stmt;
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_ADDON_BY_GUID);
|
||||
|
||||
stmt->setUInt32(0, guidLow);
|
||||
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (result)
|
||||
{
|
||||
@@ -290,7 +298,9 @@ public:
|
||||
|
||||
if (id)
|
||||
{
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid = %u", id);
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_SCRIPT_ID_BY_GUID);
|
||||
stmt->setUInt32(0, id);
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
@@ -307,10 +317,13 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
QueryResult result = WorldDatabase.Query("SELECT MAX(guid) FROM waypoint_scripts");
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_SCRIPTS_MAX_ID);
|
||||
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
id = result->Fetch()->GetUInt32();
|
||||
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_WAYPOINT_SCRIPT);
|
||||
stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_WAYPOINT_SCRIPT);
|
||||
|
||||
stmt->setUInt32(0, id + 1);
|
||||
|
||||
@@ -336,7 +349,9 @@ public:
|
||||
float a8, a9, a10, a11;
|
||||
char const* a7;
|
||||
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = %u", id);
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_SCRIPT_BY_ID);
|
||||
stmt->setUInt32(0, id);
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
@@ -369,7 +384,11 @@ public:
|
||||
{
|
||||
id = atoi(arg_id);
|
||||
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT guid FROM waypoint_scripts WHERE guid = %u", id);
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_SCRIPT_ID_BY_GUID);
|
||||
|
||||
stmt->setUInt32(0, id);
|
||||
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (result)
|
||||
{
|
||||
@@ -447,7 +466,9 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid='%u'", id);
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_SCRIPT_ID_BY_GUID);
|
||||
stmt->setUInt32(0, id);
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
@@ -567,7 +588,9 @@ public:
|
||||
// User did select a visual waypoint?
|
||||
|
||||
// Check the creature
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid);
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_BY_WPGUID);
|
||||
stmt->setUInt32(0, wpGuid);
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
@@ -578,9 +601,17 @@ public:
|
||||
// Here we search for all waypoints that only differ in one from 1 thousand
|
||||
// (0.001) - There is no other way to compare C++ floats with mySQL floats
|
||||
// See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
|
||||
const char* maxDIFF = "0.01";
|
||||
result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE (abs(position_x - %f) <= %s) and (abs(position_y - %f) <= %s) and (abs(position_z - %f) <= %s)",
|
||||
target->GetPositionX(), maxDIFF, target->GetPositionY(), maxDIFF, target->GetPositionZ(), maxDIFF);
|
||||
std::string maxDiff = "0.01";
|
||||
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_BY_POS);
|
||||
stmt->setFloat(0, target->GetPositionX());
|
||||
stmt->setString(1, maxDiff);
|
||||
stmt->setFloat(2, target->GetPositionY());
|
||||
stmt->setString(3, maxDiff);
|
||||
stmt->setFloat(4, target->GetPositionZ());
|
||||
stmt->setString(5, maxDiff);
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, wpGuid);
|
||||
@@ -765,7 +796,6 @@ public:
|
||||
}
|
||||
|
||||
std::string show = show_str;
|
||||
uint32 Maxpoint;
|
||||
|
||||
//handler->PSendSysMessage("wpshow - show: %s", show);
|
||||
|
||||
@@ -780,7 +810,11 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT id, point, delay, move_flag, action, action_chance FROM waypoint_data WHERE wpguid = %u", target->GetGUIDLow());
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_ALL_BY_WPGUID);
|
||||
|
||||
stmt->setUInt32(0, target->GetGUIDLow());
|
||||
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
@@ -812,7 +846,11 @@ public:
|
||||
|
||||
if (show == "on")
|
||||
{
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT point, position_x, position_y, position_z FROM waypoint_data WHERE id = '%u'", pathid);
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_POS_BY_ID);
|
||||
|
||||
stmt->setUInt32(0, pathid);
|
||||
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
@@ -824,7 +862,11 @@ public:
|
||||
handler->PSendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff%u|r", pathid);
|
||||
|
||||
// Delete all visuals for this NPC
|
||||
QueryResult result2 = WorldDatabase.PQuery("SELECT wpguid FROM waypoint_data WHERE id = '%u' and wpguid <> 0", pathid);
|
||||
stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_WPGUID_BY_ID);
|
||||
|
||||
stmt->setUInt32(0, pathid);
|
||||
|
||||
PreparedQueryResult result2 = WorldDatabase.Query(stmt);
|
||||
|
||||
if (result2)
|
||||
{
|
||||
@@ -921,7 +963,10 @@ public:
|
||||
{
|
||||
handler->PSendSysMessage("|cff00ff00DEBUG: wp first, GUID: %u|r", pathid);
|
||||
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT position_x, position_y, position_z FROM waypoint_data WHERE point='1' AND id = '%u'", pathid);
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_POS_FIRST_BY_ID);
|
||||
stmt->setUInt32(0, pathid);
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUND, pathid);
|
||||
@@ -968,13 +1013,10 @@ public:
|
||||
{
|
||||
handler->PSendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff%u|r", pathid);
|
||||
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT MAX(point) FROM waypoint_data WHERE id = '%u'", pathid);
|
||||
if (result)
|
||||
Maxpoint = (*result)[0].GetUInt32();
|
||||
else
|
||||
Maxpoint = 0;
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_POS_LAST_BY_ID);
|
||||
stmt->setUInt32(0, pathid);
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
result = WorldDatabase.PQuery("SELECT position_x, position_y, position_z, orientation FROM waypoint_data WHERE point ='%u' AND id = '%u'", Maxpoint, pathid);
|
||||
if (!result)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDLAST, pathid);
|
||||
@@ -1018,7 +1060,10 @@ public:
|
||||
|
||||
if (show == "off")
|
||||
{
|
||||
QueryResult result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE id = '%u'", 1);
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_BY_ID);
|
||||
stmt->setUInt32(0, 1);
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
handler->SendSysMessage(LANG_WAYPOINT_VP_NOTFOUND);
|
||||
@@ -1051,7 +1096,7 @@ public:
|
||||
}
|
||||
while (result->NextRow());
|
||||
// set "wpguid" column to "empty" - no visual waypoint spawned
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_ALL_WAYPOINT_DATA_WPGUID);
|
||||
stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_ALL_WPGUID);
|
||||
|
||||
WorldDatabase.Execute(stmt);
|
||||
//WorldDatabase.PExecute("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");
|
||||
|
||||
Reference in New Issue
Block a user