Mysql data not properly getting processed into enum -
oliverrud - 25.08.2013
I'm currently trying to load up some account data from mysql into a enum using sscanf, but it doesn't seem to work.
My enum looks like this.
Код:
enum accountinfo {
ID,
Username[MAX_PLAYER_NAME],
Hours,
Minutes,
Points,
Group,
Race[10],
Bool:Logged,
Session,
// etc etc
};
new AccountData[MAX_PLAYERS][accountinfo];
Код:
stock AccountLogin(playerid){
new string[100];
format(string,sizeof(string),"SELECT id,username,hours,minutes,points,groups,race FROM accounts WHERE username = '%s'",AccountData[playerid][Username]);
mysql_query(string);
mysql_store_result();
new query[500];
if(mysql_fetch_row_format(query,"|")){
print(query);
sscanf(query, "e<p<|>is[24]iiiis[10]>", AccountData[playerid]);
print(query);
print(AccountData[playerid][ID]);
print(AccountData[playerid][Username]);
print(AccountData[playerid][Hours]);
}
mysql_free_result();
return 1;
}
That's the code I'm having problems with, when printing query it seems correct so I'm suspecting it's something with sscanf, when printing AccounData ID in console it returns a smiley and my username, which makes no sense since its an integer, the ID is supposed to be your mysql assigned ID.
Username prints my username so it's okay, but it's set another place too anyways.
Hours prints <null>
I'm using sscanf 2.8.1
Re: Mysql data not properly getting processed into enum -
ProjectMan - 25.08.2013
The "query" is an array of characters (string) variable so you need to use
pawn Код:
strval(AccountData[playerid][ID]);
strval(AccountData[playerid][Hours]);
Re: Mysql data not properly getting processed into enum -
oliverrud - 25.08.2013
Quote:
Originally Posted by ProjectMan
The "query" is an array of characters (string) variable so you need to use
pawn Код:
strval(AccountData[playerid][ID]); strval(AccountData[playerid][Hours]);
|
Yeah but isn't that what sscanf does for you?
Re: Mysql data not properly getting processed into enum -
MrCathal09 - 25.08.2013
If it's printing a smily, you're leaking memory. This is generally caused in low-level languages when you call a variable that has no value, so it just returns whatever it finds in the ram.
Re: Mysql data not properly getting processed into enum -
ProjectMan - 25.08.2013
Post here of an example of what your "query" is.
Re: Mysql data not properly getting processed into enum -
Misiur - 25.08.2013
pawn Код:
new string[100];
format(string,sizeof(string),"SELECT id,username,hours,minutes,points,groups,race FROM accounts WHERE username = '%s'",AccountData[playerid][Username]);
Your query itself is 85 + 1 characters, and username can be up to MAX_PLAYER_NAME/24 characters - which will give you 110 cells, which you want to store in 100 cells space. Welp, there's your leak (if the nick is longer than 10 characters it will occur)
Re: Mysql data not properly getting processed into enum -
ProjectMan - 25.08.2013
Quote:
Originally Posted by Misiur
pawn Код:
new string[100]; format(string,sizeof(string),"SELECT id,username,hours,minutes,points,groups,race FROM accounts WHERE username = '%s'",AccountData[playerid][Username]);
Your query itself is 85 + 1 characters, and username can be up to MAX_PLAYER_NAME/24 characters - which will give you 110 cells, which you want to store in 100 cells space. Welp, there's your leak (if the nick is longer than 10 characters it will occur)
|
I should have known memory leak is the main problem.
Re: Mysql data not properly getting processed into enum -
oliverrud - 25.08.2013
Changing the size of the string didn't do anything, the query string outputs "1|Snoozy|0|0|0|0|0" which is correct.
Re: Mysql data not properly getting processed into enum -
SuperViper - 25.08.2013
print accepts a string as a parameter. To print an integer, you need to do:
pawn Код:
printf("%d", AccountData[playerid][ID]);