egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

mysqltcl scripting questions: how to catch an exception?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
tami
Voice


Joined: 05 Feb 2002
Posts: 13

PostPosted: Thu Dec 01, 2005 12:05 am    Post subject: mysqltcl scripting questions: how to catch an exception? Reply with quote

hi,

i succesfully migrated an old script using tcl-sql to mysqltcl (and this post was extremely helpful in that migration.

now i'm wishing to go to the next step.

i want to catch exceptions.

say i want to delete something from the database. however, that deleted item does not exist to begin with. how would i handle that?

i'd want the eggdrop to catch this error and display the output to a channel.

Code:
mysqlexec $mysql(conn) "delete from world where country = \"$country\"


if $country is not in the world table, then the database will process the information as such:
Query OK, 0 rows deleted.

how can i actually validate this output?

this basically leads me to trying to get the script to just find out what happens to the database afterwards. i know that in tcl-sql, i used something along these lines:

Code:

set verifydelete [ catch {
    sql exec $conn "delete from world where country = \"$country\"
} msg]
if { $verifydelete != 0 } {
    putserv "PRIVMSG $chan :ERROR when deleting country!"
}
else
{
    # all is good here, no need to have an else statement
}



this doesn't work with mysqltcl. this is also a problem when inserting duplicate entries into the database; i wish to display the output that there's a duplicate entry:

Code:

set verifyinsert [ catch {
    sql exec $conn "insert into world set country = \"$country\"
} msg]
if { $verifyinsert != 0 } {
    putserv "PRIVMSG $chan :ERROR $msg when inserting country!"
}
else
{
    # all is good here, no need to have an else statement
}


what other options are available to debug properly? i guess what i'm essentially asking for is return codes and such and also how to catch those error messages, if it wasn't clearer in my post. Smile

thanks!
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Dec 28, 2005 4:50 am    Post subject: Reply with quote

[mysqlexec] returns the number of affected rows
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber