31.08.2016, 13:46
(
Last edited by maddinat0r; 25/06/2017 at 10:24 AM.
)
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.
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:
becomesCode:new g_SQL; public OnGameModeInit() { g_SQL = mysql_connect(/* credentials */); }
Simply prepend "MySQL:" before your global MySQL variable.Code:new MySQL:g_SQL; public OnGameModeInit() { g_SQL = mysql_connect(/* credentials */); } - redundant prefixes from log level enum removed:
becomesCode:mysql_log(LOG_ERROR | LOG_DEBUG);
Just remove the "LOG_" part before any log levelCode:mysql_log(ERROR | DEBUG);
- connection handle parameter moved to last position in mysql_escape_string, mysql_stat and mysql_get_charset:
becomesCode:mysql_get_charset(destination, g_SQL, sizeof(destination));
Pass the global MySQL handle variable as the last parameter.Code:mysql_get_charset(destination, sizeof(destination), g_SQL);
RegEx:
Search:Replace:Code:(mysql_escape_string|mysql_stat|mysql_get_charset)\((.+?), ?g_SQL(.*?)\);
Code:\1\(\2\3, g_SQL\);
- password and database parameters swapped in mysql_connect:
becomesCode:mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
As the title says, simply swap the password and database values.Code:mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
- all connection options in mysql_connect moved into an own small system:
becomesCode:mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, .autoreconnect = false, .pool_size = 0);
You now have to create an extra MySQL connection options instance, setCode: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);
the options you need and pass it to mysql_connect. - mysql_option renamed into mysql_global_options:
becomesCode:mysql_option(DUPLICATE_CONNECTIONS, true);
Simply search-and-replace it.Code:mysql_global_options(DUPLICATE_CONNECTIONS, true);
- log type parameter in mysql_log removed:
becomesCode:mysql_log(ALL, LOG_TYPE_HTML);
Code:mysql_log(ALL);
- mysql_reconnect removed:
becomesCode:mysql_reconnect(g_SQL);
Just close the handle and create a new one to the same database.Code:mysql_close(g_SQL); g_SQL = mysql_connect(/* credentials */);
- mysql_current_handle removed:
Yep. Just removed. No replacement.
- connection handle parameter from all cache function removed:
simply becomesCode:cache_get_row(0, 0, g_SQL);
Same thing goes for every other cache native.Code:cache_get_row(0, 0);
RegEx:
Search: (replace "g_SQL" in the regular expression below with your used global MySQL variable)
Replace:Code:(cache_.+?\(.+?), ?g_SQL\);
Code:\1\);
- cache_get_row renamed into cache_get_value_index:
becomesCode:cache_get_row(0, 0, dest); new value = cache_get_row_int(0, 1);
Simply search-and-replace it.Code:cache_get_value_index(0, 0, dest); new value = cache_get_value_index_int(0, 1);
- cache_get_field_content renamed into cache_get_value_name:
becomesCode:cache_get_field_content(0, "string", dest); new value = cache_get_field_content_int(0, "integer");
Simply search-and-replace it.Code:cache_get_value_name(0, "string", dest); new value = cache_get_value_name(0, "integer");
- all cache_get_ functions now return their value through a reference parameter instead of returning it directly:
becomesCode:new bool:value = cache_get_value_index_bool(0, 2); new row_count = cache_get_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.Code:new bool:value; cache_get_value_index_bool(0, 2, value); new row_count; cache_get_row_count(row_count);
RegEx (will correct all "cache_get_value_" natives which are in the style "variable = cache_get_value_*(*);":
Search:Replace:Code:(.+?) ?= ?(cache_get_value_.+?\(.*?)\);
Code:\2, \1\);
- "cache_set_active(Cache:0);" doesn't unset the active cache anymore:
becomesCode:cache_set_active(Cache:0);
Easy, huh?Code:cache_unset_active();
- cache_get_data removed (use `cache_get_*_count`):
becomesCode:new rows, fields; cache_get_data(rows, fields);
Code:new rows, fields; cache_get_row_count(rows); cache_get_field_count(fields);
- parameter "clearvars" in orm_delete removed:
becomesCode:orm_delete(orm_id);
Code:orm_delete(orm_id); orm_clear_vars(orm_id);
- all y_inline support code has been outsourced, see samp-mysql-yinline-include.


