Mysql Is a heck of a troublemaker...The second episode
#1

Код:
(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)?
Reply
#2

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);
?
Reply
#3

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)
Reply
#4

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

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)");
    }
Reply
#6

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

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
Reply
#8

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)
Reply
#9

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

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)