mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
* 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 git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8953 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
038ead6db7
commit
41ecc8eab0
19
ChangeLog
19
ChangeLog
@ -1,3 +1,22 @@
|
||||
2003-07-27 Matt Vanecek <mevanecek@yahoo.com>
|
||||
|
||||
* 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 <derek@ihtfp.com>
|
||||
|
||||
* src/engine/qofbackend.h: add a new error, ERR_BACKEND_READONLY
|
||||
|
@ -217,6 +217,17 @@ pgendGUIDType (PGBackend *be, const GUID *guid)
|
||||
|
||||
/* ============================================================= */
|
||||
|
||||
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 @@ query_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
}
|
||||
else
|
||||
{
|
||||
trans = xaccMallocTransaction(be->book);
|
||||
trans = xaccMallocTransaction(pgendGetBook(be));
|
||||
xaccTransBeginEdit (trans);
|
||||
xaccTransSetGUID (trans, &trans_guid);
|
||||
}
|
||||
@ -452,7 +463,8 @@ query_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
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 @@ pgendFillOutToCheckpoint (PGBackend *be, const char *query_string)
|
||||
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 @@ pgendRunQuery (QofBackend *bend, gpointer q_p)
|
||||
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 @@ pgendRunQuery (QofBackend *bend, gpointer q_p)
|
||||
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,13 @@ pgend_book_load_poll (QofBackend *bend, QofBook *book)
|
||||
|
||||
if (be->blist)
|
||||
{
|
||||
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 ");
|
||||
*/
|
||||
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 +1532,17 @@ pgend_book_load_single (QofBackend *bend, QofBook *book)
|
||||
pgendDisable(be);
|
||||
be->version_check = (guint32) time(0);
|
||||
|
||||
pgend_set_book (be, book);
|
||||
|
||||
pgendKVPInit(be);
|
||||
|
||||
if (be->blist)
|
||||
{
|
||||
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 ");
|
||||
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 +1563,9 @@ pgend_price_load_single (QofBackend *bend, QofBook *book)
|
||||
{
|
||||
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 +1579,7 @@ pgend_price_load_single (QofBackend *bend, QofBook *book)
|
||||
/* re-enable events */
|
||||
pgendEnable(be);
|
||||
gnc_engine_resume_events();
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
@ -1768,7 +1777,6 @@ pgend_session_begin (QofBackend *backend,
|
||||
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 +2352,17 @@ pgend_session_begin (QofBackend *backend,
|
||||
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 +2394,8 @@ pgendDisable (PGBackend *be)
|
||||
be->be.percentage = NULL;
|
||||
be->be.events_pending = NULL;
|
||||
be->be.process_events = NULL;
|
||||
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
#include "builder.h"
|
||||
#include "qofbackend-p.h"
|
||||
#include "qofbook.h"
|
||||
|
||||
typedef struct _pgend PGBackend;
|
||||
|
||||
@ -125,6 +126,7 @@ Account * pgendAccountLookup (PGBackend *be, const GUID *acct_guid);
|
||||
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);
|
||||
|
@ -130,7 +130,7 @@ pgendStoreBook (PGBackend *be, QofBook *book)
|
||||
/* ============================================================= */
|
||||
|
||||
/* ============================================================= */
|
||||
/* 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 @@ get_one_book_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
}
|
||||
|
||||
void
|
||||
pgendGetBook (PGBackend *be, QofBook *book)
|
||||
pgendBookRestore (PGBackend *be, QofBook *book)
|
||||
{
|
||||
char * bufp;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -59,16 +59,23 @@ sqlEscapeString (sqlEscape *b, const char *str)
|
||||
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 @@ sqlEscapeString (sqlEscape *b, const char *str)
|
||||
}
|
||||
*dst_tail = 0;
|
||||
|
||||
LEAVE("b->escape = %s", b->escape);
|
||||
return b->escape;
|
||||
}
|
||||
|
||||
|
@ -363,7 +363,7 @@ pgendPriceFind (QofBackend *bend, gpointer olook)
|
||||
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 (QofBackend *bend, gpointer olook)
|
||||
pgendPriceFind (bend, look);
|
||||
look->type = LOOKUP_EARLIEST_AFTER;
|
||||
pgendPriceFind (bend, look);
|
||||
LEAVE(" ");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -389,10 +390,16 @@ pgendPriceFind (QofBackend *bend, gpointer olook)
|
||||
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 @@ pgendPriceFind (QofBackend *bend, gpointer olook)
|
||||
/* re-enable events */
|
||||
pgendEnable(be);
|
||||
gnc_engine_resume_events();
|
||||
LEAVE(" ");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -442,6 +450,7 @@ pgendPriceFind (QofBackend *bend, gpointer olook)
|
||||
/* re-enable events */
|
||||
pgendEnable(be);
|
||||
gnc_engine_resume_events();
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
|
Loading…
Reference in New Issue
Block a user