SA-MP Forums Archive
[Tutorial] Threaded query - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+----- Forum: Lançamentos/Releases (https://sampforum.blast.hk/forumdisplay.php?fid=56)
+----- Thread: [Tutorial] Threaded query (/showthread.php?tid=312472)



Threaded query - AppleX - 21.01.2012

Os ъnicos requisitos deste tutorial sгo:
- Noзгo bбsica sobre SQL.
- MySQL plugin R6+

Vi muitos posts de ajuda em MySQL, vi que os cуdigos iriam travar o servidor no momento da query, assim como no cуdigo abaixo:

pawn Код:
mysql_query("SELECT integer FROM table");
Enquanto fazer a query, o servidor vai ficar travado, MAS no plugin do BlueG vocк pode fazer THREADED QUERY, ou seja, farб a query e o servidor vai continuar rodando ao mesmo tempo.
Vocк pode usar:
pawn Код:
mysql_query("SELECT integer FROM table", 25);
Assim a callback vai ser processada em outra thread, PORЙM, vocк vai ter que usar tudo isso dentro da callback OnQueryFinish.
pawn Код:
public OnQueryFinish(query[], resultid, extraid, connectionHandle)
{
    if(resultid == 25)
    {
       
        mysql_store_result();
        print("Threaded query finalizada com sucesso.", mysql_fetch_int());
        mysql_free_result();   
    }
    return 1;
}
Vocк pode optar por uma callback personalizada com o mysql_query_callback, й muito similar ao mysql_query.
pawn Код:
public OnPlayerConnect(playerid)
{
    mysql_query_callback(playerid, "SELECT color FROM table", "Callback");
    // Aqui as funзхes, o servidor nгo irб travar na query...

    for(new i; i < 25; i++) print("O SERVIDOR NГO TRAVOU NA QUERY...");
    return 1;
}

forward Callback(query[], index, extraid, connectionHandle);
public Callback(query[], index, extraid, connectionHandle)
{
    mysql_store_result();
    SetPlayerColor(index, mysql_fetch_int());
    return mysql_free_result();
}
OBS: THREADED QUERY й mais lento, mas nгo irб travar o servidor.


Re: Threaded query - -Prodigy- - 21.01.2012

I know this is the wrong section, but I wanted to ask ( since there are no other "Threading" tuts around ):

Would you also thread stuff like this:
pawn Код:
mysql_query("INSERT INTO Bans (BannedName, IP) VALUES ('Test', '192.168.0.1')");
AND
pawn Код:
mysql_query("UPDATE Users SET Admin = 5 WHERE Username = 'Test'");
?
If so, what would go under the thread branch?

Thanks, and sorry for the English language .


Re: Threaded query - AppleX - 21.01.2012

pawn Код:
mysql_query("INSERT INTO Bans (BannedName, IP) VALUES ('Test', '192.168.0.1')", 2);
pawn Код:
public OnQueryFinish(query[], resultid, extraid, connectionHandle)
{
    // Here their functions that you use after doing an select/insert/update/delete query. So it's the same thing.
    return 1;
}



Re: Threaded query - steki. - 21.01.2012

Muito bom, mas pouco ъtil nesse forum.

Eu tambйm queria ressaltar o uso de ENUMS na hora de organizar, se for usar o OnQueryFinish, onde temos a mesma callback para resultados diferentes, como ocorre nos DIALOGS.

@-Prodgy-

At the last parameter of the mysql_query, define a constant like: QUERY_NULL, and set it to an unreachable number that you'll never use on threaded queries. That will make your query threaded, but you are not going to use the result, so that won't make the AMX thread freeze. So, like mysql_query("INSERT;", QUERY_NULL);

Drop me a PM if you need further concerns.


Re: Threaded query - -Prodigy- - 22.01.2012

Thanks Stewie, that actually helped. Thanks again AppleX .


Re: Threaded query - Ricop522 - 23.01.2012

Boa, sу tб mto resumido
Coloca mais exemplos..