This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [SOLVED] [C++]  QueryResult result = CharacterDatabase.PQuer  (Read 1198 times)

bizzlesnaff

  • Registred Member
  • Wiki Incarnate
  • *****
  • Posts: 124
    • View Profile
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..:(
« Last Edit: July 14, 2015, 06:36:06 am by Admin »

Kaev

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 308
    • View Profile
Re: [C++]  QueryResult result = CharacterDatabase.PQuery
« Reply #1 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.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Daweo

  • Registred Member
  • Race Changer
  • *****
  • Posts: 39
    • View Profile
Re: [C++]  QueryResult result = CharacterDatabase.PQuery
« Reply #2 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...
}
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

bizzlesnaff

  • Registred Member
  • Wiki Incarnate
  • *****
  • Posts: 124
    • View Profile
Re: [C++]  QueryResult result = CharacterDatabase.PQuery
« Reply #3 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)
                         
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Rochet2

  • Contributors
  • Polygonshifter
  • *****
  • Posts: 59
    • View Profile
    • http://rochet2.github.io/
Re: [SOLVED] [C++]  QueryResult result = CharacterDatabase.P
« Reply #4 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
« Last Edit: January 01, 1970, 01:00:00 am by Admin »