mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
continue roughing in support for books
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6456 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
af4740e50c
commit
e82222d5b2
@ -11,6 +11,7 @@ libgncmod_backend_postgres_la_LIBADD = -lpq \
|
||||
libgncmod_backend_postgres_la_SOURCES = \
|
||||
PostgresBackend.c \
|
||||
account.c \
|
||||
book.c \
|
||||
builder.c \
|
||||
checkpoint.c \
|
||||
escape.c \
|
||||
@ -27,6 +28,7 @@ noinst_HEADERS = \
|
||||
PostgresBackend.h \
|
||||
account.h \
|
||||
base-autogen.h \
|
||||
book.h \
|
||||
builder.h \
|
||||
checkpoint.h \
|
||||
check-autogen.h \
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-book-p.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-engine-util.h"
|
||||
@ -55,6 +56,7 @@
|
||||
#include "TransactionP.h"
|
||||
|
||||
#include "account.h"
|
||||
#include "book.h"
|
||||
#include "builder.h"
|
||||
#include "checkpoint.h"
|
||||
#include "events.h"
|
||||
@ -709,6 +711,8 @@ pgendSync (Backend *bend, GNCBook *book)
|
||||
}
|
||||
be->freshly_created_db = FALSE;
|
||||
|
||||
pgendStoreBook (be, book);
|
||||
|
||||
/* store the account group hierarchy, and then all transactions */
|
||||
pgendStoreGroup (be, grp);
|
||||
pgendStoreAllTransactions (be, grp);
|
||||
@ -731,6 +735,12 @@ pgendSync (Backend *bend, GNCBook *book)
|
||||
pgendGetMassTransactions (be, grp);
|
||||
}
|
||||
|
||||
/* hack alert -- In some deranged theory, we should be
|
||||
* syncing prices here, as well as syncing any/all other
|
||||
* engine structures that need to be stored. But instead,
|
||||
* price syn is handled as a separate routine ...
|
||||
*/
|
||||
|
||||
/* re-enable events */
|
||||
pgendEnable(be);
|
||||
gnc_engine_resume_events();
|
||||
@ -764,24 +774,66 @@ trans_traverse_cb (Transaction *trans, void *cb_data)
|
||||
static void
|
||||
pgendSyncSingleFile (Backend *bend, GNCBook *book)
|
||||
{
|
||||
char book_guid[40];
|
||||
char buff[4000];
|
||||
char *p;
|
||||
PGBackend *be = (PGBackend *)bend;
|
||||
AccountGroup *grp = gnc_book_get_group (book);
|
||||
|
||||
ENTER ("be=%p, grp=%p", be, grp);
|
||||
|
||||
/* hack alert -- we shouldn't be doing a global delete,
|
||||
* we should only be deleting the stuff that's in this particular
|
||||
* book .... */
|
||||
p = "BEGIN;\n"
|
||||
"LOCK TABLE gncBook IN EXCLUSIVE MODE;\n"
|
||||
"LOCK TABLE gncAccount IN EXCLUSIVE MODE;\n"
|
||||
"LOCK TABLE gncCommodity IN EXCLUSIVE MODE;\n"
|
||||
"LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n"
|
||||
"LOCK TABLE gncEntry IN EXCLUSIVE MODE;\n"
|
||||
"DELETE FROM gncEntry;\n"
|
||||
"DELETE FROM gncTransaction;\n"
|
||||
"DELETE FROM gncAccount;\n"
|
||||
"DELETE FROM gncCommodity;\n";
|
||||
"LOCK TABLE gncEntry IN EXCLUSIVE MODE;\n";
|
||||
SEND_QUERY (be,p, );
|
||||
FINISH_QUERY(be->connection);
|
||||
|
||||
guid_to_string_buff (gnc_book_get_guid(book), book_guid);
|
||||
|
||||
/* First, we delete all of the accounts, splits and transactions
|
||||
* associated with this book. Its very tempting to just delete
|
||||
* everything in the SQL db, but we note that there may be several
|
||||
* books stored here, and we want to delete only one book.
|
||||
*/
|
||||
/* do the one-book equivalent of "DELETE FROM gncTransaction;" */
|
||||
p = buff;
|
||||
p = stpcpy (p, "DELETE FROM gncTransaction WHERE "
|
||||
" gncTransaction.transGuid = gncEntry.transGuid AND "
|
||||
" gncEntry.accountGuid = gncAccount.accountGuid AND "
|
||||
" gncAccount.bookGuid = '");
|
||||
p = stpcpy (p, book_guid);
|
||||
p = stpcpy (p, "';");
|
||||
SEND_QUERY (be,buff, );
|
||||
FINISH_QUERY(be->connection);
|
||||
|
||||
/* do the one-book equivalent of "DELETE FROM gncEntry;" */
|
||||
p = buff;
|
||||
p = stpcpy (p, "DELETE FROM gncEntry WHERE "
|
||||
" gncEntry.accountGuid = gncAccount.accountGuid AND "
|
||||
" gncAccount.bookGuid = '");
|
||||
p = stpcpy (p, book_guid);
|
||||
p = stpcpy (p, "';");
|
||||
SEND_QUERY (be,buff, );
|
||||
FINISH_QUERY(be->connection);
|
||||
|
||||
|
||||
/* do the one-book equivalent of "DELETE FROM gncAccount;" */
|
||||
p = buff;
|
||||
p = stpcpy (p, "DELETE FROM gncAccount WHERE bookGuid='");
|
||||
p = stpcpy (p, book_guid);
|
||||
p = stpcpy (p, "';");
|
||||
SEND_QUERY (be,buff, );
|
||||
FINISH_QUERY(be->connection);
|
||||
|
||||
/* store the book struct */
|
||||
pgendStoreBookNoLock (be, book, TRUE);
|
||||
|
||||
/* Store accounts and commodities */
|
||||
xaccClearMarkDownGr (grp, 0);
|
||||
pgendStoreGroupNoLock (be, grp, TRUE, TRUE);
|
||||
@ -792,6 +844,13 @@ pgendSyncSingleFile (Backend *bend, GNCBook *book)
|
||||
xaccGroupBeginStagedTransactionTraversals(grp);
|
||||
xaccGroupStagedTransactionTraversal (grp, 1, trans_traverse_cb, be);
|
||||
|
||||
/* hack alert -- In some deranged theory, we should be
|
||||
* syncing prices here, as well as syncing any/all other
|
||||
* engine structures that need to be stored. But instead,
|
||||
* price sync is handled as a separate routine ...
|
||||
*/
|
||||
|
||||
|
||||
p = "COMMIT;";
|
||||
SEND_QUERY (be,p, );
|
||||
FINISH_QUERY(be->connection);
|
||||
@ -800,7 +859,7 @@ pgendSyncSingleFile (Backend *bend, GNCBook *book)
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
/* Please read the commend for pgendSync to truly understand
|
||||
/* Please read the comment for pgendSync to truly understand
|
||||
* how this routine works. Its somewhat subtle.
|
||||
*/
|
||||
|
||||
@ -1240,6 +1299,8 @@ pgend_book_load_poll (Backend *bend)
|
||||
|
||||
be->book = gnc_session_get_book (be->session);
|
||||
|
||||
pgendGetBook (be, be->book);
|
||||
|
||||
grp = pgendGetTopGroup (be);
|
||||
|
||||
/* don't send events to GUI, don't accept callbacks to backend */
|
||||
@ -1277,6 +1338,8 @@ pgend_book_load_single (Backend *bend)
|
||||
|
||||
be->book = gnc_session_get_book (be->session);
|
||||
|
||||
pgendGetBook (be, be->book);
|
||||
|
||||
grp = pgendGetTopGroup (be);
|
||||
|
||||
/* don't send events to GUI, don't accept callbacks to backend */
|
||||
@ -2036,6 +2099,7 @@ pgendInit (PGBackend *be)
|
||||
|
||||
be->my_pid = 0;
|
||||
be->do_account = 0;
|
||||
be->do_book = 0;
|
||||
be->do_checkpoint = 0;
|
||||
be->do_price = 0;
|
||||
be->do_session = 0;
|
||||
|
@ -6,6 +6,7 @@ include(`table.m4')
|
||||
divert
|
||||
|
||||
store_one_only_header(account);
|
||||
store_one_only_header(book);
|
||||
store_one_only_header(modity);
|
||||
store_one_only_header(session);
|
||||
store_one_only_header(split);
|
||||
@ -13,27 +14,32 @@ store_one_only_header(transaction);
|
||||
store_one_only_header(price);
|
||||
|
||||
store_audit_header(account);
|
||||
store_audit_header(book);
|
||||
store_audit_header(modity);
|
||||
store_audit_header(split);
|
||||
store_audit_header(transaction);
|
||||
store_audit_header(price);
|
||||
|
||||
compare_one_only_header(account);
|
||||
compare_one_only_header(book);
|
||||
compare_one_only_header(modity);
|
||||
compare_one_only_header(split);
|
||||
compare_one_only_header(transaction);
|
||||
compare_one_only_header(price);
|
||||
|
||||
put_one_only_header(account);
|
||||
put_one_only_header(book);
|
||||
put_one_only_header(modity);
|
||||
put_one_only_header(split);
|
||||
put_one_only_header(transaction);
|
||||
put_one_only_header(price);
|
||||
|
||||
compare_version_header(account);
|
||||
compare_version_header(book);
|
||||
compare_version_header(transaction);
|
||||
compare_version_header(price);
|
||||
|
||||
is_deleted_header(account);
|
||||
is_deleted_header(book);
|
||||
is_deleted_header(transaction);
|
||||
is_deleted_header(price);
|
||||
|
@ -6,6 +6,7 @@ include(`table.m4')
|
||||
divert
|
||||
|
||||
store_one_only(account)
|
||||
store_one_only(book)
|
||||
store_one_only(modity)
|
||||
store_one_only(session)
|
||||
store_one_only(split)
|
||||
@ -13,27 +14,32 @@ store_one_only(transaction)
|
||||
store_one_only(price)
|
||||
|
||||
store_audit(account)
|
||||
store_audit(book)
|
||||
store_audit(modity)
|
||||
store_audit(split)
|
||||
store_audit(transaction)
|
||||
store_audit(price)
|
||||
|
||||
compare_one_only(account)
|
||||
compare_one_only(book)
|
||||
compare_one_only(modity)
|
||||
compare_one_only(split)
|
||||
compare_one_only(transaction)
|
||||
compare_one_only(price)
|
||||
|
||||
put_one_only(account)
|
||||
put_one_only(book)
|
||||
put_one_only(modity)
|
||||
put_one_only(split)
|
||||
put_one_only(transaction)
|
||||
put_one_only(price)
|
||||
|
||||
compare_version(account)
|
||||
compare_version(book)
|
||||
compare_version(transaction)
|
||||
compare_version(price)
|
||||
|
||||
is_deleted(account)
|
||||
is_deleted(book)
|
||||
is_deleted(transaction)
|
||||
is_deleted(price)
|
||||
|
@ -83,7 +83,6 @@ pgendStoreBookNoLock (PGBackend *be, GNCBook *book,
|
||||
if (0 < pgendBookCompareVersion (be, book)) return;
|
||||
}
|
||||
book->version ++; /* be sure to update the version !! */
|
||||
book->version_check = be->version_check;
|
||||
|
||||
if ((0 == book->idata) &&
|
||||
(FALSE == kvp_frame_is_empty (gnc_book_get_slots(book))))
|
||||
|
@ -214,6 +214,9 @@ pgendStorePriceDBNoLock (PGBackend *be, GNCPriceDB *prdb)
|
||||
gnc_commodity_table *comtab;
|
||||
|
||||
comtab = gnc_book_get_commodity_table (be->book);
|
||||
printf ("duude comtab=%p book=%p session=%p sess-boo=%p\n",
|
||||
comtab, be->book, be->session,
|
||||
gnc_session_get_book(be->session));
|
||||
|
||||
/* clear the marks on commodities -- we use this to mark
|
||||
* the thing as 'already stored', avoiding redundant stores */
|
||||
|
@ -39,7 +39,7 @@ CREATE TABLE gncAuditTrail (
|
||||
CREATE TABLE gncAccountTrail (
|
||||
accountGuid CHAR(32) NOT NULL, -- override, not a primary key anymore
|
||||
parentGuid CHAR(32) NOT NULL,
|
||||
-- not yet bookGuid CHAR(32) NOT NULL,
|
||||
bookGuid CHAR(32) NOT NULL,
|
||||
accountName TEXT NOT NULL CHECK (accountName <> ''),
|
||||
accountCode TEXT,
|
||||
description TEXT,
|
||||
@ -51,13 +51,14 @@ CREATE TABLE gncAccountTrail (
|
||||
|
||||
CREATE INDEX gncAccountTrail_account_idx ON gncAccountTrail (accountGuid);
|
||||
|
||||
-- CREATE TABLE gncBookTrail (
|
||||
-- bookGuid CHAR(32) NOT NULL,
|
||||
-- version INT4 NOT NULL,
|
||||
-- iguid INT4 DEFAULT 0
|
||||
-- ) INHERITS (gncAuditTrail);
|
||||
--
|
||||
-- CREATE INDEX gncBookTrail_book_idx ON gncBookTrail (bookGuid);
|
||||
CREATE TABLE gncBookTrail (
|
||||
bookGuid CHAR(32) NOT NULL,
|
||||
book_open CHAR DEFAULT 'n',
|
||||
version INT4 NOT NULL,
|
||||
iguid INT4 DEFAULT 0
|
||||
) INHERITS (gncAuditTrail);
|
||||
|
||||
CREATE INDEX gncBookTrail_book_idx ON gncBookTrail (bookGuid);
|
||||
|
||||
CREATE TABLE gncCommodityTrail (
|
||||
commodity TEXT NOT NULL, -- override, not a primary key anymore
|
||||
|
@ -44,11 +44,12 @@ CREATE TABLE gncCommodity (
|
||||
fraction INT DEFAULT '100'
|
||||
);
|
||||
|
||||
-- CREATE TABLE gncBook (
|
||||
-- bookGuid CHAR(32) PRIMARY KEY,
|
||||
-- version INT4 NOT NULL,
|
||||
-- iguid INT4 UNIQUE DEFAULT nextval('gnc_iguid_seq')
|
||||
-- );
|
||||
CREATE TABLE gncBook (
|
||||
bookGuid CHAR(32) PRIMARY KEY,
|
||||
book_open CHAR DEFAULT 'n',
|
||||
version INT4 NOT NULL,
|
||||
iguid INT4 UNIQUE DEFAULT nextval('gnc_iguid_seq')
|
||||
);
|
||||
|
||||
-- Account structure -- parentGUID points to parent account
|
||||
-- guid. There is no supports for Groups in this schema.
|
||||
@ -57,7 +58,7 @@ CREATE TABLE gncCommodity (
|
||||
CREATE TABLE gncAccount (
|
||||
accountGuid CHAR(32) PRIMARY KEY,
|
||||
parentGuid CHAR(32) NOT NULL,
|
||||
-- not yet bookGuid CHAR(32) NOT NULL,
|
||||
bookGuid CHAR(32) NOT NULL,
|
||||
accountName TEXT NOT NULL CHECK (accountName <> ''),
|
||||
accountCode TEXT,
|
||||
description TEXT,
|
||||
|
@ -16,4 +16,4 @@ INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,0,0,'Version Table');
|
||||
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,1,1,'iGUID in Main Tables');
|
||||
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,2,1,'Fix gncSubtotalReconedBalance');
|
||||
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,3,1,'Add kvp_timespec tables');
|
||||
-- not yet -- INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,4,1,'Add support for multiple books');
|
||||
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,4,1,'Add support for multiple books');
|
||||
|
@ -13,6 +13,7 @@ define(`account', `gncAccount, Account, Account, a,
|
||||
commodity, , char *, gnc_commodity_get_unique_name(xaccAccountGetCommodity(ptr)),
|
||||
version, , int32, xaccAccountGetVersion(ptr),
|
||||
iguid, , int32, ptr->idata,
|
||||
bookGUID, , GUID *, gnc_book_get_guid(xaccAccountGetBook(ptr)),
|
||||
parentGUID, , GUID *, xaccAccountGetGUID(xaccAccountGetParentAccount(ptr)),
|
||||
accountGUID, KEY, GUID *, xaccAccountGetGUID(ptr),
|
||||
')
|
||||
|
@ -37,7 +37,7 @@ static short module = MOD_BACKEND;
|
||||
/* ============================================================= */
|
||||
|
||||
#define PGEND_CURRENT_MAJOR_VERSION 1
|
||||
#define PGEND_CURRENT_MINOR_VERSION 3
|
||||
#define PGEND_CURRENT_MINOR_VERSION 4
|
||||
#define PGEND_CURRENT_REV_VERSION 1
|
||||
|
||||
/* ============================================================= */
|
||||
@ -347,9 +347,6 @@ add_multiple_book_support (PGBackend *be)
|
||||
SEND_QUERY (be,buff, );
|
||||
FINISH_QUERY(be->connection);
|
||||
|
||||
SEND_QUERY (be,p, );
|
||||
FINISH_QUERY(be->connection);
|
||||
|
||||
p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
|
||||
" (1,4,1,'End Add multiple book support');";
|
||||
SEND_QUERY (be,p, );
|
||||
@ -414,12 +411,10 @@ pgendUpgradeDB (PGBackend *be)
|
||||
{
|
||||
add_kvp_timespec_tables (be);
|
||||
}
|
||||
#ifdef NOT_YET
|
||||
if (4 > vers.minor)
|
||||
{
|
||||
add_multiple_book_support (be);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user