sql question
#1

hey all, please do anyone know how to check if player's account exist on the table 'accounts' on the database (MySQL R39-6) please

for example:-
Code:
new rows, fields;
cache_get_data(rows, fields, DB);
if(rows) // it exist
{
   // some code 
}
Reply
#2

Using threaded queries, you can do something such as this:
pawn Code:
mysql_format(gSQLConnection, local_query, sizeof local_query, "SELECT NULL FROM accounts WHERE Name = '%e'", local_playername);
mysql_tquery(gSLQConnection, local_query, "OnAccountCheck", "i", playerid);
pawn Code:
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
      if(cache_num_rows() == 0)
      {
               // account doesn't exist, do something
      }

      else
      {
               // account does exist, do something else
      }

      return 1;
}
There's no need for anything else to get the amount of rows, you can just use the native num rows function. You can also pass more data through the specifer param in tquery (also add them to the callback definitions).
Reply
#3

Quote:
Originally Posted by Abagail
View Post
Using threaded queries, you can do something such as this:
pawn Code:
mysql_format(gSQLConnection, local_query, sizeof local_query, "SELECT NULL FROM accounts WHERE Name = '%e'", local_playername);
mysql_tquery(gSLQConnection, local_query, "OnAccountCheck", "i", playerid);
pawn Code:
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
      if(cache_num_rows() == 0)
      {
               // account doesn't exist, do something
      }

      else
      {
               // account does exist, do something else
      }

      return 1;
}
There's no need for anything else to get the amount of rows, you can just use the native num rows function. You can also pass more data through the specifer param in tquery (also add them to the callback definitions).
Thanks dude
+repped
Reply
#4

Hey all, sorry for bumbing the thread again but i have proplem creating an Function to check if player's account exists on the Database
i tried this method...
Code:
new pExists_action[MAX_PLAYER_NAME + 1];
new bool:pExists[MAX_PLAYER_NAME + 1];
SQL_Exists(name[], table[] = 'accounts', field[] = 'Name')
{
    switch(pExists_action[name])
	{
	    case 0: { 
		     new Query[200]; mysql_format(SQL_DB, Query, sizeof(Query), "SELECT NULL FROM %s WHERE %s = '%e'", table, field, name);
             mysql_tquery(SQL_DB, Query, "AccountExistsCheck", "s", name);
	    }
	    case 1: { 
		     if(pExists[name])
			 {
			    return 1;
			 }
			 else 
			 {
			    return 0;
			 }
	    }
    }		
}

forward AccountExistsCheck(name[]);
public AccountExistsCheck(name[])
{
    if(cache_num_rows() == 0)
    {
	   pExists = false;
	}
	else 
	{
	   pExists = true;
	}
	pExists_action[name] = 1;
	return 1;
}
but i can't complete it iam out of ideas i tried to call the function 2 times with switch statement.... but failed so please i need some help
Reply
#5

Bumb.... please some help iam stuck with this proplem please
Reply
#6

You cannot create these kinds of wrappers with threaded queries. These kind of wrappers rely on an immediate, synchronous response. The entire point of using threaded (asynchronous) queries, however, is to NOT block the main thread while waiting for a response. The exact opposite. When you send a threaded query you basically tell the system: execute this query in your own time and call me back when you're done and meanwhile I will continue doing other things.
Reply
#7

Quote:
Originally Posted by Vince
View Post
You cannot create these kinds of wrappers with threaded queries. These kind of wrappers rely on an immediate, synchronous response. The entire point of using threaded (asynchronous) queries, however, is to NOT block the main thread while waiting for a response. The exact opposite. When you send a threaded query you basically tell the system: execute this query in your own time and call me back when you're done and meanwhile I will continue doing other things.
Didn't understand 100% but iam trying to create an function to check if the player's account exists on the database easily and i won't create callback for every snippet or it will be useless but if i tried to follow your words may i use something like
Code:
SQL_Exists(name[], table[] = 'accounts', field[] = 'Name')
{
   new Query[200]; mysql_format(SQL_DB, Query, sizeof(Query), "SELECT NULL FROM %s WHERE %s = '%e'", 
   table, field, name);
   mysql_tquery(SQL_DB, Query, "", "");
   if(cache_num_rows() > 0)
   {
      return true;
   }
   else 
   {
      return false;
   }
}
if iam wrong please correct my example code
Reply
#8

Removed.

Edit:

Actually why would you select NULL in your query? Perhaps replace it with a few column names or an asterix (*)? If you query NULL, you'll get what you ask for -> Nothing.
Reply
#9

Quote:
Originally Posted by Rosie
View Post
Removed.

Edit:

Actually why would you select NULL in your query? Perhaps replace it with a few column names or an asterix (*)? If you query NULL, you'll get what you ask for -> Nothing.
its just an example but thank you for the tip

Edit:
Code:
SQL_Exists(name[], table[] = 'accounts', field[] = 'Name')
{
   new Query[200]; mysql_format(SQL_DB, Query, sizeof(Query), "SELECT * FROM %s WHERE %s = '%e' LIMIT 1", table, field, name);
   mysql_tquery(SQL_DB, Query, "", "");
   if(cache_num_rows() > 0)
   {
      return true;
   }
   else 
   {
      return false;
   }
   return 1;
}
this one always return this error on every used place
Code:
 warning 209: function "SQL_Exists" should return a value
please some help ??
Reply
#10

Quote:
Originally Posted by Zorono
View Post
iam trying to create an function to check if the player's account exists on the database easily and i won't create callback for every snippet
Yes, obviously. But like I said you cannot use tquery for that because tquery does not provide an immediate response. If you want things like this you need to use the "normal" query method. The normal query method provides an immediate response but it blocks the main server thread while it's executing.

If the main server thread is blocked then nothing is being done: no callbacks, no functions, no sync. So if that query takes more than 40 or so milliseconds to execute then you will already start to notice the effects. This effect gets progressively worse with the number of queries, the number of players and the size of the database.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)