Hey,
i have a little problem with my own script. I try to update a row in the database. I use PExecute to send the Update Statement:
Player* target;
uint64 targetGuid;
string targetName;
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
return false;
QueryResult getData = WorldDatabase.PQuery(“SELECT id FROM testtable WHERE characterguid = %u”,player->GetSession()->GetPlayer()->GetGUID());
uint64 fetchid;
do
{
Field* fields = getData->Fetch();
fetchid = fields[0].GetUInt64();
} while (getData->NextRow());
string UpdateField;
UpdateField = “column1”;
WorldDatabase.PExecute(“UPDATE testtable SET %s = %u WHERE id = %u”, UpdateField.c_str(), targetGuid, fetchid);
handler->PSendSysMessage(“UPDATE testtable SET %s = %u WHERE id = %u”, UpdateField.c_str(), targetGuid, fetchid);
For example:
UpdateField is not static. The string change, but in this example it is “column1”.
targetGuid is the GUID from player target. In this example it has the value 2.
fetchid has the value 1.
So, if the sql statement work, then it is: UPDATE testtable SET column1 = 2 WHERE id = 1
but it does not work. It make this statement: UPDATE testtable SET column1 = 2 WHERE id = 0
So i check the fetchid value and with
handler->PSendSysMessage(“Fetchid: %u”, fetchid);
before the PExecute i get the value 1 and not 0. So what change my fetchid from 1 to 0? Does Pexecute accept only two arguments? If i remove targetGuid and write instead the dynamic value a static value in the statement
WorldDatabase.PExecute(“UPDATE testtable SET %s = 2 WHERE id = %u”, UpdateField.c_str(), fetchid);
handler->PSendSysMessage(“UPDATE testtable SET %s = 2 WHERE id = %u”, UpdateField.c_str(), fetchid);
it works. The chathandler say "UPDATE testtable SET column1 = 2 WHERE id = 1. I dont understand it… Need help for it and sorry for my bad english. Its late and my english skills are not so good /emoticons/default_smile.png