Advertisement
EmuDevs

EmuDevs: TrinityCore - More about PreparedStatement & Query

Sep 4th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. /*
  2.  *╔═╦═╦═╦╦╦══╦═╦╗─╔╦══╗
  3.  *║╦╣║║║║║╠╗╗║╦╣╚╦╝║══╣
  4.  *║╩╣║║║║║╠╩╝║╩╬╗║╔╬══║
  5.  *╚═╩╩═╩╩═╩══╩═╝╚═╝╚══╝
  6.  *            http://emudevs.com
  7. */
  8.  
  9. class npc_tutorial_gossip : public CreatureScript
  10. {
  11. private:
  12.     npc_tutorial_gossip() : CreatureScript("npc_tutorial_gossip") { }
  13.  
  14.     bool OnGossipHello(Player* player, Creature* creature)
  15.     {
  16.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Do Action", GOSSIP_SENDER_MAIN, 1);
  17.         player->SEND_GOSSIP_MENU(1, creature->GetGUID());
  18.         return true;
  19.     }
  20.  
  21.     bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 actions)
  22.     {
  23.         player->PlayerTalkClass->ClearMenus();
  24.         if (actions == 1)
  25.         {
  26.             /*    LOAD POINTS PREPARED STATEMENT   */
  27.             //PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_LOAD_POINTS);
  28.             //PreparedQueryResult result = LoginDatabase.Query(stmt);
  29.             //if (!result)
  30.             //{
  31.             //  TC_LOG_ERROR(LOG_FILTER_GENERAL, "Loaded 0 points");
  32.             //  return;
  33.             //}
  34.  
  35.             //do
  36.             //{
  37.             //  Field* fields = result->Fetch();
  38.             //  TC_LOG_ERROR(LOG_FILTER_GENERAL, "ID: %d, Points: %d", fields[0].GetUInt32(), fields[1].GetUInt32());
  39.             //}while(result->NextRow());
  40.             //TC_LOG_ERROR(LOG_FILTER_GENERAL, "Loading points completed!");
  41.  
  42.            /*    SAVE POINTS */
  43.             PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_POINTS);
  44.             PreparedStatement* _stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_POINTS);
  45.             stmt->setUInt32(0, player->GetSession()->GetAccountId());
  46.             PreparedQueryResult result = LoginDatabase.Query(stmt);
  47.  
  48.             uint32 votePoints;
  49.             if (result)
  50.             {
  51.                 do
  52.                 {
  53.                     Field* fields = result->Fetch();
  54.                     votePoints = fields[0].GetUInt32();
  55.                     votePoints -= 35;
  56.                 }while(result->NextRow());
  57.             }
  58.             _stmt->setUInt32(0, votePoints);
  59.             _stmt->setUInt32(1, player->GetSession()->GetAccountId());
  60.             LoginDatabase.Execute(_stmt);
  61.         }
  62.         return true;
  63.     }
  64. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement