| View previous topic :: View next topic |
| Author |
Message |
tami Voice
Joined: 05 Feb 2002 Posts: 13
|
Posted: Thu Dec 01, 2005 12:05 am Post subject: mysqltcl scripting questions: how to catch an exception? |
|
|
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.
thanks! |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Dec 28, 2005 4:50 am Post subject: |
|
|
[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 |
|
 |
|
|
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
|
|