27.07.2012, 10:19
Quote:
Thank you for the time that you spend for us,
i got an another question is it possible to not call and callback with the mysql func query? like this Код:
new query[768]; format(query, sizeof(query), "SELECT * FROM `"db_players"` WHERE ID = %d LIMIT 1", id); mysql_function_query(MySQL_Handle, query, false,"",""); mysql_store_result(MySQL_Handle); new resultat = mysql_num_rows(MySQL_Handle); mysql_free_result(MySQL_Handle); if(resultat >= 1) { return 1; } return 0; |
This code has to follow the examples I set in the post above yours, as well. There are no exceptions to this.
Quote:
Is this correct usage of new query:
pawn Код:
|
pawn Код:
format(query, sizeof(query), "UPDATE playerdata SET score=%d,money=%d WHERE user='%s'", score, money, pname);
mysql_function_query(dbHandle, query, false, "", "");
Additionally, since you're not going to fire a callback once the query finishes, there's no need to pass the score, money and pname parameters to an nonexistent callback.
Quote:
Thanks. (Already repped you when you replied me, but I didn't made a post)
Now I have 3 new questions: 1. Cache can be used in every thread, if no, when it's bad to use it ? 2. Which one is faster, sscanf, or cache_get_row ? 3. Why you use "LIMIT" in this: Код:
mysql_function_query(dbHandle, "SELECT kills,deaths,level FROM players WHERE name = 'MP2' LIMIT 0,1", true, "OnPlayerDataLoad", "i", playerid); |
1. Cache functions can be used in every thread, yes. I suppose that the benefit from the cache functions is negligible in many cases and I have not ran any speed tests with queries that only receive, lets say, 1-2 fields of data.
2. However I'll combine the answer to the second question with the first one a bit: you need to think through what the plugin does in the first place. When you use cache, it stores the data to a vector as soon as the query is finished. This means that later on, the MySQL result does not have to be accessed, only the vector. About the parsing: you cannot use sscanf with caching, because it does not output a raw string with all fields. I have found sscanf to be quite quite fast in the past though, and I might be wrong, but I think when parsing about 20 fields, the cache_get_row and sscanf parsing were almost the same in speed. Or if slower, then the benefit of not having to use mysql_fetch_row makes up for all the lost microseconds!
3. I am not sure whether that code is from the original post or not, but it would be smart to specify a LIMIT clause when you're expecting that the query could return multiple rows. This will just speed up the behavior a bit since only one row will be returned to the plugin by the MySQL server. However if the name is a PRIMARY KEY, this should not be an issue (that'll allow only one such name to be present). Also I'd suggest everyone to use a system of unique keys for registered player. This will also make using multiple tables a lot easier.
Sorry, I have been real busy with personal stuff and taking a vacation from my job in the past few weeks. I know that you and few others have requested for a tutorial on a saving/account system. I am going to make one, yes, but it needs some more thinking to be done.
Sorry for the late reply, and thanks for using the tutorial!