Modcraft - The community dedicated to quality WoW modding!

Wrath of the Lich King Modding => Serverside Modding => Topic started by: bizzlesnaff on July 13, 2015, 01:02:48 am

Title: [SOLVED] [C++]  QueryResult result = CharacterDatabase.PQuer
Post by: bizzlesnaff on July 13, 2015, 01:02:48 am
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: [Select]
QueryResult result = CharacterDatabase.PQuery("SELECT x FROM y WHERE z='%u'", player->GetName());

if (result <= 0)
{
well...something happen here ;)
}

Yeah..something like that..but it didn't work..:(
Title: Re: [C++]  QueryResult result = CharacterDatabase.PQuery
Post by: Kaev on July 13, 2015, 09:52:57 am
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.
Title: Re: [C++]  QueryResult result = CharacterDatabase.PQuery
Post by: Daweo on July 13, 2015, 09:53:49 am
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: [Select]
QueryResult result = CharacterDatabase.PQuery("SELECT x FROM y WHERE z='%u'", player->GetName());

if (result <= 0)
{
well...something happen here ;)
}

Yeah..something like that..but it didn't work..:(

At first for string you have to use %s and into this PQuery function you have to use char* or const char*.

Code: [Select]
QueryResult result = CharacterDatabase.PQuery("SELECT x FROM y WHERE z='%s'", player->GetName().c_str());

And to count maybe you should use Count function:

Code: [Select]
SELECT COUNT(column_name) FROM table_name;

EDIT:
I think it should be like this...
Code: [Select]
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...
}
Title: Re: [C++]  QueryResult result = CharacterDatabase.PQuery
Post by: bizzlesnaff on July 14, 2015, 06:35:51 am
Thank you both ;) It work with this ;)
Code: [Select]
Field * fields = result->Fetch();
uint32 result2 = fields[0].GetUInt32();
ChatHandler(player->GetSession()).PSendSysMessage("Points: %u", result2);
if (result2 <= 0)
                         
Title: Re: [SOLVED] [C++]  QueryResult result = CharacterDatabase.P
Post by: Rochet2 on July 14, 2015, 10:07:59 am
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 (https://github.com/ElunaLuaEngine/Eluna/issues/89" onclick="window.open(this.href);return false;)