mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add deletion to audit trails
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4497 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
be05767fd7
commit
d3ff389662
@ -653,6 +653,12 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans,
|
||||
p = be->buff; *p = 0;
|
||||
for (node=deletelist; node; node=node->next)
|
||||
{
|
||||
Split *s;
|
||||
GUID guid;
|
||||
string_to_guid ((char *)(node->data), &guid);
|
||||
s = xaccSplitLookup(&guid);
|
||||
pgendStoreAuditSplit (be, s, SQL_DELETE);
|
||||
|
||||
p = stpcpy (p, "DELETE FROM gncEntry WHERE entryGuid='");
|
||||
p = stpcpy (p, node->data);
|
||||
p = stpcpy (p, "';\n");
|
||||
@ -691,10 +697,12 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans,
|
||||
for (node=start; node; node=node->next)
|
||||
{
|
||||
Split * s = node->data;
|
||||
pgendStoreAuditSplit (be, s, SQL_DELETE);
|
||||
p = stpcpy (p, "DELETE FROM gncEntry WHERE entryGuid='");
|
||||
p = guid_to_string_buff (xaccSplitGetGUID(s), p);
|
||||
p = stpcpy (p, "';\n");
|
||||
}
|
||||
pgendStoreAuditTransaction (be, trans, SQL_DELETE);
|
||||
p = be->buff;
|
||||
p = stpcpy (p, "DELETE FROM gncTransaction WHERE transGuid='");
|
||||
p = guid_to_string_buff (xaccTransGetGUID(trans), p);
|
||||
@ -1753,9 +1761,13 @@ pgend_account_commit_edit (Backend * bend,
|
||||
|
||||
if (acct->do_free)
|
||||
{
|
||||
const GUID *guid = xaccAccountGetGUID(acct);
|
||||
pgendStoreAuditAccount (be, acct, SQL_DELETE);
|
||||
pgendKVPDelete (be, guid);
|
||||
|
||||
p = be->buff; *p = 0;
|
||||
p = stpcpy (p, "DELETE FROM gncAccount WHERE accountGuid='");
|
||||
p = guid_to_string_buff (xaccAccountGetGUID(acct), p);
|
||||
p = guid_to_string_buff (guid, p);
|
||||
p = stpcpy (p, "';");
|
||||
SEND_QUERY (be,be->buff, 444);
|
||||
FINISH_QUERY(be->connection);
|
||||
@ -1924,7 +1936,8 @@ pgend_price_commit_edit (Backend * bend, GNCPrice *pr)
|
||||
|
||||
if (pr->do_free)
|
||||
{
|
||||
bufp = be->buff;
|
||||
pgendStoreAuditPrice (be, pr, SQL_DELETE);
|
||||
bufp = be->buff; *bufp = 0;
|
||||
bufp = stpcpy (bufp, "DELETE FROM gncPrice WHERE priceGuid='");
|
||||
bufp = guid_to_string_buff (gnc_price_get_guid(pr), bufp);
|
||||
bufp = stpcpy (bufp, "';");
|
||||
@ -2919,9 +2932,9 @@ pgend_session_begin (GNCBook *sess, const char * sessionid,
|
||||
be->be.price_lookup = NULL;
|
||||
be->be.sync = pgendSyncSingleFile;
|
||||
be->be.sync_price = pgendSyncPriceDBSingleFile;
|
||||
PWARN ("MODE_SINGLE_FILE is beta -- \n"
|
||||
PWARN ("MODE_SINGLE_FILE is final beta -- \n"
|
||||
"we've fixed all known bugs but that doesn't mean\n"
|
||||
"there aren't any!\n");
|
||||
"there aren't any! We think its safe to use.\n");
|
||||
break;
|
||||
|
||||
case MODE_SINGLE_UPDATE:
|
||||
@ -2939,9 +2952,9 @@ pgend_session_begin (GNCBook *sess, const char * sessionid,
|
||||
be->be.price_lookup = NULL;
|
||||
be->be.sync = pgendSync;
|
||||
be->be.sync_price = pgendSyncPriceDB;
|
||||
PWARN ("MODE_SINGLE_UPDATE is beta -- \n"
|
||||
PWARN ("MODE_SINGLE_UPDATE is final beta -- \n"
|
||||
"we've fixed all known bugs but that doesn't mean\n"
|
||||
"there aren't any!\n");
|
||||
"there aren't any! We think its safe to use.\n");
|
||||
break;
|
||||
|
||||
case MODE_POLL:
|
||||
@ -2959,7 +2972,9 @@ pgend_session_begin (GNCBook *sess, const char * sessionid,
|
||||
be->be.price_lookup = pgendPriceLookup;
|
||||
be->be.sync = pgendSync;
|
||||
be->be.sync_price = pgendSyncPriceDB;
|
||||
PWARN ("MODE_POLL is experimental -- you might corrupt your data\n");
|
||||
PWARN ("MODE_POLL is alpha -- \n"
|
||||
"there are a few unfixed bugs, but maybe this mode is usable.\n"
|
||||
"It might still corrupt your data, we're not sure yet.\n");
|
||||
break;
|
||||
|
||||
case MODE_EVENT:
|
||||
|
@ -227,18 +227,10 @@ multi-user mode is fundamentally broken unless they are fixed.
|
||||
Failure to do so causes the fill-out algorithm to pull in all
|
||||
data.
|
||||
|
||||
-- Implement logging history/audit-trail in the SQL server.
|
||||
(partly done; delete not implemented. ) Need indexes on kvp ...
|
||||
|
||||
-- if another user deletes a transaction, or an account, there is no way
|
||||
for us to know. Thus, any sort of sync will probably (incorrectly)
|
||||
add the deleted transaction back in. Question: what is the best way
|
||||
of having the backend detect that another user has deleted a
|
||||
transaction?
|
||||
Method A) keep a master list of all transactions, and compare to
|
||||
that.
|
||||
Method B) keep an audit trail of deleted transactions, and check
|
||||
that.
|
||||
-- if another user deletes a transaction, or an account, we
|
||||
need to look at the audit trail to see if the thing has been deleted.
|
||||
Otherwise, any sort of sync will incorrectly
|
||||
add the deleted transaction back in.
|
||||
|
||||
-- during sync, detect and report conflicting edits to accounts
|
||||
and transactions. See the notes for pgendSync() for details
|
||||
|
@ -525,9 +525,19 @@ pgendKVPFetch (PGBackend *be, const GUID *guid, kvp_frame *kf)
|
||||
|
||||
/* =========================================================== */
|
||||
|
||||
#define CPY_KVP(TYPE) \
|
||||
{ \
|
||||
p = stpcpy (p, "INSERT INTO gncKVPValue" TYPE "Trail SELECT '"); \
|
||||
p = stpcpy (p, sess_str); \
|
||||
p = stpcpy (p, "' as sessionGuid, datetime('NOW') as date_changed, " \
|
||||
"'d' as change, * from gncKVPValue" TYPE " WHERE iguid=");\
|
||||
p = stpcpy (p, iguid_str); \
|
||||
}
|
||||
|
||||
void
|
||||
pgendKVPDeleteStr (PGBackend *be, const char *guid)
|
||||
{
|
||||
char iguid_str[80], sess_str[80];
|
||||
char * p;
|
||||
int iguid = 0;
|
||||
if (!be || !guid) return;
|
||||
@ -535,28 +545,34 @@ pgendKVPDeleteStr (PGBackend *be, const char *guid)
|
||||
iguid = pgendGetGUIDCacheIDStr (be, guid);
|
||||
if (0 == iguid) return;
|
||||
|
||||
sprintf (iguid_str, "%d;", iguid);
|
||||
guid_to_string_buff (be->sessionGuid, sess_str);
|
||||
|
||||
/* first, copy values to the audit tables */
|
||||
p = be->buff; *p = 0;
|
||||
CPY_KVP("");
|
||||
CPY_KVP("_dbl");
|
||||
CPY_KVP("_guid");
|
||||
CPY_KVP("_int64");
|
||||
CPY_KVP("_list");
|
||||
CPY_KVP("_numeric");
|
||||
CPY_KVP("_str");
|
||||
|
||||
/* then delete the values */
|
||||
p = stpcpy (p, "DELETE FROM gncKVPValue WHERE iguid=");
|
||||
p += sprintf (p, "%d", iguid);
|
||||
p = stpcpy (p, ";");
|
||||
p = stpcpy (p, iguid_str);
|
||||
p = stpcpy (p, "DELETE FROM gncKVPValue_dbl WHERE iguid=");
|
||||
p += sprintf (p, "%d", iguid);
|
||||
p = stpcpy (p, ";");
|
||||
p = stpcpy (p, iguid_str);
|
||||
p = stpcpy (p, "DELETE FROM gncKVPValue_guid WHERE iguid=");
|
||||
p += sprintf (p, "%d", iguid);
|
||||
p = stpcpy (p, ";");
|
||||
p = stpcpy (p, iguid_str);
|
||||
p = stpcpy (p, "DELETE FROM gncKVPValue_int64 WHERE iguid=");
|
||||
p += sprintf (p, "%d", iguid);
|
||||
p = stpcpy (p, ";");
|
||||
p = stpcpy (p, iguid_str);
|
||||
p = stpcpy (p, "DELETE FROM gncKVPValue_list WHERE iguid=");
|
||||
p += sprintf (p, "%d", iguid);
|
||||
p = stpcpy (p, ";");
|
||||
p = stpcpy (p, iguid_str);
|
||||
p = stpcpy (p, "DELETE FROM gncKVPValue_numeric WHERE iguid=");
|
||||
p += sprintf (p, "%d", iguid);
|
||||
p = stpcpy (p, ";");
|
||||
p = stpcpy (p, iguid_str);
|
||||
p = stpcpy (p, "DELETE FROM gncKVPValue_str WHERE iguid=");
|
||||
p += sprintf (p, "%d", iguid);
|
||||
p = stpcpy (p, ";");
|
||||
p = stpcpy (p, iguid_str);
|
||||
|
||||
SEND_QUERY (be,be->buff, );
|
||||
FINISH_QUERY(be->connection);
|
||||
|
Loading…
Reference in New Issue
Block a user