Forum OpenACS Q&A: db_transaction keeps failing

Collapse
Posted by Kolja Lehmann on
I try to insert a couple of records into the db, some of which might fail. Each record has it's own db_transaction for first creating an acs_object and then inserting other related data.
However, once one transaction fails, all the following transaction fail as well with no error message. I seems as if db_transaction sets a flag somewhere on failure and does not reset it for a new transaction.
I am using openacs 5 here, using the -dbn switch. Don't know if that does anything to it or not.
db_foreach -dbn one_db ... {
  db_transaction -dbn other_db ... {
    db_dml -dbn other_db do_something ...
  } on_error {
    ns_log notice "$errmsg"
  }
}

something like that.

Collapse
Posted by Kolja Lehmann on
I guess this is because og this code in db_abort_transaction:
    upvar "#0" [db_state_array_name_is -dbn $dbn] db_state

    db_with_handle -dbn $dbn db {
        # We set the abort flag to true.
        set db_state(db_abort_p,$db) 1
    }

So the state for this db handle is set to aborted for the whole request. I am trying to reset db_abort to 0 in my code now, because I don't know, where to do that in db_transaction. It should work, because i only have one pool defined for the db I use there. Should I post this in the bugtracker?

Collapse
Posted by Kolja Lehmann on
Ok, i found the error. It was in dB_transaction itself
in version    @cvs-id 00-database-procs.tcl,v 1.19.2.5 2003/05/23 13:11:29 lars Exp
line 1974
    if { $err_p || [db_abort_transaction_p]} {
        # An error was triggered or the transaction has been aborted.
        db_abort_transaction

must be
    if { $err_p || [db_abort_transaction_p -dbn $dbn]} {
        # An error was triggered or the transaction has been aborted.
        db_abort_transaction -dbn $dbn

and some more missing -dbn switches further down the line.
should I do anything with this? post a patch or something?

Collapse
Posted by Jade Rubick on
Yes, post a patch for it.