SQLite not saving playerdata OnPlayerDisconnect -
Mattakil - 02.10.2013
I know I made another thread, but..this is to the point. My SQLite will not save, the table matches OnGameModeInit, I learned from a tutorial and tried on a blank gamemode and it works. The system in my main game mode works the exact same, but dont work.
pawn Код:
new
Query[800],
string[100],
name[MAX_PLAYER_NAME]
;
GetPlayerName(playerid, name, sizeof(name));
if(pLogged[playerid] == 1)
{
format(Query, sizeof(Query), "UPDATE `ACCOUNTS` SET LEVEL = %d, CASH = %d, ADMINLEVEL = %d, HOURS = %d, JOB = '%d', BANNED = %d, SPAWN = %d, BANK = %d, FOOD = %d, WATER = %d, SKIN = '%d', FACTION = %d, FACTION LEVEL = %d WHERE `NAME` = %s COLLATE NOCASE", PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pAdmin],
PlayerInfo[playerid][pHours], PlayerInfo[playerid][pJob], PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pSpawn], PlayerInfo[playerid][pBank], PlayerInfo[playerid][pFood], PlayerInfo[playerid][pWater], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pFlevel], DB_Escape(name));
db_query(survival, Query);
format(string, sizeof(string), "%s's data has been successfully saved.", GetName(playerid));
printf(string);
return 1;
}
pLogged[playerid] = 0;
return 1;
}
NOTE: The reason for using GetName(playerid) and GetPlayerName is so that it saves into the DB with the "_" as I made the GetName stock to remove the underscore.
And..yeah, thanks in advance
Re: SQLite not saving playerdata OnPlayerDisconnect -
Jefff - 02.10.2013
pawn Код:
if(pLogged[playerid] == 1)
{
format(Query, sizeof(Query), "UPDATE `ACCOUNTS` SET LEVEL = %d, CASH = %d, ADMINLEVEL = %d, HOURS = %d, JOB = %d, BANNED = %d, SPAWN = %d, BANK = %d, FOOD = %d, WATER = %d, SKIN = %d, FACTION = %d, FACTION LEVEL = %d WHERE `NAME` = '%s'", PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pAdmin],
PlayerInfo[playerid][pHours], PlayerInfo[playerid][pJob], PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pSpawn], PlayerInfo[playerid][pBank], PlayerInfo[playerid][pFood], PlayerInfo[playerid][pWater], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pFlevel], DB_Escape(name));
db_query(survival, Query);
format(string, sizeof(string), "%s's data has been successfully saved.", GetName(playerid));
printf(string);
}
Re: SQLite not saving playerdata OnPlayerDisconnect -
Mattakil - 02.10.2013
Thanks man, WHERE `NAME` = '%s' Were those two fucking quotes all that was wrong? D:
Re: SQLite not saving playerdata OnPlayerDisconnect -
Jefff - 03.10.2013
string must be in ' ', integers not
Re: SQLite not saving playerdata OnPlayerDisconnect -
Mattakil - 03.10.2013
Well, I thank you..but it still doesn't work. I checked all other strings for the same issue, and fixed them. It now prints when you disconnect as it should (It didnt before) But there is still the issue with it updating to the database
Re: SQLite not saving playerdata OnPlayerDisconnect -
Pottus - 03.10.2013
Your not even freeing your results that will cause you a lot of problems, the best solution is to use sqlitei located here
https://sampforum.blast.hk/showthread.php?tid=303682 the good thing is you won't have to update anything for the time being sqlitei automatically frees your results just remember you should free them anyways. For instance when you use db_query do this.
db_free_result(db_query(survival, Query));
Sometimes of course you will need the result then can free it later when your finished but this kind of query doesn't need that. If your still having problems after that then you'll have to really look at your whole db system.
Re: SQLite not saving playerdata OnPlayerDisconnect -
Mattakil - 03.10.2013
Quote:
Originally Posted by [uL]Pottus
Your not even freeing your results that will cause you a lot of problems, the best solution is to use sqlitei located here https://sampforum.blast.hk/showthread.php?tid=303682 the good thing is you won't have to update anything for the time being sqlitei automatically frees your results just remember you should free them anyways. For instance when you use db_query do this.
db_free_result(db_query(survival, Query));
Sometimes of course you will need the result then can free it later when your finished but this kind of query doesn't need that. If your still having problems after that then you'll have to really look at your whole db system.
|
DB_Escape frees the results
Re: SQLite not saving playerdata OnPlayerDisconnect -
Konstantinos - 03.10.2013
Quote:
Originally Posted by Mattakil
DB_Escape frees the results
|
No, DB_Escape is used to escape the string - otherwise, you can be victim of SQL Injection.
db_free_result is used to free the result and it's only used if you execute a query with SELECT clause. On the rest is not needed.
Re: SQLite not saving playerdata OnPlayerDisconnect -
Mattakil - 03.10.2013
so because UPDATE is not SELECT, I do not need to free the result, yes? I had the result freed when you log in.
Re: SQLite not saving playerdata OnPlayerDisconnect -
Jefff - 03.10.2013
Replace FACTION LEVEL to FACTION_LEVEL in format