[MySQL] From StickenKid's plugin to BlueG's plugin
#1

Hello,

Quick question, could someone please help me by giving tips on how to convert StrickenKid's SQL plugin to BlueG's, what I currently need to know is how to do;
pawn Code:
mysql_fetch_field("CharacterName", string);
In BlueG's plugin?
This code would retrieve the data stored in row 'CharacterName' and store it in a string, it would look for that row in the table you requested data from in a previously-executed query, like this one;
pawn Code:
mysql_query("SELECT * FROM `characters` WHERE `Activated` = 0 AND `Deletable` = 0 AND `DenialReason` = 'DenialReason' LIMIT 1");
I hope someone can help me because I thought converting SQL to another person's plugin wouldn't be so much of a struggle but I was wrong!

Best regards,
Jesse
Reply
#2

Well converting from StrickenKid's will be different because r39 threaded and they aren't similar to the old one which I am referring to r6, I suggest you to read this https://sampwiki.blast.hk/wiki/MySQL/R33 and this https://sampforum.blast.hk/showthread.php?tid=337810 those link will help you a lot! so this is the code.

pawn Code:
new
    rCheck[MAX_PLAYERS]; // declare a per-player array/var.

//Under OnPlayerConnect
++ rCheck[playerid];

//Under OnPlayerDisconnect
++ rCheck[playerid];


//Sends a query which will be executed in another thread and calls the callback (if there is one) when the execution is finished.
mysql_tquery(connectionHandle, "SELECT * FROM `characters` WHERE `Activated` = 0 AND `Deletable` = 0 AND `DenialReason` = 'DenialReason' LIMIT 1", "OnCharactersLoad", "ii", playerid, rCheck[playerid]);

forward OnCharactersLoad(playerid, race_check);
public OnCharactersLoad(playerid, race_check)
{
    new
        rows = cache_num_rows();

    if(rCheck[playerid] != race_check) //if the race_check
        return Kick(playerid), printf("Invalid Race Check: rCheck[playerid]: %i - race_check:%i", rCheck[playerid], race_check);

    if(rows) //if rows is more than one, we proceed loading player's status.
    {
        cache_get_field_content(0, "CharacterName", destination, connectionHandle = 1, sizeof(destination));
        //and so on loading
    }
    return true;
}
Why does race_check needed?

Quote:
Originally Posted by maddinat0r
race condition check:
player A connects -> SELECT query is fired -> this query takes very long
while the query is still processing, player A with playerid 2 disconnects
player B joins now with playerid 2 -> our laggy SELECT query is finally finished, but for the wrong player

what do we do against it?
we create a connection count for each playerid and increase it everytime the playerid connects or disconnects
we also pass the current value of the connection count to our OnPlayerDataLoaded callback
then we check if current connection count is the same as connection count we passed to the callback
if yes, everything is okay, if not, we just kick the player
Reply
#3

Quote:
Originally Posted by Patrick_
View Post
Well converting from StrickenKid's will be different because r39 threaded and they aren't similar to the old one which I am referring to r6, I suggest you to read this https://sampwiki.blast.hk/wiki/MySQL/R33 and this https://sampforum.blast.hk/showthread.php?tid=337810 those link will help you a lot! so this is the code.

pawn Code:
new
    rCheck[MAX_PLAYERS]; // declare a per-player array/var.

//Under OnPlayerConnect
++ rCheck[playerid];

//Under OnPlayerDisconnect
++ rCheck[playerid];


//Sends a query which will be executed in another thread and calls the callback (if there is one) when the execution is finished.
mysql_tquery(connectionHandle, "SELECT * FROM `characters` WHERE `Activated` = 0 AND `Deletable` = 0 AND `DenialReason` = 'DenialReason' LIMIT 1", "OnCharactersLoad", "ii", playerid, rCheck[playerid]);

forward OnCharactersLoad(playerid, race_check);
public OnCharactersLoad(playerid, race_check)
{
    new
        rows = cache_num_rows();

    if(rCheck[playerid] != race_check) //if the race_check
        return Kick(playerid), printf("Invalid Race Check: rCheck[playerid]: %i - race_check:%i", rCheck[playerid], race_check);

    if(rows) //if rows is more than one, we proceed loading player's status.
    {
        cache_get_field_content(0, "CharacterName", destination, connectionHandle = 1, sizeof(destination));
        //and so on loading
    }
    return true;
}
Why does race_check needed?
Thanks for the explanation, I started converting my (At that moment bugging SQL script) and then I found a backup from a few days ago which I thought I accidentily deleted, so now I'm not going to convert my script anymore because BlueG's might be better (Threaded, faster) but I am used to StrickenKid's and I don't really feel like having to convert a script from ~7K lines... I'll rep you as I do actually understand BlueG's plugin now!

Best regards,
Jesse
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)