port the postgres backend sot that it now compiles /.w qof

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8799 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2003-06-28 20:56:43 +00:00
parent d181d075b8
commit 2bf5f33c44
26 changed files with 457 additions and 452 deletions

View File

@ -40,12 +40,8 @@
#include <libpq-fe.h> #include <libpq-fe.h>
#include "AccountP.h" #include "AccountP.h"
#include "Backend.h"
#include "BackendP.h"
#include "Group.h" #include "Group.h"
#include "GroupP.h" #include "GroupP.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"
@ -54,8 +50,12 @@
#include "gnc-pricedb.h" #include "gnc-pricedb.h"
#include "gnc-pricedb-p.h" #include "gnc-pricedb-p.h"
#include "guid.h" #include "guid.h"
#include "GNCId.h" #include "qofbackend.h"
#include "qofbackend-p.h"
#include "qofid.h"
#include "qofid-p.h" #include "qofid-p.h"
#include "qofbook.h"
#include "qofbook-p.h"
#include "TransactionP.h" #include "TransactionP.h"
#include "account.h" #include "account.h"
@ -152,7 +152,7 @@ pgendAccountLookup (PGBackend *be, const GUID *acct_guid)
ENTER("guid = %s", guid_to_string(acct_guid)); ENTER("guid = %s", guid_to_string(acct_guid));
for (node=be->blist; node; node=node->next) for (node=be->blist; node; node=node->next)
{ {
GNCBook *book = node->data; QofBook *book = node->data;
acc = xaccAccountLookup (acct_guid, book); acc = xaccAccountLookup (acct_guid, book);
if (acc) { LEAVE("acc = %p", acc); return acc; } if (acc) { LEAVE("acc = %p", acc); return acc; }
} }
@ -170,7 +170,7 @@ pgendTransLookup (PGBackend *be, const GUID *txn_guid)
ENTER("guid = %s", guid_to_string(txn_guid)); ENTER("guid = %s", guid_to_string(txn_guid));
for (node=be->blist; node; node=node->next) for (node=be->blist; node; node=node->next)
{ {
GNCBook *book = node->data; QofBook *book = node->data;
txn = xaccTransLookup (txn_guid, book); txn = xaccTransLookup (txn_guid, book);
if (txn) { LEAVE("txt = %p", txn); return txn; } if (txn) { LEAVE("txt = %p", txn); return txn; }
} }
@ -188,7 +188,7 @@ pgendSplitLookup (PGBackend *be, const GUID *split_guid)
ENTER("guid = %s", guid_to_string(split_guid)); ENTER("guid = %s", guid_to_string(split_guid));
for (node=be->blist; node; node=node->next) for (node=be->blist; node; node=node->next)
{ {
GNCBook *book = node->data; QofBook *book = node->data;
split = xaccSplitLookup (split_guid, book); split = xaccSplitLookup (split_guid, book);
if (split) { LEAVE("split = %p", split); return split; } if (split) { LEAVE("split = %p", split); return split; }
} }
@ -197,17 +197,17 @@ pgendSplitLookup (PGBackend *be, const GUID *split_guid)
return NULL; return NULL;
} }
GNCIdType QofIdType
pgendGUIDType (PGBackend *be, const GUID *guid) pgendGUIDType (PGBackend *be, const GUID *guid)
{ {
GList *node; GList *node;
GNCIdType tip = GNC_ID_NONE; QofIdType tip = GNC_ID_NONE;
ENTER("guid = %s", guid_to_string(guid)); ENTER("guid = %s", guid_to_string(guid));
for (node=be->blist; node; node=node->next) for (node=be->blist; node; node=node->next)
{ {
GNCBook *book = node->data; QofBook *book = node->data;
tip = xaccGUIDType (guid, book); tip = qof_entity_type (qof_book_get_entity_table(book), guid);
if (GNC_ID_NONE != tip) { LEAVE("tip = %s", tip); return tip; } if (GNC_ID_NONE != tip) { LEAVE("tip = %s", tip); return tip; }
} }
@ -218,7 +218,7 @@ pgendGUIDType (PGBackend *be, const GUID *guid)
/* ============================================================= */ /* ============================================================= */
static void static void
pgend_set_book (PGBackend *be, GNCBook *book) pgend_set_book (PGBackend *be, QofBook *book)
{ {
GList *node; GList *node;
be->book = book; be->book = book;
@ -237,7 +237,7 @@ pgend_set_book (PGBackend *be, GNCBook *book)
*/ */
gnc_commodity * gnc_commodity *
gnc_string_to_commodity (const char *str, GNCBook *book) gnc_string_to_commodity (const char *str, QofBook *book)
{ {
gnc_commodity_table *comtab; gnc_commodity_table *comtab;
gnc_commodity *com; gnc_commodity *com;
@ -677,18 +677,18 @@ pgendFillOutToCheckpoint (PGBackend *be, const char *query_string)
} }
static gpointer static gpointer
pgendCompileQuery (Backend *bend, Query *q) pgendCompileQuery (QofBackend *bend, Query *q)
{ {
return q; return q;
} }
static void static void
pgendFreeQuery (Backend *bend, gpointer q) pgendFreeQuery (QofBackend *bend, gpointer q)
{ {
} }
static void static void
pgendRunQuery (Backend *bend, gpointer q_p) pgendRunQuery (QofBackend *bend, gpointer q_p)
{ {
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
Query *q = (Query*) q_p; Query *q = (Query*) q_p;
@ -763,7 +763,7 @@ get_all_trans_cb (PGBackend *be, PGresult *result, int j, gpointer data)
GUID *trans_guid; GUID *trans_guid;
/* find the transaction this goes into */ /* find the transaction this goes into */
trans_guid = xaccGUIDMalloc(); trans_guid = guid_malloc();
*trans_guid = nullguid; /* just in case the read fails ... */ *trans_guid = nullguid; /* just in case the read fails ... */
string_to_guid (DB_GET_VAL("transGUID",j), trans_guid); string_to_guid (DB_GET_VAL("transGUID",j), trans_guid);
@ -788,7 +788,7 @@ pgendGetAllTransactions (PGBackend *be, AccountGroup *grp)
for (node=xaction_list; node; node=node->next) for (node=xaction_list; node; node=node->next)
{ {
xxxpgendCopyTransactionToEngine (be, (GUID *)node->data); xxxpgendCopyTransactionToEngine (be, (GUID *)node->data);
xaccGUIDFree (node->data); guid_free (node->data);
} }
g_list_free(xaction_list); g_list_free(xaction_list);
xaccAccountGroupCommitEdit (grp); xaccAccountGroupCommitEdit (grp);
@ -848,7 +848,7 @@ pgendGetAllTransactions (PGBackend *be, AccountGroup *grp)
static void static void
pgendSync (Backend *bend, GNCBook *book) pgendSync (QofBackend *bend, QofBook *book)
{ {
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
AccountGroup *grp = gnc_book_get_group (book); AccountGroup *grp = gnc_book_get_group (book);
@ -932,7 +932,7 @@ trans_traverse_cb (Transaction *trans, void *cb_data)
} }
static void static void
pgendSyncSingleFile (Backend *bend, GNCBook *book) pgendSyncSingleFile (QofBackend *bend, QofBook *book)
{ {
char book_guid[40]; char book_guid[40];
char buff[4000]; char buff[4000];
@ -956,7 +956,7 @@ pgendSyncSingleFile (Backend *bend, GNCBook *book)
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); guid_to_string_buff (qof_book_get_guid(book), book_guid);
/* First, we delete all of the accounts, splits and transactions /* First, we delete all of the accounts, splits and transactions
* associated with this book. Its very tempting to just delete * associated with this book. Its very tempting to just delete
@ -1026,7 +1026,7 @@ pgendSyncSingleFile (Backend *bend, GNCBook *book)
*/ */
static void static void
pgendSyncPriceDB (Backend *bend, GNCBook *book) pgendSyncPriceDB (QofBackend *bend, QofBook *book)
{ {
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
ENTER ("be=%p", be); ENTER ("be=%p", be);
@ -1079,7 +1079,7 @@ pgendSyncPriceDB (Backend *bend, GNCBook *book)
*/ */
static void static void
pgendSyncPriceDBSingleFile (Backend *bend, GNCBook *book) pgendSyncPriceDBSingleFile (QofBackend *bend, QofBook *book)
{ {
char buff[400], *p; char buff[400], *p;
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
@ -1091,7 +1091,7 @@ pgendSyncPriceDBSingleFile (Backend *bend, GNCBook *book)
p = stpcpy (p, "BEGIN;\n" p = stpcpy (p, "BEGIN;\n"
"LOCK TABLE gncPrice IN EXCLUSIVE MODE;\n" "LOCK TABLE gncPrice IN EXCLUSIVE MODE;\n"
"DELETE FROM gncPrice WHERE bookGuid='\n"); "DELETE FROM gncPrice WHERE bookGuid='\n");
p = guid_to_string_buff (gnc_book_get_guid(book), p); p = guid_to_string_buff (qof_book_get_guid(book), p);
p = stpcpy (p, "';"); p = stpcpy (p, "';");
SEND_QUERY (be,buff, ); SEND_QUERY (be,buff, );
FINISH_QUERY(be->connection); FINISH_QUERY(be->connection);
@ -1132,13 +1132,13 @@ pgendSessionGetMode (PGBackend *be)
/* Instead of loading the book, just set the lock error */ /* Instead of loading the book, just set the lock error */
static void static void
pgend_book_load_single_lockerr (Backend *bend, GNCBook *book) pgend_book_load_single_lockerr (QofBackend *bend, QofBook *book)
{ {
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
if (!be) return; if (!be) return;
xaccBackendSetError (&be->be, ERR_BACKEND_LOCKED); qof_backend_set_error (&be->be, ERR_BACKEND_LOCKED);
} }
/* ============================================================= */ /* ============================================================= */
@ -1267,7 +1267,7 @@ pgendSessionValidate (PGBackend *be, int break_lock)
is_gnucash_cb, is_gnucash_cb,
GINT_TO_POINTER (FALSE))); GINT_TO_POINTER (FALSE)));
if (FALSE == retval) { if (FALSE == retval) {
xaccBackendSetError (&be->be, ERR_BACKEND_DATA_CORRUPT); qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT);
return FALSE; return FALSE;
} }
@ -1305,7 +1305,7 @@ pgendSessionValidate (PGBackend *be, int break_lock)
if (FALSE == retval) if (FALSE == retval)
{ {
xaccBackendSetError (&be->be, ERR_BACKEND_PERM); qof_backend_set_error (&be->be, ERR_BACKEND_PERM);
p = "ROLLBACK;"; p = "ROLLBACK;";
SEND_QUERY (be,p, FALSE); SEND_QUERY (be,p, FALSE);
FINISH_QUERY(be->connection); FINISH_QUERY(be->connection);
@ -1321,12 +1321,12 @@ pgendSessionValidate (PGBackend *be, int break_lock)
* (The GUI allows users to break the lock, if desired). * (The GUI allows users to break the lock, if desired).
*/ */
be->be.load = pgend_book_load_single_lockerr; be->be.load = pgend_book_load_single_lockerr;
xaccBackendSetError (&be->be, ERR_BACKEND_LOCKED); qof_backend_set_error (&be->be, ERR_BACKEND_LOCKED);
retval = FALSE; retval = FALSE;
} else { } else {
/* make note of the session. */ /* make note of the session. */
be->sessionGuid = xaccGUIDMalloc(); be->sessionGuid = guid_malloc();
guid_new (be->sessionGuid); guid_new (be->sessionGuid);
guid_to_string_buff (be->sessionGuid, be->session_guid_str); guid_to_string_buff (be->sessionGuid, be->session_guid_str);
pgendStoreOneSessionOnly (be, (void *)-1, SQL_INSERT); pgendStoreOneSessionOnly (be, (void *)-1, SQL_INSERT);
@ -1375,7 +1375,7 @@ pgendSessionEnd (PGBackend *be)
SEND_QUERY (be,be->buff, ); SEND_QUERY (be,be->buff, );
FINISH_QUERY(be->connection); FINISH_QUERY(be->connection);
xaccGUIDFree (be->sessionGuid); be->sessionGuid = NULL; guid_free (be->sessionGuid); be->sessionGuid = NULL;
guid_to_string_buff (&nullguid, be->session_guid_str); guid_to_string_buff (&nullguid, be->session_guid_str);
} }
@ -1387,7 +1387,7 @@ pgendSessionEnd (PGBackend *be)
*/ */
static void static void
pgend_session_end (Backend *bend) pgend_session_end (QofBackend *bend)
{ {
int i; int i;
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
@ -1458,7 +1458,7 @@ pgend_session_end (Backend *bend)
* and never the transactions, need to be loaded. * and never the transactions, need to be loaded.
*/ */
static void static void
pgend_book_load_poll (Backend *bend, GNCBook *book) pgend_book_load_poll (QofBackend *bend, QofBook *book)
{ {
Timespec ts = gnc_iso8601_to_timespec_local (CK_BEFORE_LAST_DATE); Timespec ts = gnc_iso8601_to_timespec_local (CK_BEFORE_LAST_DATE);
AccountGroup *grp; AccountGroup *grp;
@ -1486,10 +1486,10 @@ pgend_book_load_poll (Backend *bend, GNCBook *book)
} }
pgend_set_book (be, book); pgend_set_book (be, book);
pgendGetBook (be, book); pgendGetBook (be, book);
gnc_session_set_book(be->session, book); qof_session_set_book(be->session, book);
PINFO("Book GUID = %s\n", PINFO("Book GUID = %s\n",
guid_to_string(gnc_book_get_guid(book))); guid_to_string(qof_book_get_guid(book)));
pgendGetAllAccountsInBook (be, book); pgendGetAllAccountsInBook (be, book);
@ -1512,7 +1512,7 @@ pgend_book_load_poll (Backend *bend, GNCBook *book)
*/ */
static void static void
pgend_book_load_single (Backend *bend, GNCBook *book) pgend_book_load_single (QofBackend *bend, QofBook *book)
{ {
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
@ -1553,7 +1553,7 @@ pgend_book_load_single (Backend *bend, GNCBook *book)
*/ */
static void static void
pgend_price_load_single (Backend *bend, GNCBook *book) pgend_price_load_single (QofBackend *bend, QofBook *book)
{ {
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
@ -1575,13 +1575,13 @@ pgend_price_load_single (Backend *bend, GNCBook *book)
/* ============================================================= */ /* ============================================================= */
/* /*
* These are the Backend Entry Points, which call into the various * These are the QofBackend Entry Points, which call into the various
* functions herein.. These are generic, and (eventually) pluggable. * functions herein.. These are generic, and (eventually) pluggable.
* *
*/ */
static void static void
pgend_do_load_single (Backend *bend, GNCBook *book) pgend_do_load_single (QofBackend *bend, QofBook *book)
{ {
ENTER ("be=%p", bend); ENTER ("be=%p", bend);
pgend_book_load_single (bend, book); pgend_book_load_single (bend, book);
@ -1592,7 +1592,7 @@ pgend_do_load_single (Backend *bend, GNCBook *book)
} }
static void static void
pgendDoSyncSingleFile (Backend *bend, GNCBook *book) pgendDoSyncSingleFile (QofBackend *bend, QofBook *book)
{ {
ENTER ("be=%p", bend); ENTER ("be=%p", bend);
pgendSyncSingleFile (bend, book); pgendSyncSingleFile (bend, book);
@ -1603,7 +1603,7 @@ pgendDoSyncSingleFile (Backend *bend, GNCBook *book)
} }
static void static void
pgendDoSync (Backend *bend, GNCBook *book) pgendDoSync (QofBackend *bend, QofBook *book)
{ {
ENTER ("be=%p", bend); ENTER ("be=%p", bend);
pgendSync (bend, book); pgendSync (bend, book);
@ -1614,7 +1614,7 @@ pgendDoSync (Backend *bend, GNCBook *book)
} }
static void static void
pgend_do_begin (Backend *bend, GNCIdTypeConst type, gpointer object) pgend_do_begin (QofBackend *bend, QofIdTypeConst type, gpointer object)
{ {
PGBackend *be = (PGBackend*)bend; PGBackend *be = (PGBackend*)bend;
@ -1639,7 +1639,7 @@ pgend_do_begin (Backend *bend, GNCIdTypeConst type, gpointer object)
} }
static void static void
pgend_do_commit (Backend *bend, GNCIdTypeConst type, gpointer object) pgend_do_commit (QofBackend *bend, QofIdTypeConst type, gpointer object)
{ {
PGBackend *be = (PGBackend*)bend; PGBackend *be = (PGBackend*)bend;
@ -1674,7 +1674,7 @@ pgend_do_commit (Backend *bend, GNCIdTypeConst type, gpointer object)
} }
static void static void
pgend_do_rollback (Backend *bend, GNCIdTypeConst type, gpointer object) pgend_do_rollback (QofBackend *bend, QofIdTypeConst type, gpointer object)
{ {
PGBackend *be = (PGBackend*)bend; PGBackend *be = (PGBackend*)bend;
@ -1734,8 +1734,8 @@ pgend_create_db (PGBackend *be)
} }
static void static void
pgend_session_begin (Backend *backend, pgend_session_begin (QofBackend *backend,
GNCSession *session, QofSession *session,
const char * sessionid, const char * sessionid,
gboolean ignore_lock, gboolean ignore_lock,
gboolean create_new_db) gboolean create_new_db)
@ -1756,7 +1756,7 @@ pgend_session_begin (Backend *backend,
sessionid ? sessionid : "(null)"); sessionid ? sessionid : "(null)");
/* close any dangling sessions from before; reinitialize */ /* close any dangling sessions from before; reinitialize */
pgend_session_end ((Backend *) be); pgend_session_end ((QofBackend *) be);
pgendInit (be); pgendInit (be);
be->session = session; be->session = session;
@ -1768,7 +1768,7 @@ pgend_session_begin (Backend *backend,
g_list_free (be->blist); g_list_free (be->blist);
be->blist = NULL; be->blist = NULL;
} }
pgend_set_book (be, gnc_session_get_book(session)); pgend_set_book (be, qof_session_get_book(session));
/* Parse the sessionid for the hostname, port number and db name. /* Parse the sessionid for the hostname, port number and db name.
* The expected URL format is * The expected URL format is
@ -1785,7 +1785,7 @@ pgend_session_begin (Backend *backend,
if (strncmp (sessionid, "postgres://", 11)) if (strncmp (sessionid, "postgres://", 11))
{ {
xaccBackendSetError (&be->be, ERR_BACKEND_BAD_URL); qof_backend_set_error (&be->be, ERR_BACKEND_BAD_URL);
return; return;
} }
url = g_strdup(sessionid); url = g_strdup(sessionid);
@ -1812,7 +1812,7 @@ pgend_session_begin (Backend *backend,
start = end+1; start = end+1;
if (0x0 == *start) if (0x0 == *start)
{ {
xaccBackendSetError (&be->be, ERR_BACKEND_BAD_URL); qof_backend_set_error (&be->be, ERR_BACKEND_BAD_URL);
g_free(url); g_free(url);
return; return;
} }
@ -1849,7 +1849,7 @@ pgend_session_begin (Backend *backend,
PWARN ("the following message should be shown in a gui"); PWARN ("the following message should be shown in a gui");
PWARN ("unknown mode %s, will use multi-user mode", PWARN ("unknown mode %s, will use multi-user mode",
start ? start : "(null)"); start ? start : "(null)");
xaccBackendSetMessage((Backend *)be, _("Unknown database access mode '%s'. Using default mode: multi-user."), qof_backend_set_message((QofBackend *)be, _("Unknown database access mode '%s'. Using default mode: multi-user."),
start ? start : "(null)"); start ? start : "(null)");
be->session_mode = MODE_EVENT; be->session_mode = MODE_EVENT;
} }
@ -1966,8 +1966,8 @@ pgend_session_begin (Backend *backend,
/* I wish that postgres returned usable error codes. /* I wish that postgres returned usable error codes.
* Alas, it does not, so we just bomb out. * Alas, it does not, so we just bomb out.
*/ */
xaccBackendSetError (&be->be, ERR_BACKEND_CANT_CONNECT); qof_backend_set_error (&be->be, ERR_BACKEND_CANT_CONNECT);
xaccBackendSetMessage(&be->be, msg); qof_backend_set_message(&be->be, msg);
return; return;
} }
@ -1991,12 +1991,12 @@ pgend_session_begin (Backend *backend,
/* Weird. We couldn't connect to the database, but it /* Weird. We couldn't connect to the database, but it
* does seem to exist. I presume that this is some * does seem to exist. I presume that this is some
* sort of access control problem. */ * sort of access control problem. */
xaccBackendSetError (&be->be, ERR_BACKEND_PERM); qof_backend_set_error (&be->be, ERR_BACKEND_PERM);
return; return;
} }
/* Let GUI know that we connected, but we couldn't find it. */ /* Let GUI know that we connected, but we couldn't find it. */
xaccBackendSetError (&be->be, ERR_BACKEND_NO_SUCH_DB); qof_backend_set_error (&be->be, ERR_BACKEND_NO_SUCH_DB);
return; return;
} }
@ -2017,7 +2017,7 @@ pgend_session_begin (Backend *backend,
* upgrade the database contents. */ * upgrade the database contents. */
PQfinish (be->connection); PQfinish (be->connection);
be->connection = NULL; be->connection = NULL;
xaccBackendSetError (&be->be, ERR_SQL_DB_TOO_OLD); qof_backend_set_error (&be->be, ERR_SQL_DB_TOO_OLD);
return; return;
} }
} }
@ -2049,7 +2049,7 @@ pgend_session_begin (Backend *backend,
/* I wish that postgres returned usable error codes. /* I wish that postgres returned usable error codes.
* Alas, it does not, so we just bomb out. * Alas, it does not, so we just bomb out.
*/ */
xaccBackendSetError (&be->be, ERR_BACKEND_CANT_CONNECT); qof_backend_set_error (&be->be, ERR_BACKEND_CANT_CONNECT);
return; return;
} }
@ -2106,7 +2106,7 @@ pgend_session_begin (Backend *backend,
be->connection = NULL; be->connection = NULL;
/* We just created the database! If we can't connect now, /* We just created the database! If we can't connect now,
* the server is insane! */ * the server is insane! */
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);
return; return;
} }
@ -2148,7 +2148,7 @@ pgend_session_begin (Backend *backend,
* just not to this database. Therefore, it must be a * just not to this database. Therefore, it must be a
* permission problem. * permission problem.
*/ */
xaccBackendSetError (&be->be, ERR_BACKEND_PERM); qof_backend_set_error (&be->be, ERR_BACKEND_PERM);
return; return;
} }
@ -2193,7 +2193,7 @@ pgend_session_begin (Backend *backend,
p = "COMMIT;\n"; p = "COMMIT;\n";
SEND_QUERY (be,p, ); SEND_QUERY (be,p, );
FINISH_QUERY(be->connection); FINISH_QUERY(be->connection);
xaccBackendSetError (&be->be, ERR_SQL_DB_BUSY); qof_backend_set_error (&be->be, ERR_SQL_DB_BUSY);
return; return;
} }
pgendUpgradeDB (be); pgendUpgradeDB (be);
@ -2431,7 +2431,7 @@ pgendInit (PGBackend *be)
ENTER(" "); ENTER(" ");
/* initialize global variable */ /* initialize global variable */
nullguid = *(xaccGUIDNULL()); nullguid = *(guid_null());
/* access mode */ /* access mode */
be->session_mode = MODE_EVENT; be->session_mode = MODE_EVENT;
@ -2439,7 +2439,7 @@ pgendInit (PGBackend *be)
guid_to_string_buff (&nullguid, be->session_guid_str); guid_to_string_buff (&nullguid, be->session_guid_str);
/* generic backend handlers */ /* generic backend handlers */
xaccInitBackend((Backend*)be); qof_backend_init((QofBackend*)be);
be->be.session_begin = pgend_session_begin; be->be.session_begin = pgend_session_begin;
be->be.session_end = pgend_session_end; be->be.session_end = pgend_session_end;
@ -2497,7 +2497,7 @@ pgendInit (PGBackend *be)
/* ============================================================= */ /* ============================================================= */
Backend * QofBackend *
pgendNew (void) pgendNew (void)
{ {
PGBackend *be; PGBackend *be;
@ -2507,7 +2507,7 @@ pgendNew (void)
pgendInit (be); pgendInit (be);
LEAVE(" ") LEAVE(" ")
return (Backend *) be; return (QofBackend *) be;
} }
/* ======================== END OF FILE ======================== */ /* ======================== END OF FILE ======================== */

View File

@ -41,7 +41,7 @@
#include "Transaction.h" #include "Transaction.h"
#include "builder.h" #include "builder.h"
#include "BackendP.h" #include "qofbackend-p.h"
typedef struct _pgend PGBackend; typedef struct _pgend PGBackend;
@ -56,7 +56,7 @@ typedef enum {
#define MAX_VERSION_AGE 10 #define MAX_VERSION_AGE 10
struct _pgend { struct _pgend {
Backend be; QofBackend be;
/* session mode */ /* session mode */
AccessMode session_mode; AccessMode session_mode;
@ -78,7 +78,7 @@ struct _pgend {
/* counter used to nest callback disables */ /* counter used to nest callback disables */
int nest_count; int nest_count;
/* callback hooks are saved in snr during disables */ /* callback hooks are saved in snr during disables */
Backend snr; QofBackend snr;
/* my postgres backend pid, used for telling apart notifies */ /* my postgres backend pid, used for telling apart notifies */
int my_pid; int my_pid;
@ -109,9 +109,9 @@ struct _pgend {
int ipath_max; int ipath_max;
/* engine data caches */ /* engine data caches */
GNCSession *session; QofSession *session;
GNCBook *book; /* the currently open book -- XXX -- depricate ???*/ QofBook *book; /* the currently open book -- XXX -- depricate ???*/
BookList *blist; /* list of books in this db */ QofBookList *blist; /* list of books in this db */
GList *tmp_return; GList *tmp_return;
}; };
@ -119,12 +119,12 @@ struct _pgend {
/* /*
* pgendNew creates a new postgres backend * pgendNew creates a new postgres backend
*/ */
Backend * pgendNew (void); QofBackend * pgendNew (void);
Account * pgendAccountLookup (PGBackend *be, const GUID *acct_guid); Account * pgendAccountLookup (PGBackend *be, const GUID *acct_guid);
Transaction * pgendTransLookup (PGBackend *be, const GUID *txn_guid); Transaction * pgendTransLookup (PGBackend *be, const GUID *txn_guid);
Split * pgendSplitLookup (PGBackend *be, const GUID *split_guid); Split * pgendSplitLookup (PGBackend *be, const GUID *split_guid);
GNCIdType pgendGUIDType (PGBackend *be, const GUID *guid); QofIdType pgendGUIDType (PGBackend *be, const GUID *guid);
void pgendDisable (PGBackend *be); void pgendDisable (PGBackend *be);
void pgendEnable (PGBackend *be); void pgendEnable (PGBackend *be);

View File

@ -32,12 +32,12 @@
#include <libpq-fe.h> #include <libpq-fe.h>
#include "AccountP.h" #include "AccountP.h"
#include "Backend.h" #include "qofbackend.h"
#include "BackendP.h" #include "qofbackend-p.h"
#include "Group.h" #include "Group.h"
#include "GroupP.h" #include "GroupP.h"
#include "gnc-book.h" #include "qofbook.h"
#include "gnc-book-p.h" #include "qofbook-p.h"
#include "gnc-commodity.h" #include "gnc-commodity.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "gnc-event.h" #include "gnc-event.h"
@ -259,7 +259,7 @@ typedef struct
typedef struct typedef struct
{ {
GNCBook * book; QofBook * book;
GList * resolve_info; GList * resolve_info;
} GetAccountData; } GetAccountData;
@ -274,7 +274,7 @@ static gpointer
get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data) get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data)
{ {
GetAccountData * gad = data; GetAccountData * gad = data;
GNCBook * book = gad->book; QofBook * book = gad->book;
Account *parent; Account *parent;
Account *acc; Account *acc;
GUID acct_guid; GUID acct_guid;
@ -325,7 +325,7 @@ get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data)
PINFO ("parent GUID=%s", DB_GET_VAL("parentGUID",j)); PINFO ("parent GUID=%s", DB_GET_VAL("parentGUID",j));
acct_guid = nullguid; /* just in case the read fails ... */ acct_guid = nullguid; /* just in case the read fails ... */
string_to_guid (DB_GET_VAL("parentGUID",j), &acct_guid); string_to_guid (DB_GET_VAL("parentGUID",j), &acct_guid);
if (guid_equal(xaccGUIDNULL(), &acct_guid)) if (guid_equal(guid_null(), &acct_guid))
{ {
/* if the parent guid is null, then this /* if the parent guid is null, then this
* account belongs in the top group */ * account belongs in the top group */
@ -361,7 +361,7 @@ get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data)
} }
static void static void
pgendGetAccounts (PGBackend *be, GNCBook *book) pgendGetAccounts (PGBackend *be, QofBook *book)
{ {
GetAccountData gad; GetAccountData gad;
@ -430,7 +430,7 @@ pgendGetAccounts (PGBackend *be, GNCBook *book)
void void
pgendGetAllAccounts (PGBackend *be) pgendGetAllAccounts (PGBackend *be)
{ {
BookList *node; QofBookList *node;
char * bufp; char * bufp;
ENTER ("be=%p", be); ENTER ("be=%p", be);
@ -449,7 +449,7 @@ pgendGetAllAccounts (PGBackend *be)
for (node=be->blist; node; node=node->next) for (node=be->blist; node; node=node->next)
{ {
GNCBook *book = node->data; QofBook *book = node->data;
AccountGroup *topgrp = gnc_book_get_group (book); AccountGroup *topgrp = gnc_book_get_group (book);
pgendGetAllAccountKVP (be, topgrp); pgendGetAllAccountKVP (be, topgrp);
@ -463,7 +463,7 @@ pgendGetAllAccounts (PGBackend *be)
} }
void void
pgendGetAllAccountsInBook (PGBackend *be, GNCBook *book) pgendGetAllAccountsInBook (PGBackend *be, QofBook *book)
{ {
char *p, buff[400]; char *p, buff[400];
AccountGroup *topgrp; AccountGroup *topgrp;
@ -478,7 +478,7 @@ pgendGetAllAccountsInBook (PGBackend *be, GNCBook *book)
p = buff; p = buff;
p = stpcpy (p, "SELECT * FROM gncAccount WHERE bookGuid='"); p = stpcpy (p, "SELECT * FROM gncAccount WHERE bookGuid='");
p = guid_to_string_buff (gnc_book_get_guid(book), p); p = guid_to_string_buff (qof_book_get_guid(book), p);
p = stpcpy (p, "';"); p = stpcpy (p, "';");
SEND_QUERY (be, buff, ); SEND_QUERY (be, buff, );
pgendGetAccounts (be, book); pgendGetAccounts (be, book);
@ -574,12 +574,12 @@ pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid)
/* ============================================================= */ /* ============================================================= */
void void
pgend_account_commit_edit (Backend * bend, pgend_account_commit_edit (QofBackend * bend,
Account * acct) Account * acct)
{ {
AccountGroup *parent; AccountGroup *parent;
char *p; char *p;
GNCBackendError err; QofBackendError err;
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
ENTER ("be=%p, acct=%p", be, acct); ENTER ("be=%p, acct=%p", be, acct);
@ -617,7 +617,7 @@ pgend_account_commit_edit (Backend * bend,
PWARN(" account data in engine is newer\n" PWARN(" account data in engine is newer\n"
" account must be rolled back. This function\n" " account must be rolled back. This function\n"
" is not completely implemented !! \n"); " is not completely implemented !! \n");
xaccBackendSetError (&be->be, ERR_BACKEND_MODIFIED); qof_backend_set_error (&be->be, ERR_BACKEND_MODIFIED);
LEAVE ("rolled back"); LEAVE ("rolled back");
return; return;
} }

View File

@ -25,12 +25,12 @@
#define POSTGRES_ACCOUNT_H #define POSTGRES_ACCOUNT_H
#include "Group.h" #include "Group.h"
#include "gnc-book.h" #include "qofbook.h"
#include "guid.h" #include "guid.h"
#include "PostgresBackend.h" #include "PostgresBackend.h"
void pgendGetAllAccountsInBook (PGBackend *be, GNCBook *); void pgendGetAllAccountsInBook (PGBackend *be, QofBook *);
void pgendGetAllAccounts (PGBackend *be); void pgendGetAllAccounts (PGBackend *be);
@ -39,6 +39,6 @@ void pgendStoreGroupNoLock (PGBackend *be, AccountGroup *grp,
gboolean do_mark, gboolean do_check_version); gboolean do_mark, gboolean do_check_version);
Account * pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid); Account * pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid);
void pgend_account_commit_edit (Backend * bend, Account * acct); void pgend_account_commit_edit (QofBackend * bend, Account * acct);
#endif /* POSTGRES_ACCOUNT_H */ #endif /* POSTGRES_ACCOUNT_H */

View File

@ -31,10 +31,10 @@
#include <libpq-fe.h> #include <libpq-fe.h>
#include "Backend.h" #include "qofbackend.h"
#include "BackendP.h" #include "qofbackend-p.h"
#include "book.h" #include "book.h"
#include "gnc-book-p.h" #include "qofbook-p.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "gnc-pricedb.h" #include "gnc-pricedb.h"
#include "guid.h" #include "guid.h"
@ -73,7 +73,7 @@ static short module = MOD_BACKEND;
*/ */
void void
pgendStoreBookNoLock (PGBackend *be, GNCBook *book, pgendStoreBookNoLock (PGBackend *be, QofBook *book,
gboolean do_check_version) gboolean do_check_version)
{ {
if (!be || !book) return; if (!be || !book) return;
@ -87,7 +87,7 @@ pgendStoreBookNoLock (PGBackend *be, GNCBook *book,
book->version ++; /* be sure to update the version !! */ book->version ++; /* be sure to update the version !! */
if ((0 == book->idata) && if ((0 == book->idata) &&
(FALSE == kvp_frame_is_empty (gnc_book_get_slots(book)))) (FALSE == kvp_frame_is_empty (qof_book_get_slots(book))))
{ {
book->idata = pgendNewGUIDidx(be); book->idata = pgendNewGUIDidx(be);
} }
@ -103,7 +103,7 @@ pgendStoreBookNoLock (PGBackend *be, GNCBook *book,
} }
void void
pgendStoreBook (PGBackend *be, GNCBook *book) pgendStoreBook (PGBackend *be, QofBook *book)
{ {
char *p; char *p;
ENTER ("be=%p, book=%p", be, book); ENTER ("be=%p, book=%p", be, book);
@ -137,7 +137,7 @@ pgendStoreBook (PGBackend *be, GNCBook *book)
static gpointer static gpointer
get_one_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; QofBook *book = (QofBook *) data;
GUID guid; GUID guid;
/* first, lets see if we've already got this one */ /* first, lets see if we've already got this one */
@ -145,7 +145,7 @@ get_one_book_cb (PGBackend *be, PGresult *result, int j, gpointer data)
guid = nullguid; /* just in case the read fails ... */ guid = nullguid; /* just in case the read fails ... */
string_to_guid (DB_GET_VAL("bookGuid",j), &guid); string_to_guid (DB_GET_VAL("bookGuid",j), &guid);
gnc_book_set_guid (book, guid); qof_book_set_guid (book, guid);
book->book_open = (DB_GET_VAL("book_open",j))[0]; book->book_open = (DB_GET_VAL("book_open",j))[0];
book->version = atoi(DB_GET_VAL("version",j)); book->version = atoi(DB_GET_VAL("version",j));
@ -155,7 +155,7 @@ get_one_book_cb (PGBackend *be, PGresult *result, int j, gpointer data)
} }
void void
pgendGetBook (PGBackend *be, GNCBook *book) pgendGetBook (PGBackend *be, QofBook *book)
{ {
char * bufp; char * bufp;
@ -186,9 +186,9 @@ pgendGetBook (PGBackend *be, GNCBook *book)
static gpointer static gpointer
get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data) get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data)
{ {
BookList *blist = (BookList *) data; QofBookList *blist = (QofBookList *) data;
BookList *node; QofBookList *node;
GNCBook *book; QofBook *book;
GUID guid; GUID guid;
PINFO ("book GUID=%s", DB_GET_VAL("bookGUID",j)); PINFO ("book GUID=%s", DB_GET_VAL("bookGUID",j));
@ -206,8 +206,8 @@ get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data)
if (!book) if (!book)
{ {
book = gnc_book_new(); book = qof_book_new();
gnc_book_set_guid (book, guid); qof_book_set_guid (book, guid);
} }
book->book_open = (DB_GET_VAL("book_open",j))[0]; book->book_open = (DB_GET_VAL("book_open",j))[0];
@ -217,10 +217,10 @@ get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data)
return blist; return blist;
} }
BookList * QofBookList *
pgendGetAllBooks (PGBackend *be, BookList *blist) pgendGetAllBooks (PGBackend *be, QofBookList *blist)
{ {
BookList *node; QofBookList *node;
char * bufp; char * bufp;
ENTER ("be=%p", be); ENTER ("be=%p", be);
@ -234,7 +234,7 @@ pgendGetAllBooks (PGBackend *be, BookList *blist)
/* get the KVP data for each book too */ /* get the KVP data for each book too */
for (node=blist; node; node=node->next) for (node=blist; node; node=node->next)
{ {
GNCBook *book = node->data; QofBook *book = node->data;
if (0 != book->idata) if (0 != book->idata)
{ {
book->kvp_data = pgendKVPFetch (be, book->idata, book->kvp_data); book->kvp_data = pgendKVPFetch (be, book->idata, book->kvp_data);
@ -248,7 +248,7 @@ pgendGetAllBooks (PGBackend *be, BookList *blist)
/* ============================================================= */ /* ============================================================= */
void void
pgend_book_transfer_begin(Backend *bend, GNCBook *newbook) pgend_book_transfer_begin(QofBackend *bend, QofBook *newbook)
{ {
PGBackend *be = (PGBackend *) bend; PGBackend *be = (PGBackend *) bend;
@ -261,7 +261,7 @@ pgend_book_transfer_begin(Backend *bend, GNCBook *newbook)
} }
void void
pgend_book_transfer_commit(Backend *bend, GNCBook *newbook) pgend_book_transfer_commit(QofBackend *bend, QofBook *newbook)
{ {
/* PGBackend *be = (PGBackend *) bend; */ /* PGBackend *be = (PGBackend *) bend; */
ENTER (" "); ENTER (" ");

View File

@ -24,19 +24,19 @@
#ifndef POSTGRES_BOOK_H #ifndef POSTGRES_BOOK_H
#define POSTGRES_BOOK_H #define POSTGRES_BOOK_H
#include "gnc-book.h" #include "qofbook.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "guid.h" #include "guid.h"
#include "PostgresBackend.h" #include "PostgresBackend.h"
BookList * pgendGetAllBooks (PGBackend *be, BookList *); QofBookList * pgendGetAllBooks (PGBackend *be, QofBookList *);
void pgendGetBook (PGBackend *be, GNCBook *book); void pgendGetBook (PGBackend *be, QofBook *book);
void pgendStoreBookNoLock (PGBackend *be, GNCBook *book, int do_check_version); void pgendStoreBookNoLock (PGBackend *be, QofBook *book, int do_check_version);
void pgendStoreBook (PGBackend *be, GNCBook *book); void pgendStoreBook (PGBackend *be, QofBook *book);
void pgend_book_transfer_begin (Backend *, GNCBook*); void pgend_book_transfer_begin (QofBackend *, QofBook*);
void pgend_book_transfer_commit (Backend *, GNCBook*); void pgend_book_transfer_commit (QofBackend *, QofBook*);
#endif /* POSTGRES_BOOK_H */ #endif /* POSTGRES_BOOK_H */

View File

@ -44,13 +44,13 @@
#include "Account.h" #include "Account.h"
#include "AccountP.h" #include "AccountP.h"
#include "Backend.h" #include "qofbackend.h"
#include "BackendP.h" #include "qofbackend-p.h"
#include "Group.h" #include "Group.h"
#include "gnc-commodity.h" #include "gnc-commodity.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "guid.h" #include "guid.h"
#include "GNCId.h" #include "qofid.h"
#include "builder.h" #include "builder.h"
#include "checkpoint.h" #include "checkpoint.h"

View File

@ -28,6 +28,8 @@
* Escapes the ' and \ characters in a string * Escapes the ' and \ characters in a string
*/ */
#include "config.h"
#define _GNU_SOURCE #define _GNU_SOURCE
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>

View File

@ -28,14 +28,14 @@
#include <libpq-fe.h> #include <libpq-fe.h>
#include <stdlib.h> #include <stdlib.h>
#include "Backend.h"
#include "BackendP.h"
#include "events.h" #include "events.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "gnc-event.h" #include "gnc-event.h"
#include "gnc-event-p.h" #include "gnc-event-p.h"
#include "guid.h" #include "guid.h"
#include "GNCId.h" #include "qofbackend.h"
#include "qofbackend-p.h"
#include "qofid.h"
#include "qofid-p.h" #include "qofid-p.h"
#include "PostgresBackend.h" #include "PostgresBackend.h"
@ -53,7 +53,7 @@ static short module = MOD_EVENT;
/* ============================================================= */ /* ============================================================= */
gboolean gboolean
pgendEventsPending (Backend *bend) pgendEventsPending (QofBackend *bend)
{ {
PGBackend *be = (PGBackend *) bend; PGBackend *be = (PGBackend *) bend;
PGnotify *note; PGnotify *note;
@ -140,7 +140,7 @@ typedef struct _event {
Timespec stamp; Timespec stamp;
GNCEngineEventType type; GNCEngineEventType type;
GUID guid; GUID guid;
GNCIdType obj_type; QofIdType obj_type;
} Event; } Event;
@ -155,7 +155,7 @@ get_event_cb (PGBackend *be, PGresult *result, int j, gpointer data)
GNCEngineEventType type; GNCEngineEventType type;
char change = (DB_GET_VAL("change",j))[0]; char change = (DB_GET_VAL("change",j))[0];
char objtype = (DB_GET_VAL("objtype",j))[0]; char objtype = (DB_GET_VAL("objtype",j))[0];
GNCIdType obj_type = GNC_ID_NONE; QofIdType obj_type = GNC_ID_NONE;
guid_str = DB_GET_VAL("guid",j); guid_str = DB_GET_VAL("guid",j);
PINFO ("event %c for %s", change, guid_str); PINFO ("event %c for %s", change, guid_str);
@ -238,7 +238,7 @@ get_event_cb (PGBackend *be, PGresult *result, int j, gpointer data)
} }
gboolean gboolean
pgendProcessEvents (Backend *bend) pgendProcessEvents (QofBackend *bend)
{ {
PGBackend *be = (PGBackend *) bend; PGBackend *be = (PGBackend *) bend;
GList *node, *pending = NULL; GList *node, *pending = NULL;
@ -268,7 +268,7 @@ pgendProcessEvents (Backend *bend)
for (node = pending; node; node = node->next) for (node = pending; node; node = node->next)
{ {
Event *ev = (Event *) node->data; Event *ev = (Event *) node->data;
GNCIdType local_obj_type; QofIdType local_obj_type;
/* lets see if the local cache has this item in it */ /* lets see if the local cache has this item in it */
local_obj_type = pgendGUIDType (be, &(ev->guid)); local_obj_type = pgendGUIDType (be, &(ev->guid));

View File

@ -34,11 +34,11 @@
#ifndef POSTGRES_EVENTS_H #ifndef POSTGRES_EVENTS_H
#define POSTGRES_EVENTS_H #define POSTGRES_EVENTS_H
#include "Backend.h" #include "qofbackend.h"
#include "PostgresBackend.h" #include "PostgresBackend.h"
gboolean pgendEventsPending (Backend *); gboolean pgendEventsPending (QofBackend *);
gboolean pgendProcessEvents (Backend *); gboolean pgendProcessEvents (QofBackend *);
void pgendSessionGetPid (PGBackend *); void pgendSessionGetPid (PGBackend *);
void pgendSessionSetupNotifies (PGBackend *); void pgendSessionSetupNotifies (PGBackend *);

View File

@ -8,7 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include <glib.h> #include <glib.h>
#include "Backend.h" #include "qofbackend.h"
#include "PostgresBackend.h" #include "PostgresBackend.h"
#include "gnc-backend-api.h" #include "gnc-backend-api.h"
@ -17,7 +17,7 @@
/* version of the gnc module system interface we require */ /* version of the gnc module system interface we require */
int libgncmod_backend_postgres_LTX_gnc_module_system_interface = 0; int libgncmod_backend_postgres_LTX_gnc_module_system_interface = 0;
//int libgncmod_backend_postgres_LTX_gnc_module_system_interface = 0;
/* module versioning uses libtool semantics. */ /* module versioning uses libtool semantics. */
int libgncmod_backend_postgres_LTX_gnc_module_current = 0; int libgncmod_backend_postgres_LTX_gnc_module_current = 0;
int libgncmod_backend_postgres_LTX_gnc_module_revision = 0; int libgncmod_backend_postgres_LTX_gnc_module_revision = 0;
@ -30,7 +30,7 @@ char *libgncmod_backend_postgres_LTX_gnc_module_path(void);
char *libgncmod_backend_postgres_LTX_gnc_module_description(void); char *libgncmod_backend_postgres_LTX_gnc_module_description(void);
int libgncmod_backend_postgres_LTX_gnc_module_init(int refcount); int libgncmod_backend_postgres_LTX_gnc_module_init(int refcount);
int libgncmod_backend_postgres_LTX_gnc_module_end(int refcount); int libgncmod_backend_postgres_LTX_gnc_module_end(int refcount);
Backend * libgncmod_backend_postgres_LTX_gnc_backend_new(void); QofBackend * libgncmod_backend_postgres_LTX_gnc_backend_new(void);
char * char *
libgncmod_backend_postgres_LTX_gnc_module_path(void) libgncmod_backend_postgres_LTX_gnc_module_path(void)
@ -76,7 +76,7 @@ libgncmod_backend_postgres_LTX_gnc_module_end(int refcount)
* temporarily * temporarily
****************************************************************/ ****************************************************************/
Backend * QofBackend *
libgncmod_backend_postgres_LTX_gnc_backend_new(void) { libgncmod_backend_postgres_LTX_gnc_backend_new(void) {
return pgendNew(); return pgendNew();
} }

View File

@ -41,16 +41,19 @@
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>
#include "builder.h" #include "Account.h"
#include "escape.h" #include "Transaction.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "gncquery.h"
#include "Transaction.h"
#include "Account.h"
#include "QueryNewP.h" #include "qofquery.h"
#include "QueryCoreP.h" #include "qofquery-p.h"
#include "qofquerycore-p.h"
#include "qofqueryobject.h"
#include "gncquery.h"
#include "builder.h"
#include "escape.h"
static short module = MOD_BACKEND; static short module = MOD_BACKEND;
@ -167,16 +170,16 @@ sql_sort_get_type(char *p, GSList * path)
* done by the Query C code. */ * done by the Query C code. */
static char * static char *
sql_sort_order(char *p, QueryNewSort_t sort) sql_sort_order(char *p, QofQuerySort *sort)
{ {
GSList *path; GSList *path;
gboolean increasing; gboolean increasing;
increasing = gncQuerySortGetIncreasing(sort); increasing = qof_query_sort_get_increasing(sort);
ENTER("incr=%d", increasing); ENTER("incr=%d", increasing);
path = gncQuerySortGetParamPath(sort); path = qof_query_sort_get_param_path(sort);
if (path == NULL) { if (path == NULL) {
/* Ok, we're not sorting on anything here. */ /* Ok, we're not sorting on anything here. */
@ -213,12 +216,12 @@ sql_sort_order(char *p, QueryNewSort_t sort)
/* distinct clauses */ /* distinct clauses */
static char * static char *
sql_sort_distinct(char *p, QueryNewSort_t sort) sql_sort_distinct(char *p, QofQuerySort *sort)
{ {
GSList *path; GSList *path;
ENTER("."); ENTER(".");
path = gncQuerySortGetParamPath(sort); path = qof_query_sort_get_param_path(sort);
if (NULL != path) { if (NULL != path) {
p = stpcpy(p, ", "); p = stpcpy(p, ", ");
@ -242,13 +245,13 @@ sql_sort_distinct(char *p, QueryNewSort_t sort)
/* does sorting require a reference to this particular table? */ /* does sorting require a reference to this particular table? */
static gboolean static gboolean
sql_sort_sort_need_account(QueryNewSort_t sort) sql_sort_sort_need_account(QofQuerySort *sort)
{ {
gboolean need_account = FALSE; gboolean need_account = FALSE;
GSList *path; GSList *path;
ENTER("."); ENTER(".");
path = gncQuerySortGetParamPath(sort); path = qof_query_sort_get_param_path(sort);
if (path) if (path)
if (!safe_strcmp(path->data, SPLIT_ACCT_FULLNAME) || if (!safe_strcmp(path->data, SPLIT_ACCT_FULLNAME) ||
@ -261,12 +264,12 @@ sql_sort_sort_need_account(QueryNewSort_t sort)
} }
static gboolean static gboolean
sql_sort_need_account(Query * q) sql_sort_need_account(QofQuery * q)
{ {
gboolean need_account = FALSE; gboolean need_account = FALSE;
QueryNewSort_t s1, s2, s3; QofQuerySort *s1, *s2, *s3;
gncQueryGetSorts(q, &s1, &s2, &s3); qof_query_get_sorts(q, &s1, &s2, &s3);
need_account = sql_sort_sort_need_account(s1) || need_account = sql_sort_sort_need_account(s1) ||
sql_sort_sort_need_account(s2) || sql_sort_sort_need_account(s3); sql_sort_sort_need_account(s2) || sql_sort_sort_need_account(s3);
@ -278,13 +281,13 @@ sql_sort_need_account(Query * q)
/* does sorting require a reference to this particular table? */ /* does sorting require a reference to this particular table? */
static gboolean static gboolean
sql_sort_sort_need_entry(QueryNewSort_t sort) sql_sort_sort_need_entry(QofQuerySort *sort)
{ {
gboolean need_entry = FALSE; gboolean need_entry = FALSE;
GSList *path; GSList *path;
ENTER("."); ENTER(".");
path = gncQuerySortGetParamPath(sort); path = qof_query_sort_get_param_path(sort);
if (path) if (path)
if (!safe_strcmp(path->data, SPLIT_VALUE) || if (!safe_strcmp(path->data, SPLIT_VALUE) ||
@ -297,12 +300,12 @@ sql_sort_sort_need_entry(QueryNewSort_t sort)
} }
static gboolean static gboolean
sql_sort_need_entry(Query * q) sql_sort_need_entry(QofQuery * q)
{ {
gboolean need_entry = FALSE; gboolean need_entry = FALSE;
QueryNewSort_t s1, s2, s3; QofQuerySort *s1, *s2, *s3;
gncQueryGetSorts(q, &s1, &s2, &s3); qof_query_get_sorts(q, &s1, &s2, &s3);
need_entry = sql_sort_sort_need_entry(s1) || need_entry = sql_sort_sort_need_entry(s1) ||
sql_sort_sort_need_entry(s2) || sql_sort_sort_need_entry(s3); sql_sort_sort_need_entry(s2) || sql_sort_sort_need_entry(s3);
@ -311,7 +314,7 @@ sql_sort_need_entry(Query * q)
} }
/* =========================================================== */ /* =========================================================== */
/* Macro for QUERYCORE_STRING query types /* Macro for QOF_QUERYCORE_STRING query types
* Note that postgres supports both case-sensitive and * Note that postgres supports both case-sensitive and
* case-insensitve string searches, and it also supports * case-insensitve string searches, and it also supports
* regex! yahooo! * regex! yahooo!
@ -323,28 +326,28 @@ sql_sort_need_entry(Query * q)
\ \
if (invert) \ if (invert) \
sq->pq = stpcpy (sq->pq, "NOT ("); \ sq->pq = stpcpy (sq->pq, "NOT ("); \
if (pd->how == COMPARE_NEQ) \ if (pd->how == QOF_COMPARE_NEQ) \
sq->pq = stpcpy (sq->pq, "NOT ("); \ sq->pq = stpcpy (sq->pq, "NOT ("); \
if (pdata->is_regex || pdata->options == STRING_MATCH_CASEINSENSITIVE) \ if (pdata->is_regex || pdata->options == QOF_STRING_MATCH_CASEINSENSITIVE) \
sq->pq = stpcpy(sq->pq, fieldname " ~"); \ sq->pq = stpcpy(sq->pq, fieldname " ~"); \
else \ else \
sq->pq = stpcpy(sq->pq, fieldname " ="); \ sq->pq = stpcpy(sq->pq, fieldname " ="); \
if (pdata->options == STRING_MATCH_CASEINSENSITIVE) { \ if (pdata->options == QOF_STRING_MATCH_CASEINSENSITIVE) { \
sq->pq = stpcpy(sq->pq, "*"); \ sq->pq = stpcpy(sq->pq, "*"); \
} \ } \
sq->pq = stpcpy(sq->pq, " '"); \ sq->pq = stpcpy(sq->pq, " '"); \
tmp = sqlEscapeString (sq->escape, pdata->matchstring); \ tmp = sqlEscapeString (sq->escape, pdata->matchstring); \
sq->pq = stpcpy(sq->pq, tmp); \ sq->pq = stpcpy(sq->pq, tmp); \
sq->pq = stpcpy(sq->pq, "'"); \ sq->pq = stpcpy(sq->pq, "'"); \
if (pd->how == COMPARE_NEQ) \ if (pd->how == QOF_COMPARE_NEQ) \
sq->pq = stpcpy (sq->pq, ") "); \ sq->pq = stpcpy (sq->pq, ") "); \
if (invert) \ if (invert) \
sq->pq = stpcpy (sq->pq, ") "); \ sq->pq = stpcpy (sq->pq, ") "); \
} }
/* =========================================================== */ /* =========================================================== */
/* Macro for QUERYCORE_NUMERIC type terms. The logic used here in the /* Macro for QOF_QUERYCORE_NUMERIC type terms. The logic used here in the
* SQL exactly matches that used in the Query.c code. If * SQL exactly matches that used in the qofquery.c code. If
* that code is incorrect or has changed, then the code below is * that code is incorrect or has changed, then the code below is
* broken as well. * broken as well.
*/ */
@ -358,10 +361,10 @@ sql_sort_need_entry(Query * q)
\ \
switch(pdata->options) \ switch(pdata->options) \
{ \ { \
case NUMERIC_MATCH_CREDIT: \ case QOF_NUMERIC_MATCH_CREDIT: \
sq->pq = stpcpy(sq->pq, signcheck " <= 0 AND "); \ sq->pq = stpcpy(sq->pq, signcheck " <= 0 AND "); \
break; \ break; \
case NUMERIC_MATCH_DEBIT: \ case QOF_NUMERIC_MATCH_DEBIT: \
sq->pq = stpcpy(sq->pq, signcheck " >= 0 AND "); \ sq->pq = stpcpy(sq->pq, signcheck " >= 0 AND "); \
break; \ break; \
default: \ default: \
@ -369,33 +372,33 @@ sql_sort_need_entry(Query * q)
} \ } \
switch(pd->how) \ switch(pd->how) \
{ \ { \
case COMPARE_GTE: \ case QOF_COMPARE_GTE: \
sq->pq = stpcpy(sq->pq, \ sq->pq = stpcpy(sq->pq, \
fieldname " >= "comtable" * float8"); \ fieldname " >= "comtable" * float8"); \
sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \ sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \
break; \ break; \
case COMPARE_GT: \ case QOF_COMPARE_GT: \
sq->pq = stpcpy(sq->pq, \ sq->pq = stpcpy(sq->pq, \
fieldname " > "comtable" * float8"); \ fieldname " > "comtable" * float8"); \
sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \ sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \
break; \ break; \
case COMPARE_LTE: \ case QOF_COMPARE_LTE: \
sq->pq = stpcpy(sq->pq, \ sq->pq = stpcpy(sq->pq, \
fieldname " <= "comtable" * float8"); \ fieldname " <= "comtable" * float8"); \
sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \ sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \
break; \ break; \
case COMPARE_LT: \ case QOF_COMPARE_LT: \
sq->pq = stpcpy(sq->pq, \ sq->pq = stpcpy(sq->pq, \
fieldname " < "comtable" * float8"); \ fieldname " < "comtable" * float8"); \
sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \ sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \
break; \ break; \
case COMPARE_EQUAL: \ case QOF_COMPARE_EQUAL: \
sq->pq = stpcpy(sq->pq, \ sq->pq = stpcpy(sq->pq, \
"abs(" fieldname " - abs("comtable" * float8"); \ "abs(" fieldname " - abs("comtable" * float8"); \
sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \ sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \
sq->pq = stpcpy(sq->pq, ")) < 1"); \ sq->pq = stpcpy(sq->pq, ")) < 1"); \
break; \ break; \
case COMPARE_NEQ: \ case QOF_COMPARE_NEQ: \
sq->pq = stpcpy(sq->pq, \ sq->pq = stpcpy(sq->pq, \
"abs(" fieldname " - abs("comtable" * float8"); \ "abs(" fieldname " - abs("comtable" * float8"); \
sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \ sq->pq += sprintf (sq->pq, "(%22.18g)", amt); \
@ -423,7 +426,7 @@ sql_sort_need_entry(Query * q)
/* =========================================================== */ /* =========================================================== */
static const char * static const char *
kvp_table_name(kvp_value_t value_t) kvp_table_name(KvpValueType value_t)
{ {
switch (value_t) { switch (value_t) {
case KVP_TYPE_GINT64: case KVP_TYPE_GINT64:
@ -468,25 +471,25 @@ kvp_path_name(GSList * path)
} }
static const char * static const char *
compare_op_name(query_compare_t how) compare_op_name(QofQueryCompare how)
{ {
switch (how) { switch (how) {
case COMPARE_LT: case QOF_COMPARE_LT:
return " < "; return " < ";
case COMPARE_LTE: case QOF_COMPARE_LTE:
return " <= "; return " <= ";
case COMPARE_EQUAL: case QOF_COMPARE_EQUAL:
return " = "; return " = ";
case COMPARE_GTE: case QOF_COMPARE_GTE:
return " >= "; return " >= ";
case COMPARE_GT: case QOF_COMPARE_GT:
return " > "; return " > ";
case COMPARE_NEQ: case QOF_COMPARE_NEQ:
return " != "; return " != ";
default: default:
@ -495,9 +498,9 @@ compare_op_name(query_compare_t how)
} }
static char * static char *
kvp_left_operand(kvp_value * value) kvp_left_operand(KvpValue * value)
{ {
kvp_value_t value_t; KvpValueType value_t;
const char *kvptable; const char *kvptable;
g_return_val_if_fail(value, NULL); g_return_val_if_fail(value, NULL);
@ -526,9 +529,9 @@ kvp_left_operand(kvp_value * value)
} }
static char * static char *
kvp_right_operand(sqlQuery * sq, kvp_value * value) kvp_right_operand(sqlQuery * sq, KvpValue * value)
{ {
kvp_value_t value_t; KvpValueType value_t;
const char *kvptable; const char *kvptable;
g_return_val_if_fail(value, NULL); g_return_val_if_fail(value, NULL);
@ -603,10 +606,10 @@ add_kvp_clause(sqlQuery * sq, const char *kvptable, const char *entity_table,
} }
static void static void
sqlQuery_kvp_build(sqlQuery * sq, GSList * sort_path, query_compare_t how, sqlQuery_kvp_build(sqlQuery * sq, GSList * sort_path, QofQueryCompare how,
gboolean invert, query_kvp_t kpd) gboolean invert, query_kvp_t kpd)
{ {
kvp_value_t value_t; KvpValueType value_t;
const char *kvptable; const char *kvptable;
const char *op; const char *op;
GList *list; GList *list;
@ -625,7 +628,7 @@ sqlQuery_kvp_build(sqlQuery * sq, GSList * sort_path, query_compare_t how,
value_t = kvp_value_get_type(kpd->value); value_t = kvp_value_get_type(kpd->value);
if (value_t == KVP_TYPE_GUID && how != COMPARE_EQUAL) { if (value_t == KVP_TYPE_GUID && how != QOF_COMPARE_EQUAL) {
PWARN("guid non-equality comparison not supported"); PWARN("guid non-equality comparison not supported");
return; return;
} }
@ -708,9 +711,9 @@ sqlQuery_build(sqlQuery * sq, Query * q)
GList *il, *jl, *qterms, *andterms; GList *il, *jl, *qterms, *andterms;
GList *tables = NULL; GList *tables = NULL;
GSList *path; GSList *path;
QueryNewTerm_t qt; QofQueryTerm *qt;
QueryPredData_t pd; QofQueryPredData *pd;
QueryNewSort_t s1, s2, s3; QofQuerySort *s1, *s2, *s3;
int more_or = 0; int more_or = 0;
int more_and = 0; int more_and = 0;
int max_rows; int max_rows;
@ -724,23 +727,23 @@ sqlQuery_build(sqlQuery * sq, Query * q)
return NULL; return NULL;
/* Only Split searches are allowed */ /* Only Split searches are allowed */
if (safe_strcmp(gncQueryGetSearchFor(q), GNC_ID_SPLIT)) { if (safe_strcmp(qof_query_get_search_for(q), GNC_ID_SPLIT)) {
PERR("Only SPLITs are supported, not %s", gncQueryGetSearchFor(q)); PERR("Only SPLITs are supported, not %s", qof_query_get_search_for(q));
return NULL; return NULL;
} }
/* Determine whether the query will need to reference certain /* Determine whether the query will need to reference certain
* tables. See note above for details. */ * tables. See note above for details. */
qterms = gncQueryGetTerms(q); qterms = qof_query_get_terms(q);
for (il = qterms; il; il = il->next) { for (il = qterms; il; il = il->next) {
/* andterms is GList of query terms that must be anded */ /* andterms is GList of query terms that must be anded */
andterms = il->data; andterms = il->data;
for (jl = andterms; jl; jl = jl->next) { for (jl = andterms; jl; jl = jl->next) {
qt = (QueryNewTerm_t) jl->data; qt = (QofQueryTerm *) jl->data;
pd = gncQueryTermGetPredData(qt); pd = qof_query_term_get_pred_data(qt);
path = gncQueryTermGetParamPath(qt); path = qof_query_term_get_param_path(qt);
g_assert(path); g_assert(path);
@ -752,13 +755,13 @@ sqlQuery_build(sqlQuery * sq, Query * q)
} else if (!safe_strcmp(path->data, SPLIT_VALUE)) { } else if (!safe_strcmp(path->data, SPLIT_VALUE)) {
need_entry = TRUE; need_entry = TRUE;
need_trans_commodity = TRUE; need_trans_commodity = TRUE;
} else if (!safe_strcmp(pd->type_name, QUERYCORE_GUID)) { } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_GUID)) {
if (!safe_strcmp(path->data, QUERY_PARAM_GUID)) if (!safe_strcmp(path->data, QOF_QUERY_PARAM_GUID))
need_entry = TRUE; need_entry = TRUE;
else if (!safe_strcmp(path->data, SPLIT_ACCOUNT)) { else if (!safe_strcmp(path->data, SPLIT_ACCOUNT)) {
need_account = TRUE; need_account = TRUE;
} }
} else if (!safe_strcmp(pd->type_name, QUERYCORE_KVP)) { } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_KVP)) {
if (!safe_strcmp(path->data, SPLIT_KVP)) if (!safe_strcmp(path->data, SPLIT_KVP))
need_entry = TRUE; need_entry = TRUE;
else if (!safe_strcmp(path->data, SPLIT_ACCOUNT)) else if (!safe_strcmp(path->data, SPLIT_ACCOUNT))
@ -779,7 +782,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
sq->pq = sq->q_base; sq->pq = sq->q_base;
sq->pq = stpcpy(sq->pq, "SELECT DISTINCT gncTransaction.* "); sq->pq = stpcpy(sq->pq, "SELECT DISTINCT gncTransaction.* ");
gncQueryGetSorts(q, &s1, &s2, &s3); qof_query_get_sorts(q, &s1, &s2, &s3);
/* For SELECT DISTINCT, ORDER BY expressions must appear in target list */ /* For SELECT DISTINCT, ORDER BY expressions must appear in target list */
sq->pq = sql_sort_distinct(sq->pq, s1); sq->pq = sql_sort_distinct(sq->pq, s1);
@ -847,44 +850,44 @@ sqlQuery_build(sqlQuery * sq, Query * q)
} }
more_and = 1; more_and = 1;
qt = (QueryNewTerm_t) jl->data; qt = (QofQueryTerm *) jl->data;
pd = gncQueryTermGetPredData(qt); pd = qof_query_term_get_pred_data(qt);
path = gncQueryTermGetParamPath(qt); path = qof_query_term_get_param_path(qt);
invert = gncQueryTermIsInverted(qt); invert = qof_query_term_is_inverted(qt);
if (!safe_strcmp(pd->type_name, QUERYCORE_GUID)) { if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_GUID)) {
query_guid_t pdata = (query_guid_t) pd; query_guid_t pdata = (query_guid_t) pd;
GList *node; GList *node;
char *field = NULL; char *field = NULL;
PINFO("term is QUERYCORE_GUID"); PINFO("term is QOF_QUERYCORE_GUID");
if (!safe_strcmp(path->data, QUERY_PARAM_GUID)) { if (!safe_strcmp(path->data, QOF_QUERY_PARAM_GUID)) {
field = "gncEntry.entryGUID"; field = "gncEntry.entryGUID";
g_assert(pdata->options != GUID_MATCH_ALL); g_assert(pdata->options != QOF_GUID_MATCH_ALL);
} else if (!safe_strcmp(path->data, SPLIT_TRANS) && } else if (!safe_strcmp(path->data, SPLIT_TRANS) &&
!safe_strcmp(path->next->data, QUERY_PARAM_GUID)) { !safe_strcmp(path->next->data, QOF_QUERY_PARAM_GUID)) {
field = "gncEntry.transGUID"; field = "gncEntry.transGUID";
g_assert(pdata->options != GUID_MATCH_ALL); g_assert(pdata->options != QOF_GUID_MATCH_ALL);
} else if (!safe_strcmp(path->data, SPLIT_ACCOUNT) && } else if (!safe_strcmp(path->data, SPLIT_ACCOUNT) &&
!safe_strcmp(path->next->data, QUERY_PARAM_GUID)) { !safe_strcmp(path->next->data, QOF_QUERY_PARAM_GUID)) {
field = "gncEntry.accountGUID"; field = "gncEntry.accountGUID";
g_assert(pdata->options != GUID_MATCH_ALL); g_assert(pdata->options != QOF_GUID_MATCH_ALL);
} else if (!safe_strcmp(path->data, SPLIT_TRANS) && } else if (!safe_strcmp(path->data, SPLIT_TRANS) &&
!safe_strcmp(path->next->data, TRANS_SPLITLIST) && !safe_strcmp(path->next->data, TRANS_SPLITLIST) &&
!safe_strcmp(path->next->next->data, !safe_strcmp(path->next->next->data,
SPLIT_ACCOUNT_GUID)) { SPLIT_ACCOUNT_GUID)) {
field = "gncEntry.accountGUID"; field = "gncEntry.accountGUID";
g_assert(pdata->options == GUID_MATCH_ALL); g_assert(pdata->options == QOF_GUID_MATCH_ALL);
} else if (!safe_strcmp(path->data, QUERY_PARAM_BOOK) && } else if (!safe_strcmp(path->data, QOF_QUERY_PARAM_BOOK) &&
!safe_strcmp(path->next->data, QUERY_PARAM_GUID)) { !safe_strcmp(path->next->data, QOF_QUERY_PARAM_GUID)) {
/* XXX: Need to support the Book GUID? (gncAccount.bookGUID) */ /* XXX: Need to support the Book GUID? (gncAccount.bookGUID) */
field = "gncAccount.bookGUID"; field = "gncAccount.bookGUID";
g_assert(pdata->options != GUID_MATCH_ALL); g_assert(pdata->options != QOF_GUID_MATCH_ALL);
} else { } else {
PINFO("Unknown GUID parameter, %s", (char *)path->data); PINFO("Unknown GUID parameter, %s", (char *)path->data);
} }
@ -898,11 +901,11 @@ sqlQuery_build(sqlQuery * sq, Query * q)
for (node = pdata->guids; node; node = node->next) { for (node = pdata->guids; node; node = node->next) {
switch (pdata->options) { switch (pdata->options) {
case GUID_MATCH_NONE: case QOF_GUID_MATCH_NONE:
sq->pq = stpcpy(sq->pq, "NOT "); sq->pq = stpcpy(sq->pq, "NOT ");
/* fall through */ /* fall through */
case GUID_MATCH_ANY: case QOF_GUID_MATCH_ANY:
sq->pq = stpcpy(sq->pq, field); sq->pq = stpcpy(sq->pq, field);
sq->pq = stpcpy(sq->pq, "='"); sq->pq = stpcpy(sq->pq, "='");
sq->pq = sq->pq =
@ -911,7 +914,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
sq->pq = stpcpy(sq->pq, "'"); sq->pq = stpcpy(sq->pq, "'");
break; break;
case GUID_MATCH_ALL: case QOF_GUID_MATCH_ALL:
sq->pq = stpcpy(sq->pq, sq->pq = stpcpy(sq->pq,
" EXISTS ( SELECT true FROM gncEntry e" " EXISTS ( SELECT true FROM gncEntry e"
" WHERE " " WHERE "
@ -932,12 +935,12 @@ sqlQuery_build(sqlQuery * sq, Query * q)
if (node->next) { if (node->next) {
switch (pdata->options) { switch (pdata->options) {
case GUID_MATCH_ANY: case QOF_GUID_MATCH_ANY:
sq->pq = stpcpy(sq->pq, " OR "); sq->pq = stpcpy(sq->pq, " OR ");
break; break;
case GUID_MATCH_ALL: case QOF_GUID_MATCH_ALL:
case GUID_MATCH_NONE: case QOF_GUID_MATCH_NONE:
sq->pq = stpcpy(sq->pq, " AND "); sq->pq = stpcpy(sq->pq, " AND ");
break; break;
@ -956,7 +959,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
more_and = 0; more_and = 0;
} }
} else if (!safe_strcmp(pd->type_name, QUERYCORE_STRING)) { } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_STRING)) {
query_string_t pdata = (query_string_t) pd; query_string_t pdata = (query_string_t) pd;
if (!safe_strcmp(path->data, SPLIT_ACTION)) { if (!safe_strcmp(path->data, SPLIT_ACTION)) {
@ -988,7 +991,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
(char *)(path->data)); (char *)(path->data));
} else if (!safe_strcmp(pd->type_name, QUERYCORE_NUMERIC)) { } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_NUMERIC)) {
query_numeric_t pdata = (query_numeric_t) pd; query_numeric_t pdata = (query_numeric_t) pd;
@ -1019,7 +1022,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
PINFO("Unknown NUMERIC: %s", (char *)(path->data)); PINFO("Unknown NUMERIC: %s", (char *)(path->data));
} }
} else if (!safe_strcmp(pd->type_name, QUERYCORE_DATE)) { } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_DATE)) {
query_date_t pdata = (query_date_t) pd; query_date_t pdata = (query_date_t) pd;
char *field = NULL; char *field = NULL;
const char *op = NULL; const char *op = NULL;
@ -1046,7 +1049,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
if (invert) if (invert)
sq->pq = stpcpy(sq->pq, ") "); sq->pq = stpcpy(sq->pq, ") ");
} else if (!safe_strcmp(pd->type_name, QUERYCORE_CHAR)) { } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_CHAR)) {
query_char_t pdata = (query_char_t) pd; query_char_t pdata = (query_char_t) pd;
int got_one = 0; int got_one = 0;
@ -1057,7 +1060,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
if (invert) if (invert)
sq->pq = stpcpy(sq->pq, "NOT ("); sq->pq = stpcpy(sq->pq, "NOT (");
if (pdata->options == CHAR_MATCH_NONE) if (pdata->options == QOF_CHAR_MATCH_NONE)
sq->pq = stpcpy(sq->pq, "NOT "); sq->pq = stpcpy(sq->pq, "NOT ");
sq->pq = stpcpy(sq->pq, "("); sq->pq = stpcpy(sq->pq, "(");
@ -1073,7 +1076,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
} else } else
PINFO("Unknown CHAR type, %s", (char *)(path->data)); PINFO("Unknown CHAR type, %s", (char *)(path->data));
} else if (!safe_strcmp(pd->type_name, QUERYCORE_KVP)) { } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_KVP)) {
query_kvp_t pdata = (query_kvp_t) pd; query_kvp_t pdata = (query_kvp_t) pd;
PINFO("term is a KVP"); PINFO("term is a KVP");
@ -1099,15 +1102,15 @@ sqlQuery_build(sqlQuery * sq, Query * q)
* if the limit is set to a finite number of rows. * if the limit is set to a finite number of rows.
*/ */
if (gncQuerySortGetParamPath(s1) != NULL) { if (qof_query_sort_get_param_path(s1) != NULL) {
sq->pq = stpcpy(sq->pq, "ORDER BY "); sq->pq = stpcpy(sq->pq, "ORDER BY ");
sq->pq = sql_sort_order(sq->pq, s1); sq->pq = sql_sort_order(sq->pq, s1);
if (gncQuerySortGetParamPath(s2) != NULL) { if (qof_query_sort_get_param_path(s2) != NULL) {
sq->pq = stpcpy(sq->pq, ", "); sq->pq = stpcpy(sq->pq, ", ");
sq->pq = sql_sort_order(sq->pq, s2); sq->pq = sql_sort_order(sq->pq, s2);
if (gncQuerySortGetParamPath(s3) != NULL) { if (qof_query_sort_get_param_path(s3) != NULL) {
sq->pq = stpcpy(sq->pq, ", "); sq->pq = stpcpy(sq->pq, ", ");
sq->pq = sql_sort_order(sq->pq, s3); sq->pq = sql_sort_order(sq->pq, s3);
} }
@ -1116,7 +1119,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
/* ---------------------------------------------------- */ /* ---------------------------------------------------- */
/* limit the query result to a finite number of rows */ /* limit the query result to a finite number of rows */
max_rows = gncQueryGetMaxResults(q); max_rows = qof_query_get_max_results(q);
if (0 <= max_rows) { if (0 <= max_rows) {
sq->pq = stpcpy(sq->pq, " LIMIT "); sq->pq = stpcpy(sq->pq, " LIMIT ");
sq->pq += snprintf(sq->pq, 30, "%d", max_rows); sq->pq += snprintf(sq->pq, 30, "%d", max_rows);

View File

@ -203,7 +203,7 @@ typedef struct store_data_s {
#include "kvp-autogen.c" #include "kvp-autogen.c"
static void static void
store_cb (const char *key, kvp_value *val, gpointer p) store_cb (const char *key, KvpValue *val, gpointer p)
{ {
store_data_t *cb_data = (store_data_t *) p; store_data_t *cb_data = (store_data_t *) p;
PGBackend *be = cb_data->be; PGBackend *be = cb_data->be;
@ -310,7 +310,7 @@ store_cb (const char *key, kvp_value *val, gpointer p)
case KVP_TYPE_FRAME: case KVP_TYPE_FRAME:
{ {
kvp_frame *frame; KvpFrame *frame;
PINFO ("path=%s type=frame", cb_data->path); PINFO ("path=%s type=frame", cb_data->path);
frame = kvp_value_get_frame (val); frame = kvp_value_get_frame (val);
kvp_frame_for_each_slot (frame, store_cb, p); kvp_frame_for_each_slot (frame, store_cb, p);
@ -328,7 +328,7 @@ store_cb (const char *key, kvp_value *val, gpointer p)
} }
void void
pgendKVPStore (PGBackend *be, guint32 iguid, kvp_frame *kf) pgendKVPStore (PGBackend *be, guint32 iguid, KvpFrame *kf)
{ {
store_data_t cb_data; store_data_t cb_data;
if (!be || 0 == iguid || !kf) return; if (!be || 0 == iguid || !kf) return;
@ -389,9 +389,9 @@ pgendKVPInit (PGBackend *be)
*/ */
#define KVP_HANDLER_SETUP \ #define KVP_HANDLER_SETUP \
kvp_frame *kf = (kvp_frame *) data; \ KvpFrame *kf = (KvpFrame *) data; \
kvp_frame *final; \ KvpFrame *final; \
kvp_value * kv=NULL; \ KvpValue * kv=NULL; \
char *path, *tail; \ char *path, *tail; \
int ipath; \ int ipath; \
\ \
@ -495,8 +495,8 @@ list_handler (PGBackend *be, PGresult *result, int j, gpointer data)
kf = pgendGetResults (be, TYPE##_handler, kf); \ kf = pgendGetResults (be, TYPE##_handler, kf); \
} }
kvp_frame * KvpFrame *
pgendKVPFetch (PGBackend *be, guint32 iguid, kvp_frame *kf) pgendKVPFetch (PGBackend *be, guint32 iguid, KvpFrame *kf)
{ {
char * p; char * p;
char iguid_str[40]; char iguid_str[40];

View File

@ -64,10 +64,10 @@ void pgendKVPInit (PGBackend *);
* use as a GUID cache index. * use as a GUID cache index.
*/ */
void pgendKVPStore (PGBackend *, guint32 iguid, kvp_frame *); void pgendKVPStore (PGBackend *, guint32 iguid, KvpFrame *);
void pgendKVPDelete (PGBackend *, guint32 iguid); void pgendKVPDelete (PGBackend *, guint32 iguid);
kvp_frame * pgendKVPFetch (PGBackend *, guint32 iguid, kvp_frame *); KvpFrame * pgendKVPFetch (PGBackend *, guint32 iguid, KvpFrame *);
guint32 pgendNewGUIDidx (PGBackend *be); guint32 pgendNewGUIDidx (PGBackend *be);

View File

@ -30,8 +30,8 @@
#include <string.h> #include <string.h>
#include <libpq-fe.h> #include <libpq-fe.h>
#include "gnc-book.h" #include "qofbook.h"
#include "gnc-book-p.h" #include "qofbook-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"
@ -66,7 +66,7 @@ get_commodities_cb (PGBackend *be, PGresult *result, int j, gpointer data)
for (node=be->blist; node; node=node->next) for (node=be->blist; node; node=node->next)
{ {
gnc_commodity *com; gnc_commodity *com;
GNCBook *book = node->data; QofBook *book = node->data;
gnc_commodity_table *comtab = gnc_book_get_commodity_table (book); gnc_commodity_table *comtab = gnc_book_get_commodity_table (book);
if (!comtab) continue; if (!comtab) continue;
@ -207,7 +207,7 @@ commodity_mark_cb (gnc_commodity *cm, gpointer user_data)
void void
pgendStorePriceDBNoLock (PGBackend *be, GNCBook *book) pgendStorePriceDBNoLock (PGBackend *be, QofBook *book)
{ {
GNCPriceDB *prdb; GNCPriceDB *prdb;
gnc_commodity_table *comtab; gnc_commodity_table *comtab;
@ -226,7 +226,7 @@ pgendStorePriceDBNoLock (PGBackend *be, GNCBook *book)
} }
void void
pgendStorePriceDB (PGBackend *be, GNCBook *book) pgendStorePriceDB (PGBackend *be, QofBook *book)
{ {
char *p; char *p;
ENTER ("be=%p, book=%p", be, book); ENTER ("be=%p, book=%p", be, book);
@ -257,7 +257,7 @@ pgendStorePriceDB (PGBackend *be, GNCBook *book)
static gpointer static gpointer
get_price_cb (PGBackend *be, PGresult *result, int j, gpointer data) get_price_cb (PGBackend *be, PGresult *result, int j, gpointer data)
{ {
GNCBook *book = data; QofBook *book = data;
GNCPriceDB *prdb; GNCPriceDB *prdb;
GNCPrice *pr; GNCPrice *pr;
gint32 sql_vers, local_vers; gint32 sql_vers, local_vers;
@ -329,7 +329,7 @@ get_price_cb (PGBackend *be, PGresult *result, int j, gpointer data)
void void
pgendGetAllPricesInBook (PGBackend *be, GNCBook *book) pgendGetAllPricesInBook (PGBackend *be, QofBook *book)
{ {
char buff[400], *p; char buff[400], *p;
@ -342,7 +342,7 @@ pgendGetAllPricesInBook (PGBackend *be, GNCBook *book)
/* Get them ALL */ /* Get them ALL */
p = buff; p = buff;
p = stpcpy (p, "SELECT * FROM gncPrice WHERE bookGuid='"); p = stpcpy (p, "SELECT * FROM gncPrice WHERE bookGuid='");
p = guid_to_string_buff (gnc_book_get_guid(book), p); p = guid_to_string_buff (qof_book_get_guid(book), p);
p = stpcpy (p, "';"); p = stpcpy (p, "';");
SEND_QUERY (be, buff, ); SEND_QUERY (be, buff, );
pgendGetResults (be, get_price_cb, book); pgendGetResults (be, get_price_cb, book);
@ -353,7 +353,7 @@ pgendGetAllPricesInBook (PGBackend *be, GNCBook *book)
/* ============================================================= */ /* ============================================================= */
void void
pgendPriceFind (Backend *bend, gpointer olook) pgendPriceFind (QofBackend *bend, gpointer olook)
{ {
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
GNCPriceLookup *look = (GNCPriceLookup *)olook; GNCPriceLookup *look = (GNCPriceLookup *)olook;
@ -451,7 +451,7 @@ pgendPriceFind (Backend *bend, gpointer olook)
/* ============================================================= */ /* ============================================================= */
void void
pgend_price_begin_edit (Backend * bend, GNCPrice *pr) pgend_price_begin_edit (QofBackend * bend, GNCPrice *pr)
{ {
if (pr && pr->db && pr->db->dirty) if (pr && pr->db && pr->db->dirty)
{ {
@ -461,7 +461,7 @@ pgend_price_begin_edit (Backend * bend, GNCPrice *pr)
} }
void void
pgend_price_commit_edit (Backend * bend, GNCPrice *pr) pgend_price_commit_edit (QofBackend * bend, GNCPrice *pr)
{ {
char * bufp; char * bufp;
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
@ -491,7 +491,7 @@ pgend_price_commit_edit (Backend * bend, GNCPrice *pr)
" price must be rolled back. This function\n" " price must be rolled back. This function\n"
" is not completely implemented !! \n"); " is not completely implemented !! \n");
LEAVE ("rolled back"); LEAVE ("rolled back");
xaccBackendSetError (&be->be, ERR_BACKEND_MODIFIED); qof_backend_set_error (&be->be, ERR_BACKEND_MODIFIED);
return; return;
} }
pr->version ++; /* be sure to update the version !! */ pr->version ++; /* be sure to update the version !! */

View File

@ -28,13 +28,13 @@
void pgendGetAllCommodities (PGBackend *be); void pgendGetAllCommodities (PGBackend *be);
void pgendGetCommodity (PGBackend *be, const char * unique_name); void pgendGetCommodity (PGBackend *be, const char * unique_name);
void pgendStorePriceDB (PGBackend *be, GNCBook *book); void pgendStorePriceDB (PGBackend *be, QofBook *book);
void pgendStorePriceDBNoLock (PGBackend *be, GNCBook *book); void pgendStorePriceDBNoLock (PGBackend *be, QofBook *book);
void pgendGetAllPricesInBook (PGBackend *be, GNCBook *); void pgendGetAllPricesInBook (PGBackend *be, QofBook *);
void pgendPriceFind (Backend *bend, gpointer olook); void pgendPriceFind (QofBackend *bend, gpointer olook);
void pgend_price_begin_edit (Backend * bend, GNCPrice *pr); void pgend_price_begin_edit (QofBackend * bend, GNCPrice *pr);
void pgend_price_commit_edit (Backend * bend, GNCPrice *pr); void pgend_price_commit_edit (QofBackend * bend, GNCPrice *pr);
#endif /* POSTGRES_PRICE_H */ #endif /* POSTGRES_PRICE_H */

View File

@ -34,8 +34,8 @@
#include <glib.h> #include <glib.h>
#include <libpq-fe.h> #include <libpq-fe.h>
#include <stdlib.h> #include <stdlib.h>
#include "Backend.h" #include "qofbackend.h"
#include "BackendP.h" #include "qofbackend-p.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "PostgresBackend.h" #include "PostgresBackend.h"
@ -60,8 +60,8 @@ int sendQuery(PGBackend *be,char * buff) {
gchar * msg = (gchar *)PQerrorMessage(be->connection); gchar * msg = (gchar *)PQerrorMessage(be->connection);
PERR("send query failed:\n" PERR("send query failed:\n"
"\t%s", msg); "\t%s", msg);
xaccBackendSetMessage(&be->be, msg); qof_backend_set_message(&be->be, msg);
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);
return ERR_BACKEND_SERVER_ERR; return ERR_BACKEND_SERVER_ERR;
} }
LEAVE("PQsendQuery rc = %d", rc); LEAVE("PQsendQuery rc = %d", rc);
@ -102,8 +102,8 @@ int finishQuery(PGBackend *be) {
gchar * msg = (gchar *)PQerrorMessage(be->connection); gchar * msg = (gchar *)PQerrorMessage(be->connection);
PERR("finish query failed:\n\t%s", msg); PERR("finish query failed:\n\t%s", msg);
PQclear(result); PQclear(result);
xaccBackendSetMessage(&be->be, msg); qof_backend_set_message(&be->be, msg);
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);
break; break;
} }
PQclear(result); PQclear(result);

View File

@ -40,11 +40,11 @@
#include <libpq-fe.h> #include <libpq-fe.h>
#include "Backend.h" #include "qofbackend.h"
#include "BackendP.h" #include "qofbackend-p.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "guid.h" #include "guid.h"
#include "GNCId.h" #include "qofid.h"
#include "PostgresBackend.h" #include "PostgresBackend.h"
@ -66,7 +66,7 @@ gpointer pgendGetResults (PGBackend *be,
/* The gnc_string_to_commodity() routine finds the commodity by /* The gnc_string_to_commodity() routine finds the commodity by
* parsing a string of the form NAMESPACE::MNEMONIC * parsing a string of the form NAMESPACE::MNEMONIC
*/ */
gnc_commodity * gnc_string_to_commodity (const char *str, GNCBook *book); gnc_commodity * gnc_string_to_commodity (const char *str, QofBook *book);
int sendQuery(PGBackend *be,char * buff); int sendQuery(PGBackend *be,char * buff);
int finishQuery(PGBackend *be); int finishQuery(PGBackend *be);
@ -95,8 +95,8 @@ int finishQuery(PGBackend *be);
gchar * msg = (gchar *)PQerrorMessage(be->connection); \ gchar * msg = (gchar *)PQerrorMessage(be->connection); \
/* hack alert -- we need kinder, gentler error handling */\ /* hack alert -- we need kinder, gentler error handling */\
PERR("send query failed:\n\t%s", msg); \ PERR("send query failed:\n\t%s", msg); \
xaccBackendSetMessage (&be->be, msg); \ qof_backend_set_message (&be->be, msg); \
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); \ qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR); \
return retval; \ return retval; \
} \ } \
} \ } \
@ -124,8 +124,8 @@ int finishQuery(PGBackend *be);
msg = PQresultErrorMessage(result); \ msg = PQresultErrorMessage(result); \
PERR("finish query failed:\n\t%s", msg); \ PERR("finish query failed:\n\t%s", msg); \
PQclear(result); \ PQclear(result); \
xaccBackendSetMessage (&be->be, msg); \ qof_backend_set_message (&be->be, msg); \
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); \ qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR); \
break; \ break; \
} \ } \
PQclear(result); \ PQclear(result); \
@ -151,8 +151,8 @@ int finishQuery(PGBackend *be);
{ \ { \
PERR("failed to get result to query:\n\t%s", msg); \ PERR("failed to get result to query:\n\t%s", msg); \
PQclear (result); \ PQclear (result); \
xaccBackendSetMessage (&be->be, msg); \ qof_backend_set_message (&be->be, msg); \
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR);\ qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);\
break; \ break; \
} \ } \
} \ } \
@ -182,8 +182,8 @@ int finishQuery(PGBackend *be);
if (result) \ if (result) \
PQclear (result); \ PQclear (result); \
result = NULL; \ result = NULL; \
xaccBackendSetMessage (&be->be, msg); \ qof_backend_set_message (&be->be, msg); \
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR);\ qof_backend_set_error (&be->be, ERR_BACKEND_SERVER_ERR);\
} \ } \
} \ } \
@ -202,7 +202,7 @@ int finishQuery(PGBackend *be);
} \ } \
if (1 < nrows) { \ if (1 < nrows) { \
PERR ("unexpected duplicate records"); \ PERR ("unexpected duplicate records"); \
xaccBackendSetError (&be->be, ERR_BACKEND_DATA_CORRUPT); \ qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT); \
break; \ break; \
} else if (1 == nrows) } else if (1 == nrows)

View File

@ -13,16 +13,16 @@ 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)), bookGUID, , GUID *, qof_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),
') ')
define(`book', `gncBook, Book, GNCBook, b, define(`book', `gncBook, Book, QofBook, b,
book_open, , char, ptr->book_open, book_open, , char, ptr->book_open,
version, , int32, ptr->version, version, , int32, ptr->version,
iguid, , int32, ptr->idata, iguid, , int32, ptr->idata,
bookGUID, KEY, GUID *, gnc_book_get_guid(ptr), bookGUID, KEY, GUID *, qof_book_get_guid(ptr),
') ')
define(`split', `gncEntry, Split, Split, e, define(`split', `gncEntry, Split, Split, e,
@ -77,7 +77,7 @@ define(`price', `gncPrice, Price, GNCPrice, p,
valueNum, , int64, gnc_numeric_num(gnc_price_get_value(ptr)), valueNum, , int64, gnc_numeric_num(gnc_price_get_value(ptr)),
valueDenom, , int64, gnc_numeric_denom(gnc_price_get_value(ptr)), valueDenom, , int64, gnc_numeric_denom(gnc_price_get_value(ptr)),
version, , int32, gnc_price_get_version(ptr), version, , int32, gnc_price_get_version(ptr),
bookGUID, , GUID *, gnc_book_get_guid(gnc_price_get_book(ptr)), bookGUID, , GUID *, qof_book_get_guid(gnc_price_get_book(ptr)),
priceGUID, KEY, GUID *, gnc_price_get_guid(ptr), priceGUID, KEY, GUID *, gnc_price_get_guid(ptr),
') ')

View File

@ -7,17 +7,17 @@
#include <unistd.h> #include <unistd.h>
#include "AccountP.h" #include "AccountP.h"
#include "Backend.h" #include "qofbackend.h"
#include "PostgresBackend.h" #include "PostgresBackend.h"
#include "TransactionP.h" #include "TransactionP.h"
#include "TransLog.h" #include "TransLog.h"
#include "gnc-book.h" #include "qofbook.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "gnc-module.h" #include "gnc-module.h"
#include "gnc-session-p.h" #include "qofsession-p.h"
#include "gncquery.h" #include "gncquery.h"
#include "QueryNew.h" #include "qofquery.h"
#include "test-stuff.h" #include "test-stuff.h"
#include "test-engine-stuff.h" #include "test-engine-stuff.h"
@ -34,9 +34,9 @@ struct _dbinfo {
typedef struct _dbinfo DbInfo; typedef struct _dbinfo DbInfo;
static void static void
save_xml_file(GNCSession * session, const char *filename_base) save_xml_file(QofSession * session, const char *filename_base)
{ {
GNCBackendError io_err; QofBackendError io_err;
char cwd[1024]; char cwd[1024];
char *filename; char *filename;
@ -46,24 +46,24 @@ save_xml_file(GNCSession * session, const char *filename_base)
filename = g_strdup_printf("file:/%s/%s", cwd, filename_base); filename = g_strdup_printf("file:/%s/%s", cwd, filename_base);
gnc_session_begin(session, filename, FALSE, TRUE); qof_session_begin(session, filename, FALSE, TRUE);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
g_return_if_fail(io_err == ERR_BACKEND_NO_ERR); g_return_if_fail(io_err == ERR_BACKEND_NO_ERR);
gnc_session_save(session, NULL); qof_session_save(session, NULL);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
g_return_if_fail(io_err == ERR_BACKEND_NO_ERR); g_return_if_fail(io_err == ERR_BACKEND_NO_ERR);
gnc_session_end(session); qof_session_end(session);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
g_return_if_fail(io_err == ERR_BACKEND_NO_ERR); g_return_if_fail(io_err == ERR_BACKEND_NO_ERR);
g_free(filename); g_free(filename);
} }
static void static void
save_xml_files(GNCSession * session_1, GNCSession * session_2) save_xml_files(QofSession * session_1, QofSession * session_2)
{ {
g_return_if_fail(session_1 && session_2); g_return_if_fail(session_1 && session_2);
@ -97,39 +97,39 @@ db_file_url(DbInfo *dbinfo)
} }
static gboolean static gboolean
save_db_file(GNCSession * session, DbInfo *dbinfo) save_db_file(QofSession * session, DbInfo *dbinfo)
{ {
GNCBackendError io_err; QofBackendError io_err;
char *filename; char *filename;
g_return_val_if_fail(session && dbinfo->dbname && dbinfo->mode, FALSE); g_return_val_if_fail(session && dbinfo->dbname && dbinfo->mode, FALSE);
filename = db_file_url(dbinfo); filename = db_file_url(dbinfo);
gnc_session_begin(session, filename, FALSE, TRUE); qof_session_begin(session, filename, FALSE, TRUE);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Beginning db session", "Beginning db session",
__FILE__, __LINE__, __FILE__, __LINE__,
"can't begin session for %s in mode %s", dbinfo->dbname, dbinfo->mode)) "can't begin session for %s in mode %s", dbinfo->dbname, dbinfo->mode))
return FALSE; return FALSE;
gnc_session_save(session, NULL); qof_session_save(session, NULL);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Saving db session", "Saving db session",
__FILE__, __LINE__, __FILE__, __LINE__,
"can't save session for %s in mode %s", dbinfo->dbname, dbinfo->mode)) "can't save session for %s in mode %s", dbinfo->dbname, dbinfo->mode))
return FALSE; return FALSE;
gnc_session_end(session); qof_session_end(session);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Ending db session", "Ending db session",
__FILE__, __LINE__, __FILE__, __LINE__,
"can't end session for %s in mode %s", dbinfo->dbname, dbinfo->mode)) "can't end session for %s in mode %s", dbinfo->dbname, dbinfo->mode))
return FALSE; return FALSE;
do_test(gnc_session_get_url(session) == NULL, "session url not NULL"); do_test(qof_session_get_url(session) == NULL, "session url not NULL");
g_free(filename); g_free(filename);
@ -137,9 +137,9 @@ save_db_file(GNCSession * session, DbInfo *dbinfo)
} }
static gboolean static gboolean
load_db_file(GNCSession * session, DbInfo *dbinfo, gboolean end_session) load_db_file(QofSession * session, DbInfo *dbinfo, gboolean end_session)
{ {
GNCBackendError io_err; QofBackendError io_err;
PGBackend *be; PGBackend *be;
char *filename; char *filename;
@ -147,12 +147,12 @@ load_db_file(GNCSession * session, DbInfo *dbinfo, gboolean end_session)
filename = db_file_url(dbinfo); filename = db_file_url(dbinfo);
gnc_session_begin(session, filename, FALSE, FALSE); qof_session_begin(session, filename, FALSE, FALSE);
be = (PGBackend *)gnc_session_get_backend(session); be = (PGBackend *)qof_session_get_backend(session);
dbinfo->conn = be->connection; dbinfo->conn = be->connection;
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Beginning db session", "Beginning db session",
__FILE__, __LINE__, __FILE__, __LINE__,
@ -160,8 +160,8 @@ load_db_file(GNCSession * session, DbInfo *dbinfo, gboolean end_session)
dbinfo->dbname, dbinfo->mode)) dbinfo->dbname, dbinfo->mode))
return FALSE; return FALSE;
gnc_session_load(session, NULL); qof_session_load(session, NULL);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Loading db session", "Loading db session",
__FILE__, __LINE__, __FILE__, __LINE__,
@ -170,8 +170,8 @@ load_db_file(GNCSession * session, DbInfo *dbinfo, gboolean end_session)
return FALSE; return FALSE;
if (end_session) { if (end_session) {
gnc_session_end(session); qof_session_end(session);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Ending db session", "Ending db session",
__FILE__, __LINE__, __FILE__, __LINE__,
@ -179,7 +179,7 @@ load_db_file(GNCSession * session, DbInfo *dbinfo, gboolean end_session)
dbinfo->dbname, dbinfo->mode)) dbinfo->dbname, dbinfo->mode))
return FALSE; return FALSE;
do_test(gnc_session_get_url(session) == NULL, "session url not NULL"); do_test(qof_session_get_url(session) == NULL, "session url not NULL");
} }
g_free(filename); g_free(filename);
@ -190,19 +190,19 @@ load_db_file(GNCSession * session, DbInfo *dbinfo, gboolean end_session)
static gboolean static gboolean
test_access(DbInfo *dbinfo, gboolean multi_user) test_access(DbInfo *dbinfo, gboolean multi_user)
{ {
GNCBackendError io_err; QofBackendError io_err;
GNCSession *session_1; QofSession *session_1;
GNCSession *session_2; QofSession *session_2;
char *filename; char *filename;
g_return_val_if_fail(dbinfo->dbname && dbinfo->mode, FALSE); g_return_val_if_fail(dbinfo->dbname && dbinfo->mode, FALSE);
filename = db_file_url(dbinfo); filename = db_file_url(dbinfo);
session_1 = gnc_session_new(); session_1 = qof_session_new();
gnc_session_begin(session_1, filename, FALSE, FALSE); qof_session_begin(session_1, filename, FALSE, FALSE);
io_err = gnc_session_get_error(session_1); io_err = qof_session_get_error(session_1);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Beginning db session", "Beginning db session",
__FILE__, __LINE__, __FILE__, __LINE__,
@ -210,10 +210,10 @@ test_access(DbInfo *dbinfo, gboolean multi_user)
dbinfo->dbname, dbinfo->mode)) dbinfo->dbname, dbinfo->mode))
return FALSE; return FALSE;
session_2 = gnc_session_new(); session_2 = qof_session_new();
gnc_session_begin(session_2, filename, FALSE, FALSE); qof_session_begin(session_2, filename, FALSE, FALSE);
io_err = gnc_session_get_error(session_2); io_err = qof_session_get_error(session_2);
if (multi_user) { if (multi_user) {
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
@ -231,8 +231,8 @@ test_access(DbInfo *dbinfo, gboolean multi_user)
return FALSE; return FALSE;
} }
gnc_session_destroy(session_1); qof_session_destroy(session_1);
gnc_session_destroy(session_2); qof_session_destroy(session_2);
return TRUE; return TRUE;
} }
@ -285,17 +285,17 @@ add_commodity_to_delete(gnc_commodity * com, gpointer data)
} }
static void static void
remove_unneeded_commodities(GNCSession * session) remove_unneeded_commodities(QofSession * session)
{ {
CommodityDeleteInfo cdi; CommodityDeleteInfo cdi;
GNCBook *book; QofBook *book;
GList *node; GList *node;
g_return_if_fail(session); g_return_if_fail(session);
cdi.hash = g_hash_table_new(g_direct_hash, g_direct_equal); cdi.hash = g_hash_table_new(g_direct_hash, g_direct_equal);
book = gnc_session_get_book(session); book = qof_session_get_book(session);
xaccGroupForEachAccount(gnc_book_get_group(book), xaccGroupForEachAccount(gnc_book_get_group(book),
mark_account_commodities, cdi.hash, TRUE); mark_account_commodities, cdi.hash, TRUE);
@ -320,7 +320,7 @@ remove_unneeded_commodities(GNCSession * session)
} }
static Query * static Query *
make_get_all_query(GNCSession * session) make_get_all_query(QofSession * session)
{ {
Query *q; Query *q;
@ -328,19 +328,19 @@ make_get_all_query(GNCSession * session)
q = xaccMallocQuery(); q = xaccMallocQuery();
xaccQuerySetBook(q, gnc_session_get_book(session)); xaccQuerySetBook(q, qof_session_get_book(session));
xaccQueryAddClearedMatch(q, xaccQueryAddClearedMatch(q,
CLEARED_NO | CLEARED_NO |
CLEARED_CLEARED | CLEARED_CLEARED |
CLEARED_RECONCILED | CLEARED_RECONCILED |
CLEARED_FROZEN | CLEARED_VOIDED, QUERY_AND); CLEARED_FROZEN | CLEARED_VOIDED, QOF_QUERY_AND);
return q; return q;
} }
static void static void
multi_user_get_everything(GNCSession * session, GNCSession * base) multi_user_get_everything(QofSession * session, QofSession * base)
{ {
Query *q; Query *q;
@ -354,16 +354,16 @@ multi_user_get_everything(GNCSession * session, GNCSession * base)
/* load in prices from base */ /* load in prices from base */
if (base) if (base)
gnc_pricedb_equal(gnc_book_get_pricedb(gnc_session_get_book(base)), gnc_pricedb_equal(gnc_book_get_pricedb(qof_session_get_book(base)),
gnc_book_get_pricedb(gnc_session_get_book gnc_book_get_pricedb(qof_session_get_book
(session))); (session)));
} }
static gboolean static gboolean
test_updates(GNCSession * session, DbInfo *dbinfo, gboolean multi_user) test_updates(QofSession * session, DbInfo *dbinfo, gboolean multi_user)
{ {
GNCBackendError io_err; QofBackendError io_err;
GNCSession *session_2; QofSession *session_2;
char *filename; char *filename;
char str1[GUID_ENCODING_LENGTH+1]; char str1[GUID_ENCODING_LENGTH+1];
char str2[GUID_ENCODING_LENGTH+1]; char str2[GUID_ENCODING_LENGTH+1];
@ -373,8 +373,8 @@ test_updates(GNCSession * session, DbInfo *dbinfo, gboolean multi_user)
filename = db_file_url(dbinfo); filename = db_file_url(dbinfo);
gnc_session_begin(session, filename, FALSE, FALSE); qof_session_begin(session, filename, FALSE, FALSE);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Beginning db update session", "Beginning db update session",
__FILE__, __LINE__, __FILE__, __LINE__,
@ -384,8 +384,8 @@ test_updates(GNCSession * session, DbInfo *dbinfo, gboolean multi_user)
make_random_changes_to_session(session); make_random_changes_to_session(session);
if (!multi_user) { if (!multi_user) {
gnc_session_end(session); qof_session_end(session);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Ending db session", "Ending db session",
__FILE__, __LINE__, __FILE__, __LINE__,
@ -394,7 +394,7 @@ test_updates(GNCSession * session, DbInfo *dbinfo, gboolean multi_user)
return FALSE; return FALSE;
} }
session_2 = gnc_session_new(); session_2 = qof_session_new();
if (!load_db_file(session_2, dbinfo, !multi_user)) if (!load_db_file(session_2, dbinfo, !multi_user))
return FALSE; return FALSE;
@ -405,19 +405,19 @@ test_updates(GNCSession * session, DbInfo *dbinfo, gboolean multi_user)
remove_unneeded_commodities(session); remove_unneeded_commodities(session);
remove_unneeded_commodities(session_2); remove_unneeded_commodities(session_2);
ok = gnc_book_equal(gnc_session_get_book(session), ok = qof_book_equal(qof_session_get_book(session),
gnc_session_get_book(session_2)); qof_session_get_book(session_2));
guid_to_string_buff(gnc_book_get_guid(gnc_session_get_book(session)), str1); guid_to_string_buff(qof_book_get_guid(qof_session_get_book(session)), str1);
guid_to_string_buff(gnc_book_get_guid(gnc_session_get_book(session_2))), str2); guid_to_string_buff(qof_book_get_guid(qof_session_get_book(session_2)), str2);
do_test_args(ok, "Books equal after update", __FILE__, __LINE__, do_test_args(ok, "Books equal after update", __FILE__, __LINE__,
"Books not equal for session %s in mode %si\n" "Books not equal for session %s in mode %si\n"
"book 1: %s,\nbook 2: %s", "book 1: %s,\nbook 2: %s",
dbinfo->dbname, dbinfo->mode, str1, str2); dbinfo->dbname, dbinfo->mode, str1, str2);
if (multi_user) { if (multi_user) {
gnc_session_end(session); qof_session_end(session);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Ending db session", "Ending db session",
__FILE__, __LINE__, __FILE__, __LINE__,
@ -425,8 +425,8 @@ test_updates(GNCSession * session, DbInfo *dbinfo, gboolean multi_user)
dbinfo->dbname, dbinfo->mode)) dbinfo->dbname, dbinfo->mode))
return FALSE; return FALSE;
gnc_session_end(session_2); qof_session_end(session_2);
io_err = gnc_session_get_error(session_2); io_err = qof_session_get_error(session_2);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Ending db session", "Ending db session",
__FILE__, __LINE__, __FILE__, __LINE__,
@ -440,7 +440,7 @@ test_updates(GNCSession * session, DbInfo *dbinfo, gboolean multi_user)
return FALSE; return FALSE;
} }
gnc_session_destroy(session_2); qof_session_destroy(session_2);
g_free(filename); g_free(filename);
return TRUE; return TRUE;
@ -457,15 +457,15 @@ num_trans_helper(Transaction * trans, gpointer data)
} }
static int static int
session_num_trans(GNCSession * session) session_num_trans(QofSession * session)
{ {
AccountGroup *group; AccountGroup *group;
GNCBook *book; QofBook *book;
int num = 0; int num = 0;
g_return_val_if_fail(session, 0); g_return_val_if_fail(session, 0);
book = gnc_session_get_book(session); book = qof_session_get_book(session);
group = gnc_book_get_group(book); group = gnc_book_get_group(book);
xaccGroupForEachTransaction(group, num_trans_helper, &num); xaccGroupForEachTransaction(group, num_trans_helper, &num);
@ -474,28 +474,28 @@ session_num_trans(GNCSession * session)
} }
typedef struct { typedef struct {
GNCSession *session_base; QofSession *session_base;
DbInfo *dbinfo; DbInfo *dbinfo;
gint loaded; gint loaded;
gint total; gint total;
} QueryTestData; } QueryTestData;
static gboolean static gboolean
test_raw_query(GNCSession * session, Query * q) test_raw_query(QofSession * session, Query * q)
{ {
const char *sql_query_string; const char *sql_query_string;
PGresult *result; PGresult *result;
PGBackend *be; PGBackend *be;
sqlQuery *sq; sqlQuery *sq;
gboolean ok; gboolean ok;
QueryNew *qn = q; QofQuery *qn = q;
g_return_val_if_fail(session && q, FALSE); g_return_val_if_fail(session && q, FALSE);
be = (PGBackend *) gnc_session_get_backend(session); be = (PGBackend *) qof_session_get_backend(session);
if (gnc_should_log(module, GNC_LOG_DETAIL)) if (gnc_should_log(module, GNC_LOG_DETAIL))
gncQueryPrint(qn); qof_query_print(qn);
sq = sqlQuery_new(); sq = sqlQuery_new();
sql_query_string = sqlQuery_build(sq, q); sql_query_string = sqlQuery_build(sq, q);
@ -532,34 +532,34 @@ static gboolean
test_trans_query(Transaction * trans, gpointer data) test_trans_query(Transaction * trans, gpointer data)
{ {
QueryTestData *qtd = data; QueryTestData *qtd = data;
GNCBackendError io_err; QofBackendError io_err;
GNCSession *session; QofSession *session;
char *filename; char *filename;
GNCBook *book; QofBook *book;
GList *list; GList *list;
Query *q; Query *q;
filename = db_file_url(qtd->dbinfo); filename = db_file_url(qtd->dbinfo);
session = gnc_session_new(); session = qof_session_new();
gnc_session_begin(session, filename, FALSE, FALSE); qof_session_begin(session, filename, FALSE, FALSE);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Beginning db session", "Beginning db session",
__FILE__, __LINE__, __FILE__, __LINE__,
"can't begin session for %s", filename)) "can't begin session for %s", filename))
return FALSE; return FALSE;
gnc_session_load(session, NULL); qof_session_load(session, NULL);
io_err = gnc_session_get_error(session); io_err = qof_session_get_error(session);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Loading db session", "Loading db session",
__FILE__, __LINE__, __FILE__, __LINE__,
"can't load session for %s", filename)) "can't load session for %s", filename))
return FALSE; return FALSE;
book = gnc_session_get_book(session); book = qof_session_get_book(session);
q = make_trans_query(trans, get_random_query_type() | GUID_QT); q = make_trans_query(trans, get_random_query_type() | GUID_QT);
xaccQuerySetBook(q, book); xaccQuerySetBook(q, book);
@ -590,7 +590,7 @@ test_trans_query(Transaction * trans, gpointer data)
success("found right transaction"); success("found right transaction");
xaccFreeQuery(q); xaccFreeQuery(q);
gnc_session_destroy(session); qof_session_destroy(session);
g_free(filename); g_free(filename);
g_list_free(list); g_list_free(list);
@ -598,10 +598,10 @@ test_trans_query(Transaction * trans, gpointer data)
} }
static gboolean static gboolean
compare_balances(GNCSession * session_1, GNCSession * session_2) compare_balances(QofSession * session_1, QofSession * session_2)
{ {
GNCBook *book_1 = gnc_session_get_book(session_1); QofBook *book_1 = qof_session_get_book(session_1);
GNCBook *book_2 = gnc_session_get_book(session_2); QofBook *book_2 = qof_session_get_book(session_2);
GList *list; GList *list;
GList *node; GList *node;
gboolean ok; gboolean ok;
@ -659,16 +659,16 @@ compare_balances(GNCSession * session_1, GNCSession * session_2)
} }
static gboolean static gboolean
test_queries(GNCSession * session_base, DbInfo *dbinfo) test_queries(QofSession * session_base, DbInfo *dbinfo)
{ {
QueryTestData qtd; QueryTestData qtd;
AccountGroup *group; AccountGroup *group;
GNCBook *book; QofBook *book;
gboolean ok; gboolean ok;
g_return_val_if_fail(dbinfo->dbname && dbinfo->mode, FALSE); g_return_val_if_fail(dbinfo->dbname && dbinfo->mode, FALSE);
book = gnc_session_get_book(session_base); book = qof_session_get_book(session_base);
group = gnc_book_get_group(book); group = gnc_book_get_group(book);
qtd.session_base = session_base; qtd.session_base = session_base;
@ -687,11 +687,11 @@ test_queries(GNCSession * session_base, DbInfo *dbinfo)
} }
typedef struct { typedef struct {
GNCSession *session_1; QofSession *session_1;
GNCSession *session_2; QofSession *session_2;
GNCBook *book_1; QofBook *book_1;
GNCBook *book_2; QofBook *book_2;
AccountGroup *group_1; AccountGroup *group_1;
AccountGroup *group_2; AccountGroup *group_2;
@ -704,18 +704,18 @@ static gboolean
test_trans_update(Transaction * trans, gpointer data) test_trans_update(Transaction * trans, gpointer data)
{ {
UpdateTestData *td = data; UpdateTestData *td = data;
GNCBackendError io_err; QofBackendError io_err;
Transaction *trans_2; Transaction *trans_2;
GNCBook *book_1; QofBook *book_1;
GNCBook *book_2; QofBook *book_2;
GUID guid; GUID guid;
gboolean ok; gboolean ok;
/* FIXME remove */ /* FIXME remove */
return TRUE; return TRUE;
book_1 = gnc_session_get_book(td->session_1); book_1 = qof_session_get_book(td->session_1);
book_2 = gnc_session_get_book(td->session_2); book_2 = qof_session_get_book(td->session_2);
guid = *xaccTransGetGUID(trans); guid = *xaccTransGetGUID(trans);
@ -724,7 +724,7 @@ test_trans_update(Transaction * trans, gpointer data)
td->accounts_1); td->accounts_1);
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
io_err = gnc_session_get_error(td->session_1); io_err = qof_session_get_error(td->session_1);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"changing transaction in session 1", "changing transaction in session 1",
__FILE__, __LINE__, __FILE__, __LINE__,
@ -749,7 +749,7 @@ test_trans_update(Transaction * trans, gpointer data)
ok = ok && (trans->version == trans_2->version); ok = ok && (trans->version == trans_2->version);
/* /*
ok = ok && (gnc_session_get_error (td->session_2) == ERR_BACKEND_MODIFIED); ok = ok && (qof_session_get_error (td->session_2) == ERR_BACKEND_MODIFIED);
*/ */
if (!do_test_args(ok, if (!do_test_args(ok,
@ -800,7 +800,7 @@ drop_database(DbInfo *dbinfo)
} }
static gboolean static gboolean
test_updates_2(GNCSession * session_base, DbInfo *dbinfo) test_updates_2(QofSession * session_base, DbInfo *dbinfo)
{ {
UpdateTestData td; UpdateTestData td;
char *filename; char *filename;
@ -818,18 +818,18 @@ test_updates_2(GNCSession * session_base, DbInfo *dbinfo)
multi_user_get_everything(session_base, NULL); multi_user_get_everything(session_base, NULL);
td.session_1 = session_base; td.session_1 = session_base;
td.book_1 = gnc_session_get_book(session_base); td.book_1 = qof_session_get_book(session_base);
td.group_1 = gnc_book_get_group(td.book_1); td.group_1 = gnc_book_get_group(td.book_1);
td.accounts_1 = xaccGroupGetSubAccounts(td.group_1); td.accounts_1 = xaccGroupGetSubAccounts(td.group_1);
td.session_2 = gnc_session_new(); td.session_2 = qof_session_new();
if (!load_db_file(td.session_2, dbinfo, FALSE)) if (!load_db_file(td.session_2, dbinfo, FALSE))
return FALSE; return FALSE;
multi_user_get_everything(td.session_2, NULL); multi_user_get_everything(td.session_2, NULL);
td.book_2 = gnc_session_get_book(td.session_2); td.book_2 = qof_session_get_book(td.session_2);
td.group_2 = gnc_book_get_group(td.book_2); td.group_2 = gnc_book_get_group(td.book_2);
td.accounts_2 = xaccGroupGetSubAccounts(td.group_2); td.accounts_2 = xaccGroupGetSubAccounts(td.group_2);
@ -857,7 +857,7 @@ test_updates_2(GNCSession * session_base, DbInfo *dbinfo)
ok = ok && (account_1->version == account_2->version); ok = ok && (account_1->version == account_2->version);
ok = ok ok = ok
&& (gnc_session_get_error(td.session_2) == ERR_BACKEND_MODIFIED); && (qof_session_get_error(td.session_2) == ERR_BACKEND_MODIFIED);
if (!do_test_args(ok, if (!do_test_args(ok,
"test account rollback", "test account rollback",
@ -891,7 +891,7 @@ test_updates_2(GNCSession * session_base, DbInfo *dbinfo)
xaccTransCommitEdit(trans); xaccTransCommitEdit(trans);
xaccQueryAddGUIDMatch(q, xaccAccountGetGUID(child), xaccQueryAddGUIDMatch(q, xaccAccountGetGUID(child),
GNC_ID_ACCOUNT, QUERY_AND); GNC_ID_ACCOUNT, QOF_QUERY_AND);
xaccQuerySetBook(q, td.book_2); xaccQuerySetBook(q, td.book_2);
@ -921,9 +921,9 @@ test_updates_2(GNCSession * session_base, DbInfo *dbinfo)
return FALSE; return FALSE;
} }
gnc_session_end(td.session_1); qof_session_end(td.session_1);
gnc_session_end(td.session_2); qof_session_end(td.session_2);
gnc_session_destroy(td.session_2); qof_session_destroy(td.session_2);
g_list_free(td.accounts_1); g_list_free(td.accounts_1);
g_list_free(td.accounts_2); g_list_free(td.accounts_2);
@ -934,22 +934,22 @@ test_updates_2(GNCSession * session_base, DbInfo *dbinfo)
static gboolean static gboolean
test_mode(DbInfo *dbinfo, gboolean updates, gboolean multi_user) test_mode(DbInfo *dbinfo, gboolean updates, gboolean multi_user)
{ {
GNCSession *session; QofSession *session;
GNCSession *session_db; QofSession *session_db;
gboolean ok; gboolean ok;
gchar *modesave = dbinfo->mode; gchar *modesave = dbinfo->mode;
gchar *sumode = "single-update"; gchar *sumode = "single-update";
session = get_random_session(); session = get_random_session();
add_random_transactions_to_book(gnc_session_get_book(session), 20); add_random_transactions_to_book(qof_session_get_book(session), 20);
dbinfo->mode = sumode; dbinfo->mode = sumode;
if (!save_db_file(session, dbinfo)) if (!save_db_file(session, dbinfo))
return FALSE; return FALSE;
dbinfo->mode = modesave; dbinfo->mode = modesave;
session_db = gnc_session_new(); session_db = qof_session_new();
if (!load_db_file(session_db, dbinfo, !multi_user)) if (!load_db_file(session_db, dbinfo, !multi_user))
return FALSE; return FALSE;
@ -961,18 +961,18 @@ test_mode(DbInfo *dbinfo, gboolean updates, gboolean multi_user)
multi_user_get_everything(session_db, session); multi_user_get_everything(session_db, session);
} }
ok = gnc_book_equal(gnc_session_get_book(session), ok = qof_book_equal(qof_session_get_book(session),
gnc_session_get_book(session_db)); qof_session_get_book(session_db));
do_test_args(ok, "Books equal", __FILE__, __LINE__, do_test_args(ok, "Books equal", __FILE__, __LINE__,
"Books not equal for session %s in mode %s", "Books not equal for session %s in mode %s",
dbinfo->dbname, dbinfo->mode); dbinfo->dbname, dbinfo->mode);
if (multi_user) { if (multi_user) {
GNCBackendError io_err; QofBackendError io_err;
gnc_session_end(session_db); qof_session_end(session_db);
io_err = gnc_session_get_error(session_db); io_err = qof_session_get_error(session_db);
if (!do_test_args(io_err == ERR_BACKEND_NO_ERR, if (!do_test_args(io_err == ERR_BACKEND_NO_ERR,
"Ending db session", "Ending db session",
__FILE__, __LINE__, __FILE__, __LINE__,
@ -998,8 +998,8 @@ test_mode(DbInfo *dbinfo, gboolean updates, gboolean multi_user)
if (updates && !test_updates_2(session_db, dbinfo)) if (updates && !test_updates_2(session_db, dbinfo))
return FALSE; return FALSE;
gnc_session_destroy(session); qof_session_destroy(session);
gnc_session_destroy(session_db); qof_session_destroy(session_db);
return ok; return ok;
} }
@ -1038,7 +1038,7 @@ run_test(DbInfo *dbinfo)
static void static void
test_performance(DbInfo *dbinfo) test_performance(DbInfo *dbinfo)
{ {
GNCSession *session; QofSession *session;
gchar *modesave = dbinfo->mode; gchar *modesave = dbinfo->mode;
gchar *sumode = "single-update"; gchar *sumode = "single-update";
@ -1053,8 +1053,8 @@ test_performance(DbInfo *dbinfo)
REPORT_CLOCK(0, "Finished saving session"); REPORT_CLOCK(0, "Finished saving session");
dbinfo->mode = modesave; dbinfo->mode = modesave;
gnc_session_destroy(session); qof_session_destroy(session);
session = gnc_session_new(); session = qof_session_new();
if (!load_db_file(session, dbinfo, FALSE)) if (!load_db_file(session, dbinfo, FALSE))
return; return;
@ -1062,15 +1062,15 @@ test_performance(DbInfo *dbinfo)
gnc_set_log_level(MOD_TEST, GNC_LOG_INFO); gnc_set_log_level(MOD_TEST, GNC_LOG_INFO);
START_CLOCK(0, "Starting to save transactions"); START_CLOCK(0, "Starting to save transactions");
add_random_transactions_to_book(gnc_session_get_book(session), 100); add_random_transactions_to_book(qof_session_get_book(session), 100);
REPORT_CLOCK(0, "Finished saving transactions"); REPORT_CLOCK(0, "Finished saving transactions");
REPORT_CLOCK_TOTAL(0, "total"); REPORT_CLOCK_TOTAL(0, "total");
REPORT_CLOCK_TOTAL(1, "deleting kvp"); REPORT_CLOCK_TOTAL(1, "deleting kvp");
REPORT_CLOCK_TOTAL(2, "storing kvp"); REPORT_CLOCK_TOTAL(2, "storing kvp");
gnc_session_end(session); qof_session_end(session);
gnc_session_destroy(session); qof_session_destroy(session);
} }
#endif #endif

View File

@ -15,8 +15,8 @@
#include "Account.h" #include "Account.h"
#include "Group.h" #include "Group.h"
#include "Period.h" #include "Period.h"
#include "gnc-book.h" #include "qofbook.h"
#include "gnc-book-p.h" #include "qofbook-p.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "gnc-module.h" #include "gnc-module.h"
#include "test-stuff.h" #include "test-stuff.h"
@ -28,9 +28,9 @@
static void static void
run_test (void) run_test (void)
{ {
GNCBackendError io_err; QofBackendError io_err;
GNCSession *session; QofSession *session;
GNCBook *openbook, *closedbook; QofBook *openbook, *closedbook;
AccountGroup *grp; AccountGroup *grp;
AccountList *acclist, *anode; AccountList *acclist, *anode;
Account * acc = NULL; Account * acc = NULL;
@ -51,12 +51,12 @@ run_test (void)
session = get_random_session (); session = get_random_session ();
test_url = "postgres://localhost/qqq?mode=single-update"; test_url = "postgres://localhost/qqq?mode=single-update";
gnc_session_begin (session, test_url, FALSE, TRUE); qof_session_begin (session, test_url, FALSE, TRUE);
io_err = gnc_session_get_error (session); io_err = qof_session_get_error (session);
g_return_if_fail (io_err == ERR_BACKEND_NO_ERR); g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
openbook = gnc_session_get_book (session); openbook = qof_session_get_book (session);
if (!openbook) if (!openbook)
{ {
failure("book not created"); failure("book not created");
@ -119,8 +119,8 @@ run_test (void)
tsmiddle = tsfirst; tsmiddle = tsfirst;
tsmiddle.tv_sec = (tsfirst.tv_sec + tslast.tv_sec)/2; tsmiddle.tv_sec = (tsfirst.tv_sec + tslast.tv_sec)/2;
gnc_session_save (session, NULL); qof_session_save (session, NULL);
io_err = gnc_session_get_error (session); io_err = qof_session_get_error (session);
g_return_if_fail (io_err == ERR_BACKEND_NO_ERR); g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
// stdout is broken with guile for some reason // stdout is broken with guile for some reason
@ -135,12 +135,12 @@ run_test (void)
exit(get_rv()); exit(get_rv());
} }
gnc_session_save (session, NULL); qof_session_save (session, NULL);
io_err = gnc_session_get_error (session); io_err = qof_session_get_error (session);
g_return_if_fail (io_err == ERR_BACKEND_NO_ERR); g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
gnc_session_end (session); qof_session_end (session);
io_err = gnc_session_get_error (session); io_err = qof_session_get_error (session);
g_return_if_fail (io_err == ERR_BACKEND_NO_ERR); g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
success ("periods lightly tested and seem to work"); success ("periods lightly tested and seem to work");

View File

@ -710,7 +710,7 @@ pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid)
/* I beleive its a programming error to get this case. /* I beleive its a programming error to get this case.
* Print a warning for now... */ * Print a warning for now... */
PERR ("no such transaction in the database. This is unexpected ...\n"); PERR ("no such transaction in the database. This is unexpected ...\n");
xaccBackendSetError (&be->be, ERR_SQL_MISSING_DATA); qof_backend_set_error (&be->be, ERR_SQL_MISSING_DATA);
pgendEnable(be); pgendEnable(be);
gnc_engine_resume_events(); gnc_engine_resume_events();
return 0; return 0;
@ -723,7 +723,7 @@ pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid)
PERR ("!!!!!!!!!!!SQL database is corrupt!!!!!!!\n" PERR ("!!!!!!!!!!!SQL database is corrupt!!!!!!!\n"
"too many transactions with GUID=%s\n", "too many transactions with GUID=%s\n",
guid_to_string (trans_guid)); guid_to_string (trans_guid));
xaccBackendSetError (&be->be, ERR_BACKEND_DATA_CORRUPT); qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT);
pgendEnable(be); pgendEnable(be);
gnc_engine_resume_events(); gnc_engine_resume_events();
return 0; return 0;
@ -923,7 +923,7 @@ pgendSyncTransaction (PGBackend *be, GUID *trans_guid)
/* ============================================================= */ /* ============================================================= */
void void
pgend_trans_commit_edit (Backend * bend, pgend_trans_commit_edit (QofBackend * bend,
Transaction * trans, Transaction * trans,
Transaction * oldtrans) Transaction * oldtrans)
{ {
@ -1025,7 +1025,7 @@ pgend_trans_commit_edit (Backend * bend,
* routine. Our rollback routine updates from the latest in * routine. Our rollback routine updates from the latest in
* the sql database, and voila! we are good to go. * the sql database, and voila! we are good to go.
*/ */
xaccBackendSetError (&be->be, ERR_BACKEND_MODIFIED); qof_backend_set_error (&be->be, ERR_BACKEND_MODIFIED);
return; return;
} }
} }
@ -1088,7 +1088,7 @@ pgend_trans_commit_edit (Backend * bend,
*/ */
void void
pgend_trans_rollback_edit (Backend * bend, Transaction * trans) pgend_trans_rollback_edit (QofBackend * bend, Transaction * trans)
{ {
PGBackend *be = (PGBackend *)bend; PGBackend *be = (PGBackend *)bend;
const GUID * trans_guid; const GUID * trans_guid;
@ -1102,7 +1102,7 @@ pgend_trans_rollback_edit (Backend * bend, Transaction * trans)
if (-1 < pgendTransactionGetDeletedVersion (be, trans)) if (-1 < pgendTransactionGetDeletedVersion (be, trans))
{ {
LEAVE ("destroyed"); LEAVE ("destroyed");
xaccBackendSetError (&be->be, ERR_BACKEND_MOD_DESTROY); qof_backend_set_error (&be->be, ERR_BACKEND_MOD_DESTROY);
return; return;
} }

View File

@ -48,8 +48,8 @@ void pgendCopySplitsToEngine (PGBackend *be, Transaction *trans);
void pgendStoreAllTransactions (PGBackend *be, AccountGroup *grp); void pgendStoreAllTransactions (PGBackend *be, AccountGroup *grp);
void pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans, gboolean do_check_version); void pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans, gboolean do_check_version);
void pgend_trans_commit_edit (Backend * bend, Transaction * trans, Transaction * oldtrans); void pgend_trans_commit_edit (QofBackend * bend, Transaction * trans, Transaction * oldtrans);
void pgend_trans_rollback_edit (Backend * bend, Transaction * trans); void pgend_trans_rollback_edit (QofBackend * bend, Transaction * trans);

View File

@ -36,12 +36,12 @@
#include "AccountP.h" #include "AccountP.h"
#include "Group.h" #include "Group.h"
#include "GroupP.h" #include "GroupP.h"
#include "gnc-book.h"
#include "gnc-book-p.h"
#include "gnc-commodity.h" #include "gnc-commodity.h"
#include "gnc-engine-util.h" #include "gnc-engine-util.h"
#include "gnc-event.h" #include "gnc-event.h"
#include "guid.h" #include "guid.h"
#include "qofbook.h"
#include "qofbook-p.h"
#include "Transaction.h" #include "Transaction.h"
#include "TransactionP.h" #include "TransactionP.h"
@ -59,7 +59,7 @@ static short module = MOD_TXN;
static gpointer static gpointer
get_mass_trans_cb (PGBackend *be, PGresult *result, int j, gpointer data) get_mass_trans_cb (PGBackend *be, PGresult *result, int j, gpointer data)
{ {
GNCBook *book = data; QofBook *book = data;
GList *xaction_list = be->tmp_return; GList *xaction_list = be->tmp_return;
Transaction *trans; Transaction *trans;
gnc_commodity *currency = NULL; gnc_commodity *currency = NULL;
@ -123,7 +123,7 @@ get_mass_trans_cb (PGBackend *be, PGresult *result, int j, gpointer data)
static gpointer static gpointer
get_mass_entry_cb (PGBackend *be, PGresult *result, int j, gpointer data) get_mass_entry_cb (PGBackend *be, PGresult *result, int j, gpointer data)
{ {
GNCBook *book = data; QofBook *book = data;
Transaction *trans=NULL; Transaction *trans=NULL;
Account *acc; Account *acc;
Split *s; Split *s;
@ -218,7 +218,7 @@ get_mass_entry_cb (PGBackend *be, PGresult *result, int j, gpointer data)
/* ============================================================= */ /* ============================================================= */
void void
pgendGetMassTransactions (PGBackend *be, GNCBook *book) pgendGetMassTransactions (PGBackend *be, QofBook *book)
{ {
char *p, buff[900]; char *p, buff[900];
GList *node, *xaction_list = NULL; GList *node, *xaction_list = NULL;
@ -235,7 +235,7 @@ pgendGetMassTransactions (PGBackend *be, GNCBook *book)
" WHERE gncTransaction.transGuid = gncEntry.transGuid AND " " WHERE gncTransaction.transGuid = gncEntry.transGuid AND "
" gncEntry.accountGuid = gncAccount.accountGuid AND " " gncEntry.accountGuid = gncAccount.accountGuid AND "
" gncAccount.bookGuid = '"); " gncAccount.bookGuid = '");
p = guid_to_string_buff(gnc_book_get_guid (book), p); p = guid_to_string_buff(qof_book_get_guid (book), p);
p = stpcpy (p, "';"); p = stpcpy (p, "';");
SEND_QUERY (be, buff, ); SEND_QUERY (be, buff, );
@ -252,7 +252,7 @@ pgendGetMassTransactions (PGBackend *be, GNCBook *book)
" FROM gncEntry, gncAccount " " FROM gncEntry, gncAccount "
" WHERE gncEntry.accountGuid = gncAccount.accountGuid AND " " WHERE gncEntry.accountGuid = gncAccount.accountGuid AND "
" gncAccount.bookGuid = '"); " gncAccount.bookGuid = '");
p = guid_to_string_buff(gnc_book_get_guid (book), p); p = guid_to_string_buff(qof_book_get_guid (book), p);
p = stpcpy (p, "';"); p = stpcpy (p, "';");
SEND_QUERY (be, buff, ); SEND_QUERY (be, buff, );
pgendGetResults (be, get_mass_entry_cb, book); pgendGetResults (be, get_mass_entry_cb, book);

View File

@ -23,10 +23,10 @@
#ifndef POSTGRES_TXN_MASS_H #ifndef POSTGRES_TXN_MASS_H
#define POSTGRES_TXN_MASS_H #define POSTGRES_TXN_MASS_H
#include "gnc-book.h" #include "qofbook.h"
#include "PostgresBackend.h" #include "PostgresBackend.h"
void pgendGetMassTransactions (PGBackend *be, GNCBook*); void pgendGetMassTransactions (PGBackend *be, QofBook*);
#endif /* POSTGRES_TXN_MASS_H */ #endif /* POSTGRES_TXN_MASS_H */

View File

@ -339,20 +339,20 @@ add_multiple_book_support (PGBackend *be)
p = buff; p = buff;
p = stpcpy (p, "UPDATE gncAccount SET bookGuid = '"); p = stpcpy (p, "UPDATE gncAccount SET bookGuid = '");
p = guid_to_string_buff (gnc_book_get_guid (be->book), p); p = guid_to_string_buff (qof_book_get_guid (be->book), p);
p = stpcpy (p, "';\n"); p = stpcpy (p, "';\n");
p = stpcpy (p, "UPDATE gncAccountTrail SET bookGuid = '"); p = stpcpy (p, "UPDATE gncAccountTrail SET bookGuid = '");
p = guid_to_string_buff (gnc_book_get_guid (be->book), p); p = guid_to_string_buff (qof_book_get_guid (be->book), p);
p = stpcpy (p, "';\n"); p = stpcpy (p, "';\n");
SEND_QUERY (be,buff, ); SEND_QUERY (be,buff, );
FINISH_QUERY(be->connection); FINISH_QUERY(be->connection);
p = buff; p = buff;
p = stpcpy (p, "UPDATE gncPrice SET bookGuid = '"); p = stpcpy (p, "UPDATE gncPrice SET bookGuid = '");
p = guid_to_string_buff (gnc_book_get_guid (be->book), p); p = guid_to_string_buff (qof_book_get_guid (be->book), p);
p = stpcpy (p, "';\n"); p = stpcpy (p, "';\n");
p = stpcpy (p, "UPDATE gncPriceTrail SET bookGuid = '"); p = stpcpy (p, "UPDATE gncPriceTrail SET bookGuid = '");
p = guid_to_string_buff (gnc_book_get_guid (be->book), p); p = guid_to_string_buff (qof_book_get_guid (be->book), p);
p = stpcpy (p, "';\n"); p = stpcpy (p, "';\n");
SEND_QUERY (be,buff, ); SEND_QUERY (be,buff, );
FINISH_QUERY(be->connection); FINISH_QUERY(be->connection);
@ -360,7 +360,7 @@ add_multiple_book_support (PGBackend *be)
p = buff; p = buff;
p = stpcpy (p, "INSERT INTO gncBook (bookGuid, book_open, version, iguid) " p = stpcpy (p, "INSERT INTO gncBook (bookGuid, book_open, version, iguid) "
"VALUES ('"); "VALUES ('");
p = guid_to_string_buff (gnc_book_get_guid (be->book), p); p = guid_to_string_buff (qof_book_get_guid (be->book), p);
p = stpcpy (p, "', 'y', 1, 0);"); p = stpcpy (p, "', 'y', 1, 0);");
SEND_QUERY (be,buff, ); SEND_QUERY (be,buff, );
FINISH_QUERY(be->connection); FINISH_QUERY(be->connection);
@ -387,7 +387,7 @@ pgendDBVersionIsCurrent (PGBackend *be)
if (1 > vers.major) if (1 > vers.major)
{ {
xaccBackendSetError (&be->be, ERR_BACKEND_DATA_CORRUPT); qof_backend_set_error (&be->be, ERR_BACKEND_DATA_CORRUPT);
return -1; return -1;
} }
@ -397,7 +397,7 @@ pgendDBVersionIsCurrent (PGBackend *be)
/* check to see if this client can connect */ /* check to see if this client can connect */
if (PGEND_CURRENT_MAJOR_VERSION < vers.major) if (PGEND_CURRENT_MAJOR_VERSION < vers.major)
{ {
xaccBackendSetError (&be->be, ERR_BACKEND_TOO_NEW); qof_backend_set_error (&be->be, ERR_BACKEND_TOO_NEW);
return -1; return -1;
} }