Updating BlueG's MySQL plugin R33+ scripts to R40 -
maddinat0r - 31.08.2016
This small guide will list all code-breaking changes introduced in R40 and how to fix them in your script. I will also provide regular expressions in some places (search-and-replace regex) which will easily fix the corresponding change for you. All regular expressions were tested in Notepad++, however I do NOT guarantee that they will replace always everything correctly. Make sure to backup your script before you apply the regular expressions, and always review all changes made by them.
Follow the guide step by step. Don't skip anything, or you'll quickly end up with confusing instructions and results.
- new "MySQL" tag for connection handles:
Code:
new g_SQL;
public OnGameModeInit()
{
g_SQL = mysql_connect(/* credentials */);
}
becomes
Code:
new MySQL:g_SQL;
public OnGameModeInit()
{
g_SQL = mysql_connect(/* credentials */);
}
Simply prepend "MySQL:" before your global MySQL variable.
- redundant prefixes from log level enum removed:
Code:
mysql_log(LOG_ERROR | LOG_DEBUG);
becomes
Code:
mysql_log(ERROR | DEBUG);
Just remove the "LOG_" part before any log level
- connection handle parameter moved to last position in mysql_escape_string, mysql_stat and mysql_get_charset:
Code:
mysql_get_charset(destination, g_SQL, sizeof(destination));
becomes
Code:
mysql_get_charset(destination, sizeof(destination), g_SQL);
Pass the global MySQL handle variable as the last parameter.
RegEx:
Search:
Code:
(mysql_escape_string|mysql_stat|mysql_get_charset)\((.+?), ?g_SQL(.*?)\);
Replace:
- password and database parameters swapped in mysql_connect:
Code:
mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
becomes
Code:
mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
As the title says, simply swap the password and database values.
- all connection options in mysql_connect moved into an own small system:
Code:
mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, .autoreconnect = false, .pool_size = 0);
becomes
Code:
new MySQLOpt:options = mysql_init_options();
mysql_set_option(options, AUTO_RECONNECT, false);
mysql_set_option(options, POOL_SIZE, 0);
mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, options);
You now have to create an extra MySQL connection options instance, set
the options you need and pass it to mysql_connect.
- mysql_option renamed into mysql_global_options:
Code:
mysql_option(DUPLICATE_CONNECTIONS, true);
becomes
Code:
mysql_global_options(DUPLICATE_CONNECTIONS, true);
Simply search-and-replace it.
- log type parameter in mysql_log removed:
Code:
mysql_log(ALL, LOG_TYPE_HTML);
becomes
- mysql_reconnect removed:
Code:
mysql_reconnect(g_SQL);
becomes
Code:
mysql_close(g_SQL);
g_SQL = mysql_connect(/* credentials */);
Just close the handle and create a new one to the same database.
- mysql_current_handle removed:
Yep. Just removed. No replacement.
- connection handle parameter from all cache function removed:
Code:
cache_get_row(0, 0, g_SQL);
simply becomes
Code:
cache_get_row(0, 0);
Same thing goes for every other cache native.
RegEx:
Search: (replace "g_SQL" in the regular expression below with your used global MySQL variable)
Code:
(cache_.+?\(.+?), ?g_SQL\);
Replace:
- cache_get_row renamed into cache_get_value_index:
Code:
cache_get_row(0, 0, dest);
new value = cache_get_row_int(0, 1);
becomes
Code:
cache_get_value_index(0, 0, dest);
new value = cache_get_value_index_int(0, 1);
Simply search-and-replace it.
- cache_get_field_content renamed into cache_get_value_name:
Code:
cache_get_field_content(0, "string", dest);
new value = cache_get_field_content_int(0, "integer");
becomes
Code:
cache_get_value_name(0, "string", dest);
new value = cache_get_value_name(0, "integer");
Simply search-and-replace it.
- all cache_get_ functions now return their value through a reference parameter instead of returning it directly:
Code:
new bool:value = cache_get_value_index_bool(0, 2);
new row_count = cache_get_row_count();
becomes
Code:
new bool:value;
cache_get_value_index_bool(0, 2, value);
new row_count;
cache_get_row_count(row_count);
All cache_get_ functions that returned data through their return value before now return it through a reference parameter. Instead they now return an status code, indicating if the function successfully executed or not.
RegEx (will correct all "cache_get_value_" natives which are in the style "variable = cache_get_value_*(*);":
Search:
Code:
(.+?) ?= ?(cache_get_value_.+?\(.*?)\);
Replace:
- "cache_set_active(Cache:0);" doesn't unset the active cache anymore:
Code:
cache_set_active(Cache:0);
becomes
Code:
cache_unset_active();
Easy, huh?
- cache_get_data removed (use `cache_get_*_count`):
Code:
new rows, fields;
cache_get_data(rows, fields);
becomes
Code:
new rows, fields;
cache_get_row_count(rows);
cache_get_field_count(fields);
- parameter "clearvars" in orm_delete removed:
Code:
orm_delete(orm_id);
becomes
Code:
orm_delete(orm_id);
orm_clear_vars(orm_id);
- all y_inline support code has been outsourced, see samp-mysql-yinline-include.
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
Shinja - 31.08.2016
Can't wait for it, don't forget to implement example-script login/register as always, it's really useful
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
maddinat0r - 31.08.2016
Already done (thanks to Konstantinos)!
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
TommyB - 01.09.2016
Thanks!
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
HydraHumza - 01.09.2016
Awesome. Can't wait to check it
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
PrO.GameR - 01.09.2016
Awesome, now I can instantly update to R40 when it comes out.
Btw is there any specific reason behind those change names?
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
maddinat0r - 01.09.2016
Quote:
Originally Posted by PrO.GameR
Awesome, now I can instantly update to R40 when it comes out.
Btw is there any specific reason behind those change names?
|
I guess you're talking about cache_get_field_content and cache_get_row.
- Those two natives do basically the same (retrieve values from the active cache), yet they have completely unrelated names.
- When you first use cache_get_row, you might think it retrieves a whole row out of the result set, but it doesn't.
- cache_get_field_content has the word "field" in it, which refers to a column in MySQL terminology. Again, you don't retrieve the "content of a column".
Those two natives retrieve values from the cache, specified by an row index. One uses a column index, while the other one uses a column name to get the desired value. That's why they're named "cache_get_value_index" and "cache_get_value_name" now.
Oh, and thanks to some preprocessor magic, you can omit the "_index" and "_value" part, e.g.
Code:
cache_get_value(0, 0, string); //will resolve to cache_get_value_index
cache_get_value_float(0, "health", health); //will resolve to cache_get_value_name_float
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
nGen.SoNNy - 05.09.2016
Nice tutorial!
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
markparker12 - 05.09.2016
A really helpful tutorial.
Thanks for this.
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
MerryDeer - 05.09.2016
RegEx don't work in pawno!!
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
vannesenn - 05.09.2016
When I replace cache_get_row_int with cache_get_value_index_int, I get warning that number of parameters doesn't match definition.
Here's my code
Code:
_dan = cache_get_row_int(0, 0) + 1;
becomes
Code:
_dan = cache_get_value_index_int(0, 0) + 1;
I like new plugin, and major changes, but you fucked up little bit with changing functions names.
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
IstuntmanI - 05.09.2016
Quote:
Originally Posted by vannesenn
When I replace cache_get_row_int with cache_get_value_index_int, I get warning that number of parameters doesn't match definition.
Here's my code
Code:
_dan = cache_get_row_int(0, 0) + 1;
becomes
Code:
_dan = cache_get_value_index_int(0, 0) + 1;
I like new plugin, and major changes, but you fucked up little bit with changing functions names.
|
Quote:
all cache_get_ functions now return their value through a reference parameter instead of returning it directly
|
So you have to do it like this:
Code:
cache_get_value_index_int(0, 0, _dan);
_dan += 1;
I think that he made a bad decision for getting a column's value through a reference parameter. I get his idea of making every function return a status value, but still.
One important downside: we have to transform all our lines using SetGVar* or SetPVar* to use a temporary variable, which I don't like to.
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
vannesenn - 05.09.2016
Then author should edit topic. Wiki says one, topic says second. Also, some parts of code explanation are weird.
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
vannesenn - 05.09.2016
Well, why I can't use char array?
Code:
cache_get_value_index_int(0, 20, _HRP_kVisina{_playerid});
cache_get_value_index_int(0, 21, _HRP_kOMasa{_playerid});
cache_get_value_index_int(0, 22, _HRP_kMMasa{_playerid});
cache_get_value_index_int(0, 23, _HRP_kMSala{_playerid});
Code:
error 035: argument type mismatch (argument 3)
I think I'll roll back on R39. I understand why he changed functions names, but why functions don't return value like before R40?
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
nGen.SoNNy - 05.09.2016
The same problem with using gvar and pvar... i don't want to store the result in some temporary var and then into the gvar. I think i will stay on R39 till this R40 will return values.
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
Slawiii - 05.09.2016
Nice Work Man
but i saved MySQL R33+ in my memory
its hard to transfer it but i will try i like it so Good Job man
Thank you .
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
Spmn - 05.09.2016
Quote:
Originally Posted by IstuntmanI
So you have to do it like this:
Code:
cache_get_value_index_int(0, 0, _dan);
_dan += 1;
I think that he made a bad decision for getting a column's value through a reference parameter. I get his idea of making every function return a status value, but still.
One important downside: we have to transform all our lines using SetGVar* or SetPVar* to use a temporary variable, which I don't like to.
|
Well, just add wrapper functions for those affected:
Code:
stock cache_get_row_int(row, field_idx, connectionHandle = 1)
{
#pragma unused connectionHandle
new retval = cellmin; // so this wrapper function will return cellmin in case of fail
cache_get_value_index_int(row, field_idx, retval);
return retval;
}
// and so on for cache_get_row_float, etc
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
maddinat0r - 06.09.2016
Quote:
Originally Posted by vannesenn
Then author should edit topic. Wiki says one, topic says second. Also, some parts of code explanation are weird.
|
If you'd actually read the tutorial, you would have seen that directly after changing the names of the cache_get_value functions there's the "cache_get_value return their values through a reference parameter" point.
The wiki is also correctly describing the new functions, and even provides small examples along them.
Quote:
Originally Posted by nGen.SoNNy
The same problem with using gvar and pvar... i don't want to store the result in some temporary var and then into the gvar. I think i will stay on R39 till this R40 will return values.
|
Then you're going to stay on R39 forever. I don't intend to change these functions
again in the next update.
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
DandyCorleone - 06.09.2016
Good job
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 -
Max_Andolini - 09.09.2016
Integer is wrong;
cache_get_value_name(0, "string", dest);
new value = cache_get_value_name(0, "integer");
New;
new value;
cache_get_value_name_int(0, "integer", value);