Saving issue -
Scenario - 19.10.2010
Hello... Recently I've been getting a lot of bug reports on my currently released MySQL script. I was able to fix some of the problems with crashing upon performing commands, but this one I have no idea what's wrong. I was able to locate the issue and it's this custom callback that I've got.
pawn Код:
stock SavePlayerAccount(playerid)
{
new String[255], Float: health, Float: armour;
if( PlayerStatistics[playerid][pAuth] == 1)
{
format(String, sizeof(String), "UPDATE `Accounts` SET `Password` = '%s', `AdminLevel` = '%d', `Money` = '%d', `BankMoney` = '%d', `Score` = '%d', `Skin` = '%d' WHERE `UserID` = '%d'", PlayerStatistics[playerid][pPassword], PlayerStatistics[playerid][pAdminLevel], GetPlayerMoney(playerid), PlayerStatistics[playerid][pBankMoney], GetPlayerScore(playerid), GetPlayerSkin(playerid), PlayerStatistics[playerid][pDatabaseID]);
mysql_query(String);
GetPlayerPos(playerid, PlayerStatistics[playerid][pPositionX], PlayerStatistics[playerid][pPositionY], PlayerStatistics[playerid][pPositionZ]);
GetPlayerHealth(playerid, health);
GetPlayerArmour(playerid, armour);
format(String, sizeof(String), "UPDATE `Accounts` SET `Health` = '%f', `Armour` = '%f', `PositionX` = '%f', `PositionY` = '%d', `PositionZ` = '%d' WHERE `UserID` = '%d'", health, armour, PlayerStatistics[playerid][pPositionX], PlayerStatistics[playerid][pPositionY], PlayerStatistics[playerid][pPositionZ], PlayerStatistics[playerid][pDatabaseID]);
mysql_query(String);
}
return 1;
}
Can anybody see anything wrong with that? I'll show you more as you need it.
Re: Saving issue -
Scenario - 20.10.2010
BUMP... BUMP... BUMP...
Re: Saving issue -
Calgon - 20.10.2010
pawn Код:
format(String, sizeof(String), "UPDATE `Accounts` SET `Password` = '%s', `AdminLevel` = '%d', `Money` = '%d', `BankMoney` = '%d', `Score` = '%d', `Skin` = '%d' WHERE `UserID` = '%d'", PlayerStatistics[playerid][pPassword], PlayerStatistics[playerid][pAdminLevel], GetPlayerMoney(playerid), PlayerStatistics[playerid][pBankMoney], GetPlayerScore(playerid), GetPlayerSkin(playerid), PlayerStatistics[playerid][pDatabaseID]);
Does this query actually output any errors?
pawn Код:
format(String, sizeof(String), "UPDATE `Accounts` SET `Health` = '%f', `Armour` = '%f', `PositionX` = '%f', `PositionY` = '%d', `PositionZ` = '%d' WHERE `UserID` = '%d'", health, armour, PlayerStatistics[playerid][pPositionX], PlayerStatistics[playerid][pPositionY], PlayerStatistics[playerid][pPositionZ], PlayerStatistics[playerid][pDatabaseID]);
You've clearly confused 2 floats as integers (PositionY and PositionZ are not integers, they are floats, use %f). This could possibly be one of the causes of the crashes, though I've never experienced this in the MySQL plugin that I use.
Re: Saving issue -
Scenario - 20.10.2010
I'm suprised I didn't see that as I checked the code over and over again... I am getting an error in the console though:
Код:
[14:07:01] RealCop228 has logged in to their account!
[14:07:01] [death] RealCop228 died 255
[14:07:06] Executing SavePlayerAccount
[14:07:07] [MySQL] Error (0): Failed to exeute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.
[14:07:07] [part] RealCop228 has left the server (0:1)
This is my latest stock function, thanks for pointing it out.
pawn Код:
stock SavePlayerAccount(playerid)
{
new String[255], Float: health, Float: armour;
if( PlayerStatistics[playerid][pAuth] == 1)
{
format(String, sizeof(String), "UPDATE `Accounts` SET `Password` = '%s', `AdminLevel` = '%d', `Money` = '%d', `BankMoney` = '%d', `Score` = '%d', `Skin` = '%d' WHERE `UserID` = '%d'", PlayerStatistics[playerid][pPassword], PlayerStatistics[playerid][pAdminLevel], GetPlayerMoney(playerid), PlayerStatistics[playerid][pBankMoney], GetPlayerScore(playerid), GetPlayerSkin(playerid), PlayerStatistics[playerid][pDatabaseID]);
mysql_query(String);
GetPlayerPos(playerid, PlayerStatistics[playerid][pPositionX], PlayerStatistics[playerid][pPositionY], PlayerStatistics[playerid][pPositionZ]);
GetPlayerHealth(playerid, health);
GetPlayerArmour(playerid, armour);
format(String, sizeof(String), "UPDATE `Accounts` SET `Health` = '%f', `Armour` = '%f', `PositionX` = '%f', `PositionY` = '%f', `PositionZ` = '%f' WHERE `UserID` = '%d'", health, armour, PlayerStatistics[playerid][pPositionX], PlayerStatistics[playerid][pPositionY], PlayerStatistics[playerid][pPositionZ], PlayerStatistics[playerid][pDatabaseID]);
mysql_query(String);
}
return 1;
}
Re: Saving issue -
Calgon - 20.10.2010
Is there any proper query log that displays queries that were executed? Like mysql_log.txt in BlueG's plugin?
Re: Saving issue -
Scenario - 20.10.2010
No, that's all I got. I'm switching plugins though, as I'm beginning not to like Strickenkid's. You would recommend BlueG's I suppose?
Re: Saving issue -
Scenario - 20.10.2010
I am pissed, yet happy. It was Strickenkid's plugin all along, BlueG's works fine!

