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:
Linas Vepstas 2001-12-31 23:02:37 +00:00
parent af4740e50c
commit e82222d5b2
11 changed files with 106 additions and 28 deletions

View File

@ -11,6 +11,7 @@ libgncmod_backend_postgres_la_LIBADD = -lpq \
libgncmod_backend_postgres_la_SOURCES = \ libgncmod_backend_postgres_la_SOURCES = \
PostgresBackend.c \ PostgresBackend.c \
account.c \ account.c \
book.c \
builder.c \ builder.c \
checkpoint.c \ checkpoint.c \
escape.c \ escape.c \
@ -27,6 +28,7 @@ noinst_HEADERS = \
PostgresBackend.h \ PostgresBackend.h \
account.h \ account.h \
base-autogen.h \ base-autogen.h \
book.h \
builder.h \ builder.h \
checkpoint.h \ checkpoint.h \
check-autogen.h \ check-autogen.h \

View File

@ -42,6 +42,7 @@
#include "Group.h" #include "Group.h"
#include "GroupP.h" #include "GroupP.h"
#include "gnc-book.h" #include "gnc-book.h"
#include "gnc-book-p.h"
#include "gnc-commodity.h" #include "gnc-commodity.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
@ -55,6 +56,7 @@
#include "TransactionP.h" #include "TransactionP.h"
#include "account.h" #include "account.h"
#include "book.h"
#include "builder.h" #include "builder.h"
#include "checkpoint.h" #include "checkpoint.h"
#include "events.h" #include "events.h"
@ -709,6 +711,8 @@ pgendSync (Backend *bend, GNCBook *book)
} }
be->freshly_created_db = FALSE; be->freshly_created_db = FALSE;
pgendStoreBook (be, book);
/* store the account group hierarchy, and then all transactions */ /* store the account group hierarchy, and then all transactions */
pgendStoreGroup (be, grp); pgendStoreGroup (be, grp);
pgendStoreAllTransactions (be, grp); pgendStoreAllTransactions (be, grp);
@ -731,6 +735,12 @@ pgendSync (Backend *bend, GNCBook *book)
pgendGetMassTransactions (be, grp); 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 */ /* re-enable events */
pgendEnable(be); pgendEnable(be);
gnc_engine_resume_events(); gnc_engine_resume_events();
@ -764,24 +774,66 @@ trans_traverse_cb (Transaction *trans, void *cb_data)
static void static void
pgendSyncSingleFile (Backend *bend, GNCBook *book) pgendSyncSingleFile (Backend *bend, GNCBook *book)
{ {
char book_guid[40];
char buff[4000];
char *p; char *p;
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
AccountGroup *grp = gnc_book_get_group (book); AccountGroup *grp = gnc_book_get_group (book);
ENTER ("be=%p, grp=%p", be, grp); 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" p = "BEGIN;\n"
"LOCK TABLE gncBook IN EXCLUSIVE MODE;\n"
"LOCK TABLE gncAccount IN EXCLUSIVE MODE;\n" "LOCK TABLE gncAccount IN EXCLUSIVE MODE;\n"
"LOCK TABLE gncCommodity IN EXCLUSIVE MODE;\n" "LOCK TABLE gncCommodity IN EXCLUSIVE MODE;\n"
"LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n" "LOCK TABLE gncTransaction IN EXCLUSIVE MODE;\n"
"LOCK TABLE gncEntry 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";
SEND_QUERY (be,p, ); SEND_QUERY (be,p, );
FINISH_QUERY(be->connection); 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 */ /* Store accounts and commodities */
xaccClearMarkDownGr (grp, 0); xaccClearMarkDownGr (grp, 0);
pgendStoreGroupNoLock (be, grp, TRUE, TRUE); pgendStoreGroupNoLock (be, grp, TRUE, TRUE);
@ -792,6 +844,13 @@ pgendSyncSingleFile (Backend *bend, GNCBook *book)
xaccGroupBeginStagedTransactionTraversals(grp); xaccGroupBeginStagedTransactionTraversals(grp);
xaccGroupStagedTransactionTraversal (grp, 1, trans_traverse_cb, be); 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;"; p = "COMMIT;";
SEND_QUERY (be,p, ); SEND_QUERY (be,p, );
FINISH_QUERY(be->connection); 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. * 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); be->book = gnc_session_get_book (be->session);
pgendGetBook (be, be->book);
grp = pgendGetTopGroup (be); grp = pgendGetTopGroup (be);
/* don't send events to GUI, don't accept callbacks to backend */ /* 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); be->book = gnc_session_get_book (be->session);
pgendGetBook (be, be->book);
grp = pgendGetTopGroup (be); grp = pgendGetTopGroup (be);
/* don't send events to GUI, don't accept callbacks to backend */ /* don't send events to GUI, don't accept callbacks to backend */
@ -2036,6 +2099,7 @@ pgendInit (PGBackend *be)
be->my_pid = 0; be->my_pid = 0;
be->do_account = 0; be->do_account = 0;
be->do_book = 0;
be->do_checkpoint = 0; be->do_checkpoint = 0;
be->do_price = 0; be->do_price = 0;
be->do_session = 0; be->do_session = 0;

View File

@ -6,6 +6,7 @@ include(`table.m4')
divert divert
store_one_only_header(account); store_one_only_header(account);
store_one_only_header(book);
store_one_only_header(modity); store_one_only_header(modity);
store_one_only_header(session); store_one_only_header(session);
store_one_only_header(split); store_one_only_header(split);
@ -13,27 +14,32 @@ store_one_only_header(transaction);
store_one_only_header(price); store_one_only_header(price);
store_audit_header(account); store_audit_header(account);
store_audit_header(book);
store_audit_header(modity); store_audit_header(modity);
store_audit_header(split); store_audit_header(split);
store_audit_header(transaction); store_audit_header(transaction);
store_audit_header(price); store_audit_header(price);
compare_one_only_header(account); compare_one_only_header(account);
compare_one_only_header(book);
compare_one_only_header(modity); compare_one_only_header(modity);
compare_one_only_header(split); compare_one_only_header(split);
compare_one_only_header(transaction); compare_one_only_header(transaction);
compare_one_only_header(price); compare_one_only_header(price);
put_one_only_header(account); put_one_only_header(account);
put_one_only_header(book);
put_one_only_header(modity); put_one_only_header(modity);
put_one_only_header(split); put_one_only_header(split);
put_one_only_header(transaction); put_one_only_header(transaction);
put_one_only_header(price); put_one_only_header(price);
compare_version_header(account); compare_version_header(account);
compare_version_header(book);
compare_version_header(transaction); compare_version_header(transaction);
compare_version_header(price); compare_version_header(price);
is_deleted_header(account); is_deleted_header(account);
is_deleted_header(book);
is_deleted_header(transaction); is_deleted_header(transaction);
is_deleted_header(price); is_deleted_header(price);

View File

@ -6,6 +6,7 @@ include(`table.m4')
divert divert
store_one_only(account) store_one_only(account)
store_one_only(book)
store_one_only(modity) store_one_only(modity)
store_one_only(session) store_one_only(session)
store_one_only(split) store_one_only(split)
@ -13,27 +14,32 @@ store_one_only(transaction)
store_one_only(price) store_one_only(price)
store_audit(account) store_audit(account)
store_audit(book)
store_audit(modity) store_audit(modity)
store_audit(split) store_audit(split)
store_audit(transaction) store_audit(transaction)
store_audit(price) store_audit(price)
compare_one_only(account) compare_one_only(account)
compare_one_only(book)
compare_one_only(modity) compare_one_only(modity)
compare_one_only(split) compare_one_only(split)
compare_one_only(transaction) compare_one_only(transaction)
compare_one_only(price) compare_one_only(price)
put_one_only(account) put_one_only(account)
put_one_only(book)
put_one_only(modity) put_one_only(modity)
put_one_only(split) put_one_only(split)
put_one_only(transaction) put_one_only(transaction)
put_one_only(price) put_one_only(price)
compare_version(account) compare_version(account)
compare_version(book)
compare_version(transaction) compare_version(transaction)
compare_version(price) compare_version(price)
is_deleted(account) is_deleted(account)
is_deleted(book)
is_deleted(transaction) is_deleted(transaction)
is_deleted(price) is_deleted(price)

View File

@ -83,7 +83,6 @@ pgendStoreBookNoLock (PGBackend *be, GNCBook *book,
if (0 < pgendBookCompareVersion (be, book)) return; if (0 < pgendBookCompareVersion (be, book)) return;
} }
book->version ++; /* be sure to update the version !! */ book->version ++; /* be sure to update the version !! */
book->version_check = be->version_check;
if ((0 == book->idata) && if ((0 == book->idata) &&
(FALSE == kvp_frame_is_empty (gnc_book_get_slots(book)))) (FALSE == kvp_frame_is_empty (gnc_book_get_slots(book))))

View File

@ -214,6 +214,9 @@ pgendStorePriceDBNoLock (PGBackend *be, GNCPriceDB *prdb)
gnc_commodity_table *comtab; gnc_commodity_table *comtab;
comtab = gnc_book_get_commodity_table (be->book); 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 /* clear the marks on commodities -- we use this to mark
* the thing as 'already stored', avoiding redundant stores */ * the thing as 'already stored', avoiding redundant stores */

View File

@ -39,7 +39,7 @@ CREATE TABLE gncAuditTrail (
CREATE TABLE gncAccountTrail ( CREATE TABLE gncAccountTrail (
accountGuid CHAR(32) NOT NULL, -- override, not a primary key anymore accountGuid CHAR(32) NOT NULL, -- override, not a primary key anymore
parentGuid CHAR(32) NOT NULL, parentGuid CHAR(32) NOT NULL,
-- not yet bookGuid CHAR(32) NOT NULL, bookGuid CHAR(32) NOT NULL,
accountName TEXT NOT NULL CHECK (accountName <> ''), accountName TEXT NOT NULL CHECK (accountName <> ''),
accountCode TEXT, accountCode TEXT,
description TEXT, description TEXT,
@ -51,13 +51,14 @@ CREATE TABLE gncAccountTrail (
CREATE INDEX gncAccountTrail_account_idx ON gncAccountTrail (accountGuid); CREATE INDEX gncAccountTrail_account_idx ON gncAccountTrail (accountGuid);
-- CREATE TABLE gncBookTrail ( CREATE TABLE gncBookTrail (
-- bookGuid CHAR(32) NOT NULL, bookGuid CHAR(32) NOT NULL,
-- version INT4 NOT NULL, book_open CHAR DEFAULT 'n',
-- iguid INT4 DEFAULT 0 version INT4 NOT NULL,
-- ) INHERITS (gncAuditTrail); iguid INT4 DEFAULT 0
-- ) INHERITS (gncAuditTrail);
-- CREATE INDEX gncBookTrail_book_idx ON gncBookTrail (bookGuid);
CREATE INDEX gncBookTrail_book_idx ON gncBookTrail (bookGuid);
CREATE TABLE gncCommodityTrail ( CREATE TABLE gncCommodityTrail (
commodity TEXT NOT NULL, -- override, not a primary key anymore commodity TEXT NOT NULL, -- override, not a primary key anymore

View File

@ -44,11 +44,12 @@ CREATE TABLE gncCommodity (
fraction INT DEFAULT '100' fraction INT DEFAULT '100'
); );
-- CREATE TABLE gncBook ( CREATE TABLE gncBook (
-- bookGuid CHAR(32) PRIMARY KEY, bookGuid CHAR(32) PRIMARY KEY,
-- version INT4 NOT NULL, book_open CHAR DEFAULT 'n',
-- iguid INT4 UNIQUE DEFAULT nextval('gnc_iguid_seq') version INT4 NOT NULL,
-- ); iguid INT4 UNIQUE DEFAULT nextval('gnc_iguid_seq')
);
-- Account structure -- parentGUID points to parent account -- Account structure -- parentGUID points to parent account
-- guid. There is no supports for Groups in this schema. -- guid. There is no supports for Groups in this schema.
@ -57,7 +58,7 @@ CREATE TABLE gncCommodity (
CREATE TABLE gncAccount ( CREATE TABLE gncAccount (
accountGuid CHAR(32) PRIMARY KEY, accountGuid CHAR(32) PRIMARY KEY,
parentGuid CHAR(32) NOT NULL, parentGuid CHAR(32) NOT NULL,
-- not yet bookGuid CHAR(32) NOT NULL, bookGuid CHAR(32) NOT NULL,
accountName TEXT NOT NULL CHECK (accountName <> ''), accountName TEXT NOT NULL CHECK (accountName <> ''),
accountCode TEXT, accountCode TEXT,
description TEXT, description TEXT,

View File

@ -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,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,2,1,'Fix gncSubtotalReconedBalance');
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,3,1,'Add kvp_timespec tables'); 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');

View File

@ -13,6 +13,7 @@ define(`account', `gncAccount, Account, Account, a,
commodity, , char *, gnc_commodity_get_unique_name(xaccAccountGetCommodity(ptr)), commodity, , char *, gnc_commodity_get_unique_name(xaccAccountGetCommodity(ptr)),
version, , int32, xaccAccountGetVersion(ptr), version, , int32, xaccAccountGetVersion(ptr),
iguid, , int32, ptr->idata, iguid, , int32, ptr->idata,
bookGUID, , GUID *, gnc_book_get_guid(xaccAccountGetBook(ptr)),
parentGUID, , GUID *, xaccAccountGetGUID(xaccAccountGetParentAccount(ptr)), parentGUID, , GUID *, xaccAccountGetGUID(xaccAccountGetParentAccount(ptr)),
accountGUID, KEY, GUID *, xaccAccountGetGUID(ptr), accountGUID, KEY, GUID *, xaccAccountGetGUID(ptr),
') ')

View File

@ -37,7 +37,7 @@ static short module = MOD_BACKEND;
/* ============================================================= */ /* ============================================================= */
#define PGEND_CURRENT_MAJOR_VERSION 1 #define PGEND_CURRENT_MAJOR_VERSION 1
#define PGEND_CURRENT_MINOR_VERSION 3 #define PGEND_CURRENT_MINOR_VERSION 4
#define PGEND_CURRENT_REV_VERSION 1 #define PGEND_CURRENT_REV_VERSION 1
/* ============================================================= */ /* ============================================================= */
@ -347,9 +347,6 @@ add_multiple_book_support (PGBackend *be)
SEND_QUERY (be,buff, ); SEND_QUERY (be,buff, );
FINISH_QUERY(be->connection); FINISH_QUERY(be->connection);
SEND_QUERY (be,p, );
FINISH_QUERY(be->connection);
p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n" p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
" (1,4,1,'End Add multiple book support');"; " (1,4,1,'End Add multiple book support');";
SEND_QUERY (be,p, ); SEND_QUERY (be,p, );
@ -414,12 +411,10 @@ pgendUpgradeDB (PGBackend *be)
{ {
add_kvp_timespec_tables (be); add_kvp_timespec_tables (be);
} }
#ifdef NOT_YET
if (4 > vers.minor) if (4 > vers.minor)
{ {
add_multiple_book_support (be); add_multiple_book_support (be);
} }
#endif
} }
} }