Problems with mysql result storage - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problems with mysql result storage (
/showthread.php?tid=162437)
Problems with mysql result storage -
baske007 - 23.07.2010
Hello everyone,
I am busy with a gamemode, with some mysql stuff in it, but I get some warnings when I place mysql_free_result on the places that I think are right.
Example:
pawn Код:
stock CheckAccount(username[])
{
format(query, sizeof(query), "SELECT id FROM players WHERE username='%s'", username);
mysql_query(query);
mysql_store_result();
if (mysql_num_rows() == 1)
{
return 1;
}
else
{
return 0;
}
mysql_free_result();
}
Warnings:
pawn Код:
C:\Users\User\Desktop\samp\gamemodes\****.pwn(57) : warning 225: unreachable code
C:\Users\User\Desktop\samp\gamemodes\****.pwn(58) : warning 209: function "CheckAccount" should return a value
Line 57 is the mysql_free_result, and line 58 is ofcourse the } sign.
So, is this a problem for the script? Or can I just ignore it? Can I remove it?
Thanks so far,
Bas
Re: Problems with mysql result storage -
Jeffry - 23.07.2010
pawn Код:
stock CheckAccount(username[])
{
format(query, sizeof(query), "SELECT id FROM players WHERE username='%s'", username);
mysql_query(query);
mysql_store_result();
if (mysql_num_rows() == 1)
{
return 1;
}
else
{
return 0;
}
mysql_free_result(); // THIS will never be called!!
return 1; // THIS fixes the second warning, but wont be called.
}
So maybe try this:
pawn Код:
stock CheckAccount(username[])
{
format(query, sizeof(query), "SELECT id FROM players WHERE username='%s'", username);
mysql_query(query);
mysql_store_result();
if (mysql_num_rows() == 1)
{
mysql_free_result();
return 1;
}
else
{
return 0;
}
}
But I'm not sure, I never worked with MySQL.
Re: Problems with mysql result storage -
baske007 - 23.07.2010
Thanks for your reply. The warnings are gone now, thanks so far. But I'm afraid I'm going to get some errors after I added some more querys. Thanks anyway
Re: Problems with mysql result storage -
Jeffry - 23.07.2010
Hehe. Have fun with learning then. ^^
Re: Problems with mysql result storage -
TransformerOwl - 23.07.2010
I see a way to improve this code a little. Why don't you just return the received ID?
pawn Код:
// query and store result
new resultID = strval(mysql_fetch_row());
mysql_free_result();
There are numerous ways to improve the code and "fix" it. Result needs to be freed after using mysql_store_result!