From 57636f50e429cfe3ef4f13332556e03fdb4116dc Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Mon, 8 May 2006 03:02:15 +0000 Subject: [PATCH] Make qof_commit_edit() (and macro version) call qof_backend_run_commit() instead of qof_backend_run_begin(). Minor cleanups of qof_commit_edit() and qof_begin_edit(). git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13955 57a11ea4-9604-0410-9ed3-97b8803252fd --- lib/libqof/qof/qofutil.c | 37 ++++++++++++++++++++++--------------- lib/libqof/qof/qofutil.h | 6 +++--- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/libqof/qof/qofutil.c b/lib/libqof/qof/qofutil.c index 6e34c219a3..87b7995d66 100644 --- a/lib/libqof/qof/qofutil.c +++ b/lib/libqof/qof/qofutil.c @@ -231,14 +231,18 @@ qof_begin_edit(QofInstance *inst) { QofBackend * be; - if (!inst) { return FALSE; } - (inst->editlevel)++; - if (1 < inst->editlevel) { return FALSE; } - if (0 >= inst->editlevel) { inst->editlevel = 1; } + if (!inst) return FALSE; + inst->editlevel++; + if (1 < inst->editlevel) return FALSE; + if (0 >= inst->editlevel) + inst->editlevel = 1; + be = qof_book_get_backend (inst->book); - if (be && qof_backend_begin_exists(be)) { - qof_backend_run_begin(be, inst); - } else { inst->dirty = TRUE; } + if (be && qof_backend_begin_exists(be)) + qof_backend_run_begin(be, inst); + else + inst->dirty = TRUE; + return TRUE; } @@ -246,18 +250,21 @@ gboolean qof_commit_edit(QofInstance *inst) { QofBackend * be; - if (!inst) { return FALSE; } - (inst->editlevel)--; - if (0 < inst->editlevel) { return FALSE; } + if (!inst) return FALSE; + inst->editlevel--; + if (0 < inst->editlevel) return FALSE; + if ((-1 == inst->editlevel) && inst->dirty) { - be = qof_book_get_backend ((inst)->book); - if (be && qof_backend_begin_exists(be)) { - qof_backend_run_begin(be, inst); + be = qof_book_get_backend (inst->book); + if (be && qof_backend_commit_exists(be)) { + qof_backend_run_commit(be, inst); } - inst->editlevel = 0; } - if (0 > inst->editlevel) { inst->editlevel = 0; } + if (0 > inst->editlevel) { + PERR ("unbalanced call - resetting (was %d)", inst->editlevel); + inst->editlevel = 0; + } return TRUE; } diff --git a/lib/libqof/qof/qofutil.h b/lib/libqof/qof/qofutil.h index 98ab38c536..c3a4274dae 100644 --- a/lib/libqof/qof/qofutil.h +++ b/lib/libqof/qof/qofutil.h @@ -354,12 +354,12 @@ gboolean qof_begin_edit(QofInstance *inst); /* The pricedb suffers from delayed update... */ \ /* This may be setting a bad precedent for other types, I fear. */ \ /* Other types probably really should handle begin like this. */ \ - if ((-1 == (inst)->editlevel) && (inst)->dirty) \ + if ((-1 == (inst)->editlevel) && (inst)->dirty) \ { \ QofBackend * be; \ be = qof_book_get_backend ((inst)->book); \ - if (be && qof_backend_begin_exists(be)) { \ - qof_backend_run_begin(be, (inst)); \ + if (be && qof_backend_commit_exists(be)) { \ + qof_backend_run_commit(be, (inst)); \ } \ (inst)->editlevel = 0; \ } \