Raised This Month: $ Target: $400
 0% 

SQLx to global variable problem


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Bad_Bud
Senior Member
Join Date: Oct 2006
Location: The internet
Old 01-07-2007 , 01:09   SQLx to global variable problem
Reply With Quote #1

I have a problem with calling SQL queries and storing data in global variables. I have a test function that is called when a client types in a command in his console. I wanted to be able to store this player's data in a global array for his specific player id in the array. (Array[id])

The problem comes in when I call the SQL_Threadquery, which in turn uses a query handler with set parameters. I have no idea I'm supposed to pass a player's id into the handler function, or if it is even possible, so I decided to use a global variable to store the retrieved information to carry back into the function that called the Threadquery in the first place, which has an instance of the player's playerid.

I noticed that no data was returning when I printed it to the screen for the player to see, so I did a test, and printed out the result in two different places: one local, one global. The local print is the correct data, but the global print fails miserably.

Here are the functions...

PHP Code:
public SQL_CallQuery(Query[],Type)
{
 
copy(SQL_CurrentQuery,511,Query)
 
 
SQL_CurrentType=Type
 
 SQL_ThreadQuery
(SQL_Tuple,"SQL_QueryHandle",Query)

PHP Code:
public SQLTEST(id)
{
 new 
Query[256]
 
 
format(Query,255,"SELECT JobID FROM playerdata WHERE SteamID='%s'",UserSteamID[id])
 
 
SQL_ResultInt=1337
 
 SQL_CallQuery
(Query,1)
 
 
client_print(id,print_chat,"Global JobID: %d",SQL_ResultInt)
 
 return 
PLUGIN_HANDLED

PHP Code:
public SQL_QueryHandle(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 
Number=250
   
   
while(SQL_MoreResults(Query))
   {
    
Number=SQL_ReadResult(Query,0)
    
    
client_print(0,print_chat,"Local JobID: %d",Number)
    
    
SQL_NextRow(Query)
   }
   
   
SQL_ResultInt=Number
 
 
return PLUGIN_CONTINUE

Ignore the strange complexity of the functions calling functions and blah blah, I was trying stuff to try and get this to work.

Note: Global JobID print is 500, local is 1.

1 is the correct JobID.
Bad_Bud 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 22:26.


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