Could not save MySQL query O.o
#7

Ah, ok. When you are using unthreaded queries, the server has to wait until you get result. When I'm saying server, that means all commands, and everything will be unresponsive for all players. That's why we are using threaded queries. It creates separate thread in your server's CPU, and calls back to your script when the result is ready (at least that's how I understand it). Lag eliminated, but requires you to provide a callback - function which will be called after retrieving results. It has to be a public function, like with timers. So, your code has to look like:

pawn Код:
stock GetName(playerid)
{
    new AccName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, AccName, sizeof(AccName));
    return pName;
}

public OnPlayerDisconnect(playerid, reason)
{
    mysql_format(sqldb, query, sizeof(query), "INSERT INTO accounts (accname) VALUES ('%e')", GetName(playerid));
    mysql_tquery(sqldb, query, "InsertCallback", "d", playerid);
    return 1;
}

forward InsertCallback(playerid);
public InsertCallback(playerid)
{
    PlayerInfo[playerid][pSQLID] = cache_insert_id(sqldb);

    printf("Player %d was saved with dbID %d", playerid, PlayerInfo[playerid][pSQLID]);
    return 1;
}
I used %e and mysql_format - ****** sql injection to learn about dangers of using %s instead %e with strings.
Reply


Messages In This Thread
Could not save MySQL query O.o - by venomlivno8 - 20.02.2014, 13:28
Re: Could not save MySQL query O.o - by MrTinder - 20.02.2014, 13:31
Re: Could not save MySQL query O.o - by venomlivno8 - 20.02.2014, 13:33
Re: Could not save MySQL query O.o - by MrTinder - 20.02.2014, 13:34
Re: Could not save MySQL query O.o - by Misiur - 20.02.2014, 13:36
Re: Could not save MySQL query O.o - by venomlivno8 - 20.02.2014, 13:41
Re: Could not save MySQL query O.o - by Misiur - 20.02.2014, 13:49
AW: Could not save MySQL query O.o - by 'Pawno. - 20.02.2014, 14:10

Forum Jump:


Users browsing this thread: 1 Guest(s)