Small Issue

Hello, I’m having issues with one of my commands.

Here is the script:


      static bool HandlePhaseGoCommand(ChatHandler * handler, const char * args)

      {

          if(!*args)

              return false;


            // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r

            char* cId = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");

            if (!cId)

                return false;


            uint32 id = atol(cId);

            if (!id)

                return false;


            char* phasing = strtok(NULL, " ");


            const GameObjectTemplate *gInfo = sObjectMgr->GetGameObjectTemplate(id);


            if (!gInfo)

            {

                handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, id);

                handler->SetSentErrorMessage(true);

                return false;

            }


            if (gInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(gInfo->displayId))

            {

                // report to DB errors log as in loading case

                sLog->outErrorDb("Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", id, gInfo->type, gInfo->displayId);

                handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, id);

                handler->SetSentErrorMessage(true);

                return false;

            }


            Player* chr = handler->GetSession()->GetPlayer();

            float x = float(chr->GetPositionX());

            float y = float(chr->GetPositionY());

            float z = float(chr->GetPositionZ());

            float o = float(chr->GetOrientation());

            Map *map = chr->GetMap();


            GameObject* pGameObj = new GameObject;

            uint32 db_lowGUID = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);


            if (!pGameObj->Create(db_lowGUID, gInfo->entry, map, chr->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))

            {

                delete pGameObj;

                return false;

            }


            if (phasing)

            {

                uint32 value = atoi((char*)phasing);

                QueryResult res, result;

                res = CharacterDatabase.PQuery("SELECT is_in_phase FROM phase WHERE guid='%u'", chr->GetGUID());

                if(res)

                {

                    do

                    {

                        Field * fields = res->Fetch();

                        if(fields[0].GetInt32() != value)

                        {

                            handler->SendSysMessage("You must be in the correct phase to build.");

                            return false;

                        }

                        result = CharacterDatabase.PQuery("SELECT * FROM phase_members WHERE guid='%u' AND phase='%u'", chr->GetGUID(),

                            fields[0].GetUInt32());

                        if(result)

                        {

                            do

                            {

                                if(result->GetRowCount() < 1)

                                {

                                    handler->SendSysMessage("You must be added to this phase before you can build.");

                                    return false;

                                }

                                else

                                {

                                    return true;

                                }

                            }while(result->NextRow());

                        }

                    }while(res->NextRow());

                }

            }


            // fill the gameobject data and save to the db

            pGameObj->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());


            // this will generate a new guid if the object is in an instance

            if (!pGameObj->LoadFromDB(db_lowGUID, map))

            {

                delete pGameObj;

                return false;

            }


            map->Add(pGameObj);


            // TODO: is it really necessary to add both the real and DB table guid here ?

            sObjectMgr->AddGameobjectToGrid(db_lowGUID, sObjectMgr->GetGOData(db_lowGUID));


            handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, id, gInfo->name.c_str(), db_lowGUID, x, y, z);

          return true;

      };

What I’m having issues with is practically with the QueryResult “result”.

[CODE] if (phasing)

{

uint32 value = atoi((char*)phasing);

QueryResult res, result;

res = CharacterDatabase.PQuery("SELECT is_in_phase FROM phase WHERE guid='%u'", chr->GetGUID());

if(res)

{

 do

 {

  Field * fields = res->Fetch();

  if(fields[0].GetInt32() != value)

  {

   handler->SendSysMessage("You must be in the correct phase to build.");

   return false;

  }

  result = CharacterDatabase.PQuery("SELECT * FROM phase_members WHERE guid='%u' AND phase='%u'", chr->GetGUID(),

   fields[0].GetUInt32());

  if(result)

  {

   do

   {

	Field * fields = result->Fetch();

	if(result->GetRowCount() < 1)

	{

	 handler->SendSysMessage("You must be added to this phase before you can build.");

	 return false;

	}

	else

	{

	 return true;

	}

   }while(result->NextRow());

  }

 }while(res->NextRow());

}

}[/CODE]

fields[0].GetUInt32() is I believe my issue. It is like it isn’t even inputting the data from my first QueryResult “res”. It even does that to “value”. My first error

You must be in the correct phase to build.

Will show perfectly, but when it goes through the other, it doesn’t do anything. Even when I add;


if(!result)

  return false;

It gives me “Incorrect Syntax” error message in the ingame chat. All I would like to know is why can’t it show the second error? Or tell me what is wrong with doing field[0].GetUInt32(). I’ve used countless lines of QueryResult code and never had this issue. But, I never coded a QueryResult in a command before.

Fixed the issue with a simple SELECT COUNT(*) at the beginning of the query.