SA-MP Forums Archive
Mysql Is a heck of a troublemaker...The second episode - 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: Mysql Is a heck of a troublemaker...The second episode (/showthread.php?tid=264965)



Mysql Is a heck of a troublemaker...The second episode - DeadAhead - 28.06.2011

Код:
(mysql log)
[22:35:43] CMySQLHandler::FreeResult() - The result is already empty.

[22:35:43] >> mysql_query( Connection handle: 1 )

[22:35:44] CMySQLHandler::Query(SELECT * FROM members WHERE username='[CLS]Killing_Torcher') - Successfully executed.

[22:35:44] >> mysql_store_result( Connection handle: 1 )

[22:35:44] CMySQLHandler::StoreResult() - Result was stored.

[22:35:44] >> mysql_fetch_field_row( Connection handle: 1 )

[22:35:44] CMySQLHandler::FetchField(locked) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[22:35:44] >> mysql_retrieve_row( Connection handle: 1 )
Trouble Maker: FetchField(locked)

pawn Код:
new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    mysql_real_escape_string(name,name);

    mysql_free_result();
    new Field[150];
    printf("[DEBUG] 'name' value: %s",name);
    format(query,sizeof(query),"SELECT * FROM members WHERE username='%s'",name);
    mysql_query(query);
    mysql_store_result();
    mysql_fetch_field_row(Field, "locked");
    if (mysql_retrieve_row()) {
    if (Field[0] == 1)
    {
        ShowPlayerDialog(playerid,1337,DIALOG_STYLE_MSGBOX,"Kicked","You have been Kicked out of the Server.\nThe Account you are using has been locked","OK","");
        Kick(playerid);
    }
    }
    else
    {
        mysql_query("INSERT INTO members (Username,Locked) VALUES('[CLS]Killing_Torcher',1)");
    }


Any idea(s)?


Re: Mysql Is a heck of a troublemaker...The second episode - FUNExtreme - 28.06.2011

This is not a fix to your problem, just another way of doing it

Why don't you just use
pawn Код:
format(query,sizeof(query),"SELECT locked FROM members WHERE username='%s'",name);
?


Re: Mysql Is a heck of a troublemaker...The second episode - DeadAhead - 28.06.2011

Quote:
Originally Posted by FUNExtreme
Посмотреть сообщение
This is not a fix to your problem, just another way of doing it

Why don't you just use
pawn Код:
format(query,sizeof(query),"SELECT locked FROM members WHERE username='%s'",name);
?
That was my previous code, i had some more to that Query, but i just used * to test if , Even since that might be un-logical to me, that would be the cause of my problem. (forgot to change it back)


AW: Mysql Is a heck of a troublemaker...The second episode - Blowfish - 28.06.2011

As far as I know you need to run mysql_retrieve_row BEFORE you can successfully call mysql_fetch_field_row.


Re: AW: Mysql Is a heck of a troublemaker...The second episode - Donya - 28.06.2011

pawn Код:
new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    mysql_real_escape_string(name,name);
    mysql_free_result();
    new Field[32];
    printf("[DEBUG] 'name' value: %s", name);
    format(query,sizeof(query),"SELECT * FROM members WHERE username = '%s'",name);
    mysql_query(query);
    mysql_store_result();
    while (mysql_retrieve_row())
    {
        mysql_get_field("locked", Field);
        if (strval(Field) == 1)
        {
            ShowPlayerDialog(playerid,1337,DIALOG_STYLE_MSGBOX,"Kicked","You have been Kicked out of the Server.\nThe Account you are using has been locked","OK","");
            Kick(playerid);
        }
    }
    else
    {
        mysql_query("INSERT INTO members (Username,Locked) VALUES('[CLS]Killing_Torcher',1)");
    }



AW: Mysql Is a heck of a troublemaker...The second episode - Blowfish - 28.06.2011

So what would be the exact answer?
You did exactly what I said.


Re: Mysql Is a heck of a troublemaker...The second episode - Donya - 28.06.2011

edit: nvm, i dont really get the difference between mysql_get_field and that. owell..

oh.. quote from mysql wiki: "Note: This function has a macro: mysql_get_field(const fieldname[], string[])."

sorry. i guess it is the same


AW: Mysql Is a heck of a troublemaker...The second episode - Blowfish - 28.06.2011

Well, that's wrong.
mysql_get_field is a macro to mysql_fetch_field row, so it's basically the same function
and they behave the same, except for the different order of the parameters.

You can find the corresponding line of code in the header file on line 26:
Код:
#define mysql_get_field(%1,%2) mysql_fetch_field_row(%2,%1)



Re: Mysql Is a heck of a troublemaker...The second episode - Donya - 28.06.2011

yep, didn't realize that lol. always liked get_field better for some reason.. thanks for letting me realize that though.


Re: Mysql Is a heck of a troublemaker...The second episode - DeadAhead - 29.06.2011

about the strval thing, I tested if that was the cause, since i didn't know what could have. I forgot to place that back.

The problem was with mysql_retrieve_row.

oh and, i didnt use a While loop, since it is supposed to give out only 1 row. Works now.

Thank you everyone!