Raised This Month: $ Target: $400
 0% 

help mysql in amxx prob


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
moimel
Junior Member
Join Date: Mar 2009
Old 10-20-2009 , 16:15   help mysql in amxx prob
Reply With Quote #1

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?

Last edited by Exolent[jNr]; 10-20-2009 at 16:21. Reason: Use [CODE], [PHP], or [PAWN] tags next time.
moimel is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-20-2009 , 16:21   Re: help mysql in amxx prob
Reply With Quote #2

Use threaded queries.
http://forums.alliedmods.net/showthr...highlight=sqlx
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-20-2009 , 16:49   Re: help mysql in amxx prob
Reply With Quote #3

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.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Reply



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

Forum Jump


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


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