SA-MP Forums Archive
MySQL query leads to crash sometimes! - 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: MySQL query leads to crash sometimes! (/showthread.php?tid=626233)



MySQL query leads to crash sometimes! - YouHack - 12.01.2017

Well hello again!
My server crash sometimes when a user do the command /vipname.
PHP код:
CMD:vipname(playeridparams[])
{
    new 
text[6], szMessage[256];
    new 
vehicleid GetPlayerVehicleID(playerid);
    if(
sscanf(params"s[50]"text)) return SCM(playeridCOLOR_WHITE"SYNTAX: /vipname [name]");
    if(
PlayerInfo[playerid][pPremiumAccount] != 1) return SCM(playeridCOLOR_ERROR"You don't have a premium account");
    {
        if(
vText[playerid] != -1) return SCM(playeridCOLOR_WHITE"Use first /removename to put another name on your car.");
        if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SCM(playeridCOLOR_WHITE"You aren't in any car.");
        if(
GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SCM(playeridCOLOR_ERROR"You aren't the driver.");
        if(
GetVehicleModel(GetPlayerVehicleID(playerid)) != 411) return SCM(playeridCOLOR_ERROR"Car must be an Infernus in order to apply this command.");
        if(
OwnedVeh(vehicleid))
        {
            
vText[playerid] = CreateObject(19327, -2597.0762, -2638.4270, -5.3536, -87.699990.4001, -87.1805);
            
SetObjectMaterialText(vText[playerid] , text050"Arial"1510xFFFFFFFF01);
            
AttachObjectToVehicle(vText[playerid] , vehicleid0.0,-1.90.3270.00.00.0);
            
format(szMessagesizeof(szMessage), "{F2CF09}Vipname is: '%s'"text);
            
SCM(playeridCOLOR_YELLOWszMessage);
            new var[
64];
            
mysql_format(SQL, var, sizeof(var),"UPDATE `users` SET `vipnameinf`='%s' WHERE `name`='%d'"textPlayerInfo[playerid][pNormalName]);
            
mysql_tquery(SQL, var,"","");
        }
    }
    return 
1;

Also , i can't make a query to load the vipnameinf OnPlayerLogin . :/
Using MySQL R34.


Re: MySQL query leads to crash sometimes! - AjaxM - 12.01.2017

Below posts got it right.


Re: MySQL query leads to crash sometimes! - oMa37 - 12.01.2017

Increase the text size to 50, You have defined it as 6 and 50 in the sscanf check, I'm not sure if this is the issue but you should fix that.

PHP код:
new text[50];
if(
sscanf(params"s[50]"text)) return ... 
EDIT:

PHP код:
UPDATE `usersSET `vipnameinf`='%s' WHERE `name`='%d' 
the 'name' column is a string? If so change it to `name`='%s'


Re: MySQL query leads to crash sometimes! - Wolfe - 12.01.2017

As said above ^

pawn Код:
mysql_format(SQL, var, sizeof(var),"UPDATE `users` SET `vipnameinf`='%s' WHERE `name`='%d'", text, PlayerInfo[playerid][pNormalName]);
You're attempting to save a player name as %d when it needs to be saved as a string. %d treats it as if it was an integer.

Integer = whole number
String = characters

However I'm not sure if that would cause the crash, but it could be.

The fixed version would be;
pawn Код:
mysql_format(SQL, var, sizeof(var),"UPDATE `users` SET `vipnameinf`='%s' WHERE `name`='%s'", text, PlayerInfo[playerid][pNormalName]);



Re: MySQL query leads to crash sometimes! - YouHack - 12.01.2017

so %d used for a number , not string? if so, why it is working sometimes?


Re: MySQL query leads to crash sometimes! - darkdrago - 12.01.2017

%d is for integers, i don't really know why it sometimes works for you but the string is %s
If you use %d it would give some random numbers


Re: MySQL query leads to crash sometimes! - iLearner - 12.01.2017

Quote:

UPDATE `users` SET `vipnameinf`='%s' WHERE `name`='%d'

Integers dont need ' '


Re: MySQL query leads to crash sometimes! - YouHack - 12.01.2017

i will try it 6~9 times and see if crash now.