Converting a query (to RC7)
#8

Quote:
Originally Posted by AndreT
Посмотреть сообщение
This OnPlayerDataLoad thingy is the callback that will be fired. You specify the callback in your mysql_function_query call. This string is the callback that will be called once the query is finished.

This is in OnPlayerConnect:
pawn Код:
format(query, sizeof(query), "SELECT ... FROM bans WHERE BanName = '%s' LIMIT 0,1", name);
mysql_function_query(1, query, "OnBanCheckFinish", "i", playerid);
You run the ban check query.

This is OnBanCheckFinish, the callback called when the ban checking query finishes.
pawn Код:
forward OnBanCheckFinish(playerid);
public OnBanCheckFinish(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows == 1)
    {
        // player is banned!?
    }
    else
    {
        // player is not banned, so call the data loading query
        new name[24];
        GetPlayerName(playerid, name, sizeof(name));
        format(query, sizeof(query), "SELECT ... FROM accounts WHERE Name = '%s' LIMIT 0,1", name);
        mysql_function_query(1, query, true, "OnPlayerDataLoad", "i", playerid);
    }
}
Now, in case the player is not banned, we will select the player's data from the accounts table. As you can see from the code above, OnPlayerDataLoad(playerid) is the callback that will be fired when our accounts query finishes.

Now the OnPlayerDataLoad query, same as I described before:
pawn Код:
forward OnUserDataLoad(playerid);
public OnUserDataLoad(playerid)
{
    // Get the amount of rows and fields in each row returned by this query.
    new rows, fields;
    cache_get_data(rows, fields);
    // We should only have ONE row, this is why I added the LIMIT 0,1 clause to your query.
    if(rows)
    {
        // We have a row!
        new name[24];
        cache_get_row(0, 0, name);
    }
    else
    {
        // This player most likely does not exist :(
    }
    // Return 1 to make sure that the plugin clears the cache.
    return 1;
}
Now a major thing which I think you still did not understand:
QUERIES LIKE "SELECT name FROM players WHERE name = 'ANDRE'" ARE VERY USELESS - YOU ALREADY KNOW THE NAME. SO SELECT OTHER DATA.
Select queries aren't only used to retrieve data, people also use them for checking if the user exists and other things. If you select *, that would return the whole row which would be worse than just selecting one column.
Reply


Messages In This Thread
Converting a query (to RC7) - by Tee - 04.06.2012, 23:42
Re: Converting a query (to RC7) - by AndreT - 04.06.2012, 23:56
Re: Converting a query (to RC7) - by Tee - 05.06.2012, 00:08
Re: Converting a query (to RC7) - by AndreT - 05.06.2012, 00:28
Re: Converting a query (to RC7) - by Tee - 05.06.2012, 00:44
Re: Converting a query (to RC7) - by Tee - 05.06.2012, 00:48
Re: Converting a query (to RC7) - by Calgon - 05.06.2012, 01:08
Re: Converting a query (to RC7) - by SuperViper - 05.06.2012, 01:10
Re: Converting a query (to RC7) - by Tee - 05.06.2012, 01:12
Re: Converting a query (to RC7) - by AndreT - 05.06.2012, 09:59

Forum Jump:


Users browsing this thread: 1 Guest(s)