Help with MySQL plugin, function: cache_delete()
#1

Hello,
Today I'm learning how use MySQL.
All was fine until I saw this:
Quote:

Use cache_delete() if you don't need the query's result anymore or you will experience memory leaks.

This information is for the function: mysql_query
But I see this too:
Quote:

It's highly recommended to thread all your queries (even INSERT & UPDATE).

So I decided use mysql_tquery, but I don't know if I need delete cache or something similar. Also that function needs a cache id but the function mysql_tquery only returns 0 or 1
The queries are only of INSERT and UPDATE (I don't need callbacks), I'm still learning.
I'm using this plugin:
https://sampforum.blast.hk/showthread.php?tid=56564
Thanks if anyone can help me.
Reply
#2

Cache gets deleted when you return 1 in your callback.

Delete example:

pawn Код:
mysql_format(g_ConnectionHandle, str, "DELETE FROM accounts WHERE Name='%s'", GetName(playerid));
mysql_function_query(g_ConnectionHandle, str, true, "", "");
When selecting:

pawn Код:
mysql_format(g_ConnectionHandle, str, "SELECT * FROM accounts WHERE Name='%s'", GetName(playerid));
mysql_function_query(g_ConnectionHandle, str, true, "onPlayerLogin", "d", playerid);

forward onPlayerLogin(playerid);

public onPlayerLogin(playerid)
{
    new rows, fields, str[150];
    cache_get_data(rows, fields);

    cache_get_row(0, 1, str); //0 is first row (should only be a single row if selecting specific user), 1 is the 2nd field in the row.
    format(UserStats[playerid][Password], 129, "%s", str);
    //etc
    return 1; //cache gets deleted here
}
Reply
#3

So in this function
pawn Код:
mysql_function_query(g_ConnectionHandle, str, true, "", "");
That hasn't a callback, then the cache is deleted? or I need use another query with a callback?
Thank you for your help
Reply
#4

Quote:
Originally Posted by Su37Erich
Посмотреть сообщение
So in this function
pawn Код:
mysql_function_query(g_ConnectionHandle, str, true, "", "");
That hasn't a callback, then the cache is deleted? or I need use another query with a callback?
Thank you for your help
You don't need to use a callback for anything else than SELECT queries.
Reply
#5

I know that, but the cache is deleted?
Reply
#6

If there is no result, there is no cache. I hope that is clear? Only a SELECT, SHOW or DESCRIBE query produces a result and thus a cache. The latter two are barely used in a live environment.
Reply
#7

Thank you all for the help, now I understand.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)