Quote:
Originally Posted by Splav
Hello, all
I have special function written to R6 MySQL plugin
How can I rewrite it on R7 version?
Sorry for my English
|
Quote:
Originally Posted by Coicatak
Erm. How to get the return value of a callback?
For example here, my callback "LoadSQLVehicle" return the id of the created vehicle with CreateVehicle() or -1 if there was an error. So, how to I get this returned value?
Код:
mysql_format_ex(str, "SELECT * FROM vehicle WHERE veh_id=%d", id);
mysql_query(str, "LoadSQLVehicle", "ii", i, 0);
|
Quote:
Originally Posted by scott1
I all,
i am triyng to update my gm to the r7,
but i got an probleme,
before i was using R5
i made when playerconnect
Код:
if(IsIpBanned(ip))
{
}
IsIpBanned return 1 if find row with the select, and 0 if not.
But with the R7 on don't know how to do it, because i must call an another callback .
Thank you
Max
|
Functions like that are not exactly "supported" by the new plugin and the threaded approach. Why? Because the query is not executed in the script execution thread and a callback will be fired once the query has finished.
Previously the server worked like this:
1. Do a million of things - synchronize players, run OnPlayerUpdate, other callbacks and code.
2. Query is fired!
3. Server waits until query is finished - does not do anything else meanwhile.
4. Can proceed with the code where it was left off before the query started.
Now it looks like this:
1. Do a million of things...
2. Query is fired!
3. Do a million of things...
4. Do a million of things...
5. Callback is called once query finishes.
So this means that functions like the ones you mentioned have become more difficult to create. It is possible, but I would not suggest it.
To show some code modifications, lets say you have something like the poster above mentioned:
pawn Код:
stock fromUnixTime(time)
{
new unbantime[25];
format(str, sizeof(str), "SELECT FROM_UNIXTIME( %d )", time);
if(mysql_query(str) && mysql_store_result())
{
mysql_fetch_row_format(unbantime);
}
mysql_free_result();
return unbantime;
}
This is probably called like this:
pawn Код:
format(string, sizeof(string), "Hey, the unban time is %s!", fromUnixTime(timeeeeee));
Now what you will have to do is make the query inside your function where format is called. Pass the necessary parameters that you desire to keep to mysql_function_query.
pawn Код:
format(query, sizeof(query), "SELECT FROM_UNIXTME(%d)", timeeeeee);
mysql_function_query(connectionHandle, query, true, "OnUnixTimeSelected", "i", playerid); // Change the "i" and following parameters according to what you need!
// now a new callback, out of the previous scope.
forward OnUnixTimeSelected(...);
public OnUnixTimeSelected(...)
{
cache_get_data(rows, fields, connectionHandle);
if(rows)
cache_get_row(0, 0, time);
// Continue operating with the time string.
return 1;
}
Hopefully this helps you a bit!
Quote:
Originally Posted by costel_nistor96
"row" parameter from cache_get_field_content is always 0 ? If not, when is different ?
|
It depends on which row you're actually parsing. If your query returns 4 rows and you know it does, you can do:
pawn Код:
cache_get_field_content(0, ...);
cache_get_field_content(1, ...);
cache_get_field_content(2, ...);
cache_get_field_content(3, ...);
But mostly, it is used in loops:
pawn Код:
cache_get_data(rows, fields, connectionHandle);
for(new i = 0; i != rows; i++)
{
cache_get_field_content(i, ...);
}