[Tutorial] Using BlueG's MySQL plugin R7 (with cache)

Is there a logical way with threaded queries to perform multiple select queries in a single callback or block of code? I'm asking this because my login script has to get data from a bans, accounts and achievement table in that specific order. It seems awkward to have three callbacks within other callbacks, and I must make sure that it runs correctly...

Old code (StrickenKid's plugin):
Code:
stock LoginPlayer(playerid)
{
	new string[128], qry[128], res[1050], PlayerStats[72][50], AchievementStatus[22];
//------------------------------------------------------------------------------
	format(qry, sizeof(qry), "UPDATE accounts SET LastIP = '%s', LastVisit = SYSDATE(), LoggedIn = 1 WHERE name = '%s';", PlayerInfo[playerid][PlayerIP], pNick(playerid));
	mysql_query(qry);
//------------------------------------------------------------------------------	
	format(qry, sizeof(qry), "SELECT COUNT(*) FROM bans WHERE accountId = (SELECT accountId FROM accounts WHERE name = '%s') LIMIT 1;", pNick(playerid));
	mysql_query(qry);
	mysql_store_result();
	mysql_fetch_field_num(0, res);
	mysql_free_result();
	if(strval(res))
	{
		format(qry, sizeof(qry), "UPDATE accounts SET LoggedIn = 0 WHERE name = '%s';", pNick(playerid));
		mysql_query(qry);
		SendClientMessage(playerid, COLOUR_SYSTEM, "Nice try ban evading! If you think this ban is unfair, post an unban appeal at "SERVER_SITE"/forum!");
		format(string, sizeof(string), "[Server ban]: %s (%d) - account marked as banned", pNick(playerid), playerid);
		SendClientMessageToAll(COLOUR_ADMIN, string);
		printf(string);
		SendAdminActionToIRC(string);
		SaveLog("Logs", "AttempetdBanEvadings", string);
		format(string, sizeof(string), "%s (%d) - account marked as banned", pNick(playerid), playerid);
		ShowKickBanTextDrawForPlayer(playerid, "banned", "attempting to ban evade");
		return SetTimerEx("DelayedBan", 10, false, "ds", playerid, "attempting to ban evade");
	}
//------------------------------------------------------------------------------	
	format(qry, sizeof(qry), "SELECT * FROM accounts WHERE name = '%s';", pNick(playerid));
	mysql_query(qry);
	mysql_store_result();
	mysql_fetch_row(res, "|");
	explode(PlayerStats, res, "|");
	mysql_free_result();
//------------------------------------------------------------------------------
	PlayerInfo[playerid][LoggedIn] = 1;
 	PlayerInfo[playerid][Registered] = 1;
	PlayerInfo[playerid][accountId] = strval(PlayerStats[0]);
	PlayerInfo[playerid][Level] = strval(PlayerStats[6]);
	SetPlayerScore(playerid, strval(PlayerStats[7]));
 	PlayerInfo[playerid][BankBalance] = strval(PlayerStats[8]);
	SetPlayerMoneyEx(playerid, strval(PlayerStats[9]));
	SetPlayerWantedLevel(playerid, strval(PlayerStats[10]));
	SetPlayerDrunkLevel(playerid, strval(PlayerStats[11]));
	PlayerInfo[playerid][FightStyle] = strval(PlayerStats[12]);
	PlayerInfo[playerid][Skin] = strval(PlayerStats[13]);
  	PlayerInfo[playerid][Kills] = strval(PlayerStats[14]);
   	PlayerInfo[playerid][Deaths] = strval(PlayerStats[15]);
    PlayerInfo[playerid][Donator] = strval(PlayerStats[18]);
	PlayerInfo[playerid][MysterybagsFound] = strval(PlayerStats[19]);
    PlayerInfo[playerid][ReactionTestsWon] = strval(PlayerStats[20]);
    PlayerInfo[playerid][SaveSkin] = strval(PlayerStats[21]);
    PlayerInfo[playerid][AutoIPLogin] =  strval(PlayerStats[22]);
	PlayerInfo[playerid][HoursConnected] = strval(PlayerStats[23]);
    PlayerInfo[playerid][MinutesConnected] = strval(PlayerStats[24]);
    PlayerInfo[playerid][DaysConnected] = strval(PlayerStats[25]);
    PlayerInfo[playerid][RegularPlayer] = strval(PlayerStats[26]);
    PlayerInfo[playerid][NoPM] = strval(PlayerStats[27]);
    PlayerInfo[playerid][GotoEnabled] = strval(PlayerStats[28]);
    PlayerInfo[playerid][PreferedColour] = strval(PlayerStats[29]);
    PlayerInfo[playerid][WatchPMs] = strval(PlayerStats[30]);
    PlayerInfo[playerid][WatchCMDs] = strval(PlayerStats[31]);
    PlayerInfo[playerid][WatchPlayerInfo] = strval(PlayerStats[32]);
    PlayerInfo[playerid][FavouriteVehicle] = strval(PlayerStats[33]);
	PlayerInfo[playerid][Bomb] = strval(PlayerStats[34]);
	PlayerInfo[playerid][RejoinDM] = strval(PlayerStats[35]);
	PlayerInfo[playerid][Drugs] = strval(PlayerStats[36]);
	PlayerInfo[playerid][Seeds] = strval(PlayerStats[37]);
	PlayerInfo[playerid][DuelsDone] = strval(PlayerStats[38]);
	PlayerInfo[playerid][DuelsWon] = strval(PlayerStats[39]);
	PlayerInfo[playerid][CTX] = floatstr(PlayerStats[40]);
    PlayerInfo[playerid][CTY] = floatstr(PlayerStats[41]);
    PlayerInfo[playerid][CTZ] = floatstr(PlayerStats[42]);
    PlayerInfo[playerid][CTInterior] = strval(PlayerStats[43]);
    PlayerInfo[playerid][CTWorld] = strval(PlayerStats[44]);
    // mode similar code
//------------------------------------------------------------------------------
	format(qry, sizeof(qry), "SELECT * FROM achievements WHERE accountId = %d;", strval(PlayerStats[0]));
	mysql_query(qry);
	mysql_store_result();
	mysql_fetch_row(res, "|");
	explode(PlayerStats, res, "|");
	mysql_free_result();
//------------------------------------------------------------------------------
	PlayerInfo[playerid][NeedForSkills_Progress] = strval(PlayerStats[1]);
	PlayerInfo[playerid][Drifter_Progress] = strval(PlayerStats[2]);
	PlayerInfo[playerid][RaceAchievements_Progress] = strval(PlayerStats[3]);
	PlayerInfo[playerid][WTFLottoHax_Progress] = strval(PlayerStats[4]);
	PlayerInfo[playerid][SpankMe_Progress] = strval(PlayerStats[5]);
	PlayerInfo[playerid][Sn1p3r_Progress] = strval(PlayerStats[6]);
	PlayerInfo[playerid][Whore_Progress] = strval(PlayerStats[7]);
	PlayerInfo[playerid][Ninja_Progress] = strval(PlayerStats[8]);
//------------------------------------------------------------------------------
	format(string, sizeof(string), "Welcome back to "DC_RED""SERVER_NAME""DC_GREEN", %s!", pNick(playerid));
	SendClientMessage(playerid, COLOUR_GREEN, string);
//------------------------------------------------------------------------------
	// mode generic code
//------------------------------------------------------------------------------
	CheckForAchievements(playerid);
//------------------------------------------------------------------------------
	return 1;
}
I really don't know how to do this without turning everything into one giant mess..
Reply


Messages In This Thread
Using BlueG's MySQL plugin R7 and newer (with cache) - by AndreT - 27.04.2012, 22:55
Re: Using BlueG's MySQL plugin R7 (with cache) - by Ricop522 - 28.04.2012, 05:01
Re: Using BlueG's MySQL plugin R7 (with cache) - by Niko_boy - 28.04.2012, 05:04
Respuesta: Using BlueG's MySQL plugin R7 (with cache) - by [Vector] - 28.04.2012, 05:36
Re: Using BlueG's MySQL plugin R7 (with cache) - by Burridge - 28.04.2012, 08:31
Re: Respuesta: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 28.04.2012, 08:51
Re: Using BlueG's MySQL plugin R7 (with cache) - by Lorenc_ - 28.04.2012, 09:39
Respuesta: Using BlueG's MySQL plugin R7 (with cache) - by [Vector] - 30.04.2012, 19:20
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 30.04.2012, 20:03
Re: Using BlueG's MySQL plugin R7 (with cache) - by MP2 - 18.05.2012, 16:50
Re: Using BlueG's MySQL plugin R7 (with cache) - by kikito - 18.05.2012, 16:51
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 18.05.2012, 19:29
Re: Using BlueG's MySQL plugin R7 (with cache) - by MP2 - 18.05.2012, 19:44
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 18.05.2012, 19:51
Re: Using BlueG's MySQL plugin R7 (with cache) - by MP2 - 18.05.2012, 20:03
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 18.05.2012, 20:37
Re: Using BlueG's MySQL plugin R7 (with cache) - by MP2 - 18.05.2012, 21:42
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 19.05.2012, 08:18
Re: Using BlueG's MySQL plugin R7 (with cache) - by MP2 - 19.05.2012, 12:04
Re: Using BlueG's MySQL plugin R7 (with cache) - by Hiddos - 19.05.2012, 12:07
Re: Using BlueG's MySQL plugin R7 (with cache) - by Luis- - 20.05.2012, 00:29
Re : Using BlueG's MySQL plugin R7 (with cache) - by Vukilore - 21.05.2012, 16:28
Respuesta: Using BlueG's MySQL plugin R7 (with cache) - by Sauxe - 22.05.2012, 03:26
Re: Using BlueG's MySQL plugin R7 (with cache) - by TheArcher - 23.05.2012, 19:06
Re: Using BlueG's MySQL plugin R7 (with cache) - by AShop - 27.05.2012, 18:08
Re: Using BlueG's MySQL plugin R7 (with cache) - by Luis- - 27.05.2012, 18:19
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 27.05.2012, 19:16
Re: Using BlueG's MySQL plugin R7 (with cache) - by ArchBishop - 27.05.2012, 20:25
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 27.05.2012, 20:43
Re: Using BlueG's MySQL plugin R7 (with cache) - by ArchBishop - 28.05.2012, 20:21
AW: Re: Using BlueG's MySQL plugin R7 (with cache) - by Extremo - 11.06.2012, 07:01
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 11.06.2012, 10:08
Re: Using BlueG's MySQL plugin R7 (with cache) - by Kyle - 11.06.2012, 11:08
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 11.06.2012, 11:56
AW: Using BlueG's MySQL plugin R7 (with cache) - by Extremo - 11.06.2012, 12:18
Re: Using BlueG's MySQL plugin R7 (with cache) - by MP2 - 23.06.2012, 09:23
Re: Using BlueG's MySQL plugin R7 (with cache) - by Kyle - 23.06.2012, 10:13
Re: Using BlueG's MySQL plugin R7 (with cache) - by MP2 - 23.06.2012, 13:37
Re: Using BlueG's MySQL plugin R7 (with cache) - by Kyle - 23.06.2012, 13:40
AW: Using BlueG's MySQL plugin R7 (with cache) - by Cank - 23.06.2012, 14:02
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 23.06.2012, 14:34
Re: Using BlueG's MySQL plugin R7 (with cache) - by SWEMike - 30.06.2012, 12:37
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 30.06.2012, 20:21
Re: Using BlueG's MySQL plugin R7 (with cache) - by Splav - 02.07.2012, 13:10
Re: Using BlueG's MySQL plugin R7 (with cache) - by Coicatak - 10.07.2012, 12:08
Re : Using BlueG's MySQL plugin R7 (with cache) - by scott1 - 16.07.2012, 17:39
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 17.07.2012, 20:28
Re : Using BlueG's MySQL plugin R7 (with cache) - by scott1 - 18.07.2012, 11:34
Re: Using BlueG's MySQL plugin R7 (with cache) - by Gumica - 22.07.2012, 12:35
Re: Re : Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 27.07.2012, 10:19
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 29.09.2012, 22:53
Re: Using BlueG's MySQL plugin R7 (with cache) - by Richie© - 03.10.2012, 21:08
Re: Using BlueG's MySQL plugin R7 (with cache) - by ReneG - 04.10.2012, 05:00
Re: Using BlueG's MySQL plugin R7 (with cache) - by Richie© - 04.10.2012, 20:54
Re: Using BlueG's MySQL plugin R7 (with cache) - by ScriptWriter - 12.10.2012, 15:56
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 13.10.2012, 12:58
Re: Using BlueG's MySQL plugin R7 (with cache) - by ScriptWriter - 13.10.2012, 13:03
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 13.10.2012, 13:05
Re: Using BlueG's MySQL plugin R7 (with cache) - by ScriptWriter - 13.10.2012, 13:15
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 13.10.2012, 14:33
Re: Using BlueG's MySQL plugin R7 (with cache) - by ScriptWriter - 13.10.2012, 14:54
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 13.10.2012, 15:04
Re: Using BlueG's MySQL plugin R7 (with cache) - by ScriptWriter - 01.11.2012, 07:58
Re: Using BlueG's MySQL plugin R7 (with cache) - by Edvin - 01.11.2012, 08:01
Re: Using BlueG's MySQL plugin R7 (with cache) - by ScriptWriter - 01.11.2012, 08:20
Re: Using BlueG's MySQL plugin R7 (with cache) - by IstuntmanI - 01.11.2012, 12:52
Re: Using BlueG's MySQL plugin R7 (with cache) - by ScriptWriter - 01.11.2012, 14:06
Re: Using BlueG's MySQL plugin R7 (with cache) - by IstuntmanI - 01.11.2012, 14:13
Re: Using BlueG's MySQL plugin R7 (with cache) - by ScriptWriter - 01.11.2012, 15:00
Re: Using BlueG's MySQL plugin R7 (with cache) - by ReneG - 01.11.2012, 16:09
Re: Using BlueG's MySQL plugin R7 (with cache) - by ReneG - 11.11.2012, 19:25
Re: Using BlueG's MySQL plugin R7 (with cache) - by AirKite - 11.11.2012, 20:05
Re: Using BlueG's MySQL plugin R7 (with cache) - by fordawinzz - 23.11.2012, 12:33
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 23.11.2012, 13:50
Re: Using BlueG's MySQL plugin R7 (with cache) - by fordawinzz - 24.11.2012, 09:38
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 24.11.2012, 11:20
Re: Using BlueG's MySQL plugin R7 (with cache) - by EterNo - 26.11.2012, 12:54
Re: Using BlueG's MySQL plugin R7 (with cache) - by EterNo - 26.11.2012, 18:28
Re: Using BlueG's MySQL plugin R7 (with cache) - by CoDeZ - 26.11.2012, 21:30
Re: Using BlueG's MySQL plugin R7 (with cache) - by Marusa - 03.12.2012, 18:26
Re: Using BlueG's MySQL plugin R7 (with cache) - by DaLgakıran - 30.05.2013, 14:01
Re: Using BlueG's MySQL plugin R7 (with cache) - by AndreT - 09.06.2013, 10:28
Re: Using BlueG's MySQL plugin R7 (with cache) - by Yashas - 21.07.2013, 08:56
Re: Using BlueG's MySQL plugin R7 (with cache) - by Richie© - 21.07.2013, 09:07
Re: Using BlueG's MySQL plugin R7 (with cache) - by Yashas - 21.07.2013, 09:21
Re: Using BlueG's MySQL plugin R7 (with cache) - by Richie© - 21.07.2013, 10:52
Re: Using BlueG's MySQL plugin R7 (with cache) - by Misiur - 21.07.2013, 10:57
Re: Using BlueG's MySQL plugin R7 (with cache) - by IstuntmanI - 21.07.2013, 11:14
Re: Using BlueG's MySQL plugin R7 (with cache) - by Grumbles - 28.07.2013, 23:46
Re: Using BlueG's MySQL plugin R7 (with cache) - by Luis- - 29.07.2013, 03:28
Re: Using BlueG's MySQL plugin R7 (with cache) - by Grumbles - 29.07.2013, 15:22
Re: Using BlueG's MySQL plugin R7 (with cache) - by Yashas - 30.07.2013, 03:07
Re: Using BlueG's MySQL plugin R7 (with cache) - by Michalec - 29.10.2013, 14:43
Re: Using BlueG's MySQL plugin R7 (with cache) - by gotwarzone - 12.11.2013, 08:50
Re : Using BlueG's MySQL plugin R7 (with cache) - by ombre - 11.01.2014, 13:35
Re: Using BlueG's MySQL plugin R7 (with cache) - by anou1 - 13.01.2014, 16:52
Re: Using BlueG's MySQL plugin R7 (with cache) - by dusk - 14.01.2014, 13:25
Re: Using BlueG's MySQL plugin R7 (with cache) - by KevinPRINCE - 22.02.2014, 20:51
Re: Using BlueG's MySQL plugin R7 (with cache) - by Guest4390857394857 - 20.03.2014, 08:03
Re: Using BlueG's MySQL plugin R7 (with cache) - by AiRaLoKa - 16.05.2014, 13:03
Re: Using BlueG's MySQL plugin R7 (with cache) - by ~Yoshi - 05.09.2015, 00:50
Re: Using BlueG's MySQL plugin R7 (with cache) - by AmigaBlizzard - 27.01.2016, 23:27
Re: Using BlueG's MySQL plugin R7 (with cache) - by maddinat0r - 29.01.2016, 13:07
Re: Using BlueG's MySQL plugin R7 (with cache) - by AmigaBlizzard - 07.02.2016, 12:05
Re: Using BlueG's MySQL plugin R7 (with cache) - by maddinat0r - 07.02.2016, 14:38
Re: Using BlueG's MySQL plugin R7 (with cache) - by AmigaBlizzard - 10.02.2016, 20:42
Re: Using BlueG's MySQL plugin R7 (with cache) - by Slawiii - 11.05.2016, 18:26
Re: Using BlueG's MySQL plugin R7 (with cache) - by thesuperuser - 13.05.2016, 12:36
Re: Using BlueG's MySQL plugin R7 (with cache) - by iSpy - 13.05.2016, 12:38

Forum Jump:


Users browsing this thread: 6 Guest(s)