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:
Code:new g_SQL; public OnGameModeInit() { g_SQL = mysql_connect(/* credentials */); }
Code:new MySQL:g_SQL; public OnGameModeInit() { g_SQL = mysql_connect(/* credentials */); }
- redundant prefixes from log level enum removed:
Code:mysql_log(LOG_ERROR | LOG_DEBUG);
Code:mysql_log(ERROR | DEBUG);
- 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));
Code:mysql_get_charset(destination, sizeof(destination), g_SQL);
RegEx:
Search: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:
Code:mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
Code:mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
- 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);
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);
the options you need and pass it to mysql_connect. - mysql_option renamed into mysql_global_options:
Code:mysql_option(DUPLICATE_CONNECTIONS, true);
Code:mysql_global_options(DUPLICATE_CONNECTIONS, true);
- log type parameter in mysql_log removed:
Code:mysql_log(ALL, LOG_TYPE_HTML);
Code:mysql_log(ALL);
- mysql_reconnect removed:
Code:mysql_reconnect(g_SQL);
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:
Code:cache_get_row(0, 0, g_SQL);
Code:cache_get_row(0, 0);
RegEx:
Search: (replace "g_SQL" in the regular expression below with your used global MySQL variable)
Code:(cache_.+?\(.+?), ?g_SQL\);
Code:\1\);
- cache_get_row renamed into cache_get_value_index:
Code:cache_get_row(0, 0, dest); new value = cache_get_row_int(0, 1);
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:
Code:cache_get_field_content(0, "string", dest); new value = cache_get_field_content_int(0, "integer");
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:
Code:new bool:value = cache_get_value_index_bool(0, 2); new row_count = cache_get_row_count();
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:Code:(.+?) ?= ?(cache_get_value_.+?\(.*?)\);
Code:\2, \1\);
- "cache_set_active(Cache:0);" doesn't unset the active cache anymore:
Code:cache_set_active(Cache:0);
Code:cache_unset_active();
- cache_get_data removed (use `cache_get_*_count`):
Code: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:
Code: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.