SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 23/07/2010, 02:47 PM   #1
baske007
Big Clucker
 
Join Date: Apr 2010
Location: Netherlands
Posts: 78
Reputation: 0
Question Problems with mysql result storage

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 Code:
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 Code:
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
baske007 is offline  
Old 23/07/2010, 03:09 PM   #2
Jeffry
High-roller
 
Jeffry's Avatar
 
Join Date: Oct 2009
Location: Germany
Posts: 1,598
Reputation: 69
Default Re: Problems with mysql result storage

pawn Code:
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 Code:
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.
__________________
Jeffry is offline  
Old 23/07/2010, 03:13 PM   #3
baske007
Big Clucker
 
Join Date: Apr 2010
Location: Netherlands
Posts: 78
Reputation: 0
Default Re: Problems with mysql result storage

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
baske007 is offline  
Old 23/07/2010, 03:32 PM   #4
Jeffry
High-roller
 
Jeffry's Avatar
 
Join Date: Oct 2009
Location: Germany
Posts: 1,598
Reputation: 69
Default Re: Problems with mysql result storage

Hehe. Have fun with learning then. ^^
__________________
Jeffry is offline  
Old 23/07/2010, 04:17 PM   #5
TransformerOwl
Little Clucker
 
Join Date: Jul 2010
Posts: 16
Reputation: 0
Default Re: Problems with mysql result storage

I see a way to improve this code a little. Why don't you just return the received ID?
pawn Code:
// 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!
TransformerOwl is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 02:26 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.