AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help sql_threadquery (https://forums.alliedmods.net/showthread.php?t=107126)

moimel 10-23-2009 05:03

Help sql_threadquery
 
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.

Sylwester 10-23-2009 07:12

Re: Help sql_threadquery
 
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


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

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