Thanks, Calgon!
Re: Saving issue -
Calgon - 20.10.2010
Yes, I would, I've been using it for a while now.
Re: Saving issue -
Scenario - 21.10.2010
Hopefully somebody could explain this problem to me...
When I log in to my server, I can register fine without any issues. My account is in the database, but only the username and password are saved, which is normal. When I leave the server, the "SavePlayerAccount" function is executed and in the 'mysql_log.txt' file, everything is showing as successful! Example:
Код:
[18:48:09] ---------------------------
[18:48:09] MySQL Debugging activated (10/21/10)
[18:48:09] ---------------------------
[18:48:09]
[18:48:09] >> mysql_connect( )
[18:48:09] CMySQLHandler::CMySQLHandler() - constructor called.
[18:48:09] CMySQLHandler::CMySQLHandler() - Connecting to "blah" | DB: "blah" | Username: "blah" ...
[18:48:09] CMySQLHandler::Connect() - Connection was successful.
[18:48:09] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.
[18:48:09] >> mysql_query( Connection handle: 1 )
[18:48:09] CMySQLHandler::Query(SELECT * FROM `Vehicles`) - Successfully executed.
[18:48:09] >> mysql_store_result( Connection handle: 1 )
[18:48:09] CMySQLHandler::StoreResult() - Result was stored.
[18:48:09] >> mysql_num_rows( Connection handle: 1 )
[18:48:09] CMySQLHandler::NumRows() - Returned 0 row(s)
[18:48:09] >> mysql_free_result( Connection handle: 1 )
[18:48:09] CMySQLHandler::FreeResult() - Result was successfully free'd.
[18:48:37] >> mysql_real_escape_string( Connection handle: 1 )
[18:48:37] CMySQLHandler::EscapeString(RealCop228); - Escaped 10 characters to RealCop228.
[18:48:37] >> mysql_query( Connection handle: 1 )
[18:48:38] CMySQLHandler::Query(SELECT `UserID` FROM `Accounts` WHERE `Username` = 'RealCop228') - Successfully executed.
[18:48:38] >> mysql_store_result( Connection handle: 1 )
[18:48:38] CMySQLHandler::StoreResult() - Result was stored.
[18:48:38] >> mysql_num_rows( Connection handle: 1 )
[18:48:38] CMySQLHandler::NumRows() - Returned 0 row(s)
[18:48:38] >> mysql_free_result( Connection handle: 1 )
[18:48:38] CMySQLHandler::FreeResult() - Result was successfully free'd.
[18:48:42] >> mysql_real_escape_string( Connection handle: 1 )
[18:48:42] CMySQLHandler::EscapeString(RealCop228); - Escaped 10 characters to RealCop228.
[18:48:42] >> mysql_query( Connection handle: 1 )
[18:48:42] CMySQLHandler::Query(INSERT INTO `Accounts` (Username, Password) VALUES('RealCop228', 'blahblahblahblah')) - Successfully executed.
[18:48:42] >> mysql_query( Connection handle: 1 )
[18:48:42] CMySQLHandler::Query(UPDATE `Accounts` SET `AdminLevel` = '0', `Money` = '10000', `BankMoney` = '0', `Score` = '0', `Skin` = '170' WHERE `UserID` = '0') - Successfully executed.
[18:48:42] >> mysql_query( Connection handle: 1 )
[18:48:42] CMySQLHandler::Query(UPDATE `Accounts` SET `Health` = '0.000000', `Armour` = '0.000000', `PositionX` = '50.000000', `PositionY` = '50.000000', `PositionZ` = '50.000000' WHERE `UserID` = '0') - Successfully executed.
In the database, however, nothing is showing up but the username and password - even though it's all been successful. This is the "SavePlayerAccount" function:
pawn Код:
stock SavePlayerAccount(playerid)
{
new String[255], Float: health, Float: armour;
if(PlayerStatistics[playerid][pAuth] == 1)
{
format(String, sizeof(String), "UPDATE `Accounts` SET `AdminLevel` = '%d', `Money` = '%d', `BankMoney` = '%d', `Score` = '%d', `Skin` = '%d' WHERE `UserID` = '%d'", PlayerStatistics[playerid][pAdminLevel], GetPlayerMoney(playerid), PlayerStatistics[playerid][pBankMoney], GetPlayerScore(playerid), GetPlayerSkin(playerid), PlayerStatistics[playerid][pDatabaseID]);
mysql_query(String);
GetPlayerPos(playerid, PlayerStatistics[playerid][pPositionX], PlayerStatistics[playerid][pPositionY], PlayerStatistics[playerid][pPositionZ]);
GetPlayerHealth(playerid, health);
GetPlayerArmour(playerid, armour);
format(String, sizeof(String), "UPDATE `Accounts` SET `Health` = '%f', `Armour` = '%f', `PositionX` = '%f', `PositionY` = '%f', `PositionZ` = '%f' WHERE `UserID` = '%d'", health, armour, PlayerStatistics[playerid][pPositionX], PlayerStatistics[playerid][pPositionY], PlayerStatistics[playerid][pPositionZ], PlayerStatistics[playerid][pDatabaseID]);
mysql_query(String);
}
return 1;
}
This is what happens when a player registers on the server...
pawn Код:
new rand = random(sizeof(RandomSpawn));
new buf[130], EscapedName[MAX_PLAYER_NAME];
mysql_real_escape_string(GetName(playerid), EscapedName);
WP_Hash(buf, sizeof (buf), inputtext);
format(Query, sizeof(Query), "INSERT INTO `Accounts` (Username, Password) VALUES('%s', '%s')", EscapedName, buf);
mysql_query(Query);
PlayerStatistics[playerid][pAuth] = 1;
format(string, sizeof(string), "You have been automatically logged in, %s!", GetName(playerid));
SendClientMessage(playerid, COLOR_ORANGE, string);
TogglePlayerSpectating(playerid, false);
SetSpawnInfo(playerid, 0, 170, RandomSpawn[rand][0], RandomSpawn[rand][1], RandomSpawn[rand][2], 0, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
SetPlayerHealth(playerid, 100);
GivePlayerMoneyEx(playerid, 10000);
SavePlayerAccount(playerid);
printf("%s has registered an account on the server.", GetName(playerid));
When I join the server (for the 2nd time when my username is in the database) and then leave, my stats will save. Now somebody, tell me...what the hell is wrong?
Re: Saving issue -
Grim_ - 22.10.2010
Just curious, but why do you use ' on integer and float values? It's only needed for strings.
And make sure 'PlayerStatistics[playerid][pDatabaseID]' is returning the correct value.