View Single Post
Old 01/12/2019, 12:47 PM   #2
Join Date: May 2018
Posts: 1,117
Reputation: 175
Default Re: I need help with updating mysql from R5 to R41-4

Please stop removing the thread and re-posting it. I wrote an explanation and when I tried to preview it, it was gone. I had to re-write it for a second time. I tried to preview it again just now and the thread was removed again. If I did not copy it in clipboard, I would not write it for a third time..

All functions can be found here:

The connection handle returned by `mysql_connect` is necessary for other mysql functions:
pawn Code:
// global:
new MySQL: connectionHandle;

// in `OnGameModeInit`:
connectionHandle = mysql_connect(...);
You execute a threaded query and it requires a callback (public function) to fetch data from it.
pawn Code:
mysql_tquery(connectionHandle, "SELECT ... FROM ... ORDER BY ...", "OnSomethingLoad");
You can call cache functions in the specified callback:
pawn Code:
forward OnSomethingLoad();
public OnSomethingLoad()
        The equivalent function of `mysql_store_result` is `cache_save` but it is not needed unless you want to save the result for future usage (it is kept in memory).
        Function `mysql_fetch_row_format` moves to the next row.
        `cache_get_value*` functions have a `rowid` parameter (the first parameter).
        NOTE: row and columns indexes start from 0.
        When there are multiple rows, we use an iteration variable.

    for (new i = 0, rows = cache_num_rows(); i < rows; i++)
            sscanf splitting is not possible as the result is not returned in one line.
            a column index or column name has to be used instead in the `cache_get_value*`functions (the second parameter).

        // you know the datatypes from the specifiers in sscanf line: "p<|>dd..."
        // "d" specifier is for integer, so you retrieve index 0 and index 1 as integers:
        cache_get_value_int(i, 0, BLA);
        cache_get_value_int(i, 1, BLA);

        // sscanf line: "p<|>ddffffff..."
        // "f" specifier is for integer, so you retrieve index 2, 3, 4, 5, 6 and 7 as floats:
        cache_get_value_float(i, 2, BLA);
        cache_get_value_float(i, 7, BLA);

        // sscanf line: "p<|>ddffffffs[128]s[50]..."
        // "s[size]" specifier is for strings, so you retrieve index 8 and index 9 as strings:
        // it accepts a last parameter for the length. It is required for enum-arrays and the default compiler.
        cache_get_value(i, 8, BLA, 128);
        cache_get_value(i, 9, BLA, 50);

        // the rest 7 columns are integers. From index 10 to 16.
        cache_get_value_int(i, 10, BLA);
        cache_get_value_int(i, 16, BLA);
Calisthenics is offline   Reply With Quote