SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 14/06/2014, 05:57 PM   #1
jessejanssen
Huge Clucker
 
Join Date: Apr 2008
Posts: 222
Reputation: 698
Default [MySQL] From StickenKid's plugin to BlueG's plugin

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
__________________
R.I.P. all people who passed away on the MH17
jessejanssen is offline   Reply With Quote
Old 14/06/2014, 06:16 PM   #2
Patrick
Guest
 
Posts: n/a
Default Re: [MySQL] From StickenKid's plugin to BlueG's plugin

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 http://wiki.sa-mp.com/wiki/MySQL/R33 and this http://forum.sa-mp.com/showthread.php?t=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 With Quote
Old 15/06/2014, 01:20 AM   #3
jessejanssen
Huge Clucker
 
Join Date: Apr 2008
Posts: 222
Reputation: 698
Default Re: [MySQL] From StickenKid's plugin to BlueG's plugin

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 http://wiki.sa-mp.com/wiki/MySQL/R33 and this http://forum.sa-mp.com/showthread.php?t=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
__________________
R.I.P. all people who passed away on the MH17
jessejanssen 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
BlueG MYSQL plugin SlonCHL Scripting Help 2 29/11/2013 06:02 AM
[Ajuda] MySQL Plugin do BlueG AiaN Português/Portuguese 12 20/04/2013 04:16 AM
help with blueg's mysql plugin(r7) thefatshizms Scripting Help 3 04/07/2012 02:27 PM
[HELP]BlueG's MySQL Plugin R7 [DOG]irinel1996 Scripting Help 0 09/04/2012 07:55 PM
Need help with BlueG's mysql plugin DeathTone Server Support 2 11/03/2012 03:02 AM


All times are GMT. The time now is 10:11 AM.


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