SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 31/08/2016, 02:46 PM   #1
maddinat0r
Gangsta
 
maddinat0r's Avatar
 
Join Date: Jun 2010
Location: Germany
Posts: 895
Reputation: 482
Default Updating BlueG's MySQL plugin R33+ scripts to R40

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.

Last edited by maddinat0r; 25/06/2017 at 11:24 AM.
maddinat0r is offline   Reply With Quote
Old 31/08/2016, 02:51 PM   #2
Shinja
Gangsta
 
Shinja's Avatar
 
Join Date: Jan 2016
Posts: 974
Reputation: 100
Default Re: Updating BlueG's MySQL plugin R33+ scripts to R40

Can't wait for it, don't forget to implement example-script login/register as always, it's really useful
Shinja is offline   Reply With Quote
Old 31/08/2016, 02:58 PM   #3
maddinat0r
Gangsta
 
maddinat0r's Avatar
 
Join Date: Jun 2010
Location: Germany
Posts: 895
Reputation: 482
Default Re: Updating BlueG's MySQL plugin R33+ scripts to R40

Already done (thanks to Konstantinos)!
maddinat0r is offline   Reply With Quote
Old 01/09/2016, 01:10 AM   #4
TommyB
Beta Tester
 
TommyB's Avatar
 
Join Date: Sep 2010
Location: Texas, USA.
Posts: 181
Reputation: 149
Default Re: Updating BlueG's MySQL plugin R33+ scripts to R40

Thanks!
__________________
TommyB is offline   Reply With Quote
Old 01/09/2016, 09:22 AM   #5
HydraHumza
Gangsta
 
HydraHumza's Avatar
 
Join Date: Oct 2014
Posts: 640
Reputation: 130
Default Re: Updating BlueG's MySQL plugin R33+ scripts to R40

Awesome. Can't wait to check it
__________________
Quote:
Originally Posted by Kalcor View Post
The fact is, I am right. And if you think I'm wrong, you are wrong.
HydraHumza is offline   Reply With Quote
Old 01/09/2016, 11:53 AM   #6
PrO.GameR
Gangsta
 
PrO.GameR's Avatar
 
Join Date: Oct 2012
Posts: 731
Reputation: 121
Default Re: Updating BlueG's MySQL plugin R33+ scripts to R40

Awesome, now I can instantly update to R40 when it comes out.
Btw is there any specific reason behind those change names?
__________________
Blueberry Prison Roleplay will be back soon!
Follow the forums for more information about opening day.

Forums
PrO.GameR is offline   Reply With Quote
Old 01/09/2016, 12:20 PM   #7
maddinat0r
Gangsta
 
maddinat0r's Avatar
 
Join Date: Jun 2010
Location: Germany
Posts: 895
Reputation: 482
Default Re: Updating BlueG's MySQL plugin R33+ scripts to R40

Quote:
Originally Posted by PrO.GameR View Post
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.
  1. Those two natives do basically the same (retrieve values from the active cache), yet they have completely unrelated names.
  2. When you first use cache_get_row, you might think it retrieves a whole row out of the result set, but it doesn't.
  3. 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
maddinat0r is offline   Reply With Quote
Old 05/09/2016, 11:30 AM   #8
nGen.SoNNy
High-roller
 
nGen.SoNNy's Avatar
 
Join Date: Sep 2009
Location: Romania
Posts: 1,000
Reputation: 65
Default Re: Updating BlueG's MySQL plugin R33+ scripts to R40

Nice tutorial!
__________________
If i've helped you, please click
nGen.SoNNy is offline   Reply With Quote
Old 05/09/2016, 11:33 AM   #9
markparker12
Huge Clucker
 
markparker12's Avatar
 
Join Date: Sep 2015
Posts: 152
Reputation: 25
Default Re: Updating BlueG's MySQL plugin R33+ scripts to R40

A really helpful tutorial.

Thanks for this.
__________________
Free/Paid Game Server Hosting/Web Hosting/SA-Mp HostedTab
Hiring mature, active loyal and skilled players!



My Works
markparker12 is offline   Reply With Quote
Old 05/09/2016, 05:43 PM   #10
MerryDeer
Banned
 
Join Date: Jun 2016
Posts: 726
Reputation: 8
Default Re: Updating BlueG's MySQL plugin R33+ scripts to R40

RegEx don't work in pawno!!
MerryDeer is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating BlueG's mysql causes deleted functions to return problems Partner Scripting Help 0 01/11/2014 10:31 PM
[MySQL] From StickenKid's plugin to BlueG's plugin jessejanssen Scripting Help 2 15/06/2014 02:20 AM
Trouble updating with BlueG's mysql R7 2KY Scripting Help 3 25/12/2013 04:46 AM
BlueG MySQL plugin - Failed (plugins/mysql.so: undefined symbol: _Z13stringvprintfPKcPc) linuxthefish Plugin Development 10 13/07/2013 11:56 AM


All times are GMT. The time now is 03:48 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.