The logic of mysql query functions (mysql_query vs mysql_tquery)
#1

mysql_tquery: Sends a query which will be executed in another thread and calls the callback (if there is one) when the execution is finished.
mysql_query: This native sends a non-threaded query to the MySQL server. The SA:MP server (the main PAWN thread) waits until the query has been executed and then returns the cache handle.

What i understand is, if a player calls a function it will be executed as asynchronous function.
And if there is a query request in that asynchronous function we have two choose in here. To use mysql_tquery or to use mysql_query.

Lets give an example from what i understand.
10 different player calls one asynchronous pawn function at the same time and if we use threaded mysql, those calls can be executed simultaneously. (In reality maybe not but it looks like that because the order of executions will be in mysql server. and its not going to lock samp server)

If we use non-threaded query in same story; in that case, pawn will make the order of this mysql calls and it will lock the system. It will create lots of load on server. And that may effect all the mysql calls on all different functions.

That was what i understand from my readings. I hope i dont make any mistake, if i do please teach me. that was my first question.

The second one is;

If there ise a asynchronous pawn function which includes more than one mysql calls. And if those functions depends each other... As an example lets think a money exchange between couple of players.
Lets think, this scenario will occur simultaneously.
(X have only $5 in his pocket and Y have only $1) X gives $5 to Y, X gives $5 to Z, Y gives $3 to Z, Z gives $2 to X.
If we dont use query instead of tquery, this exchange will fail. Because all that exchange functions will be triggered at the same time. And each exchange result can affect other calls in game.

So my second question is, is there a way to use tquery on depended calls.

Sorry for my poor english. Please help me to understand the logic of mysql's query functions.
Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)