AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Coding Problems (https://forums.alliedmods.net/showthread.php?t=22037)

Willmaker 12-17-2005 07:51

Coding Problems
 
1 Attachment(s)
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?

Brad 12-17-2005 09:02

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

Let us know if you have further questions.

Willmaker 12-17-2005 09:18

I have seen that page already, thanks anyway. Unfortunately, I dont know enough to be able to use that info. :(

Charr 12-17-2005 12:05

The plugin your using in incompatible with the version oof amxx your using.

twistedeuphoria 12-17-2005 14:17

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

Brad 12-17-2005 15:22

Quote:

Originally Posted by Charr
The plugin your using in incompatible with the version oof amxx your using.

Ignore this as it's wrong.

Willmaker 12-18-2005 02:37

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

Brad 12-18-2005 10:00

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.

Willmaker 12-18-2005 10:16

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?

Brad 12-18-2005 10:33

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.


All times are GMT -4. The time now is 15:52.

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