diff --git a/src/backend/postgres/PostgresBackend.c b/src/backend/postgres/PostgresBackend.c index 99ee244836..f746b98651 100644 --- a/src/backend/postgres/PostgresBackend.c +++ b/src/backend/postgres/PostgresBackend.c @@ -137,11 +137,86 @@ pgendGetUserGecos (PGBackend *be) return NULL; } -AccountGroup * -pgendGetTopGroup (PGBackend *be) +/* ============================================================= */ + +Account * +pgendAccountLookup (PGBackend *be, const GUID *acct_guid) { - if (!be) return NULL; - return gnc_book_get_group (be->book); + GList *node; + Account * acc = NULL; + + for (node=be->blist; node; node=node->next) + { + GNCBook *book = node->data; + acc = xaccAccountLookup (acct_guid, book); + if (acc) return acc; + } + + return NULL; +} + +Transaction * +pgendTransLookup (PGBackend *be, const GUID *txn_guid) +{ + GList *node; + Transaction * txn = NULL; + + for (node=be->blist; node; node=node->next) + { + GNCBook *book = node->data; + txn = xaccTransLookup (txn_guid, book); + if (txn) return txn; + } + + return NULL; +} + +Split * +pgendSplitLookup (PGBackend *be, const GUID *split_guid) +{ + GList *node; + Split * split = NULL; + + for (node=be->blist; node; node=node->next) + { + GNCBook *book = node->data; + split = xaccSplitLookup (split_guid, book); + if (split) return split; + } + + return NULL; +} + +GNCPrice * +pgendPriceLookup (PGBackend *be, const GUID *price_guid) +{ + GList *node; + GNCPrice * price = NULL; + + for (node=be->blist; node; node=node->next) + { + GNCBook *book = node->data; + price = gnc_price_lookup (price_guid, book); + if (price) return price; + } + + return NULL; +} + +GNCIdType +pgendGUIDType (PGBackend *be, const GUID *guid) +{ + GList *node; + GNCIdType tip = GNC_ID_NONE; + + for (node=be->blist; node; node=node->next) + { + GNCBook *book = node->data; + tip = xaccGUIDType (guid, book); + if (GNC_ID_NONE != tip) return tip; + } + + return GNC_ID_NONE; } /* ============================================================= */ @@ -723,7 +798,7 @@ pgendSync (Backend *bend, GNCBook *book) pgendDisable(be); pgendKVPInit(be); - pgendGetAllAccounts (be, grp); + pgendGetAllAccountsInBook (be, book); if ((MODE_SINGLE_FILE != be->session_mode) && (MODE_SINGLE_UPDATE != be->session_mode)) { @@ -1310,20 +1385,28 @@ pgend_book_load_poll (Backend *bend, GNCBook *book) if (!be) return; - be->book = book; - - pgendGetBook (be, book); - - grp = gnc_book_get_group (book); - /* don't send events to GUI, don't accept callbacks to backend */ gnc_engine_suspend_events(); pgendDisable(be); be->version_check = (guint32) time(0); pgendKVPInit(be); - pgendGetAllAccounts (be, grp); + be->book = book; + + if (be->blist) + { + /* XXX not clear what this means ... should we free old books ?? */ + PWARN ("old book list not empty "); + g_list_free (be->blist); + } + pgendGetBook (be, book); + + be->blist = g_list_append (NULL, book); + + pgendGetAllAccountsInBook (be, book); + + grp = gnc_book_get_group (book); xaccAccountGroupBeginEdit (grp); pgendGroupGetAllBalances (be, grp, ts); xaccAccountGroupCommitEdit (grp); @@ -1349,19 +1432,29 @@ pgend_book_load_single (Backend *bend, GNCBook *book) if (!be) return; - be->book = book; - - pgendGetBook (be, book); - - grp = gnc_book_get_group (book); /* don't send events to GUI, don't accept callbacks to backend */ gnc_engine_suspend_events(); pgendDisable(be); be->version_check = (guint32) time(0); + be->book = book; + pgendKVPInit(be); - pgendGetAllAccounts (be, grp); + + if (be->blist) + { + /* XXX not clear what this means ... should we free old books ?? */ + PWARN ("old book list not empty "); + g_list_free (be->blist); + } + pgendGetBook (be, book); + + be->blist = g_list_append (NULL, book); + + pgendGetAllAccountsInBook (be, book); + + grp = gnc_book_get_group (book); pgendGetMassTransactions (be, grp); /* re-enable events */ @@ -1981,7 +2074,7 @@ pgend_session_begin (Backend *backend, be->be.price_begin_edit = pgend_price_begin_edit; be->be.price_commit_edit = pgend_price_commit_edit; be->be.run_query = pgendRunQuery; - be->be.price_lookup = pgendPriceLookup; + be->be.price_lookup = pgendPriceFind; be->be.sync_all = pgendSync; be->be.sync_group = NULL; be->be.sync_price = pgendSyncPriceDB; @@ -2011,7 +2104,7 @@ pgend_session_begin (Backend *backend, be->be.price_begin_edit = pgend_price_begin_edit; be->be.price_commit_edit = pgend_price_commit_edit; be->be.run_query = pgendRunQuery; - be->be.price_lookup = pgendPriceLookup; + be->be.price_lookup = pgendPriceFind; be->be.sync_all = pgendSync; be->be.sync_group = NULL; be->be.sync_price = pgendSyncPriceDB; @@ -2197,7 +2290,9 @@ pgendInit (PGBackend *be) } be->ipath_max = 0; + be->session = NULL; be->book = NULL; + be->blist = NULL; } /* ============================================================= */ diff --git a/src/backend/postgres/PostgresBackend.h b/src/backend/postgres/PostgresBackend.h index 0a25319294..ccaf6fc9fd 100644 --- a/src/backend/postgres/PostgresBackend.h +++ b/src/backend/postgres/PostgresBackend.h @@ -110,7 +110,8 @@ struct _pgend { /* engine data caches */ GNCSession *session; - GNCBook *book; + GNCBook *book; /* the currently open book -- XXX -- depricate ???*/ + BookList *blist; /* list of books in this db */ }; /* @@ -118,7 +119,11 @@ struct _pgend { */ Backend * pgendNew (void); -AccountGroup * pgendGetTopGroup (PGBackend *be); +Account * pgendAccountLookup (PGBackend *be, const GUID *acct_guid); +Transaction * pgendTransLookup (PGBackend *be, const GUID *txn_guid); +Split * pgendSplitLookup (PGBackend *be, const GUID *split_guid); +GNCPrice * pgendPriceLookup (PGBackend *be, const GUID *price_guid); +GNCIdType pgendGUIDType (PGBackend *be, const GUID *guid); void pgendDisable (PGBackend *be); void pgendEnable (PGBackend *be); diff --git a/src/backend/postgres/account.c b/src/backend/postgres/account.c index bff1569157..a365215628 100644 --- a/src/backend/postgres/account.c +++ b/src/backend/postgres/account.c @@ -35,12 +35,15 @@ #include "BackendP.h" #include "Group.h" #include "GroupP.h" +#include "gnc-book.h" +#include "gnc-book-p.h" #include "gnc-commodity.h" #include "gnc-engine-util.h" #include "gnc-event.h" #include "guid.h" #include "account.h" +#include "book.h" #include "base-autogen.h" #include "kvp-sql.h" #include "PostgresBackend.h" @@ -236,30 +239,47 @@ pgendGetAllAccountKVP (PGBackend *be, AccountGroup *grp) /* ============================================================= */ /* The pgendGetAllAccounts() routine restores the account hierarchy - * of *all* accounts in the DB. - * It implicitly assumes that the database has only one account - * hierarchy in it, i.e. any accounts without a parent will be stuffed - * into the same top group. + * of *all* accounts in the DB. Each account is stuffed into + * its corresponding book. + * + * The pgendGetAllAccountsInBook() routine only fetches the accounts + * for the indicated book. */ static gpointer get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data) { - AccountGroup *topgrp = (AccountGroup *) data; + GList *node; + GNCBook *book; Account *parent; Account *acc; - GUID guid; + GUID acct_guid, book_guid; - /* first, lets see if we've already got this one */ PINFO ("account GUID=%s", DB_GET_VAL("accountGUID",j)); - guid = nullguid; /* just in case the read fails ... */ - string_to_guid (DB_GET_VAL("accountGUID",j), &guid); - acc = xaccAccountLookup (&guid, be->book); + + /* First, find the book that pertains to this account */ + book_guid = nullguid; /* just in case the read fails ... */ + string_to_guid (DB_GET_VAL("bookGUID",j), &book_guid); + + book = NULL; + for (node=be->blist; node; node=node->next) + { + book = node->data; + if (guid_equal (&book->guid, &book_guid)) break; + book = NULL; + } + if (!book) return NULL; + + /* Next, lets see if we've already got this account */ + acct_guid = nullguid; /* just in case the read fails ... */ + string_to_guid (DB_GET_VAL("accountGUID",j), &acct_guid); + + acc = xaccAccountLookup (&acct_guid, book); if (!acc) { - acc = xaccMallocAccount(be->book); + acc = xaccMallocAccount(book); xaccAccountBeginEdit(acc); - xaccAccountSetGUID(acc, &guid); + xaccAccountSetGUID(acc, &acct_guid); } else { @@ -272,30 +292,30 @@ get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data) xaccAccountSetType(acc, xaccAccountStringToEnum(DB_GET_VAL("type",j))); xaccAccountSetCommodity(acc, gnc_string_to_commodity (DB_GET_VAL("commodity",j), - be->book)); + book)); xaccAccountSetVersion(acc, atoi(DB_GET_VAL("version",j))); acc->idata = atoi(DB_GET_VAL("iguid",j)); /* try to find the parent account */ PINFO ("parent GUID=%s", DB_GET_VAL("parentGUID",j)); - guid = nullguid; /* just in case the read fails ... */ - string_to_guid (DB_GET_VAL("parentGUID",j), &guid); - if (guid_equal(xaccGUIDNULL(), &guid)) + acct_guid = nullguid; /* just in case the read fails ... */ + string_to_guid (DB_GET_VAL("parentGUID",j), &acct_guid); + if (guid_equal(xaccGUIDNULL(), &acct_guid)) { /* if the parent guid is null, then this * account belongs in the top group */ - xaccGroupInsertAccount (topgrp, acc); + xaccGroupInsertAccount (gnc_book_get_group(book), acc); } else { /* if we haven't restored the parent account, create * an empty holder for it */ - parent = xaccAccountLookup (&guid, be->book); + parent = xaccAccountLookup (&acct_guid, book); if (!parent) { - parent = xaccMallocAccount(be->book); + parent = xaccMallocAccount(book); xaccAccountBeginEdit(parent); - xaccAccountSetGUID(parent, &guid); + xaccAccountSetGUID(parent, &acct_guid); } else { @@ -306,30 +326,66 @@ get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data) } xaccAccountCommitEdit(acc); - return topgrp; + return acc; } -AccountGroup * -pgendGetAllAccounts (PGBackend *be, AccountGroup *topgrp) +void +pgendGetAllAccounts (PGBackend *be) { + BookList *node; char * bufp; ENTER ("be=%p", be); - if (!be) return NULL; + if (!be) return; + + /* get all the books in the database */ + pgendGetAllBooks (be, be->blist); + + /* Make sure commodities table is up to date */ + pgendGetAllCommodities (be); + + /* Get them ALL */ + bufp = "SELECT * FROM gncAccount;"; + SEND_QUERY (be, bufp, ); + pgendGetResults (be, get_account_cb, NULL); + + for (node=be->blist; node; node=node->next) + { + GNCBook *book = node->data; + AccountGroup *topgrp = gnc_book_get_group (book); + pgendGetAllAccountKVP (be, topgrp); + + /* Mark the newly read group as saved, since the act of putting + * it together will have caused it to be marked up as not-saved. + */ + xaccGroupMarkSaved (topgrp); + } + + LEAVE (" "); +} + +void +pgendGetAllAccountsInBook (PGBackend *be, GNCBook *book) +{ + char *p, buff[400]; + AccountGroup *topgrp; + + ENTER ("be=%p", be); + if (!be || !book) return; /* first, make sure commodities table is up to date */ pgendGetAllCommodities (be); - if (!topgrp) - { - topgrp = xaccMallocAccountGroup(be->book); - } + /* Get everything for this book */ - /* Get them ALL */ - bufp = "SELECT * FROM gncAccount;"; - SEND_QUERY (be, bufp, NULL); - pgendGetResults (be, get_account_cb, topgrp); + p = buff; + p = stpcpy (p, "SELECT * FROM gncAccount WHERE bookGuid='"); + p = guid_to_string_buff (gnc_book_get_guid(book), p); + p = stpcpy (p, "';"); + SEND_QUERY (be, buff, ); + pgendGetResults (be, get_account_cb, NULL); + topgrp = gnc_book_get_group (book); pgendGetAllAccountKVP (be, topgrp); /* Mark the newly read group as saved, since the act of putting @@ -338,17 +394,16 @@ pgendGetAllAccounts (PGBackend *be, AccountGroup *topgrp) xaccGroupMarkSaved (topgrp); LEAVE (" "); - return topgrp; } /* ============================================================= */ -int +Account * pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid) { char *pbuff; - Account *acc; + Account *acc = NULL; int engine_data_is_newer = 0; ENTER ("be=%p", be); @@ -358,8 +413,9 @@ pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid) gnc_engine_suspend_events(); pgendDisable(be); - /* first, see if we already have such an account */ - acc = xaccAccountLookup (acct_guid, be->book); + /* First, see if we already have such an account */ + acc = pgendAccountLookup (be, acct_guid); + if (!acc) { engine_data_is_newer = -1; @@ -390,16 +446,18 @@ pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid) pbuff = stpcpy (pbuff, "';"); SEND_QUERY (be,be->buff, 0); - pgendGetResults (be, get_account_cb, pgendGetTopGroup (be)); + acc = pgendGetResults (be, get_account_cb, NULL); - acc = xaccAccountLookup (acct_guid, be->book); /* restore any kvp data associated with the transaction and splits */ - if (acc->idata) + if (acc) { - acc->kvp_data = pgendKVPFetch (be, acc->idata, acc->kvp_data); - } + if (acc->idata) + { + acc->kvp_data = pgendKVPFetch (be, acc->idata, acc->kvp_data); + } - acc->version_check = be->version_check; + acc->version_check = be->version_check; + } } /* re-enable events to the backend and GUI */ @@ -407,7 +465,7 @@ pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid) gnc_engine_resume_events(); LEAVE (" "); - return engine_data_is_newer; + return acc; } /* ============================================================= */ diff --git a/src/backend/postgres/account.h b/src/backend/postgres/account.h index 9c3838be09..92882276a7 100644 --- a/src/backend/postgres/account.h +++ b/src/backend/postgres/account.h @@ -25,15 +25,19 @@ #define POSTGRES_ACCOUNT_H #include "Group.h" +#include "gnc-book.h" #include "guid.h" #include "PostgresBackend.h" -AccountGroup * pgendGetAllAccounts (PGBackend *be, AccountGroup *topgrp); +void pgendGetAllAccountsInBook (PGBackend *be, GNCBook *); + +void pgendGetAllAccounts (PGBackend *be); + void pgendStoreGroup (PGBackend *be, AccountGroup *grp); void pgendStoreGroupNoLock (PGBackend *be, AccountGroup *grp, gboolean do_mark, gboolean do_check_version); -int pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid); +Account * pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid); void pgend_account_commit_edit (Backend * bend, Account * acct); diff --git a/src/backend/postgres/book.c b/src/backend/postgres/book.c index f916b89449..c6ceb62687 100644 --- a/src/backend/postgres/book.c +++ b/src/backend/postgres/book.c @@ -133,7 +133,7 @@ pgendStoreBook (PGBackend *be, GNCBook *book) */ static gpointer -get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data) +get_one_book_cb (PGBackend *be, PGresult *result, int j, gpointer data) { GNCBook *book = (GNCBook *) data; GUID guid; @@ -166,7 +166,7 @@ pgendGetBook (PGBackend *be, GNCBook *book) */ bufp = "SELECT * FROM gncBook WHERE book_open='y';"; SEND_QUERY (be, bufp, ); - pgendGetResults (be, get_book_cb, book); + pgendGetResults (be, get_one_book_cb, book); if (0 != book->idata) { @@ -176,6 +176,73 @@ pgendGetBook (PGBackend *be, GNCBook *book) LEAVE (" "); } +/* ============================================================= */ +/* The pgendGetAllBooks() routine creates an empty book + * for each book in the database. + */ + +static gpointer +get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data) +{ + BookList *blist = (BookList *) data; + BookList *node; + GNCBook *book; + GUID guid; + + PINFO ("book GUID=%s", DB_GET_VAL("bookGUID",j)); + guid = nullguid; /* just in case the read fails ... */ + string_to_guid (DB_GET_VAL("bookGUID",j), &guid); + + /* first, lets see if we've already got this one */ + book = NULL; + for (node=blist; node; node=node->next) + { + book = node->data; + if (guid_equal (&book->guid, &guid)) break; + book = NULL; + } + + if (!book) + { + book = gnc_book_new(); + gnc_book_set_guid (book, guid); + } + + book->book_open = (DB_GET_VAL("book_open",j))[0]; + book->version = atoi(DB_GET_VAL("version",j)); + book->idata = atoi(DB_GET_VAL("iguid",j)); + + return blist; +} + +BookList * +pgendGetAllBooks (PGBackend *be, BookList *blist) +{ + BookList *node; + char * bufp; + + ENTER ("be=%p", be); + if (!be) return NULL; + + /* Get them ALL */ + bufp = "SELECT * FROM gncBook;"; + SEND_QUERY (be, bufp, NULL); + blist = pgendGetResults (be, get_book_cb, blist); + + /* get the KVP data for each book too */ + for (node=blist; node; node=node->next) + { + GNCBook *book = node->data; + if (0 != book->idata) + { + book->kvp_data = pgendKVPFetch (be, book->idata, book->kvp_data); + } + } + + LEAVE (" "); + return blist; +} + /* ============================================================= */ void diff --git a/src/backend/postgres/book.h b/src/backend/postgres/book.h index 2b8896e27c..03b3bcb339 100644 --- a/src/backend/postgres/book.h +++ b/src/backend/postgres/book.h @@ -25,10 +25,13 @@ #define POSTGRES_BOOK_H #include "gnc-book.h" +#include "gnc-engine.h" #include "guid.h" #include "PostgresBackend.h" +BookList * pgendGetAllBooks (PGBackend *be, BookList *); + void pgendGetBook (PGBackend *be, GNCBook *book); void pgendStoreBookNoLock (PGBackend *be, GNCBook *book, int do_check_version); void pgendStoreBook (PGBackend *be, GNCBook *book); diff --git a/src/backend/postgres/checkpoint.c b/src/backend/postgres/checkpoint.c index 00c6e843db..ec35bf43ca 100644 --- a/src/backend/postgres/checkpoint.c +++ b/src/backend/postgres/checkpoint.c @@ -87,7 +87,7 @@ pgendAccountRecomputeAllCheckpoints (PGBackend *be, const GUID *acct_guid) ENTER("be=%p", be); guid_string = guid_to_string (acct_guid); - acc = xaccAccountLookup (acct_guid, be->book); + acc = pgendAccountLookup (be, acct_guid); commodity_name = gnc_commodity_get_unique_name (xaccAccountGetCommodity(acc)); diff --git a/src/backend/postgres/events.c b/src/backend/postgres/events.c index 89f4669783..f120df320c 100644 --- a/src/backend/postgres/events.c +++ b/src/backend/postgres/events.c @@ -270,7 +270,7 @@ pgendProcessEvents (Backend *bend) GNCIdType local_obj_type; /* lets see if the local cache has this item in it */ - local_obj_type = xaccGUIDType (&(ev->guid), be->book); + local_obj_type = pgendGUIDType (be, &(ev->guid)); if ((local_obj_type != GNC_ID_NONE) && (safe_strcmp (local_obj_type, ev->obj_type))) { @@ -292,16 +292,20 @@ pgendProcessEvents (Backend *bend) PERR ("account: cant' happen !!!!!!!"); break; case GNC_EVENT_CREATE: - case GNC_EVENT_MODIFY: + case GNC_EVENT_MODIFY: { + Account *acc; + /* if the remote user created an account, mirror it here */ - pgendCopyAccountToEngine (be, &(ev->guid)); - xaccGroupMarkSaved (pgendGetTopGroup (be)); + acc = pgendCopyAccountToEngine (be, &(ev->guid)); + xaccGroupMarkSaved (xaccAccountGetRoot(acc)); break; + } case GNC_EVENT_DESTROY: { - Account * acc = xaccAccountLookup (&(ev->guid), be->book); + Account * acc = pgendAccountLookup (be, &(ev->guid)); + AccountGroup *topgrp = xaccAccountGetRoot(acc); xaccAccountBeginEdit (acc); xaccAccountDestroy (acc); - xaccGroupMarkSaved (pgendGetTopGroup (be)); + xaccGroupMarkSaved (topgrp); break; } } @@ -327,7 +331,7 @@ pgendProcessEvents (Backend *bend) pgendCopyTransactionToEngine (be, &(ev->guid)); break; case GNC_EVENT_DESTROY: { - Transaction *trans = xaccTransLookup (&(ev->guid), be->book); + Transaction *trans = pgendTransLookup (be, &(ev->guid)); xaccTransBeginEdit (trans); xaccTransDestroy (trans); xaccTransCommitEdit (trans); @@ -360,7 +364,7 @@ pgendProcessEvents (Backend *bend) * the guid above */ if (GNC_ID_NONE == local_obj_type) { - local_obj_type = xaccGUIDType (&(ev->guid), be->book); + local_obj_type = pgendGUIDType (be, &(ev->guid)); if (GNC_ID_NONE != local_obj_type) { gnc_engine_generate_event (&(ev->guid), GNC_EVENT_CREATE); @@ -368,7 +372,7 @@ pgendProcessEvents (Backend *bend) } else { - local_obj_type = xaccGUIDType (&(ev->guid), be->book); + local_obj_type = pgendGUIDType (be, &(ev->guid)); if (GNC_ID_NONE != local_obj_type) { gnc_engine_generate_event (&(ev->guid), GNC_EVENT_MODIFY); diff --git a/src/backend/postgres/price.c b/src/backend/postgres/price.c index 2112a2e78a..6122b2db0d 100644 --- a/src/backend/postgres/price.c +++ b/src/backend/postgres/price.c @@ -271,7 +271,7 @@ get_price_cb (PGBackend *be, PGresult *result, int j, gpointer data) /* First, lets see if we've already got this one */ string_to_guid (DB_GET_VAL ("priceGuid", j), &guid); - pr = gnc_price_lookup (&guid, be->book); + pr = pgendPriceLookup (be, &guid); if (!pr) { @@ -351,7 +351,7 @@ pgendGetAllPrices (PGBackend *be, GNCPriceDB *prdb) /* ============================================================= */ void -pgendPriceLookup (Backend *bend, GNCPriceLookup *look) +pgendPriceFind (Backend *bend, GNCPriceLookup *look) { PGBackend *be = (PGBackend *)bend; const char * commodity_str; @@ -366,9 +366,9 @@ pgendPriceLookup (Backend *bend, GNCPriceLookup *look) if (LOOKUP_NEAREST_IN_TIME == look->type) { look->type = LOOKUP_LATEST_BEFORE; - pgendPriceLookup (bend, look); + pgendPriceFind (bend, look); look->type = LOOKUP_EARLIEST_AFTER; - pgendPriceLookup (bend, look); + pgendPriceFind (bend, look); return; } diff --git a/src/backend/postgres/price.h b/src/backend/postgres/price.h index bfd18941b9..09ab4f5846 100644 --- a/src/backend/postgres/price.h +++ b/src/backend/postgres/price.h @@ -31,7 +31,7 @@ void pgendGetCommodity (PGBackend *be, const char * unique_name); void pgendStorePriceDB (PGBackend *be, GNCPriceDB *prdb); void pgendStorePriceDBNoLock (PGBackend *be, GNCPriceDB *prdb); GNCPriceDB * pgendGetAllPrices (PGBackend *be, GNCPriceDB *prdb); -void pgendPriceLookup (Backend *bend, GNCPriceLookup *look); +void pgendPriceFind (Backend *bend, GNCPriceLookup *look); void pgend_price_begin_edit (Backend * bend, GNCPrice *pr); diff --git a/src/backend/postgres/txn.c b/src/backend/postgres/txn.c index 448fc46fc4..30b2aa9dce 100644 --- a/src/backend/postgres/txn.c +++ b/src/backend/postgres/txn.c @@ -118,7 +118,7 @@ delete_list_cb (PGBackend *be, PGresult *result, int j, gpointer data) /* If the database has splits that the engine doesn't, * collect 'em up & we'll have to delete em */ - if (NULL == xaccSplitLookup (&guid, be->book)) + if (NULL == pgendSplitLookup (be, &guid)) { DeleteTransInfo *dti; @@ -469,10 +469,10 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans) PINFO ("split GUID=%s", DB_GET_VAL("entryGUID",j)); guid = nullguid; /* just in case the read fails ... */ string_to_guid (DB_GET_VAL("entryGUID",j), &guid); - s = xaccSplitLookup (&guid, be->book); + s = pgendSplitLookup (be, &guid); if (!s) { - s = xaccMallocSplit(be->book); + s = xaccMallocSplit(trans->book); xaccSplitSetGUID(s, &guid); } @@ -490,7 +490,7 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans) /* next, find the account that this split goes into */ guid = nullguid; /* just in case the read fails ... */ string_to_guid (DB_GET_VAL("accountGUID",j), &guid); - acc = xaccAccountLookup (&guid, be->book); + acc = pgendAccountLookup (be, &guid); if (!acc) { @@ -564,12 +564,11 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans) /* account could have been pulled in by a previous * iteration of this loop. */ - account = xaccAccountLookup (&sri->account_guid, be->book); + account = pgendAccountLookup (be, &sri->account_guid); if (!account) { - pgendCopyAccountToEngine (be, &sri->account_guid); - account = xaccAccountLookup (&sri->account_guid, be->book); + account = pgendCopyAccountToEngine (be, &sri->account_guid); } if (account) @@ -661,7 +660,7 @@ pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid) pgendDisable(be); /* first, see if we already have such a transaction */ - trans = xaccTransLookup (trans_guid, be->book); + trans = pgendTransLookup (be, trans_guid); if (!trans) { trans = xaccMallocTransaction(be->book); @@ -886,7 +885,7 @@ pgendSyncTransaction (PGBackend *be, GUID *trans_guid) "\tto the database. This mode of operation is\n" "\tguarenteed to clobber other user's updates.\n"); - trans = xaccTransLookup (trans_guid); + trans = pgendTransLookup (be, trans_guid); /* hack alert -- basically, we should use the pgend_commit_transaction * routine instead, and in fact, 'StoreTransaction' diff --git a/src/backend/postgres/txnmass.c b/src/backend/postgres/txnmass.c index d0cb40c438..e7bf72ea7d 100644 --- a/src/backend/postgres/txnmass.c +++ b/src/backend/postgres/txnmass.c @@ -65,7 +65,7 @@ get_mass_trans_cb (PGBackend *be, PGresult *result, int j, gpointer data) /* first, see if we already have such a transaction */ string_to_guid (DB_GET_VAL("transGUID",j), &trans_guid); - trans = xaccTransLookup (&trans_guid, be->book); + trans = pgendTransLookup (be, &trans_guid); if (trans) { /* If transaction already exists, determine whose data is @@ -116,7 +116,7 @@ get_mass_trans_cb (PGBackend *be, PGresult *result, int j, gpointer data) static gpointer get_mass_entry_cb (PGBackend *be, PGresult *result, int j, gpointer data) { - Transaction *trans; + Transaction *trans=NULL; Account *acc; Split *s; GUID guid; @@ -132,7 +132,7 @@ get_mass_entry_cb (PGBackend *be, PGresult *result, int j, gpointer data) PINFO ("split GUID=%s", DB_GET_VAL("entryGUID",j)); guid = nullguid; /* just in case the read fails ... */ string_to_guid (DB_GET_VAL("entryGUID",j), &guid); - s = xaccSplitLookup (&guid, be->book); + s = pgendSplitLookup (be, &guid); if (!s) { s = xaccMallocSplit(be->book); @@ -151,7 +151,7 @@ get_mass_entry_cb (PGBackend *be, PGresult *result, int j, gpointer data) guid = nullguid; /* just in case the read fails ... */ string_to_guid (DB_GET_VAL("transGUID",j), &guid); - trans = xaccTransLookup (&guid, be->book); + trans = pgendTransLookup (be, &guid); if (!trans) { PERR ("trans not found, will delete this split\n" @@ -170,7 +170,7 @@ get_mass_entry_cb (PGBackend *be, PGresult *result, int j, gpointer data) /* next, find the account that this split goes into */ guid = nullguid; /* just in case the read fails ... */ string_to_guid (DB_GET_VAL("accountGUID",j), &guid); - acc = xaccAccountLookup (&guid, be->book); + acc = pgendAccountLookup (be, &guid); if (!acc) { PERR ("account not found, will delete this split\n"