From f795aca9a618f3af0d67caee044f20b4bc4da7f9 Mon Sep 17 00:00:00 2001 From: mordred Date: Fri, 4 Jan 2019 08:54:39 +0100 Subject: [PATCH] Moved spawngroup query to prepared stmt --- src/common/Database/ZoneDbConnection.cpp | 16 ++++++++++++++-- src/common/Database/ZoneDbConnection.h | 2 ++ src/world/Territory/Zone.cpp | 6 +++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/common/Database/ZoneDbConnection.cpp b/src/common/Database/ZoneDbConnection.cpp index d708ecd9..d9a081d5 100644 --- a/src/common/Database/ZoneDbConnection.cpp +++ b/src/common/Database/ZoneDbConnection.cpp @@ -7,7 +7,7 @@ Sapphire::Db::ZoneDbConnection::ZoneDbConnection( ConnectionInfo& connInfo ) : } Sapphire::Db::ZoneDbConnection::ZoneDbConnection( Sapphire::LockedWaitQueue< std::shared_ptr< Operation > >* q, - ConnectionInfo& connInfo ) : + ConnectionInfo& connInfo ) : DbConnection( q, connInfo ) { } @@ -175,7 +175,7 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements() "INSERT INTO charaglobalitem ( CharacterId, ItemId, catalogId, stack, UPDATE_DATE ) VALUES ( ?, ?, ?, ?, NOW() );", CONNECTION_SYNC ); - /// BNPC TEMPLATES + /// ZONE QUERIES prepareStatement( ZONE_SEL_BNPCTEMPLATES, "SELECT Id, Name, bNPCBaseId, bNPCNameId, mainWeaponModel, " "secWeaponModel, aggressionMode, enemyType, pose, " @@ -183,6 +183,18 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements() "FROM bnpctemplate WHERE 1;", CONNECTION_BOTH ); + prepareStatement( ZONE_SEL_SPAWNGROUPS, + "SELECT id, bNpcTemplateId, level, maxHp " + "FROM spawngroup " + "WHERE territoryTypeId = ?", + CONNECTION_BOTH ); + + prepareStatement( ZONE_SEL_SPAWNPOINTS, + "SELECT id, x, y, z, r " + "FROM spawnpoint " + "WHERE spawnGroupId = ?", + CONNECTION_BOTH ); + prepareStatement( CHARA_ITEMGLOBAL_UP, "UPDATE charaglobalitem SET stack = ?, durability = ?, stain = ? WHERE ItemId = ?;", CONNECTION_BOTH ); diff --git a/src/common/Database/ZoneDbConnection.h b/src/common/Database/ZoneDbConnection.h index fa2458e3..1c0fde7a 100644 --- a/src/common/Database/ZoneDbConnection.h +++ b/src/common/Database/ZoneDbConnection.h @@ -77,6 +77,8 @@ namespace Sapphire::Db CHARA_ITEMGLOBAL_DELETE, ZONE_SEL_BNPCTEMPLATES, + ZONE_SEL_SPAWNGROUPS, + ZONE_SEL_SPAWNPOINTS, LAND_INS, LAND_SEL, diff --git a/src/world/Territory/Zone.cpp b/src/world/Territory/Zone.cpp index 9cc4d30f..1d1090a0 100644 --- a/src/world/Territory/Zone.cpp +++ b/src/world/Territory/Zone.cpp @@ -763,9 +763,9 @@ Sapphire::Data::TerritoryTypePtr Sapphire::Zone::getTerritoryTypeInfo() const bool Sapphire::Zone::loadSpawnGroups() { auto pDb = m_pFw->get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); - auto res = pDb->query( "SELECT id, bNpcTemplateId, level, maxHp " - "FROM spawngroup " - "WHERE territoryTypeId = " + std::to_string( getTerritoryTypeId() ) + ";" ); + auto stmt = pDb->getPreparedStatement( Db::ZoneDbStatements::ZONE_SEL_SPAWNGROUPS ); + stmt->setUInt( 1, getTerritoryTypeId() ); + auto res = pDb->query( stmt ); while( res->next() ) {