AlliedModders

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

Des12 03-26-2006 20:32

dbi_query error
 
Here is the part of my code that is having problems:

Code:
new Sql:dbc new Result:result // ... public client_putinserver(id) {     set_task(1.0,"checkSteam",id)     return PLUGIN_HANDLED } public checkSteam(id) {     new query[256],sqlid[46], authid[32]     get_user_authid(id, authid, 31)     format(query,255,"SELECT steamid, reason, time FROM tempbans")     result = dbi_query(dbc,query) //**PROBLEM HERE**     while(dbi_nextrow(result) > 0)     {         dbi_result(result, "steamid" , sqlid , 45)         if(equali(authid,sqlid)) {             new reason[101], var;             dbi_result(result, "reason" , reason , 100)             var = dbi_result(result, "time")             new name[32]             get_user_name(id,name,31)             client_print(0,print_chat,"[AMXX] %s (%s) is still banned for %i minutes",name,authid,var)             server_cmd("kick #%d ^"%s (%i minutes left in ban)^"",get_user_userid(id),reason,var)             return PLUGIN_HANDLED         }             }     dbi_free_result(result)         return PLUGIN_HANDLED }

Code:

L 03/26/2006 - 20:20:18: [AMXX] Displaying debug trace (plugin "tempban.amxx")
L 03/26/2006 - 20:20:18: [AMXX] Run time error 10: native error (native "dbi_query")
L 03/26/2006 - 20:20:18: [AMXX]    [0] tempban.sma::checkSteam (line 218)
L 03/26/2006 - 20:20:18: [MYSQL] Invalid database handle 0

It suddenly stopped working today. Is this because there is only one row and it needs two or more to function?

slurpycof 03-26-2006 23:31

Code:
format(query,255,"SELECT steamid, reason, time FROM tempbans")

should be

Code:
format(query,255,"SELECT steamid, reason, time FROM tempbans WHERE steamid = '%s'",authid)

That would make it run cleaner. I would also suggest you use

public client_authorized(id){

to do the check so that you know the player has a steam id.

++edit++
Try this code
Code:
new Sql:dbc new Result:result // ... public client_authorized(id) {     new authid[32]     get_user_authid(id, authid, 31)     result = dbi_query(dbc,"SELECT steamid, reason, time FROM tempbans WHERE steamid = '%s'",authid)     if (dbi_num_rows(result) < 1) //not in db     {         return PLUGIN_CONTINUE     }     else     { //get the info from the database         dbi_nextrow(result)         new reason[101], var;         dbi_result(result, "reason" , reason , 100)         var = dbi_result(result, "time")         new name[32]         get_user_name(id,name,31)         client_print(0,print_chat,"[AMXX] %s (%s) is still banned for %i minutes",name,authid,var)         server_cmd("kick #%d ^"%s (%i minutes left in ban)^"",get_user_userid(id),reason,var)         return PLUGIN_CONTINUE     }             dbi_free_result(result)         return PLUGIN_CONTINUE }

v3x 03-26-2006 23:34

Damnit, you got to it before me ><,

Des12 03-28-2006 22:40

Wait, if you return plugin continue, does it break out of the loop? Because dbi_free_result might memory leak if it is not called before that function ends...

v3x 03-29-2006 00:04

So add dbi_free_result right before that return.

Des12 03-30-2006 23:15

I did, plugin still does not work.

Freecode 03-30-2006 23:28

Funny how nobody read the error
Code:

L 03/26/2006 - 20:20:18: [MYSQL] Invalid database handle 0
where is your connect code? do something like
if (!dbc)
return

mysticssjgoku4 03-31-2006 11:04

Also, don't use:
Code:
if (dbi_num_rows(result) < 1)

use

Code:
if (result <= RESULT_NONE)

and don't use

Code:
result = dbi_query(dbc,query)

use

Code:
result = dbi_query(dbc,"%s",query)

and make sure you're connecting ot the right database and with the right users with correct permissions....

Des12 04-01-2006 16:09

Quote:

Originally Posted by mysticssjgoku4
and don't use

Code:
result = dbi_query(dbc,query)

use

Code:
result = dbi_query(dbc,"%s",query)

What is the difference?

mysticssjgoku4 04-01-2006 17:59

Quote:

Originally Posted by Des12
Quote:

Originally Posted by mysticssjgoku4
and don't use

Code:
result = dbi_query(dbc,query)

use

Code:
result = dbi_query(dbc,"%s",query)

What is the difference?

One is wrong,
One is right.


All times are GMT -4. The time now is 16:30.

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