Help with 'mysql_tquery'
#1

Hello,
My question is this:
Could have problems using mysql_tquery loading player data and using functions like ShowPlayerDialog?
What could happen if the player disconnect before the query is executed?
I use threaded queries because the wiki recommend it, but I think that this is worse than a little of lag.
E.g.
pawn Код:
mysql_format(C_ID, query, sizeof(query), \
"SELECT * FROM Users WHERE PlayerName='%s'", PlayerName[playerid]);
mysql_tquery(C_ID, query, "LoadData", "d", playerid);
pawn Код:
public LoadData(const playerid)
{
if(cache_get_row_count(C_ID) == 1)
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "{FFFFFF}Login", "{61918B}This name is already {FFFFFF}registered\n{61918B}Please enter your password", "Enter", "Kick");
}
Now the problem will be:
1. The player connects - 0ms
2. The function mysql_tquery is called - 500ms have passed
3. The player decides disconnect immediately - 1000ms have passed
4. The function in the query is called after 1020ms, but the player isn't connected anymore, then what the hell?

I think that the worst is use threaded queries but the wiki recommends it for all the queries. Or maybe am I wrong with the problem?
Links:
https://sampwiki.blast.hk/wiki/MySQL/R33
Important
Note
It's highly recommended to thread all your queries (even INSERT & UPDATE).
Reply
#2

The chance of a player disconnecting during query execution and return is extremely small. If you must, use a variable to store an identifier, like their last opened dialoid, or their internal SQL id. The idea being that ff the player disconnects, that variable will be reset. In the query callback you can check if the value is still the same before processing the result.
Reply
#3

I'm doing this with my callbacks at the start:
pawn Код:
if(!IsPlayerConnected(playerid))
        {
            printf("Error executing callback - Load Data");
            return 0;
        }
Am I right using this?
The chances are small but can happen causing server crashes or data loss for the players.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)