From 9510b20ea24351f838bf709bb2e99f26bdd9e8e1 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Tue, 6 Apr 2010 23:10:56 +0200 Subject: [PATCH] We need to fool the Ingres code a bit more to think we are in a transaction when doing an insert followed by the retrieval of the currval of the id inserted. So we save the current transaction status set it to true do all our work commit it if we are really not in a transaction and restore the actual transaction status. Not the nicest but it should work. --- bacula/src/cats/ingres.c | 44 ++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/bacula/src/cats/ingres.c b/bacula/src/cats/ingres.c index b8a85ee5d5..647f84fb9e 100755 --- a/bacula/src/cats/ingres.c +++ b/bacula/src/cats/ingres.c @@ -678,23 +678,51 @@ bail_out: return id; } +/* + * First execute the insert query and then retrieve the currval. + * By setting transaction to true we make it an atomic transaction + * and as such we can get the currval after which we commit if + * mdb->transaction is false. This way things are an atomic operation + * for Ingres and things work. We save the current transaction status + * and set transaction in the mdb to true and at the end of this + * function we restore the actual transaction status. + */ int my_ingres_insert_id(B_DB *mdb, const char *query, const char *table_name) { + int id = 0; + bool transaction; + + /* + * Save the current transaction status and pretend we are in a transaction. + */ + transaction = mdb->transaction; + mdb->transaction = true; + /* - * First execute the insert query and then retrieve the currval. - * By setting transaction to true we make it an atomic transaction - * and as such we can get the currval after which we commit if - * mdb->transaction is false. This way its an atomic operation for - * Ingres and things work. + * Execute the INSERT query. */ - mdb->num_rows = INGexec(mdb->db, query, true); + mdb->num_rows = INGexec(mdb->db, query, mdb->transaction); if (mdb->num_rows == -1) { - return 0; + goto bail_out; } mdb->changes++; + id = my_ingres_currval(mdb, table_name); - return my_ingres_currval(mdb, table_name); + /* + * Commit if we are NOT in a transaction. + */ + if (transaction) { + INGcommit(mdb->db); + } + +bail_out: + /* + * Restore the actual transaction status. + */ + mdb->transaction = transaction; + + return id; } #ifdef HAVE_BATCH_FILE_INSERT -- 2.39.5