mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
table changes !
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4606 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
2cc209bbd0
commit
705556bf96
@ -135,6 +135,7 @@ typedef struct _event {
|
||||
Timespec stamp;
|
||||
GNCEngineEventType type;
|
||||
GUID guid;
|
||||
GNCIdType obj_type;
|
||||
} Event;
|
||||
|
||||
|
||||
@ -148,6 +149,8 @@ get_event_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
Timespec ts;
|
||||
GNCEngineEventType type;
|
||||
char change = (DB_GET_VAL("change",j))[0];
|
||||
char objtype = (DB_GET_VAL("objtype",j))[0];
|
||||
GNCIdType obj_type = GNC_ID_NONE;
|
||||
|
||||
guid_str = DB_GET_VAL("guid",j);
|
||||
PINFO ("event %c for %s", change, guid_str);
|
||||
@ -162,6 +165,16 @@ get_event_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
PERR ("unknown change type %c for guid=%s", change, guid_str);
|
||||
return data;
|
||||
}
|
||||
switch (objtype)
|
||||
{
|
||||
case 'a': obj_type = GNC_ID_ACCOUNT; break;
|
||||
case 'c': obj_type = GNC_ID_NONE; break; /* should be commodity */
|
||||
case 'e': obj_type = GNC_ID_SPLIT; break;
|
||||
case 'p': obj_type = GNC_ID_PRICE; break;
|
||||
case 't': obj_type = GNC_ID_TRANS; break;
|
||||
case 'x': obj_type = GNC_ID_NONE; break;
|
||||
case ' ': obj_type = GNC_ID_NONE; break;
|
||||
}
|
||||
|
||||
string_to_guid (guid_str, &guid);
|
||||
ts = gnc_iso8601_to_timespec_local (DB_GET_VAL("date_changed",j));
|
||||
@ -179,6 +192,7 @@ get_event_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
ev->type = type;
|
||||
ev->guid = guid;
|
||||
ev->stamp = ts;
|
||||
ev->obj_type = obj_type;
|
||||
}
|
||||
return (gpointer) list;
|
||||
}
|
||||
@ -189,6 +203,7 @@ get_event_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
ev->type = type;
|
||||
ev->guid = guid;
|
||||
ev->stamp = ts;
|
||||
ev->obj_type = obj_type;
|
||||
|
||||
/* add it to our list */
|
||||
list = g_list_prepend (list, ev);
|
||||
@ -200,8 +215,8 @@ get_event_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
{ \
|
||||
char *p; \
|
||||
p = be->buff; *p = 0; \
|
||||
p = stpcpy (p, "SELECT change, date_changed, " #guid_name \
|
||||
" AS guid FROM " #table \
|
||||
p = stpcpy (p, "SELECT objtype, change, date_changed, " \
|
||||
#guid_name " AS guid FROM " #table \
|
||||
" WHERE sessionGuid <> '"); \
|
||||
p = stpcpy (p, be->session_guid_str); \
|
||||
p = stpcpy (p, "' AND date_changed >= '"); \
|
||||
|
@ -12,12 +12,15 @@
|
||||
--
|
||||
|
||||
-- audit trail tables
|
||||
-- The change may be 'a' -- add, 'd' -- delete/drop, 'm' -- modify
|
||||
-- The change field may be 'a' -- add, 'd' -- delete/drop, 'm' -- modify
|
||||
-- The objtype field may be 'a' -- account, 'c' -- commodity, 'e' -- entry,
|
||||
-- 'k' -- kvp, 'p' -- price, 't' -- transaction
|
||||
|
||||
CREATE TABLE gncAuditTrail (
|
||||
sessionGuid CHAR(32) NOT NULL, -- who changed it
|
||||
date_changed DATETIME, -- when they changed it
|
||||
change CHAR NOT NULL
|
||||
change CHAR NOT NULL,
|
||||
objtype CHAR NOT NULL
|
||||
);
|
||||
|
||||
-- would love to inherit, but can't because this wrecks the primary key
|
||||
|
@ -5,7 +5,7 @@ changecom(`/*', `*/')
|
||||
/* data dictionary for the gnucash tables */
|
||||
/* sql table description and manipulation macros */
|
||||
|
||||
define(`account', `gncAccount, Account, Account,
|
||||
define(`account', `gncAccount, Account, Account, a,
|
||||
accountName, , char *, xaccAccountGetName(ptr),
|
||||
accountCode, , char *, xaccAccountGetCode(ptr),
|
||||
description, , char *, xaccAccountGetDescription(ptr),
|
||||
@ -16,7 +16,7 @@ define(`account', `gncAccount, Account, Account,
|
||||
accountGUID, KEY, GUID *, xaccAccountGetGUID(ptr),
|
||||
')
|
||||
|
||||
define(`split', `gncEntry, Split, Split,
|
||||
define(`split', `gncEntry, Split, Split, e,
|
||||
accountGUID, , GUID *, xaccAccountGetGUID(xaccSplitGetAccount(ptr)),
|
||||
transGUID, , GUID *, xaccTransGetGUID(xaccSplitGetParent(ptr)),
|
||||
memo, , char *, xaccSplitGetMemo(ptr),
|
||||
@ -35,7 +35,7 @@ define(`split', `gncEntry, Split, Split,
|
||||
/* date_entered, , Timespec, xaccTransRetDateEnteredTS(ptr), */
|
||||
/* as one might have guessed */
|
||||
|
||||
define(`transaction', `gncTransaction, Transaction, Transaction,
|
||||
define(`transaction', `gncTransaction, Transaction, Transaction, t,
|
||||
num, , char *, xaccTransGetNum(ptr),
|
||||
description, , char *, xaccTransGetDescription(ptr),
|
||||
currency, , commod, gnc_commodity_get_unique_name(xaccTransGetCurrency(ptr)),
|
||||
@ -47,7 +47,7 @@ define(`transaction', `gncTransaction, Transaction, Transaction,
|
||||
')
|
||||
|
||||
|
||||
define(`modity', `gncCommodity, Commodity, gnc_commodity,
|
||||
define(`modity', `gncCommodity, Commodity, gnc_commodity, c,
|
||||
namespace, , char *, gnc_commodity_get_namespace(ptr),
|
||||
fullname, , char *, gnc_commodity_get_fullname(ptr),
|
||||
mnemonic, , char *, gnc_commodity_get_mnemonic(ptr),
|
||||
@ -57,7 +57,7 @@ define(`modity', `gncCommodity, Commodity, gnc_commodity,
|
||||
')
|
||||
|
||||
|
||||
define(`price', `gncPrice, Price, GNCPrice,
|
||||
define(`price', `gncPrice, Price, GNCPrice, p,
|
||||
commodity, , commod, gnc_commodity_get_unique_name(gnc_price_get_commodity(ptr)),
|
||||
currency, , commod, gnc_commodity_get_unique_name(gnc_price_get_currency(ptr)),
|
||||
time, , Timespec, gnc_price_get_time(ptr),
|
||||
@ -70,7 +70,7 @@ define(`price', `gncPrice, Price, GNCPrice,
|
||||
')
|
||||
|
||||
|
||||
define(`checkpoint', `gncCheckpoint, Checkpoint, Checkpoint,
|
||||
define(`checkpoint', `gncCheckpoint, Checkpoint, Checkpoint, x,
|
||||
balance, , int64, ptr->balance,
|
||||
cleared_balance, , int64, ptr->cleared_balance,
|
||||
reconciled_balance, , int64, ptr->reconciled_balance,
|
||||
@ -81,7 +81,7 @@ define(`checkpoint', `gncCheckpoint, Checkpoint, Checkpoint,
|
||||
')
|
||||
|
||||
|
||||
define(`session', `gncSession, Session, void,
|
||||
define(`session', `gncSession, Session, void, x,
|
||||
session_mode, , char *, pgendSessionGetMode(be),
|
||||
hostname, , char *, pgendGetHostname(be),
|
||||
login_name, , char *, pgendGetUsername(be),
|
||||
@ -91,7 +91,7 @@ define(`session', `gncSession, Session, void,
|
||||
sessionGUID, KEY, GUID *, be->sessionGuid,
|
||||
')
|
||||
|
||||
define(`kvp_gint64', `gncKVPvalue_int64, KVPint64, store_data_t,
|
||||
define(`kvp_gint64', `gncKVPvalue_int64, KVPint64, store_data_t, k,
|
||||
type, , char *, ptr->stype,
|
||||
data, , int64, ptr->u.ival,
|
||||
iguid, KEY, int32, ptr->iguid,
|
||||
@ -99,14 +99,14 @@ define(`kvp_gint64', `gncKVPvalue_int64, KVPint64, store_data_t,
|
||||
')
|
||||
|
||||
|
||||
define(`kvp_double', `gncKVPvalue_dbl, KVPdouble, store_data_t,
|
||||
define(`kvp_double', `gncKVPvalue_dbl, KVPdouble, store_data_t, k,
|
||||
type, , char *, ptr->stype,
|
||||
data, , double, ptr->u.dbl,
|
||||
iguid, KEY, int32, ptr->iguid,
|
||||
ipath, KEY, int32, ptr->ipath,
|
||||
')
|
||||
|
||||
define(`kvp_numeric', `gncKVPvalue_numeric, KVPnumeric, store_data_t,
|
||||
define(`kvp_numeric', `gncKVPvalue_numeric, KVPnumeric, store_data_t, k,
|
||||
type, , char *, ptr->stype,
|
||||
num, , int64, ptr->u.numeric.num,
|
||||
denom, , int64, ptr->u.numeric.denom,
|
||||
@ -114,14 +114,14 @@ define(`kvp_numeric', `gncKVPvalue_numeric, KVPnumeric, store_data_t,
|
||||
ipath, KEY, int32, ptr->ipath,
|
||||
')
|
||||
|
||||
define(`kvp_string', `gncKVPvalue_str, KVPstring, store_data_t,
|
||||
define(`kvp_string', `gncKVPvalue_str, KVPstring, store_data_t, k,
|
||||
type, , char *, ptr->stype,
|
||||
data, , char *, ptr->u.str,
|
||||
iguid, KEY, int32, ptr->iguid,
|
||||
ipath, KEY, int32, ptr->ipath,
|
||||
')
|
||||
|
||||
define(`kvp_guid', `gncKVPvalue_guid, KVPguid, store_data_t,
|
||||
define(`kvp_guid', `gncKVPvalue_guid, KVPguid, store_data_t, k,
|
||||
type, , char *, ptr->stype,
|
||||
data, , char *, ptr->u.str,
|
||||
iguid, KEY, int32, ptr->iguid,
|
||||
@ -133,8 +133,9 @@ define(`kvp_guid', `gncKVPvalue_guid, KVPguid, store_data_t,
|
||||
define(`tablename', $1)
|
||||
define(`func_name', $2)
|
||||
define(`xacc_type', $3)
|
||||
define(`obj_type', $4)
|
||||
|
||||
define(`firstrec', `shift(shift(shift($@)))')
|
||||
define(`firstrec', `shift(shift(shift(shift($@))))')
|
||||
define(`nextrec', `shift(shift(shift(shift($@))))')
|
||||
|
||||
/* -------- */
|
||||
@ -403,6 +404,7 @@ pgendStoreAudit`'func_name($@)`' (PGBackend *be,
|
||||
/* sqlBuild_Set_GUID (be->builder, "sessionGUID", be->sessionGuid); */
|
||||
sqlBuild_Set_Str (be->builder, "sessionGUID", be->session_guid_str);
|
||||
sqlBuild_Set_Char (be->builder, "change", update);
|
||||
sqlBuild_Set_Char (be->builder, "objtype", ''`obj_type($@)''`);
|
||||
|
||||
buf = sqlBuild_Query (be->builder);
|
||||
SEND_QUERY (be,buf, );
|
||||
|
Loading…
Reference in New Issue
Block a user