[Tutorial] Updating BlueG's MySQL plugin R33+ scripts to R40
#1

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.

  1. 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.
  2. 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
  3. 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:
    Code:
    \1\(\2\3, g_SQL\);
  4. 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.
  5. 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.
  6. 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.
  7. log type parameter in mysql_log removed:
    Code:
    mysql_log(ALL, LOG_TYPE_HTML);
    becomes
    Code:
    mysql_log(ALL);
  8. 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.
  9. mysql_current_handle removed:
    Yep. Just removed. No replacement.

  10. 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:
    Code:
    \1\);
  11. 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.
  12. 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.
  13. 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:
    Code:
    \2, \1\);
  14. "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?
  15. 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);
  16. parameter "clearvars" in orm_delete removed:
    Code:
    orm_delete(orm_id);
    becomes
    Code:
    orm_delete(orm_id);
    orm_clear_vars(orm_id);
  17. all y_inline support code has been outsourced, see samp-mysql-yinline-include.
Reply


Messages In This Thread
Updating BlueG's MySQL plugin R33+ scripts to R40 - by maddinat0r - 31.08.2016, 13:46
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Shinja - 31.08.2016, 13:51
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by maddinat0r - 31.08.2016, 13:58
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by TommyB - 01.09.2016, 00:10
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by HydraHumza - 01.09.2016, 08:22
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by PrO.GameR - 01.09.2016, 10:53
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by maddinat0r - 01.09.2016, 11:20
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by nGen.SoNNy - 05.09.2016, 10:30
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by markparker12 - 05.09.2016, 10:33
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by MerryDeer - 05.09.2016, 16:43
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by vannesenn - 05.09.2016, 18:16
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by IstuntmanI - 05.09.2016, 18:20
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by vannesenn - 05.09.2016, 18:24
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by vannesenn - 05.09.2016, 19:29
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by nGen.SoNNy - 05.09.2016, 21:52
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Slawiii - 05.09.2016, 21:59
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Spmn - 05.09.2016, 22:03
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by maddinat0r - 06.09.2016, 07:37
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by DandyCorleone - 06.09.2016, 13:47
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Max_Andolini - 09.09.2016, 11:57
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Spmn - 09.09.2016, 14:05
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Slawiii - 16.09.2016, 18:46
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Kathleen - 21.09.2016, 14:04
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by saffierr - 09.12.2016, 14:51
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Konstantinos - 09.12.2016, 16:12
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by AroseKhanNiazi - 10.12.2016, 23:34
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by PapaSmerf - 19.12.2016, 08:55
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Konstantinos - 19.12.2016, 11:12
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by PapaSmerf - 19.12.2016, 11:29
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Konstantinos - 19.12.2016, 13:00
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Tenka - 20.12.2016, 08:57
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by PapaSmerf - 20.12.2016, 11:41
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Eloy - 22.12.2016, 17:34
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Konstantinos - 22.12.2016, 18:18
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Lordzy - 04.01.2017, 12:15
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Loinal - 07.01.2017, 17:43
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by t9ndep - 21.01.2017, 15:39
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by X337 - 21.01.2017, 15:44
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by t9ndep - 22.01.2017, 15:03
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Cypress - 27.01.2017, 12:52
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Lordzy - 27.01.2017, 13:02
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by maddinat0r - 28.01.2017, 13:46
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by Kruno88 - 08.10.2017, 12:06
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by StRaffael - 19.10.2018, 17:14
Re: Updating BlueG's MySQL plugin R33+ scripts to R40 - by KinderClans - 23.10.2018, 19:28

Forum Jump:


Users browsing this thread: 1 Guest(s)