SA-MP Forums Archive
SQL query - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SQL query (/showthread.php?tid=344890)



SQL query - iGetty - 23.05.2012

Hello, the below code does the following on the console

pawn Код:
stock SaveStats(playerid)
{
    format(SQL_Query,sizeof(SQL_Query),"UPDATE `Accounts` SET `Money` = '%d', `Level` = '%d', `AdminLevel` = '%d', `Faction` = '%d', `FactionRank` = '%d', `RegistrationStep` = '%d', `BirthDay` = '%d', `BirthMonth` = '%d', `BirthYear` = '%d', `SpawnPoint` = '%d', `TutorialComplete` = '%d' WHERE `Username` = '%s'",
    Player[playerid][Money],
    Player[playerid][Level],
    Player[playerid][AdminLevel],
    Player[playerid][Faction],
    Player[playerid][FactionRank],
    Player[playerid][RegistrationStep],
    Player[playerid][BirthDay],
    Player[playerid][BirthMonth],
    Player[playerid][BirthYear],
    Player[playerid][SpawnPoint],
    pName(playerid));
   
    mysql_query(SQL_Query);
    mysql_free_result();
    return 1;
}

Код:
[02:16:53] CMySQLHandler::Query(UPDATE `Accounts` SET `Money` = '0', `Level` = '0', `AdminLevel` = '1', `Faction` = '0', `FactionRank` = '0', `RegistrationStep` = '3', `BirthDay` = '24', `BirthMonth` = '5', `BirthYear` = '1952', `SpawnPoint` = '0', `TutorialComplete` = '74' WHERE `Username` = '') - Successfully executed.

[02:16:53] >> mysql_free_result( Connection handle: 1 )

[02:16:53] CMySQLHandler::FreeResult() - The result is already empty.
It doesn't do anything in the database and I don't know what's up with it.

Thanks for any help given!


Re: SQL query - Jonny5 - 23.05.2012

it has no Username value , so unless you have a record in the db with a blank username it wont update.,

also i dont think you have to use
mysql_free_result(); on an update or insert statement,
just on querys that return data,


Re: SQL query - iGetty - 23.05.2012

I do have a username there, it's just not finding it.

It isn't reading from the "pName(playerid)" section and it's confusing me.


Re: SQL query - Jonny5 - 23.05.2012

yes thats where the problem is,
so untill it shows a username in the query it wont update,
as no records in your database match that.


i suggest tracking down why your pname var holds no info,
or setting it with the username before this query.

is pName suppose to be a function? or a var? or what
if you post that code it will help.


Re: SQL query - iGetty - 23.05.2012

pName(playerid) is a function.

Here:

pawn Код:
pName(playerid)
{
    new pname[24];
    GetPlayerName(playerid,pname,24);
    return pname;
}



Re: SQL query - Jonny5 - 23.05.2012

yeah weird

try it like this just to make sure your query works

pawn Код:
stock SaveStats(playerid)
{
    new pname[24];
    GetPlayerName(playerid,pname,24);
    format(SQL_Query,sizeof(SQL_Query),"UPDATE `Accounts` SET `Money` = '%d', `Level` = '%d', `AdminLevel` = '%d', `Faction` = '%d', `FactionRank` = '%d', `RegistrationStep` = '%d', `BirthDay` = '%d', `BirthMonth` = '%d', `BirthYear` = '%d', `SpawnPoint` = '%d', `TutorialComplete` = '%d' WHERE `Username` = '%s'",
    Player[playerid][Money],
    Player[playerid][Level],
    Player[playerid][AdminLevel],
    Player[playerid][Faction],
    Player[playerid][FactionRank],
    Player[playerid][RegistrationStep],
    Player[playerid][BirthDay],
    Player[playerid][BirthMonth],
    Player[playerid][BirthYear],
    Player[playerid][SpawnPoint],
    pname);
   
    mysql_query(SQL_Query);
    mysql_free_result();
    return 1;
}
could also add a
printf(); to the pName functions and see what it is actually returning.

pawn Код:
pName(playerid)
{
    new pname[24];
    GetPlayerName(playerid,pname,24);
    printf("pName = %s",pname);
    return pname;
}



Re: SQL query - Jonny5 - 23.05.2012

sorry i missed this

TutorialComplete is in the query but not supplied to the format function

so pName is going where TutorialComplete =
and their is nothing being passed for the name.

eg you need to add


pawn Код:
Player[playerid][TutorialComplete ],
pName(playerid)



Re: SQL query - iGetty - 23.05.2012

LOL! Oh shit, sorry for this hassle!


I'll notify you of the outcome!

Edit: Worked! +rep for you mate.