Raised This Month: $ Target: $400
 0% 

SQLx Select Handle Help plz


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Deviance
Veteran Member
Join Date: Nov 2004
Location: Sweden
Old 04-12-2007 , 00:07   Re: SQLx Select Handle Help plz
Reply With Quote #2

Quote:
Originally Posted by hlstriker View Post
-I will have to select the current steam ids in the table to see if that player already has a row. If they don't have a row, make one then just save the data. If they do have a row, get the current knifeKills, gunKills, and totalKills and put them in variables. Once they are in variables then it will add the 2 variables together and re-save the data.
Code:
new pre_query[150]

public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
	// lots of error checking
	if(FailState == TQUERY_CONNECT_FAILED)
        	return set_fail_state("Could not connect to SQL database.")
	else if(FailState == TQUERY_QUERY_FAILED)
        	return set_fail_state("Query failed.")
   
	if(Errcode)
        	return log_amx("Error on query: %s",Error)
   
	return PLUGIN_CONTINUE
}

public SelectHandle(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 set_fail_state("Query failed.")
   
	if(Errcode)
        	return log_amx("Error on query: %s",Error)
		
	new id = Data[0]
   
	if(SQL_NumResults(Query) > 0)
    	{
        	new temp_k = SQL_ReadResult(Query, 1)
        	new temp_g = SQL_ReadResult(Query, 2)        
        	new temp_t = SQL_ReadResult(Query, 3)
        
        	knifeKills[id] += temp_k
        	gunKills[id] += temp_g   
        	totalKills[id] += temp_t
		
		format(pre_query, 149, "UPDATE table SET knifeKills='%d', gunKills='%d', totalKills='%d' WHERE steamIds='%s'", knifeKills[id], gunKills[id], totalKills[id], steamid)
		SQL_ThreadQuery(g_SqlTuple, "QueryHandle", pre_query)
	}
	else
	{
        	format(pre_query, 149, "INSERT INTO table VALUES('%s','%d','%d','%d')", steamid, knifeKills[id], gunKills[id], totalKills[id])
        	SQL_ThreadQuery(g_SqlTuple, "QueryHandle", pre_query)
    	}  
	
	return PLUGIN_CONTINUE
}

public func(id)
{
	new steamid[38], data[1]
	get_user_authid(id, steamid, 37)
    
	format(pre_query, 149, "SELECT * FROM table WHERE steamIds='%s'", steamid)
	
	data[0] = id
	SQL_ThreadQuery(g_SqlTuple, "SelectHandle", pre_query, data, 1)
}

Last edited by Deviance; 07-27-2007 at 18:25.
Deviance is offline
 



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 06:36.


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