MYSQL upgrade from R5 to r39(Help pls with fixing errors.)
#1

pawn Код:
error 017: undefined symbol "mysql_store_result"
error 017: undefined symbol "mysql_num_rows"
error 017: undefined symbol "mysql_free_result"
CODE:
pawn Код:
new Query[200], escpname[24];
    mysql_real_escape_string(sendername, escpname);
    format(Query, sizeof(Query), "SELECT * FROM `players` WHERE `Name` = '%s'", escpname);
    mysql_query_ex(Query);
    mysql_store_result();[B]//undefined symbol "mysql_store_result"[/B]
pawn Код:
forward AdminAccountExists(Name[]);
public AdminAccountExists(Name[])
{
    new Query[200], escpname[24];
    mysql_real_escape_string(Name, escpname);
    format(Query, sizeof(Query), "SELECT * FROM `admins` WHERE `Admin` = '%s'", escpname);
    mysql_query_ex(Query);
    mysql_store_result();
    if(mysql_num_rows() != 0) [B]//undefined symbol "mysql_num_rows"[/B]
    {
        mysql_free_result();
        return true;
    }
    else
    {
        mysql_free_result();[B]//undefined symbol "mysql_free_result"[/B]
        return false;
    }
}
Thank you for your help..

With best regards Scrillex.
Reply
#2

these functions had been changed too new functions
all of these funcs have mysql_ az start just change them too cache_ it will work
Reply
#3

Not that simple as you think.. I read the tutorial about mysql r6 to r7 but I didn't get thouse things.. How they are changing..
Reply
#4

example how you can do !

pawn Код:
new Query[200], escpname[24];
    mysql_format(mysql, query, sizeof(query),"SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", escpname);
    mysql_tquery(mysql, query, "AdminAccountExists", "s", escpname);

forward AdminAccountExists(Name[]);
public AdminAccountExists(Name[])
{
    new rows,fields;
    cache_get_data(rows, fields, mysql);
    if(rows)//rows if a row exists with name you have enterd
    {

    }
    else
    {
        //if account does not exists

    }
}
Reply
#5

hi
i'll convert your code to MySQL R39. i hope you learn.
MySQL +R33 have threaded Queries.

Check MySQL +R33 Wiki for Functions and Examples: https://sampwiki.blast.hk/wiki/MySQL/R33

* "MySQLh" is your mysql connection handle.
* %e in "mysql_format" will automaticly escape your string.


pawn Код:
stock AdminAccountExists(Name[])
{
    new Query[128];
    mysql_format(MySQLh, Query, sizeof(Query), "SELECT * FROM `admins` WHERE `Admin` = '%e'", Name);
    return mysql_tquery(MySQLh, Query, "OnAdminAccountExistCheck", "s", Name);
}

forward OnAdminAccountExistCheck(Name[]);
public OnAdminAccountExistCheck(Name[])
{
    new rows, fields;
    cache_get_data(rows, fields, MySQLh);
    if(rows)
    {
        return true;
    }
    else
    {
        return false;
    }
}
Reply
#6

Sorry @M4D, this will always return 1.
@OP:
Let's think for a second of threaded queries handling like dialog handling. Only change is that you specify your own callback, and not use the OnDialogResponse and determine what to run depending on dialogid.

Using y_inline can simplyfy callbacks a lot, but this function can't be directly ported. Let's say you want to fetch usernames of all admins in database.

Standard way:
pawn Код:
enum E_USER_TYPE {
    E_USER,
    E_ADMIN
}

ShowAdminUsernames(playerid)
{
    new
        query[64]
    ;

    mysql_format(dbhandle, query, sizeof query, "SELECT username FROM users WHERE type = %d", _:E_ADMIN);
    mysql_tquery(dbhandle, query, "ShowUsernames", "d", playerid);
    SendClientMessage(playerid, 0xBADA55AA, "Loading database admins");

    return 1;
}

forward ShowUsernames(playerid);
public ShowUsernames(playerid)
{
    new
        results = cache_get_row_count(),
        tmp[MAX_PLAYER_NAME + 1]
    ;
    if (!results) {
        return SendClientMessage(playerid, 0xBADA55AA, "No admins in database");
    }

    for (new idx = 0; idx != results; ++idx) {
        cache_get_field_content(idx, "username", tmp, dbhandle);
        SendClientMessage(playerid, 0xBADA55AA, tmp);
    }

    return 1;
}
Simple as that. With y_inline you can keep your logic together

pawn Код:
enum E_USER_TYPE {
    E_USER,
    E_ADMIN
}

ShowAdminUsernames(playerid)
{
    new
        query[64]
    ;
    mysql_format(dbhandle, query, sizeof query, "SELECT username FROM users WHERE type = %d", _:E_ADMIN);

    inline ShowUsernames()
    {
        new
            results = cache_get_row_count(),
            tmp[MAX_PLAYER_NAME + 1]
        ;
        //As you can see playerid is available here, scope doesn't change!
        if (!results) {
            return SendClientMessage(playerid, 0xBADA55AA, "No admins in database");
        }

        for (new idx = 0; idx != results; ++idx) {
            cache_get_field_content(idx, "username", tmp, dbhandle);
            SendClientMessage(playerid, 0xBADA55AA, tmp);
        }
    }

    mysql_tquery_inline(dbhandle, query, using inline ShowUsernames, "");
    SendClientMessage(playerid, 0xBADA55AA, "Loading database admins");

    return 1;
}
Even easier! y_dialogs supports y_inline as well so you don't have to jump between your code and OnDialogResponse callback.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)