Raised This Month: $ Target: $400
 0% 

Coding Problems


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Willmaker
Senior Member
Join Date: Dec 2004
Location: Sydney, Australia
Old 12-17-2005 , 07:51   Coding Problems
Reply With Quote #1

Im getting the following error when using this plugin.

Code:
L 12/17/2005 - 23:46:53: [MYSQL] Invalid result handle 0
L 12/17/2005 - 23:46:53: [AMXX] Displaying debug trace (plugin "logplaytime.amxx")
L 12/17/2005 - 23:46:53: [AMXX] Run time error 10: native error (native "dbi_num_rows")
L 12/17/2005 - 23:46:53: [AMXX]    [0] logplaytime.sma::client_authorized (line 112)
Would anyone be able to tell me how to fix this, or better yet, fix it for me?
Attached Files
File Type: sma Get Plugin or Get Source (logplaytime.sma - 620 views - 6.8 KB)
Willmaker is offline
Send a message via ICQ to Willmaker Send a message via AIM to Willmaker Send a message via MSN to Willmaker Send a message via Yahoo to Willmaker
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 12-17-2005 , 09:02  
Reply With Quote #2

http://forums.alliedmods.net/showthread.php?t=2632

Let us know if you have further questions.
Brad is offline
Willmaker
Senior Member
Join Date: Dec 2004
Location: Sydney, Australia
Old 12-17-2005 , 09:18  
Reply With Quote #3

I have seen that page already, thanks anyway. Unfortunately, I dont know enough to be able to use that info.
Willmaker is offline
Send a message via ICQ to Willmaker Send a message via AIM to Willmaker Send a message via MSN to Willmaker Send a message via Yahoo to Willmaker
Charr
Senior Member
Join Date: Jul 2005
Location: Long Island, New York, U
Old 12-17-2005 , 12:05  
Reply With Quote #4

The plugin your using in incompatible with the version oof amxx your using.
Charr is offline
Send a message via AIM to Charr Send a message via MSN to Charr
twistedeuphoria
Veteran Member
Join Date: Jul 2004
Old 12-17-2005 , 14:17  
Reply With Quote #5

Before you do dbi_numrows or any operation on a result, check if it was successful and if there was actaully data in it by doing:
Code:
if(result >= RESULT_OK) //There is data  if(result == RESULT_NONE) //Successful query but no data  if(result <= RESULT_FAILED) //Query failed
__________________
twistedeuphoria is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 12-17-2005 , 15:22  
Reply With Quote #6

Quote:
Originally Posted by Charr
The plugin your using in incompatible with the version oof amxx your using.
Ignore this as it's wrong.
Brad is offline
Willmaker
Senior Member
Join Date: Dec 2004
Location: Sydney, Australia
Old 12-18-2005 , 02:37  
Reply With Quote #7

Does anyone know how to properly rewrite the DBI stuff in this plugin, more specifically:

Code:
result = dbi_query(dbc,"SELECT * FROM mytime WHERE steamid = '%s'",authid) if (dbi_num_rows(result) < 1) { //not in db, set to 0
Willmaker is offline
Send a message via ICQ to Willmaker Send a message via AIM to Willmaker Send a message via MSN to Willmaker Send a message via Yahoo to Willmaker
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 12-18-2005 , 10:00  
Reply With Quote #8

Immediately after you get your result you need to check if it was successful, like Twisty said. Specifically, the following indicates the query failed:
Code:
if(result <= RESULT_FAILED) //Query failed
If the query failed, dbi_num_rows is sure to fail, as it appears to be doing.

Here's a good defensive-programming rule of thumb:

Everytime you interact with the database, be it a query, an update, or any thing else... ALWAYS check your return value for failure. Do this each and every time if for no other reason than your connection could be suddenly lost since the last time you interacted with the database.
Brad is offline
Willmaker
Senior Member
Join Date: Dec 2004
Location: Sydney, Australia
Old 12-18-2005 , 10:16  
Reply With Quote #9

Ok, Ive now got:

Code:
 public client_authorized(id){     new authid[32]     get_user_authid(id,authid,31)     if (is_user_hltv(id) ) {  //Do not do anything         return PLUGIN_CONTINUE     }     result = dbi_query(dbc,"SELECT * FROM mytime WHERE steamid = '%s'",authid)     if(result >= RESULT_OK) //There is data     if(result == RESULT_NONE) //Successful query but no data     if(result <= RESULT_FAILED) //Query failed     if (dbi_num_rows(result) < 1) { //not in db, set to 0         connecttime[id] = 0     }else{ //get totaltime from database         dbi_nextrow(result)         connecttime[id] = dbi_result(result,"connecttime")     }     return PLUGIN_CONTINUE }

Since I am a complete newbie, I dont know if I did it correctly or not.

I started up a listenserver, and got no errors. Then I changed levels, and got:

Code:
L 12/19/2005 - 02:12:04: [MYSQL] Invalid result handle 0 L 12/19/2005 - 02:12:04: [AMXX] Displaying debug trace (plugin "logplaytimesql.amxx") L 12/19/2005 - 02:12:04: [AMXX] Run time error 10: native error (native "dbi_num_rows") L 12/19/2005 - 02:12:04: [AMXX]    [0] logplaytimesql.sma::client_disconnect (line 137) L 12/19/2005 - 02:12:05: -------- Mapchange to wired ------- L 12/19/2005 - 02:12:06: [MYSQL] Invalid database handle 0 L 12/19/2005 - 02:12:06: [AMXX] Displaying debug trace (plugin "logplaytimesql.amxx") L 12/19/2005 - 02:12:06: [AMXX] Run time error 10: native error (native "dbi_query") L 12/19/2005 - 02:12:06: [AMXX]    [0] logplaytimesql.sma::client_authorized (line 111)

So what does this mean?
Willmaker is offline
Send a message via ICQ to Willmaker Send a message via AIM to Willmaker Send a message via MSN to Willmaker Send a message via Yahoo to Willmaker
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 12-18-2005 , 10:33  
Reply With Quote #10

If you check for a condition, then you should do something. You don't check a condition and then move on your merry way without doing anything.

Code:
public client_authorized(id){     new authid[32]     get_user_authid(id,authid,31)     if (is_user_hltv(id) ) {  //Do not do anything         return PLUGIN_CONTINUE     }     result = dbi_query(dbc,"SELECT * FROM mytime WHERE steamid = '%s'",authid)     if(result <= RESULT_FAILED)     {         // Query failed, place abort or retry or whatever the hell kind of code you want in here.         // My recommendation is that you either log or display (or both) the error message.     }     if (dbi_num_rows(result) < 1) { //not in db, set to 0         connecttime[id] = 0     }else{ //get totaltime from database         dbi_nextrow(result)         connecttime[id] = dbi_result(result,"connecttime")     }     return PLUGIN_CONTINUE }
There may very well be other things wrong with your code here (and I suspect there is), I didn't really get past the trio of useless if statements.
Brad is offline
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 15:52.


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