This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

mysqltcl scripting questions: how to catch an exception?

Help for those learning Tcl or writing their own scripts.
Post Reply
t
tami
Voice
Posts: 13
Joined: Tue Feb 05, 2002 8:00 pm

mysqltcl scripting questions: how to catch an exception?

Post by tami »

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: Select all

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: Select all

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: Select all

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. :)

thanks!
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

[mysqlexec] returns the number of affected rows
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
Post Reply