diff --git a/src/engine/sql/PostgresBackend.c b/src/engine/sql/PostgresBackend.c index 659651c02c..e3f12146d6 100644 --- a/src/engine/sql/PostgresBackend.c +++ b/src/engine/sql/PostgresBackend.c @@ -1951,10 +1951,36 @@ pgend_trans_commit_edit (Backend * bend, } } #else + /* roll things back is sql version is newer */ + if (0 < pgendTransactionCompareVersion (be, oldtrans)) { rollback = 1; } + /* first, see if someone else has already deleted this transaction */ - if (-1 < pgendTransactionGetDeletedVersion (be, oldtrans)) { rollback ++; } - else - if (0 < pgendTransactionCompareVersion (be, oldtrans)) { rollback ++; } + if (-1 < pgendTransactionGetDeletedVersion (be, oldtrans)) + { + if (rollback) + { + /* Although this situation should never happen, we'll try + * to gracefully handle it anyway, because otherwuise the + * transaction becomes un-modifiable, undeleteable. + * (This situation might occur with the right combo of bugs + * and crashes. We've fixed the bugs, but ... + */ + char buf[80]; + gnc_timespec_to_iso8601_buff (xaccTransRetDatePostedTS (trans), buf); + PERR ("The impossible has happened, and thats not good!\n" + "\tThe SQL database contains an active transaction that\n" + "\talso appears in the audit trail as deleted !!\n" + "\tWill try to delete transaction for good\n" + "\ttransaction is '%s' %s\n", + xaccTransGetDescription (trans), buf); + rollback = 0; + trans->do_free = TRUE; + } + else + { + rollback = 1; + } + } #endif if (rollback) { diff --git a/src/engine/sql/checkpoint.c b/src/engine/sql/checkpoint.c index c7745665b7..cb2230b26e 100644 --- a/src/engine/sql/checkpoint.c +++ b/src/engine/sql/checkpoint.c @@ -360,6 +360,8 @@ pgendAccountGetCheckpoint (PGBackend *be, Checkpoint *chk) p = stpcpy (p, "' ORDER BY date_start DESC LIMIT 1;"); SEND_QUERY (be,be->buff, ); + /* provide default value, in case there are no checkpoints */ + chk->date_start = gnc_iso8601_to_timespec_local (CK_EARLIEST_DATE); pgendGetResults (be, get_checkpoint_date_cb, chk); LEAVE("be=%p", be); diff --git a/src/engine/sql/design.txt b/src/engine/sql/design.txt index 9abec9d55e..c6617456d7 100644 --- a/src/engine/sql/design.txt +++ b/src/engine/sql/design.txt @@ -155,6 +155,21 @@ Prices need to have version numbers added. */ +Audit Trails +------------ +The backend keeps an audit trail of created, modified and deleted +transactions. These are stored in s set of tables inheriting from +the gncAuditTrail table. Identified are the date of modification, +the the session id, and the type of change. + +There is currently no support within the GUI to view the audit trails, +nor is there any way to rollback to some previous state based on this +trail. + +The audit trails are used internally to resolve certain multi-user +editing conflicts, for example, when one user attempts to edit a +transaction that has been deleteed by another. + Balances --------