AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   help mysql in amxx prob (https://forums.alliedmods.net/showthread.php?t=106935)

moimel 10-20-2009 16:15

help mysql in amxx prob
 
Hey im using amx to communicate with mysql server to do some checkings.

how ever it causes some stacks and lags , it's a while that loops all players in the server and query the sql for each player . this loop might cause this stacks. i wonder if there is any function that can delay or sleep the code for 100ms or somthing like this to depress the lags.

code:

Code:

  g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
 
  new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
  if(SqlConnection == Empty_Handle)
  {
  return PLUGIN_HANDLED;
  }
 
  new Handle:Query = SQL_PrepareQuery(SqlConnection,"SELECT * FROM blah WHERE blah ='%s' LIMIT 1", blah)
 
  if(!SQL_Execute(Query))
  {
  SQL_QueryError(Query,g_Error,511)
  return PLUGIN_HANDLED;
  }
 
  new numRows = SQL_AffectedRows ( Query );
 
  if (numRows == 1)
  {
  new currentValue;
 
  while(SQL_MoreResults(Query))
  {
    currentValue = SQL_ReadResult(Query, 7);
    SQL_NextRow(Query);
  }
 
  currentValue+=1;
 
  new Handle:Query_Update = SQL_PrepareQuery(SqlConnection,"UPDATE blah SET blah='%d' WHERE blah='%s'", blah , blah );
  SQL_Execute(Query_Update);
  SQL_FreeHandle(Query_Update);
  }
 
  SQL_FreeHandle(Query)

* dont mind the blah's (:


any suggestions to solve the lags?

Exolent[jNr] 10-20-2009 16:21

Re: help mysql in amxx prob
 
Use threaded queries.
http://forums.alliedmods.net/showthr...highlight=sqlx

Hawk552 10-20-2009 16:49

Re: help mysql in amxx prob
 
Also, you want to use SQL_NumResults() when checking the results of a SELECT query. SQL_AffectedRows() only refers to operations that actually change records, such as UPDATE, INSERT, etc.

EDIT: Actually, the whole thing could be rewritten into a single query, if you're interested.


All times are GMT -4. The time now is 17:38.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.