AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   One thing with SQLx (https://forums.alliedmods.net/showthread.php?t=49495)

Rixorster 01-05-2007 14:33

One thing with SQLx
 
So i'm trying out SQLx at the moment, so i used Hawk552's example of that 'Core' thingy (His last example on the topic).
So, i got an function like this:
Code:
public hrp_is_job(id,authid) {     SQL_ThreadQuery(sql_get_handle(),"QueryHandle","SELECT job FROM users WHERE steamid='%s'",authid) } public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {     //Thanks Hawk552 <3     if(FailState == TQUERY_CONNECT_FAILED)         return set_fail_state("[HRPi]SQL Connection Failed.")     else if(FailState == TQUERY_QUERY_FAILED)         return set_fail_state("[HRPi]Query failed.")         if(Errcode)         return log_amx("[HRPi]Error on query: %s",Error)         server_print("[HRPi] SQL Connection Successfull!")     return Handle:Query }
And, i'm calling that function with this:
Code:
    if(!hrp_is_job(id,authid) >= 2 && !hrp_is_job(id,authid) <= 11)     {         client_print(id,print_chat,"You must be an Police for the Tazer to work!")         return PLUGIN_HANDLED     }
SQL_ThreadQuery gives an error of the authid thing, but isn't that how it's supposed to be so it would work?

Also, I think i should have an 'return (something)' in 'public hrp_is_job' to return the value of the job, but what should i return?

Any help would be nice :/

teame06 01-05-2007 14:38

Re: One thing with SQLx
 
Your usage of SQL_ThreadQuery is wrong. You can't format string in SQL_ThreadQuery. You have to do it before.

Code:
SQL_ThreadQuery ( Handle:cn_tuple, const handler[], const query[], const data[]=0 )

Code:
static query[256]; format(query, 255, "SELECT job FROM users WHERE steamid='%s'", authid); SQL_ThreadQuery(sql_get_handle(),"QueryHandle", query)

Rixorster 01-05-2007 14:44

Re: One thing with SQLx
 
Quote:

Originally Posted by teame06 (Post 423970)
Your usage of SQL_ThreadQuery is wrong. You can't format string in SQL_ThreadQuery. You have to do it before.

Code:
SQL_ThreadQuery ( Handle:cn_tuple, const handler[], const query[], const data[]=0 )

Code:
static query[256]; format(query, 255, "SELECT job FROM users WHERE steamid='%s'", authid); SQL_ThreadQuery(sql_get_handle(),"QueryHandle", query)

Thanks :)
Though still, the 'if(!hrp_is_job(id,authid) >= 2 && !hrp_is_job(id,authid) <= 11)' doesn't work, but how should i be doing it then?

teame06 01-05-2007 15:53

Re: One thing with SQLx
 
SQL_ThreadQuery works in asynchronous. So you should be storing the players job into an array or something.

Also your not retrieving the data from the column.

Code:
if(SQL_NumResults(Query)) {     StoreSomeWhere = SQL_ReadResult(Query, 0); }

I don't know what plugin this is for but it look like it a TS plugin. You need to recode this plugin around to work in Asynchronous if you are going to SQL_ThreadQuery.

Rixorster 01-05-2007 16:31

Re: One thing with SQLx
 
Hmm...
Code:
public hrp_is_job_higher(id,authid[],jobid[]) {     static query[256];     format(query, 255, "SELECT job>%s FROM users WHERE steamid='%s'",jobid,authid);     SQL_ThreadQuery(sql_get_handle(),"QueryHandle", query) } public hrp_is_job_smaller(id,authid[],jobid[]) {     static query[256];     format(query, 255, "SELECT job<%s FROM users WHERE steamid='%s'",jobid,authid);     SQL_ThreadQuery(sql_get_handle(),"QueryHandle", query) } public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {     //Thanks Hawk552 <3     if(FailState == TQUERY_CONNECT_FAILED)         return set_fail_state("[HRPi]SQL Connection Failed.")     else if(FailState == TQUERY_QUERY_FAILED)         return set_fail_state("[HRPi]Query failed.")         if(Errcode)         return log_amx("[HRPi]Error on query: %s",Error)         server_print("[HRPi] SQL Query Executed Successfully!")     if(SQL_NumResults(Query)) {         StoreSomeWhere = SQL_ReadResult(Query, 0);     }     return Handle:Query }
And this gives an error:
Code:
if(!hrp_is_job_higher(id,pid,2) && !hrp_is_job_smaller(id,<,pid,11))
Argument type mismatch (argument 3) on line 129
So i guess that means something wrong with the (id,pid,2) ?

lunarwolfx 01-05-2007 17:46

Re: One thing with SQLx
 
Code:
public hrp_is_job_higher(id,authid[],jobid[]) {     new data[2]; format(data,1,"%d",id); static query[256];     format(query, 255, "SELECT job>%s FROM users WHERE steamid='%s'",jobid,authid);     SQL_ThreadQuery(sql_get_handle(),"QueryHandle", query,data,1) } public hrp_is_job_smaller(id,authid[],jobid[]) { new data[2]; format(data,1,"%d",id);     static query[256]; format(query, 255, "SELECT job<%s FROM users WHERE steamid='%s'",jobid,authid);   SQL_ThreadQuery(sql_get_handle(),"QueryHandle", query,data,1) } public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {     //Thanks Hawk552 <3     if(FailState == TQUERY_CONNECT_FAILED)          return set_fail_state("[HRPi]SQL Connection Failed.")     else if(FailState == TQUERY_QUERY_FAILED)          return set_fail_state("[HRPi]Query failed.")         if(Errcode)          return log_amx("[HRPi]Error on query: %s",Error)         server_print("[HRPi] SQL Query Executed Successfully!")      if(SQL_NumResults(Query)) {         new id = str_to_num(data)        StoreSomeWhere[id] = SQL_ReadResult(Query, 0);     }      return Handle:Query }

Sorry for the lack of indenting.

Try to pass your id through data, and make StoreSomeWhere an array.


change this:

Code:
if(!hrp_is_job_higher(id,pid,2) && !hrp_is_job_smaller(id,<,pid,11))

to this:


Code:
if(!StoreSomeWhere[id] > 2 && !StooreSomeWhere[id] <11))

Rixorster 01-05-2007 20:12

Re: One thing with SQLx
 
Fixed it already on my own, thanks anyways :)


All times are GMT -4. The time now is 22:27.

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