Weird MySql issue
#1

Alrighty, so I've noticed this issue with MySql which sometimes occur. The thing is that it sometimes just doesn't catch player's full username, and once it doesn't it sets every online player's stats to random and bugs every password.


This is what it shows in the mysql_log.txt:


Код:
[00:02:45] [DEBUG] mysql_format - connection: 1, len: 500, format: "SELECT `Password`, `ID` FROM `users` WHERE `Username` = '%e' LIMIT 1"
[00:02:45] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `Password`, `ID` FROM `users` WHERE `Username` = 'Matt_Ri", callback: "OnAccountCheck", format: "i"
As you can see, the Username is Matt_Ri when it should be Matt_Richards. And it'll continue fetching the username like that until the server is restarted.


The code (I used newbienoob's tutorial)

pawn Код:
GetPlayerIp(playerid, IP[playerid], 16);
GetPlayerName(playerid, Name[playerid], 24);
mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `users` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
OnAccountCheck:

pawn Код:
public OnAccountCheck(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows)
    {
        cache_get_field_content(0, "Password", PlayerInfo[playerid][pPass], mysql, 129);
        PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
        //Showing Dialog here.
    }
    else
    {
        //Showing Dialog Here.
    }
    return 1;
}

I don't get any errors or anything, it just doesn't get full username sometimes which I don't really understand why. I hope some of you had this issues before and managed to solve it.


Cheers.


EDIT: whoops I meant to post this in scripting support, my bad.
Reply
#2

Which mysql version do you use ?

Try, to use %s insted of %e - for names, strings.

Код:
"SELECT * FROM `users` WHERE `Username` = '%s' LIMIT 1"
Reply
#3

I'm using the newest one, R39, and I'm just going to leave this here:

%e specifier escapes a string so we can avoid sql injection which means we don't have to use mysql_real_escape_string
Reply
#4

It might be a problem with the variable (not enough size etc). Debug it:
pawn Код:
GetPlayerIp(playerid, IP[playerid], 16);
GetPlayerName(playerid, Name[playerid], 24);
mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `users` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
printf("Name[playerid]: \"%s\" & query: \"%s\"", Name[playerid], query);
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It might be a problem with the variable (not enough size etc). Debug it:
pawn Код:
GetPlayerIp(playerid, IP[playerid], 16);
GetPlayerName(playerid, Name[playerid], 24);
mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `users` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
printf("Name[playerid]: \"%s\" & query: \"%s\"", Name[playerid], query);
Debugged, it showed everything fully. As I said this happens quite randomly and once it does it just doesn't fetch the username fully and then gives random stats to every other online user.
Reply
#6

Maybe a tip, when someone logs is let it write a debugline into a file ( don't use the server logs for this bullsh*t, it'll be a mess ). Then, whenever the bug appears, look at the latest line in that document and see what's wrong. Usefull thing to use is this setup;
<date> <time> <username> <query> ( ex; 13-07-2014 10:52 Matt_Richards SELECT `Password`, `ID` FROM `users` WHERE `Username` = 'Matt_Richards' LIMIT 1 )

Another thing, if someone uses a special character in his password, it might freak out ( can't be this problem since you're using %e, I guess ).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)