17.07.2012, 20:28
Quote:
Hello, all
I have special function written to R6 MySQL plugin How can I rewrite it on R7 version? Sorry for my English |
Quote:
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:
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)) { } But with the R7 on don't know how to do it, because i must call an another callback . Thank you Max |
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;
}
pawn Код:
format(string, sizeof(string), "Hey, the unban time is %s!", fromUnixTime(timeeeeee));
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;
}
Quote:
"row" parameter from cache_get_field_content is always 0 ? If not, when is different ?
|
pawn Код:
cache_get_field_content(0, ...);
cache_get_field_content(1, ...);
cache_get_field_content(2, ...);
cache_get_field_content(3, ...);
pawn Код:
cache_get_data(rows, fields, connectionHandle);
for(new i = 0; i != rows; i++)
{
cache_get_field_content(i, ...);
}