Threaded Queries
#1

Hello all,

i know about threaded queries, but i have some questions:

-for example a login process:

How I have to write the Script and OnQueryFinish that it prevent from server lagging?

this way:

Код:
#define MYSQL_CHECK_PLAYER (1)

stock mysql_CheckAccount(playerid)
{
    new Name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
    mysql_real_escape_string(Name, Name);
    format(query, sizeof(query), "SELECT * FROM "MYSQL_ACC_TBL" WHERE Name = '%s' ORDER BY `id` DESC LIMIT 1", Name);
    mysql_query(query,MYSQL_CHECK_PLAYER,playerid);
    mysql_store_result();
    return mysql_num_rows();
}

public OnPlayerConnect(playerid)
{
         if(mysql_CheckAccount(playerid) == 1)
		{
			gPlayerAccount[playerid] = 1;
			return 1;
		}
		else
		{
			gPlayerAccount[playerid] = 0;
			return 1;
	  	}
return 1;
}

public OnQueryFinish(query[], resultid, extraid, connectionHandle)
{
	switch(resultid)
	{
		case MYSQL_CHECK_PLAYER:
		{
			return 1;
		}
	}
	return 1;
}
or maybe this way:

Код:
#define MYSQL_CHECK_PLAYER (1)

stock mysql_CheckAccount(playerid)
{
    new Name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
    mysql_real_escape_string(Name, Name);
    format(query, sizeof(query), "SELECT * FROM "MYSQL_ACC_TBL" WHERE Name = '%s' ORDER BY `id` DESC LIMIT 1", Name);
    mysql_query(query,MYSQL_CHECK_PLAYER,playerid);

}

public OnPlayerConnect(playerid)
{
      mysql_CheckAccount(playerid);
      return 1;
}

public OnQueryFinish(query[], resultid, extraid, connectionHandle)
{
	switch(resultid)
	{
		case MYSQL_CHECK_PLAYER:
		{
			    mysql_store_result();
                            if(mysql_num_rows() ==1) gPlayerAccount[extraid] = 1;
                            else gPlayerAccount[extraid] = 0;
		}
	}
	return 1;
}
i hope you can help me understand this better/corriger my code

MfG. Cody09

//Iґm going to learn english ^^
Reply


Messages In This Thread
Threaded Queries - by C0dy09 - 07.05.2012, 16:23
Re: Threaded Queries - by JaTochNietDan - 07.05.2012, 21:57
Re: Threaded Queries - by Scenario - 07.05.2012, 22:09
AW: Threaded Queries - by C0dy09 - 08.05.2012, 13:41

Forum Jump:


Users browsing this thread: 1 Guest(s)