MySQL Threaded R7 - Small Help.
#1

Hi, I'm trying to make it give me the result / date without the need of calling a function as I have many of these queries and making functions for similar queries would be hassle and lots of them too:

What is wrong with my code as data returns NULL:

[07:24:59] ProcessQueryThread(NoThreadResult) - Query was successful. (SELECT Date < UNIX_TIMESTAMP() FROM bans WHERE IP = '81.237.***.**')
[07:24:59] ProcessQueryThread(NoThreadResult) - Data caching enabled.
[07:24:59] CMySQLHandler::StoreResult() - Result was stored.
[07:24:59] CMySQLHandler::FreeResult() - Result was successfully free'd.

pawn Код:
mysql_format(MySQLConnection, MySQL, "SELECT Date < UNIX_TIMESTAMP() FROM bans WHERE IP = '%s'", plrIP);
mysql_function_query(MySQLConnection, MySQL, true, "NoThreadResult", "i", INVALID_PLAYER_ID);

new rows, fields, data[12];
cache_get_data(rows, fields);
if(rows)
{
    cache_get_row(0, 0, data);
    new expire = strval(data);
    printf("data = %s", data);
    printf("expire = %d", expire);
}
Thank you.
Reply
#2

Err.

pawn Код:
mysql_function_query(MySQLConnection, MySQL, true, "NoThreadResult", "i", INVALID_PLAYER_ID);
It actually calls "NoThreadResult" when it has GOT the result. So you just need to move your whole "getting what it returned" thing into NoThreadResult and maybe even pick a better name?

Regards.
Reply
#3

If you didn't read, I do not want it to call a function, I want to be able to get the details below the query.
Reply
#4

That's impossible.
Reply
#5

lolol, dude threaded queries sent the results to a callback, you can't do that in R7

Trust me it's not hard to convert, just do it like this

Code part 1
query

in callback:
code part 2 (needs the query results)
... (and continuum)

Secondly, what the hell? "SELECT Date < UNIX_TIMESTAMP()" does that query even work?
Reply
#6

Quote:
Originally Posted by Kar
Посмотреть сообщение
Secondly, what the hell? "SELECT Date < UNIX_TIMESTAMP()" does that query even work?
http://dev.mysql.com/doc/refman/5.5/...unix-timestamp

EDIT: Oh I actually misread LOL. No that obviously wont work.
Reply
#7

Thanks for all of you giving some advice. I've changed a bit of AndreT's code a little bit and added a field on. Would this work?

Also that query does work with the selecting the date as it tells me if the Date they will be unbanned has passed or not returning 1 for passed or 0 for not passed.

http://pastie.org/private/tzztcvzdyjg27smiyjuvw
Reply
#8

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
Thanks for all of you giving some advice. I've changed a bit of AndreT's code a little bit and added a field on. Would this work?

Also that query does work with the selecting the date as it tells me if the Date they will be unbanned has passed or not returning 1 for passed or 0 for not passed.

http://pastie.org/private/tzztcvzdyjg27smiyjuvw
Sorry I didn't read it all but I noticed one thing immediatly:

pawn Код:
mysql_function_query(MySQLConnection, MySQL, true, "CheckBanned", "is", playerid, plrIP);
That's wrong. Because you say that the function to call is "CheckBanned" but it's not. The function is actually called:

pawn Код:
public OnBanQueryFinish(playerid, ip[])
So, it should be:

pawn Код:
mysql_function_query(MySQLConnection, MySQL, true, "OnBanQueryFinish", "is", playerid, plrIP);
EDIT: Okay I actually just read the function and it's one big mess.

pawn Код:
forward OnBanQueryFinish(playerid, ip[]);
public OnBanQueryFinish(playerid, ip[])
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows)
    {
        new data[12], data2[1];
        cache_get_row(0, 0, data); // Your only selecting date, so how come you actually
        cache_get_row(1, 0, data2); // get two rows of data? Sorry maybe I am just wrong but shouldnt
        new expire = strval(data); // you only have one result? You expect a date to return
        new expirer = strval(data2);
        printf("Extracted unban time %d from string '%s'", expire, data);

        if(expirer == 1)
    {
        printf("Player is NOT Banned - Query Complete"); // Why is the player not banned if you get a 2nd result?
      mysql_format(MySQLConnection, MySQL, "DELETE FROM bans WHERE Name = '%s' LIMIT 1", ip);
      mysql_function_query(MySQLConnection, MySQL, false, "ReturnNull", "i", INVALID_PLAYER_ID); // You don't need to use "ReturnNull", you can simply use ""
        }
        else if(expirer == 0)
    {
        printf("Player is Banned - Query Complete");
            SendFormatMessage(playerid, COLOR_DEFAULT, "You are banned from this server untill %s", dater(expirer, 3));
            Kick(playerid);
            DontShow[playerid] = 1;
            return 1;
        }
    }
    return 1;
}
Man I am scratching my head here haha.
Reply
#9

Quote:
Originally Posted by Extremo
Посмотреть сообщение
Sorry I didn't read it all but I noticed one thing immediatly:

pawn Код:
mysql_function_query(MySQLConnection, MySQL, true, "CheckBanned", "is", playerid, plrIP);
That's wrong. Because you say that the function to call is "CheckBanned" but it's not. The function is actually called:

pawn Код:
public OnBanQueryFinish(playerid, ip[])
So, it should be:

pawn Код:
mysql_function_query(MySQLConnection, MySQL, true, "OnBanQueryFinish", "is", playerid, plrIP);
Yes, I didn't spot that. That wasn't in the pwn version, as the pastebin was an older version which I must of forgot to update the query. Apart from that is it all good and should work? Also thank you.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)