Raised This Month: $ Target: $400
 0% 

dbi_query error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Des12
Senior Member
Join Date: Jan 2005
Old 03-26-2006 , 20:32   dbi_query error
Reply With Quote #1

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?
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
slurpycof
Senior Member
Join Date: Nov 2004
Old 03-26-2006 , 23:31  
Reply With Quote #2

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 }
slurpycof is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 03-26-2006 , 23:34  
Reply With Quote #3

Damnit, you got to it before me ><,
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
Des12
Senior Member
Join Date: Jan 2005
Old 03-28-2006 , 22:40  
Reply With Quote #4

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...
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 03-29-2006 , 00:04  
Reply With Quote #5

So add dbi_free_result right before that return.
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
Des12
Senior Member
Join Date: Jan 2005
Old 03-30-2006 , 23:15  
Reply With Quote #6

I did, plugin still does not work.
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 03-30-2006 , 23:28  
Reply With Quote #7

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
Freecode is offline
mysticssjgoku4
Veteran Member
Join Date: Jan 2005
Location: Chicago Heights, IL
Old 03-31-2006 , 11:04  
Reply With Quote #8

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....
__________________

mysticssjgoku4 is offline
Send a message via AIM to mysticssjgoku4 Send a message via MSN to mysticssjgoku4
Des12
Senior Member
Join Date: Jan 2005
Old 04-01-2006 , 16:09  
Reply With Quote #9

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?
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
mysticssjgoku4
Veteran Member
Join Date: Jan 2005
Location: Chicago Heights, IL
Old 04-01-2006 , 17:59  
Reply With Quote #10

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.
__________________

mysticssjgoku4 is offline
Send a message via AIM to mysticssjgoku4 Send a message via MSN to mysticssjgoku4
Reply



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 16:30.


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