Forum > Serverside Modding
[SOLVED] [C++] QueryResult result = CharacterDatabase.PQuer
(1/1)
bizzlesnaff:
Yeah I'm little bit confused ;) I try to check if a database entry is 0 or smaller, but I didn't get it..:(
--- Code: ---QueryResult result = CharacterDatabase.PQuery("SELECT x FROM y WHERE z='%u'", player->GetName());
if (result <= 0) { well...something happen here ;) }
--- End code ---
Yeah..something like that..but it didn't work..:(
Kaev:
QueryResult result = CharacterDatabase.PQuery("SELECT x FROM y WHERE z='%u'", player->GetName());
%u = unsigned integer player->GetName() = string
Check printf operators for the correct one.
Daweo:
--- Quote from: "bizzlesnaff" ---Yeah I'm little bit confused ;) I try to check if a database entry is 0 or smaller, but I didn't get it..:(
--- Code: ---QueryResult result = CharacterDatabase.PQuery("SELECT x FROM y WHERE z='%u'", player->GetName());
if (result <= 0) { well...something happen here ;) }
--- End code ---
Yeah..something like that..but it didn't work..:( --- End quote ---
At first for string you have to use %s and into this PQuery function you have to use char* or const char*.
--- Code: ---QueryResult result = CharacterDatabase.PQuery("SELECT x FROM y WHERE z='%s'", player->GetName().c_str());
--- End code ---
And to count maybe you should use Count function:
--- Code: ---SELECT COUNT(column_name) FROM table_name;
--- End code ---
EDIT: I think it should be like this...
--- Code: ---QueryResult result = CharacterDatabase.PQuery("SELECT COUNT(x) FROM y WHERE z='%s'", player->GetName().c_str());
if (result) { Field* fields = result->Fetch(); uint32 count = fields[0].GetUInt32(); // Your code... }
--- End code ---
bizzlesnaff:
Thank you both ;) It work with this ;)
--- Code: ---Field * fields = result->Fetch(); uint32 result2 = fields[0].GetUInt32(); ChatHandler(player->GetSession()).PSendSysMessage("Points: %u", result2); if (result2 <= 0)
--- End code ---
Rochet2:
SQL does math with bigint - int64. So if there is any problems with the result2 being wrong, its likely that you would need to use GetInt64. Read more here: https://github.com/ElunaLuaEngine/Eluna/issues/89
Navigation
[0] Message Index
|