After discusing with Derek a bit, here's the patch that corrects bug #116546. This is against head; I've not backported to 1.8.x yet.
-- Matthew Vanecek perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);' ******************************************************************************** For 93 million miles, there is nothing between the sun and my shadow except me. I'm always getting in the way of something...
Index: ChangeLog =================================================================== RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v retrieving revision 1.1702 diff -u -r1.1702 ChangeLog --- ChangeLog 27 Jul 2003 04:02:02 -0000 1.1702 +++ ChangeLog 27 Jul 2003 17:09:01 -0000 @@ -1,3 +1,22 @@ +2003-07-27 Matt Vanecek <[EMAIL PROTECTED]> + + * src/backend/postgres/PostgresBackend.c: Added pgendGetBook(), + to retrieve the QofBook from the session, instead of storing the + book in the backend object. + - Where be->book was used, use pgendGetBook() instead. + - Enhanced debug messages. + * src/backend/postgres/PostgresBackend.h: Added the qofbook.h + include, and the pgendGetBook() prototype + * src/backend/postgres/book.c: Changed pgendGetBook to + pgendBookRestore() to reflect its functionality of restoring + the book's data to the engine. + * src/backend/postgres/price.c: In pgendPriceFind(), couched the + currenct portion of the SQL statement in an "if" statement, + because gnc_pricedb_lookup_latest_any_currency() can pass in + a NULL currency, and stpcpy() doesn't like NULLs. + * src/backend/postgres/escape.c: enhanced debug messages. + Fixes bug #116546 + 2003-07-26 Derek Atkins <[EMAIL PROTECTED]> * src/engine/qofbackend.h: add a new error, ERR_BACKEND_READONLY Index: src/backend/postgres/PostgresBackend.c =================================================================== RCS file: /home/cvs/cvsroot/gnucash/src/backend/postgres/PostgresBackend.c,v retrieving revision 1.47 diff -u -r1.47 PostgresBackend.c --- src/backend/postgres/PostgresBackend.c 28 Jun 2003 20:56:29 -0000 1.47 +++ src/backend/postgres/PostgresBackend.c 27 Jul 2003 17:09:05 -0000 @@ -217,6 +217,17 @@ /* ============================================================= */ +QofBook * +pgendGetBook(PGBackend *pbe) { + QofBook *book; + + ENTER(" "); + book = qof_session_get_book(pbe->session); + + LEAVE("book = %p", book); + return book; +} + static void pgend_set_book (PGBackend *be, QofBook *book) { @@ -438,7 +449,7 @@ } else { - trans = xaccMallocTransaction(be->book); + trans = xaccMallocTransaction(pgendGetBook(be)); xaccTransBeginEdit (trans); xaccTransSetGUID (trans, &trans_guid); } @@ -452,7 +463,8 @@ xaccTransSetVersion (trans, atoi(DB_GET_VAL("version",j))); trans->idata = atoi(DB_GET_VAL("iguid",j)); - currency = gnc_string_to_commodity (DB_GET_VAL("currency",j), be->book); + currency = gnc_string_to_commodity (DB_GET_VAL("currency",j), + pgendGetBook(be)); if (currency) xaccTransSetCurrency (trans, currency); else @@ -512,7 +524,8 @@ gnc_commodity * commodity; pgendGetCommodity (be, ri->commodity_string); - commodity = gnc_string_to_commodity (ri->commodity_string, be->book); + commodity = gnc_string_to_commodity (ri->commodity_string, + pgendGetBook(be)); if (commodity) { @@ -697,7 +710,7 @@ sqlQuery *sq; ENTER ("be=%p, qry=%p", be, q); - if (!be || !q) return; + if (!be || !q) { LEAVE("(null) args"); return; } be->version_check = (guint32) time(0); gnc_engine_suspend_events(); @@ -708,7 +721,7 @@ sq = sqlQuery_new(); sql_query_string = sqlQuery_build (sq, q); - topgroup = gnc_book_get_group (be->book); + topgroup = gnc_book_get_group (pgendGetBook(be)); /* stage transactions, save some postgres overhead */ xaccGroupBeginStagedTransactionTraversals (topgroup); @@ -1475,18 +1488,18 @@ if (be->blist) { + GList *node; + PWARN ("old book list not empty--clearing it out "); /* XXX not clear what this means ... should we free old books ?? */ - /* The old book list is set by the session when the session is - * created. It is an empty book, and should be discarded in favor - * of the Book retrieved from the database. - * PWARN ("old book list not empty "); - */ + for (node = be->blist; node; node = node->next) { + g_free(node->data); + node->data = NULL; + } g_list_free (be->blist); be->blist = NULL; } + pgendBookRestore (be, book); pgend_set_book (be, book); - pgendGetBook (be, book); - qof_session_set_book(be->session, book); PINFO("Book GUID = %s\n", guid_to_string(qof_book_get_guid(book))); @@ -1524,19 +1537,22 @@ pgendDisable(be); be->version_check = (guint32) time(0); - pgend_set_book (be, book); - pgendKVPInit(be); if (be->blist) { + GList *node; + PWARN ("old book list not empty--clearing it out "); /* XXX not clear what this means ... should we free old books ?? */ - PWARN ("old book list not empty "); + for (node = be->blist; node; node = node->next) { + g_free(node->data); + node->data = NULL; + } g_list_free (be->blist); + be->blist = NULL; } - pgendGetBook (be, book); - - be->blist = g_list_append (NULL, book); + pgendBookRestore (be, book); + pgend_set_book (be, book); pgendGetAllAccountsInBook (be, book); @@ -1557,7 +1573,9 @@ { PGBackend *be = (PGBackend *)bend; - if (!be || !book) return; + ENTER("be = %p", bend); + + if (!be || !book) { LEAVE("(null) args"); return; } pgend_set_book (be, book); @@ -1571,6 +1589,7 @@ /* re-enable events */ pgendEnable(be); gnc_engine_resume_events(); + LEAVE(" "); } /* ============================================================= */ @@ -1768,7 +1787,6 @@ g_list_free (be->blist); be->blist = NULL; } - pgend_set_book (be, qof_session_get_book(session)); /* Parse the sessionid for the hostname, port number and db name. * The expected URL format is @@ -2344,13 +2362,17 @@ void pgendDisable (PGBackend *be) { + ENTER("be = %p", be); if (0 > be->nest_count) { PERR ("too many nested enables"); } be->nest_count ++; PINFO("nest count=%d", be->nest_count); - if (1 < be->nest_count) return; + if (1 < be->nest_count) { + LEAVE("be->nest_count < 1: %d", be->nest_count); + return; + } /* save hooks */ be->snr.load = be->be.load; @@ -2382,6 +2404,8 @@ be->be.percentage = NULL; be->be.events_pending = NULL; be->be.process_events = NULL; + + LEAVE(" "); } /* ============================================================= */ Index: src/backend/postgres/PostgresBackend.h =================================================================== RCS file: /home/cvs/cvsroot/gnucash/src/backend/postgres/PostgresBackend.h,v retrieving revision 1.10 diff -u -r1.10 PostgresBackend.h --- src/backend/postgres/PostgresBackend.h 28 Jun 2003 20:56:30 -0000 1.10 +++ src/backend/postgres/PostgresBackend.h 27 Jul 2003 17:09:05 -0000 @@ -42,6 +42,7 @@ #include "builder.h" #include "qofbackend-p.h" +#include "qofbook.h" typedef struct _pgend PGBackend; @@ -125,6 +126,7 @@ Transaction * pgendTransLookup (PGBackend *be, const GUID *txn_guid); Split * pgendSplitLookup (PGBackend *be, const GUID *split_guid); QofIdType pgendGUIDType (PGBackend *be, const GUID *guid); +QofBook * pgendGetBook(PGBackend *pbe); void pgendDisable (PGBackend *be); void pgendEnable (PGBackend *be); Index: src/backend/postgres/book.c =================================================================== RCS file: /home/cvs/cvsroot/gnucash/src/backend/postgres/book.c,v retrieving revision 1.9 diff -u -r1.9 book.c --- src/backend/postgres/book.c 28 Jun 2003 20:56:31 -0000 1.9 +++ src/backend/postgres/book.c 27 Jul 2003 17:09:05 -0000 @@ -130,7 +130,7 @@ /* ============================================================= */ /* ============================================================= */ -/* The pgendGetBook() routine restores the all book data, +/* The pgendBookRestore() routine restores the all book data, * including the account heirarchy, the price db, commodities, etc. */ @@ -155,7 +155,7 @@ } void -pgendGetBook (PGBackend *be, QofBook *book) +pgendBookRestore (PGBackend *be, QofBook *book) { char * bufp; Index: src/backend/postgres/book.h =================================================================== RCS file: /home/cvs/cvsroot/gnucash/src/backend/postgres/book.h,v retrieving revision 1.5 diff -u -r1.5 book.h --- src/backend/postgres/book.h 28 Jun 2003 20:56:31 -0000 1.5 +++ src/backend/postgres/book.h 27 Jul 2003 17:09:05 -0000 @@ -32,7 +32,7 @@ QofBookList * pgendGetAllBooks (PGBackend *be, QofBookList *); -void pgendGetBook (PGBackend *be, QofBook *book); +void pgendBookRestore (PGBackend *be, QofBook *book); void pgendStoreBookNoLock (PGBackend *be, QofBook *book, int do_check_version); void pgendStoreBook (PGBackend *be, QofBook *book); Index: src/backend/postgres/escape.c =================================================================== RCS file: /home/cvs/cvsroot/gnucash/src/backend/postgres/escape.c,v retrieving revision 1.4 diff -u -r1.4 escape.c --- src/backend/postgres/escape.c 28 Jun 2003 20:56:32 -0000 1.4 +++ src/backend/postgres/escape.c 27 Jul 2003 17:09:05 -0000 @@ -59,16 +59,23 @@ char *dst_tail; size_t len, slen; - if (!b || !str) return NULL; + ENTER("str = %s", str); + + if (!b || !str) { LEAVE("(null) args"); return NULL; } /* if a string is escaped twice, just return the first */ - if (b->escape == str) - return str; + if (b->escape == str) { + LEAVE("%s: already escaped", str); + return str; + } /* if nothing to escape, just return */ len = strlen (str); slen = strcspn (str, "\\\'"); - if (len == slen) return str; + if (len == slen) { + LEAVE("nothing to escape"); + return str; + } /* count to see how much space we'll need */ p = str + slen + 1; @@ -112,6 +119,7 @@ } *dst_tail = 0; + LEAVE("b->escape = %s", b->escape); return b->escape; } Index: src/backend/postgres/price.c =================================================================== RCS file: /home/cvs/cvsroot/gnucash/src/backend/postgres/price.c,v retrieving revision 1.19 diff -u -r1.19 price.c --- src/backend/postgres/price.c 28 Jun 2003 20:56:34 -0000 1.19 +++ src/backend/postgres/price.c 27 Jul 2003 17:09:05 -0000 @@ -363,7 +363,7 @@ char * p; ENTER ("be=%p, lookup=%p", be, look); - if (!be || !look) return; + if (!be || !look) { LEAVE("(null) args"); return; } /* special case the two-way search in terms of more basic primitives */ if (LOOKUP_NEAREST_IN_TIME == look->type) @@ -372,6 +372,7 @@ pgendPriceFind (bend, look); look->type = LOOKUP_EARLIEST_AFTER; pgendPriceFind (bend, look); + LEAVE(" "); return; } @@ -389,10 +390,16 @@ p = stpcpy (p, "SELECT * FROM gncPrice" " WHERE commodity='"); p = stpcpy (p, sqlEscapeString (escape, commodity_str)); - p = stpcpy (p, "' AND currency='"); - p = stpcpy (p, sqlEscapeString (escape, currency_str)); p = stpcpy (p, "' "); + if (currency_str) { + p = stpcpy (p, "AND currency='"); + p = stpcpy (p, sqlEscapeString (escape, currency_str)); + p = stpcpy (p, "' "); + } + + PINFO("query = %s", be->buff); + sqlEscape_destroy (escape); escape = NULL; @@ -429,6 +436,7 @@ /* re-enable events */ pgendEnable(be); gnc_engine_resume_events(); + LEAVE(" "); return; } @@ -442,6 +450,7 @@ /* re-enable events */ pgendEnable(be); gnc_engine_resume_events(); + LEAVE(" "); } /* ============================================================= */
signature.asc
Description: This is a digitally signed message part
_______________________________________________ gnucash-devel mailing list [EMAIL PROTECTED] http://www.gnucash.org/cgi-bin/mailman/listinfo/gnucash-devel