Raised This Month: $ Target: $400
 0% 

Help sql_threadquery


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
moimel
Junior Member
Join Date: Mar 2009
Old 10-23-2009 , 05:03   Help sql_threadquery
Reply With Quote #1

I have somthing like this:

PHP Code:
public getValue_Frags(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
 if(
FailState == TQUERY_CONNECT_FAILED)
  return 
set_fail_state("Could not connect to SQL database.")
 else if(
FailState == TQUERY_QUERY_FAILED)
  return 
log_amx("Query failed.")
 
 if(
Errcode)
  return 
log_amx("Query failed.",Error)
 
 new 
Steam[64], msg[1024];
 
get_user_authid(currIncreaseID_FragsSteam63);
 new 
numRows SQL_AffectedRows Query );
 
 if (
numRows == 1)
 {
  new 
currentValue;
  
  while(
SQL_MoreResults(Query))
  { 
   
currentValue SQL_ReadResult(QuerycurrIncreaseRowIndex_Frags);
   
SQL_NextRow(Query);
  }
  
  
currentValue+=currIncreaseValue_Frags;
  
format(msg1023"UPDATE %s SET %s='%d' WHERE steam='%s'"currIncreaseTableName_FragscurrIncreaseRowName_FragscurrentValueSteam);
  
SQL_ThreadQuery(g_SqlTuple,"QueryHandle",msg);
 }
 
 return 
PLUGIN_CONTINUE;
}
public 
Frags idrowvaltbl[64], rowname[64] )
{
 new 
Steam[64];
 
get_user_authid(idSteam63);
 new 
msg[1024];
 
currIncreaseID_Frags id;
 
currIncreaseRowIndex_Frags row;
 
currIncreaseValue_Frags val;
 
format (currIncreaseTableName_Frags63"%s"tbl);
 
format (currIncreaseRowName_Frags63"%s"rowname);
 
 
format(msg1023"SELECT * FROM fs_stats WHERE steam='%s' LIMIT 1"Steam)
 
SQL_ThreadQuery(g_SqlTuple,"getValue_Frags",msg)

Frags() is being called when client_death event is occuring. because I cannot pass arguments directly to the getValue_Frags function through SQL_ThreadQuery() I am using global variables like currIncreaseID_Frags, currIncreaseRowIndex_Frags ... which I don't really like this method but lack of other ideas I am using it. anyway when the Frags() function is called many times (i. e someone is killing three players simultaneously)
than the global vars are being mixed , the first kill vars are overwriten by the second and the first kill getValue_Frags() is getting the second kill vars and so on!!!

any idea to solve it? I tried everything in my knowledge.
moimel is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 10-23-2009 , 07:12   Re: Help sql_threadquery
Reply With Quote #2

You can pass arguments directly to getValue_frags like this:
PHP Code:
public func(id)
{
    
//code ...

    
new cache[1024], data[2];
    
data[0] = id
    data
[1] = frags
    format
(cache1023"SELECT ...")
    
SQL_ThreadQuery(g_SqlTuple"query_handler"cachedata2)
}

public 
query_handler(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    new 
id Data[0]
    new 
frags Data[1]
    
    
//code ...

all arguments are explained here: http://www.amxmodx.org/funcwiki.php?go=func&id=1100
__________________
Impossible is Nothing

Last edited by Sylwester; 10-23-2009 at 07:15.
Sylwester is offline
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:36.


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