Forum OpenACS Q&A: why does db_transaction { ... } on_error { ... } not catch db_1rows...?

I have a db_transaction that does a bunch of inserts and one select.  Any error in the inserts is caught in the on_error block.  But if the db_1row fails to return a row, that error is not caught.

Is this the bug it sounds like, or am I failing to understand something?

I would think that db_transaction ... on_error {} should catch ANY error whether it is a db, contraint violation, or an application level divide by zero.

That's wrong?

it is a bug, but I'm not sure it's in the oacs code.  are you using tcl 8.4?  earlier version have serious issues with return -code (used by db_1row to throw its error).
It's 8.3, so maybe that's the deal...
I don't remember the details, but I experienced a similar problem, I think also with db_transaction {} on_error {}. We are using Tcl 8.3. I'm afraid I can't really offer any insights or solutions to this though.
If, as a workaround, I wrap each db_transaction in a catch, well, ...

A) Will the outer catch affect the inner goop any?

B) If the catch catches an error, how do I gracefully
  abort and rollback the transaction?

  Can I then call db_abort_transaction, or will stuff be happening at the wrong upvar levels?

C)  When will someone write backquote macro processing for Tcl?

a) no

b) if it is erroring out at the db_1row call then calling db_abort_transaction should work

btw the following returns "Caught" with tcl 8.4 under nsd 4 beta...

db_transaction {
    db_1row test "select 1 from users where user_id = -100"
} on_error {
    ns_return 200 text/html "Caught"

ns_return 200 text/html "asfd"
so if nsd 4 (or 3.5) is an option that is probably your best bet. Unless db_transaction {} works find for this simple test but doesn't for a more complex series of statements.
7: Tmac Tcl macros (response to 5)
Posted by Andrew Piskorski on
Jerry, Tmac is a macro facility for Tcl. I haven't used it, and I'm not sure how it compares to Lisp or Scheme backquote type macros. What do you think of it?