r19364 - gnucash/trunk - Merge the sql parsers of the business objects into the main sql module.

Christian Stimming cstim at code.gnucash.org
Wed Jul 14 15:39:20 EDT 2010


Author: cstim
Date: 2010-07-14 15:39:19 -0400 (Wed, 14 Jul 2010)
New Revision: 19364
Trac: http://svn.gnucash.org/trac/changeset/19364

Added:
   gnucash/trunk/src/backend/dbi/test/test-dbi-business-stuff.c
   gnucash/trunk/src/backend/dbi/test/test-dbi-business-stuff.h
   gnucash/trunk/src/backend/dbi/test/test-dbi-business.c
   gnucash/trunk/src/backend/sql/gnc-address-sql.c
   gnucash/trunk/src/backend/sql/gnc-address-sql.h
   gnucash/trunk/src/backend/sql/gnc-bill-term-sql.c
   gnucash/trunk/src/backend/sql/gnc-bill-term-sql.h
   gnucash/trunk/src/backend/sql/gnc-customer-sql.c
   gnucash/trunk/src/backend/sql/gnc-customer-sql.h
   gnucash/trunk/src/backend/sql/gnc-employee-sql.c
   gnucash/trunk/src/backend/sql/gnc-employee-sql.h
   gnucash/trunk/src/backend/sql/gnc-entry-sql.c
   gnucash/trunk/src/backend/sql/gnc-entry-sql.h
   gnucash/trunk/src/backend/sql/gnc-invoice-sql.c
   gnucash/trunk/src/backend/sql/gnc-invoice-sql.h
   gnucash/trunk/src/backend/sql/gnc-job-sql.c
   gnucash/trunk/src/backend/sql/gnc-job-sql.h
   gnucash/trunk/src/backend/sql/gnc-order-sql.c
   gnucash/trunk/src/backend/sql/gnc-order-sql.h
   gnucash/trunk/src/backend/sql/gnc-owner-sql.c
   gnucash/trunk/src/backend/sql/gnc-owner-sql.h
   gnucash/trunk/src/backend/sql/gnc-tax-table-sql.c
   gnucash/trunk/src/backend/sql/gnc-tax-table-sql.h
   gnucash/trunk/src/backend/sql/gnc-vendor-sql.c
   gnucash/trunk/src/backend/sql/gnc-vendor-sql.h
Removed:
   gnucash/trunk/src/business/business-core/sql/CMakeLists.txt
   gnucash/trunk/src/business/business-core/sql/Makefile.am
   gnucash/trunk/src/business/business-core/sql/gnc-address-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-address-sql.h
   gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.h
   gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.h
   gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.h
   gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.h
   gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.h
   gnucash/trunk/src/business/business-core/sql/gnc-job-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-job-sql.h
   gnucash/trunk/src/business/business-core/sql/gnc-order-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-order-sql.h
   gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.h
   gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.h
   gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.c
   gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.h
   gnucash/trunk/src/business/business-core/sql/gncmod-business-backend-sql.c
   gnucash/trunk/src/business/business-core/sql/gncmod-business-backend-sql.h
   gnucash/trunk/src/business/business-core/sql/test/Makefile.am
   gnucash/trunk/src/business/business-core/sql/test/test-dbi-business-stuff.c
   gnucash/trunk/src/business/business-core/sql/test/test-dbi-business-stuff.h
   gnucash/trunk/src/business/business-core/sql/test/test-dbi-business.c
Modified:
   gnucash/trunk/configure.ac
   gnucash/trunk/src/CMakeLists.txt
   gnucash/trunk/src/backend/dbi/test/Makefile.am
   gnucash/trunk/src/backend/sql/CMakeLists.txt
   gnucash/trunk/src/backend/sql/Makefile.am
   gnucash/trunk/src/backend/sql/gnc-backend-sql.c
   gnucash/trunk/src/backend/sql/test/Makefile.am
   gnucash/trunk/src/business/business-core/Makefile.am
   gnucash/trunk/src/business/business-gnome/business-gnome.scm
   gnucash/trunk/src/gnc/CMakeLists.txt
   gnucash/trunk/src/optional/python-bindings/gnucash_core.i
Log:
Merge the sql parsers of the business objects into the main sql module.

Also, completely remove the business-core/sql module because it is
no longer needed. The tests of this module have been moved into
backend/dbi because they depend on sql+dbi, but not more than that.

Modified: gnucash/trunk/configure.ac
===================================================================
--- gnucash/trunk/configure.ac	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/configure.ac	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1485,8 +1485,6 @@
           src/test-core/Makefile
           src/business/Makefile
           src/business/business-core/Makefile
-          src/business/business-core/sql/Makefile
-          src/business/business-core/sql/test/Makefile
           src/business/business-core/test/Makefile
           src/business/business-utils/Makefile
           src/business/dialog-tax-table/Makefile

Modified: gnucash/trunk/src/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/CMakeLists.txt	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/CMakeLists.txt	2010-07-14 19:39:19 UTC (rev 19364)
@@ -93,7 +93,6 @@
 IF (WITH_SQL)
   ADD_SUBDIRECTORY (backend/dbi)
   ADD_SUBDIRECTORY (backend/sql)
-  ADD_SUBDIRECTORY (business/business-core/sql)
 ENDIF (WITH_SQL)
 
 ADD_SUBDIRECTORY (gnc)

Modified: gnucash/trunk/src/backend/dbi/test/Makefile.am
===================================================================
--- gnucash/trunk/src/backend/dbi/test/Makefile.am	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/backend/dbi/test/Makefile.am	2010-07-14 19:39:19 UTC (rev 19364)
@@ -6,6 +6,10 @@
     test-dbi-stuff.c
 libgncmod_test_dbi_la_LDFLAGS = -module
 
+test_dbi_business_SOURCES = \
+  test-dbi-business.c \
+  test-dbi-business-stuff.c
+
 test_dbi_basic_SOURCES = \
   test-dbi-basic.c
 
@@ -15,6 +19,7 @@
 TESTS = \
   test-dbi-basic \
   test-dbi \
+  test-dbi-business \
   test-load-backend
 
 GNC_TEST_DEPS = \
@@ -38,6 +43,7 @@
 check_PROGRAMS = \
   test-dbi-basic \
   test-dbi \
+  test-dbi-business \
   test-load-backend
 
 EXTRA_DIST = \
@@ -50,6 +56,7 @@
         ${top_builddir}/src/core-utils/libgnc-core-utils.la \
         ${top_builddir}/src/libqof/qof/libgnc-qof.la \
         ${top_builddir}/src/backend/dbi/test/libgncmod-test-dbi.la \
+        ${top_builddir}/src/backend/sql/libgnc-backend-sql.la \
         ${top_builddir}/lib/libc/libc-missing.la
 
 AM_CFLAGS = \
@@ -61,6 +68,7 @@
   -I${top_srcdir}/src/engine \
   -I${top_srcdir}/src/engine/test-core \
   -I${top_srcdir}/src/libqof/qof \
+  -I${top_srcdir}/src/backend/sql \
   -DTEST_MYSQL_URL=\"${TEST_MYSQL_URL}\" \
   -DTEST_PGSQL_URL=\"${TEST_PGSQL_URL}\" \
   ${GLIB_CFLAGS} \

Copied: gnucash/trunk/src/backend/dbi/test/test-dbi-business-stuff.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/test/test-dbi-business-stuff.c)
===================================================================
--- gnucash/trunk/src/backend/dbi/test/test-dbi-business-stuff.c	                        (rev 0)
+++ gnucash/trunk/src/backend/dbi/test/test-dbi-business-stuff.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,218 @@
+/***************************************************************************
+ *            test-dbi-business-stuff.c
+ *
+ *  Tests saving and loading business objects to a dbi/sqlite3 db
+ *
+ *  Copyright (C) 2010  Phil Longstaff <plongstaff at rogers.com>
+ ****************************************************************************/
+
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+#include "config.h"
+#include "qof.h"
+#include "cashobjects.h"
+#include "test-engine-stuff.h"
+#include "test-stuff.h"
+#include "test-dbi-stuff.h"
+#include "test-dbi-business-stuff.h"
+
+#include "Account.h"
+#include "Split.h"
+#include "Transaction.h"
+#include "gnc-commodity.h"
+#include "gncCustomer.h"
+#include "gncInvoice.h"
+#include "gncEmployee.h"
+#include "gncVendor.h"
+
+static QofLogModule log_module = "test-dbi";
+
+static void
+compare_single_customer( QofInstance* inst, gpointer user_data )
+{
+    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
+    GncCustomer* cust_1 = GNC_CUSTOMER(inst);
+    GncCustomer* cust_2 = gncCustomerLookup( info->book_2, qof_instance_get_guid(inst) );
+
+    if (!gncCustomerEqual( cust_1, cust_2 ))
+    {
+        info->result = FALSE;
+    }
+}
+
+static void
+compare_customers( QofBook* book_1, QofBook* book_2 )
+{
+    do_compare( book_1, book_2, GNC_ID_CUSTOMER, compare_single_customer, "Customer lists match" );
+}
+
+static void
+compare_single_employee( QofInstance* inst, gpointer user_data )
+{
+    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
+    GncEmployee* emp_1 = GNC_EMPLOYEE(inst);
+    GncEmployee* emp_2 = gncEmployeeLookup( info->book_2, qof_instance_get_guid(inst) );
+
+    if (!gncEmployeeEqual( emp_1, emp_2 ))
+    {
+        info->result = FALSE;
+    }
+}
+
+static void
+compare_employees( QofBook* book_1, QofBook* book_2 )
+{
+    do_compare( book_1, book_2, GNC_ID_EMPLOYEE, compare_single_employee, "Employee lists match" );
+}
+
+static void
+compare_single_invoice( QofInstance* inst, gpointer user_data )
+{
+    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
+    GncInvoice* inv_1 = GNC_INVOICE(inst);
+    GncInvoice* inv_2 = gncInvoiceLookup( info->book_2, qof_instance_get_guid(inst) );
+
+    if (!gncInvoiceEqual( inv_1, inv_2 ))
+    {
+        info->result = FALSE;
+    }
+}
+
+static void
+compare_invoices( QofBook* book_1, QofBook* book_2 )
+{
+    do_compare( book_1, book_2, GNC_ID_INVOICE, compare_single_invoice, "Invoice lists match" );
+}
+
+static void
+compare_single_job( QofInstance* inst, gpointer user_data )
+{
+    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
+    GncJob* job_1 = GNC_JOB(inst);
+    GncJob* job_2 = gncJobLookup( info->book_2, qof_instance_get_guid(inst) );
+
+    if (!gncJobEqual( job_1, job_2 ))
+    {
+        info->result = FALSE;
+    }
+}
+
+static void
+compare_jobs( QofBook* book_1, QofBook* book_2 )
+{
+    do_compare( book_1, book_2, GNC_ID_JOB, compare_single_job, "Job lists match" );
+}
+
+static void
+compare_single_vendor( QofInstance* inst, gpointer user_data )
+{
+    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
+    GncVendor* vendor_1 = GNC_VENDOR(inst);
+    GncVendor* vendor_2 = gncVendorLookup( info->book_2, qof_instance_get_guid(inst) );
+
+    if (!gncVendorEqual( vendor_1, vendor_2 ))
+    {
+        info->result = FALSE;
+    }
+}
+
+static void
+compare_vendors( QofBook* book_1, QofBook* book_2 )
+{
+    do_compare( book_1, book_2, GNC_ID_VENDOR, compare_single_vendor, "Vendor lists match" );
+}
+
+static void
+compare_single_billterm( QofInstance* inst, gpointer user_data )
+{
+    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
+    GncBillTerm* bt_1 = GNC_BILLTERM(inst);
+    GncBillTerm* bt_2 = gncBillTermLookup( info->book_2, qof_instance_get_guid(inst) );
+
+    if (!gncBillTermEqual( bt_1, bt_2 ))
+    {
+        info->result = FALSE;
+    }
+}
+
+static void
+compare_billterms( QofBook* book_1, QofBook* book_2 )
+{
+    do_compare( book_1, book_2, GNC_ID_BILLTERM, compare_single_billterm, "Billterms lists match" );
+}
+
+static void
+compare_single_taxtable( QofInstance* inst, gpointer user_data )
+{
+    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
+    GncTaxTable* tt_1 = GNC_TAXTABLE(inst);
+    GncTaxTable* tt_2 = gncTaxTableLookup( info->book_2, qof_instance_get_guid(inst) );
+
+    if (!gncTaxTableEqual( tt_1, tt_2 ))
+    {
+        info->result = FALSE;
+    }
+}
+
+static void
+compare_taxtables( QofBook* book_1, QofBook* book_2 )
+{
+    do_compare( book_1, book_2, GNC_ID_TAXTABLE, compare_single_taxtable, "TaxTable lists match" );
+}
+
+static void
+compare_books( QofBook* book_1, QofBook* book_2 )
+{
+    compare_billterms( book_1, book_2 );
+    compare_taxtables( book_1, book_2 );
+
+    compare_customers( book_1, book_2 );
+    compare_employees( book_1, book_2 );
+    compare_invoices( book_1, book_2 );
+    compare_jobs( book_1, book_2 );
+    compare_vendors( book_1, book_2 );
+}
+
+void
+test_dbi_business_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url )
+{
+    QofSession* session_2;
+    QofSession* session_3;
+
+    printf( "Testing %s\n", driver );
+
+    // Save the session data
+    session_2 = qof_session_new();
+    qof_session_begin( session_2, url, TRUE, TRUE );
+    qof_session_swap_data( session_1, session_2 );
+    qof_session_save( session_2, NULL );
+
+    // Reload the session data
+    session_3 = qof_session_new();
+    qof_session_begin( session_3, url, FALSE, FALSE );
+    qof_session_load( session_3, NULL );
+
+    // Compare with the original data
+    compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) );
+    qof_session_end( session_1 );
+    qof_session_destroy( session_1 );
+    qof_session_end( session_2 );
+    qof_session_destroy( session_2 );
+    qof_session_end( session_3 );
+    qof_session_destroy( session_3 );
+}

Copied: gnucash/trunk/src/backend/dbi/test/test-dbi-business-stuff.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/test/test-dbi-business-stuff.h)
===================================================================
--- gnucash/trunk/src/backend/dbi/test/test-dbi-business-stuff.h	                        (rev 0)
+++ gnucash/trunk/src/backend/dbi/test/test-dbi-business-stuff.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,39 @@
+/***************************************************************************
+ *            test-dbi-stuff.h
+ *
+ *  Tests saving and loading to a dbi/sqlite3 db
+ *
+ *  Copyright (C) 2009  Phil Longstaff <plongstaff at rogers.com>
+ ****************************************************************************/
+
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+#ifndef _TEST_DBI_BUSINESS_STUFF_H_
+#define _TEST_DBI_BUSINESS_STUFF_H_
+
+/**
+ * Test storing a session contents to a db, reloading into a new session, then comparing the
+ * two sessions.
+ *
+ * @param driver Driver name
+ * @param session_1 Session to test
+ * @param url Database URL
+ */
+void test_dbi_business_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url );
+
+#endif

Copied: gnucash/trunk/src/backend/dbi/test/test-dbi-business.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/test/test-dbi-business.c)
===================================================================
--- gnucash/trunk/src/backend/dbi/test/test-dbi-business.c	                        (rev 0)
+++ gnucash/trunk/src/backend/dbi/test/test-dbi-business.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,189 @@
+/***************************************************************************
+ *            test-dbi-business.c
+ *
+ *  Tests saving and loading business objects to a dbi/sqlite3 db
+ *
+ *  Copyright (C) 2010  Phil Longstaff <plongstaff at rogers.com>
+ ****************************************************************************/
+
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+#include "config.h"
+#include "qof.h"
+#include "cashobjects.h"
+#include "test-engine-stuff.h"
+#include "test-stuff.h"
+#include "test-dbi-business-stuff.h"
+
+#include "Account.h"
+#include "Transaction.h"
+#include "Split.h"
+#include "gnc-commodity.h"
+#include "gncAddress.h"
+#include "gncCustomer.h"
+#include "gncInvoice.h"
+
+#include "gnc-backend-sql.h"
+
+#include "gnc-address-sql.h"
+#include "gnc-bill-term-sql.h"
+#include "gnc-customer-sql.h"
+#include "gnc-employee-sql.h"
+#include "gnc-entry-sql.h"
+#include "gnc-invoice-sql.h"
+#include "gnc-job-sql.h"
+#include "gnc-order-sql.h"
+#include "gnc-owner-sql.h"
+#include "gnc-tax-table-sql.h"
+#include "gnc-vendor-sql.h"
+
+#define FILE_NAME "sqlite3:///tmp/test-sqlite3-file"
+#define GNC_LIB_NAME "gncmod-backend-dbi"
+
+static QofSession*
+create_session(void)
+{
+    QofSession* session = qof_session_new();
+    QofBook* book = qof_session_get_book( session );
+    Account* root = gnc_book_get_root_account( book );
+    Account* acct1;
+    Account* acct2;
+    gnc_commodity_table* table;
+    gnc_commodity* currency;
+    GncAddress* addr;
+    GncCustomer* cust;
+    GncEmployee* emp;
+    GncVendor* v;
+    GncInvoice* inv;
+    GncJob* job;
+    GncTaxTable* tt;
+    GncTaxTableEntry* tte;
+
+    table = gnc_commodity_table_get_table( book );
+    currency = gnc_commodity_table_lookup( table, GNC_COMMODITY_NS_CURRENCY, "CAD" );
+
+    acct1 = xaccMallocAccount( book );
+    xaccAccountSetType( acct1, ACCT_TYPE_BANK );
+    xaccAccountSetName( acct1, "Bank 1" );
+    xaccAccountSetCommodity( acct1, currency );
+    xaccAccountSetHidden( acct1, FALSE );
+    xaccAccountSetPlaceholder( acct1, FALSE );
+    gnc_account_append_child( root, acct1 );
+
+    acct2 = xaccMallocAccount( book );
+    xaccAccountSetType( acct2, ACCT_TYPE_BANK );
+    xaccAccountSetName( acct2, "Bank 2" );
+    xaccAccountSetCommodity( acct2, currency );
+    xaccAccountSetHidden( acct2, FALSE );
+    xaccAccountSetPlaceholder( acct2, FALSE );
+    gnc_account_append_child( root, acct2 );
+
+    tt = gncTaxTableCreate( book );
+    gncTaxTableSetName( tt, "tt" );
+    tte = gncTaxTableEntryCreate();
+    gncTaxTableEntrySetAccount( tte, acct1 );
+    gncTaxTableEntrySetType( tte, GNC_AMT_TYPE_VALUE );
+    gncTaxTableEntrySetAmount( tte, gnc_numeric_zero() );
+    gncTaxTableAddEntry( tt, tte );
+    tte = gncTaxTableEntryCreate();
+    gncTaxTableEntrySetAccount( tte, acct2 );
+    gncTaxTableEntrySetType( tte, GNC_AMT_TYPE_PERCENT );
+    gncTaxTableEntrySetAmount( tte, gnc_numeric_zero() );
+    gncTaxTableAddEntry( tt, tte );
+
+    cust = gncCustomerCreate( book );
+    gncCustomerSetID( cust, "0001" );
+    gncCustomerSetName( cust, "MyCustomer" );
+    gncCustomerSetNotes( cust, "Here are some notes" );
+    gncCustomerSetCurrency( cust, currency );
+    addr = gncAddressCreate( book, QOF_INSTANCE(cust) );
+    gncAddressSetName( addr, "theAddress" );
+    gncAddressSetAddr1( addr, "Address line #1" );
+    gncAddressSetAddr2( addr, "Address line #2" );
+    gncAddressSetAddr3( addr, "Address line #3" );
+    gncAddressSetAddr4( addr, "Address line #4" );
+    gncAddressSetPhone( addr, "(123) 555-1212" );
+    gncAddressSetPhone( addr, "(123) 555-2121" );
+    gncAddressSetEmail( addr, "cust at mycustomer.com" );
+
+    emp = gncEmployeeCreate( book );
+    gncEmployeeSetID( emp, "0001" );
+    gncEmployeeSetUsername( emp, "gnucash" );
+    gncEmployeeSetLanguage( emp, "english" );
+    gncEmployeeSetCurrency( emp, currency );
+
+    return session;
+}
+
+/* Order in which business objects need to be loaded */
+static const gchar* fixed_load_order[] =
+{ GNC_ID_BILLTERM, GNC_ID_TAXTABLE, NULL };
+
+static void
+init_business_sql(void)
+{
+    /* Initialize our pointers into the backend subsystem */
+    gnc_address_sql_initialize();
+    gnc_billterm_sql_initialize();
+    gnc_customer_sql_initialize();
+    gnc_employee_sql_initialize();
+    gnc_entry_sql_initialize();
+    gnc_invoice_sql_initialize();
+    gnc_job_sql_initialize();
+    gnc_order_sql_initialize();
+    gnc_owner_sql_initialize();
+    gnc_taxtable_sql_initialize();
+    gnc_vendor_sql_initialize();
+
+    gnc_sql_set_load_order( fixed_load_order );
+}
+
+int main (int argc, char ** argv)
+{
+    gchar* filename;
+    QofSession* session_1;
+
+    qof_init();
+    cashobjects_register();
+    qof_load_backend_library ("../../../../backend/dbi/.libs/", GNC_LIB_NAME);
+    init_business_sql();
+
+    // Create a session with data
+    session_1 = create_session();
+    filename = tempnam( "/tmp", "test-sqlite3-" );
+    printf( "Using filename: %s\n", filename );
+    test_dbi_business_store_and_reload( "sqlite3", session_1, filename );
+#if 0
+    printf( "TEST_MYSQL_URL='%s'\n", TEST_MYSQL_URL );
+    if ( strlen( TEST_MYSQL_URL ) > 0 )
+    {
+        session_1 = create_session();
+        test_dbi_store_and_reload( "mysql", session_1, TEST_MYSQL_URL );
+    }
+    printf( "TEST_PGSQL_URL='%s'\n", TEST_PGSQL_URL );
+    if ( strlen( TEST_PGSQL_URL ) > 0 )
+    {
+        session_1 = create_session();
+        test_dbi_store_and_reload( "pgsql", session_1, TEST_PGSQL_URL );
+    }
+#endif
+    print_test_results();
+    qof_close();
+    exit(get_rv());
+}
+

Modified: gnucash/trunk/src/backend/sql/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/backend/sql/CMakeLists.txt	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/backend/sql/CMakeLists.txt	2010-07-14 19:39:19 UTC (rev 19364)
@@ -18,29 +18,51 @@
 SET (libgnc_backend_sql_SOURCES
   gnc-backend-sql.c
   gnc-account-sql.c
+  gnc-address-sql.c
+  gnc-bill-term-sql.c
   gnc-book-sql.c
   gnc-budget-sql.c
   gnc-commodity-sql.c
+  gnc-customer-sql.c
+  gnc-employee-sql.c
+  gnc-entry-sql.c
+  gnc-invoice-sql.c
+  gnc-job-sql.c
   gnc-lots-sql.c
+  gnc-order-sql.c
+  gnc-owner-sql.c
   gnc-price-sql.c
   gnc-recurrence-sql.c
   gnc-schedxaction-sql.c
   gnc-slots-sql.c
+  gnc-tax-table-sql.c
   gnc-transaction-sql.c
+  gnc-vendor-sql.c
   escape.c
 )
 SET (libgnc_backend_sql_HEADERS
   gnc-account-sql.h
+  gnc-address-sql.h
   gnc-backend-sql.h
+  gnc-bill-term-sql.h
   gnc-book-sql.h
   gnc-budget-sql.h
   gnc-commodity-sql.h
+  gnc-customer-sql.h
+  gnc-employee-sql.h
+  gnc-entry-sql.h
+  gnc-invoice-sql.h
+  gnc-job-sql.h
   gnc-lots-sql.h
+  gnc-order-sql.h
+  gnc-owner-sql.h
   gnc-price-sql.h
   gnc-recurrence-sql.h
   gnc-schedxaction-sql.h
   gnc-slots-sql.h
+  gnc-tax-table-sql.h
   gnc-transaction-sql.h
+  gnc-vendor-sql.h
   escape.h
 )
 

Modified: gnucash/trunk/src/backend/sql/Makefile.am
===================================================================
--- gnucash/trunk/src/backend/sql/Makefile.am	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/backend/sql/Makefile.am	2010-07-14 19:39:19 UTC (rev 19364)
@@ -21,29 +21,51 @@
 libgnc_backend_sql_la_SOURCES = \
   gnc-backend-sql.c \
   gnc-account-sql.c \
+  gnc-address-sql.c \
+  gnc-bill-term-sql.c \
   gnc-book-sql.c \
   gnc-budget-sql.c \
   gnc-commodity-sql.c \
+  gnc-customer-sql.c \
+  gnc-employee-sql.c \
+  gnc-entry-sql.c \
+  gnc-invoice-sql.c \
+  gnc-job-sql.c \
   gnc-lots-sql.c \
+  gnc-order-sql.c \
+  gnc-owner-sql.c \
   gnc-price-sql.c \
   gnc-recurrence-sql.c \
   gnc-schedxaction-sql.c \
   gnc-slots-sql.c \
+  gnc-tax-table-sql.c \
   gnc-transaction-sql.c \
+  gnc-vendor-sql.c \
   escape.c
 
 noinst_HEADERS = \
   gnc-account-sql.h \
+  gnc-address-sql.h \
   gnc-backend-sql.h \
+  gnc-bill-term-sql.h \
   gnc-book-sql.h \
   gnc-budget-sql.h \
   gnc-commodity-sql.h \
+  gnc-customer-sql.h \
+  gnc-employee-sql.h \
+  gnc-entry-sql.h \
+  gnc-invoice-sql.h \
+  gnc-job-sql.h \
   gnc-lots-sql.h \
+  gnc-order-sql.h \
+  gnc-owner-sql.h \
   gnc-price-sql.h \
   gnc-recurrence-sql.h \
   gnc-schedxaction-sql.h \
   gnc-slots-sql.h \
+  gnc-tax-table-sql.h \
   gnc-transaction-sql.h \
+  gnc-vendor-sql.h \
   escape.h
 
 libgnc_backend_sql_la_LIBADD = \

Copied: gnucash/trunk/src/backend/sql/gnc-address-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-address-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-address-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-address-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,232 @@
+/********************************************************************\
+ * gnc-address-sql.c -- address sql backend implementation          *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-address-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-engine.h"
+
+#include "gnc-backend-sql.h"
+#include "gnc-address-sql.h"
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+#define ADDRESS_MAX_NAME_LEN 1024
+#define ADDRESS_MAX_ADDRESS_LINE_LEN 1024
+#define ADDRESS_MAX_PHONE_LEN 128
+#define ADDRESS_MAX_FAX_LEN 128
+#define ADDRESS_MAX_EMAIL_LEN 256
+
+static GncSqlColumnTableEntry col_table[] =
+{
+    { "name",  CT_STRING, ADDRESS_MAX_NAME_LEN,         COL_NNUL, "name" },
+    { "addr1", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_ONE },
+    { "addr2", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_TWO },
+    { "addr3", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_THREE },
+    { "addr4", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_FOUR },
+    { "phone", CT_STRING, ADDRESS_MAX_PHONE_LEN,        COL_NNUL, NULL, ADDRESS_PHONE },
+    { "fax",   CT_STRING, ADDRESS_MAX_FAX_LEN,          COL_NNUL, NULL, ADDRESS_FAX },
+    { "email", CT_STRING, ADDRESS_MAX_EMAIL_LEN,        COL_NNUL, NULL, ADDRESS_EMAIL },
+    { NULL }
+};
+
+typedef void (*AddressSetterFunc)( gpointer, GncAddress* );
+typedef GncAddress* (*AddressGetterFunc)( const gpointer );
+
+static void
+load_address( const GncSqlBackend* be, GncSqlRow* row,
+              QofSetterFunc setter, gpointer pObject,
+              const GncSqlColumnTableEntry* table_row )
+{
+    const GValue* val;
+    gchar* buf;
+    GncAddress* addr;
+    AddressSetterFunc a_setter = (AddressSetterFunc)setter;
+    const GncSqlColumnTableEntry* subtable;
+    const gchar* s;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( row != NULL );
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( table_row != NULL );
+
+    addr = gncAddressCreate( be->primary_book, NULL );
+    for ( subtable = col_table; subtable->col_name != NULL; subtable++ )
+    {
+        buf = g_strdup_printf( "%s_%s", table_row->col_name, subtable->col_name );
+        val = gnc_sql_row_get_value_at_col_name( row, buf );
+        g_free( buf );
+        if ( val == NULL )
+        {
+            s = NULL;
+        }
+        else
+        {
+            s = g_value_get_string( val );
+        }
+        if ( subtable->gobj_param_name != NULL )
+        {
+            g_object_set( addr, subtable->gobj_param_name, s, NULL );
+        }
+        else
+        {
+            if ( subtable->qof_param_name != NULL )
+            {
+                setter = qof_class_get_parameter_setter( GNC_ID_ADDRESS, subtable->qof_param_name );
+            }
+            else
+            {
+                setter = subtable->setter;
+            }
+            (*setter)( addr, (const gpointer)s );
+        }
+    }
+    (*a_setter)( pObject, addr );
+}
+
+static void
+add_address_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,
+                              GList** pList )
+{
+    GncSqlColumnInfo* info;
+    gchar* buf;
+    const GncSqlColumnTableEntry* subtable_row;
+    const gchar* type;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( table_row != NULL );
+    g_return_if_fail( pList != NULL );
+
+    for ( subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++ )
+    {
+        buf = g_strdup_printf( "%s_%s", table_row->col_name, subtable_row->col_name );
+        info = g_new0( GncSqlColumnInfo, 1 );
+        info->name = buf;
+        info->type = BCT_STRING;
+        info->size = subtable_row->size;
+        info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
+        info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
+        info->is_unicode = TRUE;
+        *pList = g_list_append( *pList, info );
+    }
+}
+
+static void
+add_address_colname_to_list( const GncSqlColumnTableEntry* table_row, GList** pList )
+{
+    gnc_sql_add_subtable_colnames_to_list( table_row, col_table, pList );
+}
+
+static void
+get_gvalue_address( const GncSqlBackend* be, QofIdTypeConst obj_name, const gpointer pObject,
+                    const GncSqlColumnTableEntry* table_row, GValue* value )
+{
+    AddressGetterFunc getter;
+    GncAddress* addr;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( obj_name != NULL );
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( table_row != NULL );
+    g_return_if_fail( value != NULL );
+
+    memset( value, 0, sizeof( GValue ) );
+
+    getter = (AddressGetterFunc)gnc_sql_get_getter( obj_name, table_row );
+    addr = (*getter)( pObject );
+    g_value_init( value, gnc_address_get_type() );
+    g_value_set_object( value, addr );
+}
+
+static void
+add_gvalue_address_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
+                             const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList )
+{
+    GValue value;
+    GValue* subfield_value;
+    GncAddress* addr;
+    gchar* s;
+    QofAccessFunc getter;
+    const GncSqlColumnTableEntry* subtable_row;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( obj_name != NULL );
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( table_row != NULL );
+
+    memset( &value, 0, sizeof( GValue ) );
+    get_gvalue_address( be, obj_name, pObject, table_row, &value );
+
+    if ( G_VALUE_TYPE(&value) != 0 )
+    {
+        addr = g_value_get_object( &value );
+        for ( subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++ )
+        {
+            subfield_value = g_new0( GValue, 1 );
+            if ( subtable_row->gobj_param_name != NULL )
+            {
+                g_object_get( addr, subtable_row->gobj_param_name, &s, NULL );
+            }
+            else
+            {
+                getter = gnc_sql_get_getter( GNC_ID_ADDRESS, subtable_row );
+                s = (gchar*)(*getter)( addr, NULL );
+            }
+            g_value_init( subfield_value, G_TYPE_STRING );
+            if ( s )
+            {
+                g_value_set_string( subfield_value, s );
+            }
+            else
+            {
+                g_value_set_string( subfield_value, "NULL" );
+            }
+            (*pList) = g_slist_append( (*pList), subfield_value );
+        }
+    }
+}
+
+static GncSqlColumnTypeHandler address_handler
+= { load_address,
+    add_address_col_info_to_list,
+    add_address_colname_to_list,
+    add_gvalue_address_to_slist
+  };
+
+/* ================================================================= */
+void
+gnc_address_sql_initialize( void )
+{
+    gnc_sql_register_col_type_handler( CT_ADDRESS, &address_handler );
+}
+/* ========================== END OF FILE ===================== */

Copied: gnucash/trunk/src/backend/sql/gnc-address-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-address-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-address-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-address-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,38 @@
+/* gnc-address-sql.h -- Address SQL header
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-address-sql.h
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_ADDRESS_SQL_H
+#define GNC_ADDRESS_SQL_H
+
+#include "gncAddress.h"
+
+#define CT_ADDRESS "address"
+
+void gnc_address_sql_initialize( void );
+
+#endif /* GNC_ADDRESS_SQL_H */

Modified: gnucash/trunk/src/backend/sql/gnc-backend-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-backend-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/backend/sql/gnc-backend-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -59,6 +59,18 @@
 #include "gnc-slots-sql.h"
 #include "gnc-transaction-sql.h"
 
+#include "gnc-address-sql.h"
+#include "gnc-bill-term-sql.h"
+#include "gnc-customer-sql.h"
+#include "gnc-employee-sql.h"
+#include "gnc-entry-sql.h"
+#include "gnc-invoice-sql.h"
+#include "gnc-job-sql.h"
+#include "gnc-order-sql.h"
+#include "gnc-owner-sql.h"
+#include "gnc-tax-table-sql.h"
+#include "gnc-vendor-sql.h"
+
 #if defined( S_SPLINT_S )
 #include "splint-defs.h"
 #endif
@@ -1024,7 +1036,30 @@
 }
 
 /* ================================================================= */
+/* Order in which business objects need to be loaded */
+static const gchar* business_fixed_load_order[] =
+{ GNC_ID_BILLTERM, GNC_ID_TAXTABLE, NULL };
+
 static void
+business_core_sql_init(void)
+{
+    /* Initialize our pointers into the backend subsystem */
+    gnc_address_sql_initialize();
+    gnc_billterm_sql_initialize();
+    gnc_customer_sql_initialize();
+    gnc_employee_sql_initialize();
+    gnc_entry_sql_initialize();
+    gnc_invoice_sql_initialize();
+    gnc_job_sql_initialize();
+    gnc_order_sql_initialize();
+    gnc_owner_sql_initialize();
+    gnc_taxtable_sql_initialize();
+    gnc_vendor_sql_initialize();
+
+    gnc_sql_set_load_order( business_fixed_load_order );
+}
+
+static void
 gnc_sql_init_object_handlers( void )
 {
     gnc_sql_init_book_handler();
@@ -1037,6 +1072,9 @@
     gnc_sql_init_recurrence_handler();
     gnc_sql_init_schedxaction_handler();
     gnc_sql_init_lot_handler();
+
+    /* And the business objects */
+    business_core_sql_init();
 }
 
 /* ================================================================= */

Copied: gnucash/trunk/src/backend/sql/gnc-bill-term-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-bill-term-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-bill-term-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,413 @@
+/********************************************************************\
+ * gnc-bill-term-sql.c -- billing term sql backend                  *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-bill-term-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-backend-sql.h"
+#include "gnc-slots-sql.h"
+
+#include "gncBillTermP.h"
+#include "gncInvoice.h"
+#include "gnc-bill-term-sql.h"
+#include "qof.h"
+
+#define _GNC_MOD_NAME	GNC_ID_BILLTERM
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+#define MAX_NAME_LEN 2048
+#define MAX_DESCRIPTION_LEN 2048
+#define MAX_TYPE_LEN 2048
+
+static void set_invisible( gpointer data, gboolean value );
+static gpointer bt_get_parent( gpointer data );
+static void bt_set_parent( gpointer data, gpointer value );
+static void bt_set_parent_guid( gpointer data, gpointer value );
+
+#define TABLE_NAME "billterms"
+#define TABLE_VERSION 2
+
+static GncSqlColumnTableEntry col_table[] =
+{
+    { "guid",         CT_GUID,        0,                   COL_NNUL | COL_PKEY, "guid" },
+    { "name",         CT_STRING,      MAX_NAME_LEN,        COL_NNUL,          "name" },
+    { "description",  CT_STRING,      MAX_DESCRIPTION_LEN, COL_NNUL,          NULL, GNC_BILLTERM_DESC },
+    {
+        "refcount",     CT_INT,         0,                   COL_NNUL,          NULL, NULL,
+        (QofAccessFunc)gncBillTermGetRefcount,  (QofSetterFunc)gncBillTermSetRefcount
+    },
+    {
+        "invisible",    CT_BOOLEAN,     0,                   COL_NNUL,          NULL, NULL,
+        (QofAccessFunc)gncBillTermGetInvisible, (QofSetterFunc)set_invisible
+    },
+    {
+        "parent",       CT_GUID,       0,                   0,                 NULL, NULL,
+        (QofAccessFunc)bt_get_parent,    (QofSetterFunc)bt_set_parent
+    },
+#if 0
+    {
+        "child",        CT_BILLTERMREF, 0,                   0,                 NULL, NULL,
+        (QofAccessFunc)gncBillTermReturnChild,  (QofSetterFunc)gncBillTermSetChild
+    },
+#endif
+    { "type",         CT_STRING,      MAX_TYPE_LEN,        COL_NNUL,          NULL, GNC_BILLTERM_TYPE },
+    { "duedays",      CT_INT,         0,                   0,                 0,    GNC_BILLTERM_DUEDAYS },
+    { "discountdays", CT_INT,         0,                   0,                 0,    GNC_BILLTERM_DISCDAYS },
+    { "discount",     CT_NUMERIC,     0,                   0,                 0,    GNC_BILLTERM_DISCOUNT },
+    { "cutoff",       CT_INT,         0,                   0,                 0,    GNC_BILLTERM_CUTOFF },
+    { NULL }
+};
+
+static GncSqlColumnTableEntry billterm_parent_col_table[] =
+{
+    { "parent", CT_GUID, 0, 0, NULL, NULL, NULL, (QofSetterFunc)bt_set_parent_guid },
+    { NULL }
+};
+
+typedef struct
+{
+    /*@ dependent @*/ GncBillTerm* billterm;
+    GncGUID guid;
+    gboolean have_guid;
+} billterm_parent_guid_struct;
+
+static void
+set_invisible( gpointer data, gboolean value )
+{
+    GncBillTerm* term = GNC_BILLTERM(data);
+
+    g_return_if_fail( term != NULL );
+
+    if ( value )
+    {
+        gncBillTermMakeInvisible( term );
+    }
+}
+
+static /*@ null @*//*@ dependent @*/ gpointer
+bt_get_parent( gpointer pObject )
+{
+    const GncBillTerm* billterm;
+    const GncBillTerm* pParent;
+    const GncGUID* parent_guid;
+
+    g_return_val_if_fail( pObject != NULL, NULL );
+    g_return_val_if_fail( GNC_IS_BILLTERM(pObject), NULL );
+
+    billterm = GNC_BILLTERM(pObject);
+    pParent = gncBillTermGetParent( billterm );
+    if ( pParent == NULL )
+    {
+        parent_guid = NULL;
+    }
+    else
+    {
+        parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
+    }
+
+    return (gpointer)parent_guid;
+}
+
+static void
+bt_set_parent( gpointer data, gpointer value )
+{
+    GncBillTerm* billterm;
+    GncBillTerm* parent;
+    QofBook* pBook;
+    GncGUID* guid = (GncGUID*)value;
+
+    g_return_if_fail( data != NULL );
+    g_return_if_fail( GNC_IS_BILLTERM(data) );
+
+    billterm = GNC_BILLTERM(data);
+    pBook = qof_instance_get_book( QOF_INSTANCE(billterm) );
+    if ( guid != NULL )
+    {
+        parent = gncBillTermLookup( pBook, guid );
+        if ( parent != NULL )
+        {
+            gncBillTermSetParent( billterm, parent );
+            gncBillTermSetChild( parent, billterm );
+        }
+    }
+}
+
+static void
+bt_set_parent_guid( gpointer pObject, /*@ null @*/ gpointer pValue )
+{
+    billterm_parent_guid_struct* s = (billterm_parent_guid_struct*)pObject;
+    GncGUID* guid = (GncGUID*)pValue;
+
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( pValue != NULL );
+
+    s->guid = *guid;
+    s->have_guid = TRUE;
+}
+
+static GncBillTerm*
+load_single_billterm( GncSqlBackend* be, GncSqlRow* row,
+                      GList** l_billterms_needing_parents )
+{
+    const GncGUID* guid;
+    GncBillTerm* pBillTerm;
+
+    g_return_val_if_fail( be != NULL, NULL );
+    g_return_val_if_fail( row != NULL, NULL );
+
+    guid = gnc_sql_load_guid( be, row );
+    pBillTerm = gncBillTermLookup( be->primary_book, guid );
+    if ( pBillTerm == NULL )
+    {
+        pBillTerm = gncBillTermCreate( be->primary_book );
+    }
+    gnc_sql_load_object( be, row, GNC_ID_BILLTERM, pBillTerm, col_table );
+
+    /* If the billterm doesn't have a parent, it might be because it hasn't been loaded yet.
+       If so, add this billterm to the list of billterms with no parent, along with the parent
+       GncGUID so that after they are all loaded, the parents can be fixed up. */
+    if ( gncBillTermGetParent( pBillTerm ) == NULL )
+    {
+        billterm_parent_guid_struct* s = g_malloc( (gsize)sizeof(billterm_parent_guid_struct) );
+        g_assert( s != NULL );
+
+        s->billterm = pBillTerm;
+        s->have_guid = FALSE;
+        gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, s, billterm_parent_col_table );
+        if ( s->have_guid )
+        {
+            *l_billterms_needing_parents = g_list_prepend( *l_billterms_needing_parents, s );
+        }
+        else
+        {
+            g_free( s );
+        }
+    }
+
+    qof_instance_mark_clean( QOF_INSTANCE(pBillTerm) );
+
+    return pBillTerm;
+}
+
+static void
+load_all_billterms( GncSqlBackend* be )
+{
+    GncSqlStatement* stmt;
+    GncSqlResult* result;
+    QofBook* pBook;
+
+    g_return_if_fail( be != NULL );
+
+    pBook = be->primary_book;
+
+    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
+    result = gnc_sql_execute_select_statement( be, stmt );
+    gnc_sql_statement_dispose( stmt );
+    if ( result != NULL )
+    {
+        GncSqlRow* row;
+        GList* list = NULL;
+        GList* l_billterms_needing_parents = NULL;
+
+        row = gnc_sql_result_get_first_row( result );
+        while ( row != NULL )
+        {
+            GncBillTerm* pBillTerm = load_single_billterm( be, row, &l_billterms_needing_parents );
+            if ( pBillTerm != NULL )
+            {
+                list = g_list_append( list, pBillTerm );
+            }
+            row = gnc_sql_result_get_next_row( result );
+        }
+        gnc_sql_result_dispose( result );
+
+        if ( list != NULL )
+        {
+            gnc_sql_slots_load_for_list( be, list );
+        }
+
+        /* While there are items on the list of billterms needing parents,
+           try to see if the parent has now been loaded.  Theory says that if
+           items are removed from the front and added to the back if the
+           parent is still not available, then eventually, the list will
+           shrink to size 0. */
+        if ( l_billterms_needing_parents != NULL )
+        {
+            gboolean progress_made = TRUE;
+            GncTaxTable* root;
+            Account* pParent;
+            GList* elem;
+
+            while ( progress_made )
+            {
+                progress_made = FALSE;
+                for ( elem = l_billterms_needing_parents; elem != NULL; elem = g_list_next( elem ) )
+                {
+                    billterm_parent_guid_struct* s = (billterm_parent_guid_struct*)elem->data;
+                    bt_set_parent( s->billterm, &s->guid );
+                    l_billterms_needing_parents = g_list_delete_link( l_billterms_needing_parents, elem );
+                    progress_made = TRUE;
+                }
+            }
+        }
+    }
+}
+
+/* ================================================================= */
+typedef struct
+{
+    GncSqlBackend* be;
+    gboolean is_ok;
+} write_billterms_t;
+
+static void
+do_save_billterm( QofInstance* inst, gpointer p2 )
+{
+    write_billterms_t* data = (write_billterms_t*)p2;
+
+    if ( data->is_ok )
+    {
+        data->is_ok = gnc_sql_save_billterm( data->be, inst );
+    }
+}
+
+static gboolean
+write_billterms( GncSqlBackend* be )
+{
+    write_billterms_t data;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    data.be = be;
+    data.is_ok = TRUE;
+    qof_object_foreach( GNC_ID_BILLTERM, be->primary_book, do_save_billterm, &data );
+    return data.is_ok;
+}
+
+/* ================================================================= */
+static void
+create_billterm_tables( GncSqlBackend* be )
+{
+    gint version;
+
+    g_return_if_fail( be != NULL );
+
+    version = gnc_sql_get_table_version( be, TABLE_NAME );
+    if ( version == 0 )
+    {
+        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
+    }
+    else if ( version == 1 )
+    {
+        /* Upgrade 64 bit int handling */
+        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
+        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
+    }
+}
+
+/* ================================================================= */
+gboolean
+gnc_sql_save_billterm( GncSqlBackend* be, QofInstance* inst )
+{
+    g_return_val_if_fail( inst != NULL, FALSE );
+    g_return_val_if_fail( GNC_IS_BILLTERM(inst), FALSE );
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_BILLTERM, col_table );
+}
+
+/* ================================================================= */
+static void
+load_billterm_guid( const GncSqlBackend* be, GncSqlRow* row,
+                    QofSetterFunc setter, gpointer pObject,
+                    const GncSqlColumnTableEntry* table_row )
+{
+    const GValue* val;
+    GncGUID guid;
+    GncBillTerm* term = NULL;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( row != NULL );
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( table_row != NULL );
+
+    val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
+    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
+    {
+        string_to_guid( g_value_get_string( val ), &guid );
+        term = gncBillTermLookup( be->primary_book, &guid );
+        if ( term != NULL )
+        {
+            if ( table_row->gobj_param_name != NULL )
+            {
+                g_object_set( pObject, table_row->gobj_param_name, term, NULL );
+            }
+            else
+            {
+                (*setter)( pObject, (const gpointer)term );
+            }
+        }
+        else
+        {
+            PWARN( "Billterm ref '%s' not found", g_value_get_string( val ) );
+        }
+    }
+}
+
+static GncSqlColumnTypeHandler billterm_guid_handler
+= { load_billterm_guid,
+    gnc_sql_add_objectref_guid_col_info_to_list,
+    gnc_sql_add_colname_to_list,
+    gnc_sql_add_gvalue_objectref_guid_to_slist
+  };
+/* ================================================================= */
+void
+gnc_billterm_sql_initialize( void )
+{
+    static GncSqlObjectBackend be_data =
+    {
+        GNC_SQL_BACKEND_VERSION,
+        GNC_ID_BILLTERM,
+        gnc_sql_save_billterm,				/* commit */
+        load_all_billterms,					/* initial_load */
+        create_billterm_tables,				/* create_tables */
+        NULL, NULL, NULL,
+        write_billterms						/* write */
+    };
+
+    qof_object_register_backend( GNC_ID_BILLTERM, GNC_SQL_BACKEND, &be_data );
+
+    gnc_sql_register_col_type_handler( CT_BILLTERMREF, &billterm_guid_handler );
+}
+/* ========================== END OF FILE ===================== */

Copied: gnucash/trunk/src/backend/sql/gnc-bill-term-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-bill-term-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-bill-term-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,40 @@
+/*
+ * gnc-bill-term-sql.h -- billing term sql backend
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-bill-term-sql.h
+ *  @brief load and save accounts data to SQL
+ *  @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_BILLTERM_SQL_H
+#define GNC_BILLTERM_SQL_H
+
+#include "gncBillTerm.h"
+
+#define CT_BILLTERMREF "billterm"
+
+void gnc_billterm_sql_initialize( void );
+gboolean gnc_sql_save_billterm( GncSqlBackend* be, QofInstance* inst );
+
+#endif /* GNC_BILLTERM_SQL_H */

Copied: gnucash/trunk/src/backend/sql/gnc-customer-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-customer-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-customer-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,247 @@
+/********************************************************************\
+ * gnc-customer-sql.c -- customer sql backend                       *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-customer-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-backend-sql.h"
+#include "gnc-slots-sql.h"
+
+#include "gncBillTermP.h"
+#include "gncCustomerP.h"
+#include "gncTaxTableP.h"
+#include "gnc-customer-sql.h"
+#include "gnc-address-sql.h"
+#include "gnc-bill-term-sql.h"
+#include "gnc-tax-table-sql.h"
+
+#define _GNC_MOD_NAME	GNC_ID_CUSTOMER
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+#define TABLE_NAME "customers"
+#define TABLE_VERSION 2
+
+#define MAX_NAME_LEN 2048
+#define MAX_ID_LEN 2048
+#define MAX_NOTES_LEN 2048
+
+static GncSqlColumnTableEntry col_table[] =
+{
+    { "guid",         CT_GUID,          0,             COL_NNUL | COL_PKEY, "guid" },
+    { "name",         CT_STRING,        MAX_NAME_LEN,  COL_NNUL,          "name" },
+    { "id",           CT_STRING,        MAX_ID_LEN,    COL_NNUL,          NULL, CUSTOMER_ID },
+    { "notes",        CT_STRING,        MAX_NOTES_LEN, COL_NNUL,          NULL, CUSTOMER_NOTES },
+    { "active",       CT_BOOLEAN,       0,             COL_NNUL,          NULL, QOF_PARAM_ACTIVE },
+    { "discount",     CT_NUMERIC,       0,             COL_NNUL,          NULL, CUSTOMER_DISCOUNT },
+    { "credit",       CT_NUMERIC,       0,             COL_NNUL,          NULL, CUSTOMER_CREDIT },
+    {
+        "currency",     CT_COMMODITYREF,  0,             COL_NNUL,          NULL, NULL,
+        (QofAccessFunc)gncCustomerGetCurrency, (QofSetterFunc)gncCustomerSetCurrency
+    },
+    { "tax_override", CT_BOOLEAN,       0,             COL_NNUL,          NULL, CUSTOMER_TT_OVER },
+    { "addr",         CT_ADDRESS,       0,             0,                 NULL, CUSTOMER_ADDR },
+    { "shipaddr",     CT_ADDRESS,       0,             0,                 NULL, CUSTOMER_SHIPADDR },
+    { "terms",        CT_BILLTERMREF,   0,             0,                 NULL, CUSTOMER_TERMS },
+    {
+        "tax_included", CT_INT,           0,             0,                 NULL, NULL,
+        (QofAccessFunc)gncCustomerGetTaxIncluded, (QofSetterFunc)gncCustomerSetTaxIncluded
+    },
+    {
+        "taxtable",     CT_TAXTABLEREF,   0,             0,                 NULL, NULL,
+        (QofAccessFunc)gncCustomerGetTaxTable, (QofSetterFunc)gncCustomerSetTaxTable
+    },
+    { NULL }
+};
+
+static GncCustomer*
+load_single_customer( GncSqlBackend* be, GncSqlRow* row )
+{
+    const GncGUID* guid;
+    GncCustomer* pCustomer;
+
+    g_return_val_if_fail( be != NULL, NULL );
+    g_return_val_if_fail( row != NULL, NULL );
+
+    guid = gnc_sql_load_guid( be, row );
+    pCustomer = gncCustomerLookup( be->primary_book, guid );
+    if ( pCustomer == NULL )
+    {
+        pCustomer = gncCustomerCreate( be->primary_book );
+    }
+    gnc_sql_load_object( be, row, GNC_ID_CUSTOMER, pCustomer, col_table );
+    qof_instance_mark_clean( QOF_INSTANCE(pCustomer) );
+
+    return pCustomer;
+}
+
+static void
+load_all_customers( GncSqlBackend* be )
+{
+    GncSqlStatement* stmt;
+    GncSqlResult* result;
+    QofBook* pBook;
+
+    g_return_if_fail( be != NULL );
+
+    pBook = be->primary_book;
+
+    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
+    result = gnc_sql_execute_select_statement( be, stmt );
+    gnc_sql_statement_dispose( stmt );
+    if ( result != NULL )
+    {
+        GList* list = NULL;
+        GncSqlRow* row;
+
+        row = gnc_sql_result_get_first_row( result );
+        while ( row != NULL )
+        {
+            GncCustomer* pCustomer = load_single_customer( be, row );
+            if ( pCustomer != NULL )
+            {
+                list = g_list_append( list, pCustomer );
+            }
+            row = gnc_sql_result_get_next_row( result );
+        }
+        gnc_sql_result_dispose( result );
+
+        if ( list != NULL )
+        {
+            gnc_sql_slots_load_for_list( be, list );
+        }
+    }
+}
+
+/* ================================================================= */
+static void
+create_customer_tables( GncSqlBackend* be )
+{
+    gint version;
+
+    g_return_if_fail( be != NULL );
+
+    version = gnc_sql_get_table_version( be, TABLE_NAME );
+    if ( version == 0 )
+    {
+        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
+    }
+    else if ( version == 1 )
+    {
+        /* Upgrade 64 bit int handling */
+        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
+        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
+    }
+}
+
+/* ================================================================= */
+static gboolean
+save_customer( GncSqlBackend* be, QofInstance* inst )
+{
+    g_return_val_if_fail( inst != NULL, FALSE );
+    g_return_val_if_fail( GNC_CUSTOMER(inst), FALSE );
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_CUSTOMER, col_table );
+}
+
+/* ================================================================= */
+typedef struct
+{
+    GncSqlBackend* be;
+    gboolean is_ok;
+} write_customers_t;
+
+static gboolean
+customer_should_be_saved( GncCustomer *customer )
+{
+    const char *id;
+
+    g_return_val_if_fail( customer != NULL, FALSE );
+
+    /* Make sure this is a valid customer before we save it -- should have an ID */
+    id = gncCustomerGetID( customer );
+    if ( id == NULL || *id == '\0' )
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static void
+write_single_customer( QofInstance *term_p, gpointer data_p )
+{
+    write_customers_t* data = (write_customers_t*)data_p;
+
+    g_return_if_fail( term_p != NULL );
+    g_return_if_fail( GNC_IS_CUSTOMER(term_p) );
+    g_return_if_fail( data_p != NULL );
+
+    if ( customer_should_be_saved( GNC_CUSTOMER(term_p) ) && data->is_ok )
+    {
+        data->is_ok = save_customer( data->be, term_p );
+    }
+}
+
+static gboolean
+write_customers( GncSqlBackend* be )
+{
+    write_customers_t data;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    data.be = be;
+    data.is_ok = TRUE;
+    qof_object_foreach( GNC_ID_CUSTOMER, be->primary_book, write_single_customer, (gpointer)&data );
+    return data.is_ok;
+}
+
+/* ================================================================= */
+void
+gnc_customer_sql_initialize( void )
+{
+    static GncSqlObjectBackend be_data =
+    {
+        GNC_SQL_BACKEND_VERSION,
+        GNC_ID_CUSTOMER,
+        save_customer,						/* commit */
+        load_all_customers,					/* initial_load */
+        create_customer_tables,				/* create_tables */
+        NULL, NULL, NULL,
+        write_customers						/* write */
+    };
+
+    qof_object_register_backend( GNC_ID_CUSTOMER, GNC_SQL_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Copied: gnucash/trunk/src/backend/sql/gnc-customer-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-customer-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-customer-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,35 @@
+/*
+ * gnc-customer-sql.h -- customer sql backend
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-customer-sql.h
+ *  @brief load and save customer data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_CUSTOMER_SQL_H
+#define GNC_CUSTOMER_SQL_H
+
+void gnc_customer_sql_initialize( void );
+
+#endif /* GNC_CUSTOMER_SQL_H */

Copied: gnucash/trunk/src/backend/sql/gnc-employee-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-employee-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-employee-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,281 @@
+/********************************************************************\
+ * gnc-employee-sql.c -- employee sql implementation                *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-employee-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-commodity.h"
+
+#include "gnc-backend-sql.h"
+#include "gnc-slots-sql.h"
+#include "gnc-commodity-sql.h"
+
+#include "gncEmployeeP.h"
+#include "gnc-employee-sql.h"
+#include "gnc-address-sql.h"
+
+#define _GNC_MOD_NAME	GNC_ID_EMPLOYEE
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+#define MAX_USERNAME_LEN 2048
+#define MAX_ID_LEN 2048
+#define MAX_LANGUAGE_LEN 2048
+#define MAX_ACL_LEN 2048
+
+#define TABLE_NAME "employees"
+#define TABLE_VERSION 2
+
+static GncSqlColumnTableEntry col_table[] =
+{
+    { "guid",       CT_GUID,          0,                COL_NNUL | COL_PKEY, "guid" },
+    { "username",   CT_STRING,        MAX_USERNAME_LEN, COL_NNUL,          "username" },
+    { "id",         CT_STRING,        MAX_ID_LEN,       COL_NNUL,          NULL, EMPLOYEE_ID },
+    { "language",   CT_STRING,        MAX_LANGUAGE_LEN, COL_NNUL,          NULL, EMPLOYEE_LANGUAGE },
+    { "acl",        CT_STRING,        MAX_ACL_LEN,      COL_NNUL,          NULL, EMPLOYEE_ACL },
+    { "active",     CT_BOOLEAN,       0,                COL_NNUL,          NULL, QOF_PARAM_ACTIVE },
+    {
+        "currency",   CT_COMMODITYREF,  0,                COL_NNUL,          NULL, NULL,
+        (QofAccessFunc)gncEmployeeGetCurrency, (QofSetterFunc)gncEmployeeSetCurrency
+    },
+    { "ccard_guid", CT_ACCOUNTREF,    0,                0,                 NULL, EMPLOYEE_CC },
+    { "workday",    CT_NUMERIC,       0,                COL_NNUL,          NULL, EMPLOYEE_WORKDAY },
+    { "rate",       CT_NUMERIC,       0,                COL_NNUL,          NULL, EMPLOYEE_RATE },
+    { "addr",       CT_ADDRESS,       0,                0,                 NULL, EMPLOYEE_ADDR },
+    { NULL }
+};
+
+static GncEmployee*
+load_single_employee( GncSqlBackend* be, GncSqlRow* row )
+{
+    const GncGUID* guid;
+    GncEmployee* pEmployee;
+
+    g_return_val_if_fail( be != NULL, NULL );
+    g_return_val_if_fail( row != NULL, NULL );
+
+    guid = gnc_sql_load_guid( be, row );
+    pEmployee = gncEmployeeLookup( be->primary_book, guid );
+    if ( pEmployee == NULL )
+    {
+        pEmployee = gncEmployeeCreate( be->primary_book );
+    }
+    gnc_sql_load_object( be, row, GNC_ID_EMPLOYEE, pEmployee, col_table );
+    qof_instance_mark_clean( QOF_INSTANCE(pEmployee) );
+
+    return pEmployee;
+}
+
+static void
+load_all_employees( GncSqlBackend* be )
+{
+    GncSqlStatement* stmt;
+    GncSqlResult* result;
+    QofBook* pBook;
+    gnc_commodity_table* pTable;
+
+    g_return_if_fail( be != NULL );
+
+    pBook = be->primary_book;
+    pTable = gnc_commodity_table_get_table( pBook );
+
+    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
+    result = gnc_sql_execute_select_statement( be, stmt );
+    gnc_sql_statement_dispose( stmt );
+    if ( result != NULL )
+    {
+        GncSqlRow* row;
+        GList* list = NULL;
+
+        row = gnc_sql_result_get_first_row( result );
+        while ( row != NULL )
+        {
+            GncEmployee* pEmployee = load_single_employee( be, row );
+            if ( pEmployee != NULL )
+            {
+                list = g_list_append( list, pEmployee );
+            }
+            row = gnc_sql_result_get_next_row( result );
+        }
+        gnc_sql_result_dispose( result );
+
+        if ( list != NULL )
+        {
+            gnc_sql_slots_load_for_list( be, list );
+        }
+    }
+}
+
+/* ================================================================= */
+static void
+create_employee_tables( GncSqlBackend* be )
+{
+    gint version;
+
+    g_return_if_fail( be != NULL );
+
+    version = gnc_sql_get_table_version( be, TABLE_NAME );
+    if ( version == 0 )
+    {
+        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
+    }
+    else if ( version == 1 )
+    {
+        /* Upgrade 64 bit int handling */
+        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
+        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
+    }
+}
+
+/* ================================================================= */
+static gboolean
+save_employee( GncSqlBackend* be, QofInstance* inst )
+{
+    GncEmployee* emp;
+    const GncGUID* guid;
+    gint op;
+    gboolean is_infant;
+    gboolean is_ok = TRUE;
+
+    g_return_val_if_fail( inst != NULL, FALSE );
+    g_return_val_if_fail( GNC_IS_EMPLOYEE(inst), FALSE );
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    emp = GNC_EMPLOYEE(inst);
+
+    is_infant = qof_instance_get_infant( inst );
+    if ( qof_instance_get_destroying( inst ) )
+    {
+        op = OP_DB_DELETE;
+    }
+    else if ( be->is_pristine_db || is_infant )
+    {
+        op = OP_DB_INSERT;
+    }
+    else
+    {
+        op = OP_DB_UPDATE;
+    }
+    if ( op != OP_DB_DELETE )
+    {
+        // Ensure the commodity is in the db
+        is_ok = gnc_sql_save_commodity( be, gncEmployeeGetCurrency( emp ) );
+    }
+
+    if ( is_ok )
+    {
+        is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_EMPLOYEE, emp, col_table );
+    }
+
+    if ( is_ok )
+    {
+        // Now, commit or delete any slots
+        guid = qof_instance_get_guid( inst );
+        if ( !qof_instance_get_destroying(inst) )
+        {
+            is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
+        }
+        else
+        {
+            is_ok = gnc_sql_slots_delete( be, guid );
+        }
+    }
+
+    return is_ok;
+}
+
+/* ================================================================= */
+static gboolean
+employee_should_be_saved( GncEmployee *employee )
+{
+    const char *id;
+
+    g_return_val_if_fail( employee != NULL, FALSE );
+
+    /* make sure this is a valid employee before we save it -- should have an ID */
+    id = gncEmployeeGetID( employee );
+    if ( id == NULL || *id == '\0' )
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static void
+write_single_employee( QofInstance *term_p, gpointer data_p )
+{
+    write_objects_t* s = (write_objects_t*)data_p;
+
+    g_return_if_fail( term_p != NULL );
+    g_return_if_fail( GNC_IS_EMPLOYEE(term_p) );
+    g_return_if_fail( data_p != NULL );
+
+    if ( s->is_ok && employee_should_be_saved( GNC_EMPLOYEE(term_p) ) )
+    {
+        s->is_ok = save_employee( s->be, term_p );
+    }
+}
+
+static gboolean
+write_employees( GncSqlBackend* be )
+{
+    write_objects_t data;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    data.be = be;
+    data.is_ok = TRUE;
+    qof_object_foreach( GNC_ID_EMPLOYEE, be->primary_book, write_single_employee, &data );
+
+    return data.is_ok;
+}
+
+/* ================================================================= */
+void
+gnc_employee_sql_initialize( void )
+{
+    static GncSqlObjectBackend be_data =
+    {
+        GNC_SQL_BACKEND_VERSION,
+        GNC_ID_EMPLOYEE,
+        save_employee,						/* commit */
+        load_all_employees,					/* initial_load */
+        create_employee_tables,				/* create_tables */
+        NULL, NULL, NULL,
+        write_employees						/* write */
+    };
+
+    qof_object_register_backend( GNC_ID_EMPLOYEE, GNC_SQL_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Copied: gnucash/trunk/src/backend/sql/gnc-employee-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-employee-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-employee-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,35 @@
+/*
+ * gnc-employee-sql.h -- employee sql backend
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-employee-sql.h
+ *  @brief load and save employee data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_EMPLOYEE_SQL_H
+#define GNC_EMPLOYEE_SQL_H
+
+void gnc_employee_sql_initialize( void );
+
+#endif /* GNC_EMPLOYEE_SQL_H */

Copied: gnucash/trunk/src/backend/sql/gnc-entry-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-entry-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-entry-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,296 @@
+/********************************************************************\
+ * gnc-entry-sql.c -- entry sql backend                             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-entry-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-backend-sql.h"
+#include "gnc-slots-sql.h"
+
+#include "gncEntryP.h"
+#include "gncOrderP.h"
+#include "gncInvoiceP.h"
+#include "gncTaxTableP.h"
+#include "gnc-bill-term-sql.h"
+#include "gnc-entry-sql.h"
+#include "gnc-invoice-sql.h"
+#include "gnc-order-sql.h"
+#include "gnc-owner-sql.h"
+#include "gnc-tax-table-sql.h"
+
+#define _GNC_MOD_NAME	GNC_ID_ENTRY
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+#define TABLE_NAME "entries"
+#define TABLE_VERSION 3
+#define MAX_DESCRIPTION_LEN 2048
+#define MAX_ACTION_LEN 2048
+#define MAX_NOTES_LEN 2048
+#define MAX_DISCTYPE_LEN 2048
+#define MAX_DISCHOW_LEN 2048
+
+static void entry_set_invoice( gpointer pObject, gpointer val );
+static void entry_set_bill( gpointer pObject, gpointer val );
+
+static GncSqlColumnTableEntry col_table[] =
+{
+    { "guid",          CT_GUID,        0,                   COL_NNUL | COL_PKEY, "guid" },
+    { "date",          CT_TIMESPEC,    0,                   COL_NNUL,          NULL, ENTRY_DATE },
+    { "date_entered",  CT_TIMESPEC,    0,                   0,                 NULL, ENTRY_DATE_ENTERED },
+    { "description",   CT_STRING,      MAX_DESCRIPTION_LEN, 0,                 "description" },
+    { "action",        CT_STRING,      MAX_ACTION_LEN,      0,                 NULL, ENTRY_ACTION },
+    { "notes",         CT_STRING,      MAX_NOTES_LEN,       0,                 NULL, ENTRY_NOTES },
+    { "quantity",      CT_NUMERIC,     0,                   0,                 NULL, ENTRY_QTY },
+    { "i_acct",        CT_ACCOUNTREF,  0,                   0,                 NULL, ENTRY_IACCT },
+    { "i_price",       CT_NUMERIC,     0,                   0,                 NULL, ENTRY_IPRICE },
+    {
+        "i_discount",    CT_NUMERIC,     0,                   0,                 NULL, NULL,
+        (QofAccessFunc)gncEntryGetInvDiscount, (QofSetterFunc)gncEntrySetInvDiscount
+    },
+    {
+        "invoice",       CT_INVOICEREF,  0,                   0,                 NULL, NULL,
+        (QofAccessFunc)gncEntryGetInvoice, (QofSetterFunc)entry_set_invoice
+    },
+    { "i_disc_type",   CT_STRING,      MAX_DISCTYPE_LEN,    0,        			NULL, ENTRY_INV_DISC_TYPE },
+    { "i_disc_how",    CT_STRING,      MAX_DISCHOW_LEN,     0,        			NULL, ENTRY_INV_DISC_HOW },
+    { "i_taxable",     CT_BOOLEAN,     0,                   0,        			NULL, ENTRY_INV_TAXABLE },
+    { "i_taxincluded", CT_BOOLEAN,     0,                   0,        			NULL, ENTRY_INV_TAX_INC },
+    {
+        "i_taxtable",    CT_TAXTABLEREF, 0,                   0,        			NULL, NULL,
+        (QofAccessFunc)gncEntryGetInvTaxTable, (QofSetterFunc)gncEntrySetInvTaxTable
+    },
+    { "b_acct",        CT_ACCOUNTREF,  0,                   0,        			NULL, ENTRY_BACCT },
+    { "b_price",       CT_NUMERIC,     0,                   0,        			NULL, ENTRY_BPRICE },
+    {
+        "bill",          CT_INVOICEREF,  0,                   0,        			NULL, NULL,
+        (QofAccessFunc)gncEntryGetBill, (QofSetterFunc)entry_set_bill
+    },
+    { "b_taxable",     CT_BOOLEAN,     0,                   0,        			NULL, ENTRY_BILL_TAXABLE },
+    { "b_taxincluded", CT_BOOLEAN,     0,                   0,        			NULL, ENTRY_BILL_TAX_INC },
+    {
+        "b_taxtable",    CT_TAXTABLEREF, 0,                   0,        			NULL, NULL,
+        (QofAccessFunc)gncEntryGetBillTaxTable, (QofSetterFunc)gncEntrySetBillTaxTable
+    },
+    {
+        "b_paytype",     CT_INT,         0,                   0,        			NULL, NULL,
+        (QofAccessFunc)gncEntryGetBillPayment, (QofSetterFunc)gncEntrySetBillPayment
+    },
+    { "billable",      CT_BOOLEAN,     0,                   0,        			NULL, ENTRY_BILLABLE },
+    { "billto",        CT_OWNERREF,    0,                   0,        			NULL, ENTRY_BILLTO },
+    {
+        "order_guid",    CT_ORDERREF,    0,                   0,        			NULL, NULL,
+        (QofAccessFunc)gncEntryGetOrder, (QofSetterFunc)gncEntrySetOrder
+    },
+    { NULL }
+};
+
+static void
+entry_set_invoice( gpointer pObject, gpointer val )
+{
+    GncEntry* entry;
+    GncInvoice* invoice;
+
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( GNC_IS_ENTRY(pObject) );
+    g_return_if_fail( val != NULL );
+    g_return_if_fail( GNC_IS_INVOICE(val) );
+
+    entry = GNC_ENTRY(pObject);
+    invoice = GNC_INVOICE(val);
+
+    gncInvoiceAddEntry( invoice, entry );
+}
+
+static void
+entry_set_bill( gpointer pObject, gpointer val )
+{
+    GncEntry* entry;
+    GncInvoice* bill;
+
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( GNC_IS_ENTRY(pObject) );
+    g_return_if_fail( val != NULL );
+    g_return_if_fail( GNC_IS_INVOICE(val) );
+
+    entry = GNC_ENTRY(pObject);
+    bill = GNC_INVOICE(val);
+
+    gncBillAddEntry( bill, entry );
+}
+
+static GncEntry*
+load_single_entry( GncSqlBackend* be, GncSqlRow* row )
+{
+    const GncGUID* guid;
+    GncEntry* pEntry;
+
+    g_return_val_if_fail( be != NULL, NULL );
+    g_return_val_if_fail( row != NULL, NULL );
+
+    guid = gnc_sql_load_guid( be, row );
+    pEntry = gncEntryLookup( be->primary_book, guid );
+    if ( pEntry == NULL )
+    {
+        pEntry = gncEntryCreate( be->primary_book );
+    }
+    gnc_sql_load_object( be, row, GNC_ID_ENTRY, pEntry, col_table );
+    qof_instance_mark_clean( QOF_INSTANCE(pEntry) );
+
+    return pEntry;
+}
+
+static void
+load_all_entries( GncSqlBackend* be )
+{
+    GncSqlStatement* stmt;
+    GncSqlResult* result;
+    QofBook* pBook;
+
+    g_return_if_fail( be != NULL );
+
+    pBook = be->primary_book;
+
+    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
+    result = gnc_sql_execute_select_statement( be, stmt );
+    gnc_sql_statement_dispose( stmt );
+    if ( result != NULL )
+    {
+        GncSqlRow* row;
+        GList* list = NULL;
+
+        row = gnc_sql_result_get_first_row( result );
+        while ( row != NULL )
+        {
+            GncEntry* pEntry = load_single_entry( be, row );
+            if ( pEntry != NULL )
+            {
+                list = g_list_append( list, pEntry );
+            }
+            row = gnc_sql_result_get_next_row( result );
+        }
+        gnc_sql_result_dispose( result );
+
+        if ( list != NULL )
+        {
+            gnc_sql_slots_load_for_list( be, list );
+        }
+    }
+}
+
+/* ================================================================= */
+static void
+create_entry_tables( GncSqlBackend* be )
+{
+    gint version;
+
+    g_return_if_fail( be != NULL );
+
+    version = gnc_sql_get_table_version( be, TABLE_NAME );
+    if ( version == 0 )
+    {
+        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
+    }
+    else if ( version < TABLE_VERSION )
+    {
+        /* Upgrade:
+            1->2: 64 bit int handling
+        	2->3: "entered" -> "date_entered", and it can be NULL
+        */
+        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
+        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
+    }
+}
+
+/* ================================================================= */
+static gboolean
+save_entry( GncSqlBackend* be, QofInstance* inst )
+{
+    g_return_val_if_fail( inst != NULL, FALSE );
+    g_return_val_if_fail( GNC_IS_ENTRY(inst), FALSE );
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_ENTRY, col_table );
+}
+
+/* ================================================================= */
+static void
+write_single_entry( QofInstance *term_p, gpointer data_p )
+{
+    write_objects_t* s = (write_objects_t*)data_p;
+    GncEntry* entry = GNC_ENTRY(term_p);
+
+    g_return_if_fail( term_p != NULL );
+    g_return_if_fail( GNC_IS_ENTRY(term_p) );
+    g_return_if_fail( data_p != NULL );
+
+    /* Only save if attached */
+    if ( s->is_ok && (gncEntryGetOrder( entry ) != NULL || gncEntryGetInvoice( entry ) != NULL ||
+                      gncEntryGetBill( entry ) != NULL) )
+    {
+        s->is_ok = save_entry( s->be, term_p );
+    }
+}
+
+static gboolean
+write_entries( GncSqlBackend* be )
+{
+    write_objects_t data;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    data.be = be;
+    data.is_ok = TRUE;
+    qof_object_foreach( GNC_ID_ENTRY, be->primary_book, write_single_entry, &data );
+
+    return data.is_ok;
+}
+
+/* ================================================================= */
+void
+gnc_entry_sql_initialize( void )
+{
+    static GncSqlObjectBackend be_data =
+    {
+        GNC_SQL_BACKEND_VERSION,
+        GNC_ID_ENTRY,
+        save_entry,							/* commit */
+        load_all_entries,					/* initial_load */
+        create_entry_tables,				/* create_tables */
+        NULL, NULL, NULL,
+        write_entries						/* write */
+    };
+
+    qof_object_register_backend( GNC_ID_ENTRY, GNC_SQL_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Copied: gnucash/trunk/src/backend/sql/gnc-entry-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-entry-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-entry-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,35 @@
+/*
+ * gnc-entry-sql.h -- entry sql backend
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-entry-sql.h
+ *  @brief load and save entry data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_ENTRY_SQL_H
+#define GNC_ENTRY_SQL_H
+
+void gnc_entry_sql_initialize( void );
+
+#endif /* GNC_ENTRY_SQL_H */

Copied: gnucash/trunk/src/backend/sql/gnc-invoice-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-invoice-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-invoice-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,345 @@
+/********************************************************************\
+ * gnc-invoice-sql.c - invoice sql backend                          *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-invoice-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-commodity.h"
+
+#include "gnc-backend-sql.h"
+#include "gnc-commodity-sql.h"
+#include "gnc-slots-sql.h"
+
+#include "gncBillTermP.h"
+#include "gncInvoiceP.h"
+#include "gnc-invoice-sql.h"
+#include "gnc-owner-sql.h"
+#include "gnc-bill-term-sql.h"
+
+#define _GNC_MOD_NAME	GNC_ID_INVOICE
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+#define TABLE_NAME "invoices"
+#define TABLE_VERSION 3
+
+#define MAX_ID_LEN 2048
+#define MAX_NOTES_LEN 2048
+#define MAX_BILLING_ID_LEN 2048
+
+static GncSqlColumnTableEntry col_table[] =
+{
+    { "guid",         CT_GUID,         0,                  COL_NNUL | COL_PKEY, "guid" },
+    { "id",           CT_STRING,       MAX_ID_LEN,         COL_NNUL,          NULL, INVOICE_ID },
+    { "date_opened",  CT_TIMESPEC,     0,                  0,                 NULL, INVOICE_OPENED },
+    { "date_posted",  CT_TIMESPEC,     0,                  0,                 NULL, INVOICE_POSTED },
+    { "notes",        CT_STRING,       MAX_NOTES_LEN,      COL_NNUL,          "notes" },
+    { "active",       CT_BOOLEAN,      0,                  COL_NNUL,          NULL, QOF_PARAM_ACTIVE },
+    {
+        "currency",     CT_COMMODITYREF, 0,                  COL_NNUL,          NULL, NULL,
+        (QofAccessFunc)gncInvoiceGetCurrency, (QofSetterFunc)gncInvoiceSetCurrency
+    },
+    {
+        "owner",        CT_OWNERREF,     0,                  0,                 NULL, NULL,
+        (QofAccessFunc)gncInvoiceGetOwner, (QofSetterFunc)gncInvoiceSetOwner
+    },
+    { "terms",        CT_BILLTERMREF,  0,                  0,                 NULL, INVOICE_TERMS },
+    { "billing_id",   CT_STRING,       MAX_BILLING_ID_LEN, 0,                 NULL, INVOICE_BILLINGID },
+    { "post_txn",     CT_TXREF,        0,                  0,                 NULL, INVOICE_POST_TXN },
+    {
+        "post_lot",     CT_LOTREF,       0,                  0,                 NULL, NULL,
+        (QofAccessFunc)gncInvoiceGetPostedLot, (QofSetterFunc)gncInvoiceSetPostedLot
+    },
+    { "post_acc",     CT_ACCOUNTREF,   0,                  0,                 NULL, INVOICE_ACC },
+    {
+        "billto",       CT_OWNERREF,     0,                  0,                 NULL, NULL,
+        (QofAccessFunc)gncInvoiceGetBillTo, (QofSetterFunc)gncInvoiceSetBillTo
+    },
+    {
+        "charge_amt",   CT_NUMERIC,      0,                  0,                 NULL, NULL,
+        (QofAccessFunc)gncInvoiceGetToChargeAmount, (QofSetterFunc)gncInvoiceSetToChargeAmount
+    },
+    { NULL }
+};
+
+static GncInvoice*
+load_single_invoice( GncSqlBackend* be, GncSqlRow* row )
+{
+    const GncGUID* guid;
+    GncInvoice* pInvoice;
+
+    g_return_val_if_fail( be != NULL, NULL );
+    g_return_val_if_fail( row != NULL, NULL );
+
+    guid = gnc_sql_load_guid( be, row );
+    pInvoice = gncInvoiceLookup( be->primary_book, guid );
+    if ( pInvoice == NULL )
+    {
+        pInvoice = gncInvoiceCreate( be->primary_book );
+    }
+    gnc_sql_load_object( be, row, GNC_ID_INVOICE, pInvoice, col_table );
+    qof_instance_mark_clean( QOF_INSTANCE(pInvoice) );
+
+    return pInvoice;
+}
+
+static void
+load_all_invoices( GncSqlBackend* be )
+{
+    GncSqlStatement* stmt;
+    GncSqlResult* result;
+    QofBook* pBook;
+
+    g_return_if_fail( be != NULL );
+
+    pBook = be->primary_book;
+
+    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
+    result = gnc_sql_execute_select_statement( be, stmt );
+    gnc_sql_statement_dispose( stmt );
+    if ( result != NULL )
+    {
+        GncSqlRow* row;
+        GList* list = NULL;
+
+        row = gnc_sql_result_get_first_row( result );
+        while ( row != NULL )
+        {
+            GncInvoice* pInvoice = load_single_invoice( be, row );
+            if ( pInvoice != NULL )
+            {
+                list = g_list_append( list, pInvoice );
+            }
+            row = gnc_sql_result_get_next_row( result );
+        }
+        gnc_sql_result_dispose( result );
+
+        if ( list != NULL )
+        {
+            gnc_sql_slots_load_for_list( be, list );
+        }
+    }
+}
+
+/* ================================================================= */
+static void
+create_invoice_tables( GncSqlBackend* be )
+{
+    gint version;
+
+    g_return_if_fail( be != NULL );
+
+    version = gnc_sql_get_table_version( be, TABLE_NAME );
+    if ( version == 0 )
+    {
+        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
+    }
+    else if ( version < TABLE_VERSION )
+    {
+        /* Upgrade:
+             1->2: 64 bit int handling
+        	 2->3: invoice open date can be NULL
+        */
+        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
+        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
+    }
+}
+
+/* ================================================================= */
+static gboolean
+save_invoice( GncSqlBackend* be, QofInstance* inst )
+{
+    const GncGUID* guid;
+    GncInvoice* invoice;
+    gint op;
+    gboolean is_infant;
+    gboolean is_ok = TRUE;
+
+    g_return_val_if_fail( inst != NULL, FALSE );
+    g_return_val_if_fail( GNC_IS_INVOICE(inst), FALSE );
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    invoice = GNC_INVOICE(inst);
+
+    is_infant = qof_instance_get_infant( inst );
+    if ( qof_instance_get_destroying( inst ) )
+    {
+        op = OP_DB_DELETE;
+    }
+    else if ( be->is_pristine_db || is_infant )
+    {
+        op = OP_DB_INSERT;
+    }
+    else
+    {
+        op = OP_DB_UPDATE;
+    }
+    if ( op != OP_DB_DELETE )
+    {
+        // Ensure the commodity is in the db
+        is_ok = gnc_sql_save_commodity( be, gncInvoiceGetCurrency( invoice ) );
+    }
+
+    if ( is_ok )
+    {
+        is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_INVOICE, inst, col_table );
+    }
+
+    if ( is_ok )
+    {
+        // Now, commit or delete any slots
+        guid = qof_instance_get_guid( inst );
+        if ( !qof_instance_get_destroying(inst) )
+        {
+            is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
+        }
+        else
+        {
+            is_ok = gnc_sql_slots_delete( be, guid );
+        }
+    }
+
+    return is_ok;
+}
+
+/* ================================================================= */
+static gboolean
+invoice_should_be_saved( GncInvoice *invoice )
+{
+    const char *id;
+
+    g_return_val_if_fail( invoice != NULL, FALSE );
+
+    /* make sure this is a valid invoice before we save it -- should have an ID */
+    id = gncInvoiceGetID( invoice );
+    if ( id == NULL || *id == '\0' )
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static void
+write_single_invoice( QofInstance *term_p, gpointer data_p )
+{
+    write_objects_t* s = (write_objects_t*)data_p;
+
+    g_return_if_fail( term_p != NULL );
+    g_return_if_fail( GNC_IS_INVOICE(term_p) );
+    g_return_if_fail( data_p != NULL );
+
+    if ( s->is_ok && invoice_should_be_saved( GNC_INVOICE(term_p) ) )
+    {
+        s->is_ok = save_invoice( s->be, term_p );
+    }
+}
+
+static gboolean
+write_invoices( GncSqlBackend* be )
+{
+    write_objects_t data;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    data.be = be;
+    data.is_ok = TRUE;
+    qof_object_foreach( GNC_ID_INVOICE, be->primary_book, write_single_invoice, &data );
+
+    return data.is_ok;
+}
+
+/* ================================================================= */
+static void
+load_invoice_guid( const GncSqlBackend* be, GncSqlRow* row,
+                   QofSetterFunc setter, gpointer pObject,
+                   const GncSqlColumnTableEntry* table_row )
+{
+    const GValue* val;
+    GncGUID guid;
+    GncInvoice* invoice = NULL;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( row != NULL );
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( table_row != NULL );
+
+    val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
+    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
+    {
+        string_to_guid( g_value_get_string( val ), &guid );
+        invoice = gncInvoiceLookup( be->primary_book, &guid );
+        if ( invoice != NULL )
+        {
+            if ( table_row->gobj_param_name != NULL )
+            {
+                g_object_set( pObject, table_row->gobj_param_name, invoice, NULL );
+            }
+            else
+            {
+                (*setter)( pObject, (const gpointer)invoice );
+            }
+        }
+        else
+        {
+            PWARN( "Invoice ref '%s' not found", g_value_get_string( val ) );
+        }
+    }
+}
+
+static GncSqlColumnTypeHandler invoice_guid_handler
+= { load_invoice_guid,
+    gnc_sql_add_objectref_guid_col_info_to_list,
+    gnc_sql_add_colname_to_list,
+    gnc_sql_add_gvalue_objectref_guid_to_slist
+  };
+/* ================================================================= */
+void
+gnc_invoice_sql_initialize( void )
+{
+    static GncSqlObjectBackend be_data =
+    {
+        GNC_SQL_BACKEND_VERSION,
+        GNC_ID_INVOICE,
+        save_invoice,						/* commit */
+        load_all_invoices,					/* initial_load */
+        create_invoice_tables,				/* create_tables */
+        NULL, NULL, NULL,
+        write_invoices						/* write */
+    };
+
+    qof_object_register_backend( GNC_ID_INVOICE, GNC_SQL_BACKEND, &be_data );
+
+    gnc_sql_register_col_type_handler( CT_INVOICEREF, &invoice_guid_handler );
+}
+/* ========================== END OF FILE ===================== */

Copied: gnucash/trunk/src/backend/sql/gnc-invoice-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-invoice-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-invoice-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,37 @@
+/*
+ * gnc-invoice-sql.h -- invoice sql backend
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-invoice-sql.h
+ *  @brief load and save invoice data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_INVOICE_SQL_H
+#define GNC_INVOICE_SQL_H
+
+#define CT_INVOICEREF "invoice"
+
+void gnc_invoice_sql_initialize( void );
+
+#endif /* GNC_INVOICE_SQL_H */

Copied: gnucash/trunk/src/backend/sql/gnc-job-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-job-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-job-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-job-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,221 @@
+/********************************************************************\
+ * gnc-job-sql.c -- job sql backend                                 *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-job-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-backend-sql.h"
+#include "gnc-slots-sql.h"
+
+#include "gncJobP.h"
+#include "gnc-job-sql.h"
+#include "gnc-owner-sql.h"
+
+#define _GNC_MOD_NAME	GNC_ID_JOB
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+#define TABLE_NAME "jobs"
+#define TABLE_VERSION 1
+
+#define MAX_ID_LEN 2048
+#define MAX_NAME_LEN 2048
+#define MAX_REFERENCE_LEN 2048
+
+static GncSqlColumnTableEntry col_table[] =
+{
+    { "guid",      CT_GUID,     0,                 COL_NNUL | COL_PKEY, "guid" },
+    { "id",        CT_STRING,   MAX_ID_LEN,        COL_NNUL,          NULL, JOB_ID },
+    { "name",      CT_STRING,   MAX_NAME_LEN,      COL_NNUL,          "name" },
+    { "reference", CT_STRING,   MAX_REFERENCE_LEN, COL_NNUL,          NULL, JOB_REFERENCE },
+    {
+        "active",    CT_BOOLEAN,  0,                 COL_NNUL,          NULL, NULL,
+        (QofAccessFunc)gncJobGetActive, (QofSetterFunc)gncJobSetActive
+    },
+    {
+        "owner",     CT_OWNERREF, 0,                 0,                 NULL, NULL,
+        (QofAccessFunc)gncJobGetOwner, (QofSetterFunc)gncJobSetOwner
+    },
+    { NULL }
+};
+
+static GncJob*
+load_single_job( GncSqlBackend* be, GncSqlRow* row )
+{
+    const GncGUID* guid;
+    GncJob* pJob;
+
+    g_return_val_if_fail( be != NULL, NULL );
+    g_return_val_if_fail( row != NULL, NULL );
+
+    guid = gnc_sql_load_guid( be, row );
+    pJob = gncJobLookup( be->primary_book, guid );
+    if ( pJob == NULL )
+    {
+        pJob = gncJobCreate( be->primary_book );
+    }
+    gnc_sql_load_object( be, row, GNC_ID_JOB, pJob, col_table );
+    qof_instance_mark_clean( QOF_INSTANCE(pJob) );
+
+    return pJob;
+}
+
+static void
+load_all_jobs( GncSqlBackend* be )
+{
+    GncSqlStatement* stmt;
+    GncSqlResult* result;
+    QofBook* pBook;
+
+    g_return_if_fail( be != NULL );
+
+    pBook = be->primary_book;
+
+    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
+    result = gnc_sql_execute_select_statement( be, stmt );
+    gnc_sql_statement_dispose( stmt );
+    if ( result != NULL )
+    {
+        GncSqlRow* row;
+        GList* list = NULL;
+
+        row = gnc_sql_result_get_first_row( result );
+        while ( row != NULL )
+        {
+            GncJob* pJob = load_single_job( be, row );
+            if ( pJob != NULL )
+            {
+                list = g_list_append( list, pJob );
+            }
+            row = gnc_sql_result_get_next_row( result );
+        }
+        gnc_sql_result_dispose( result );
+
+        if ( list != NULL )
+        {
+            gnc_sql_slots_load_for_list( be, list );
+        }
+    }
+}
+
+/* ================================================================= */
+static void
+create_job_tables( GncSqlBackend* be )
+{
+    gint version;
+
+    g_return_if_fail( be != NULL );
+
+    version = gnc_sql_get_table_version( be, TABLE_NAME );
+    if ( version == 0 )
+    {
+        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
+    }
+}
+
+/* ================================================================= */
+static gboolean
+save_job( GncSqlBackend* be, QofInstance* inst )
+{
+    g_return_val_if_fail( inst != NULL, FALSE );
+    g_return_val_if_fail( GNC_IS_JOB(inst), FALSE );
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_JOB, col_table );
+}
+
+/* ================================================================= */
+static gboolean
+job_should_be_saved( GncJob *job )
+{
+    const char *id;
+
+    g_return_val_if_fail( job != NULL, FALSE );
+
+    /* make sure this is a valid job before we save it -- should have an ID */
+    id = gncJobGetID( job );
+    if ( id == NULL || *id == '\0' )
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static void
+write_single_job( QofInstance *term_p, gpointer data_p )
+{
+    write_objects_t* s = (write_objects_t*)data_p;
+
+    g_return_if_fail( term_p != NULL );
+    g_return_if_fail( GNC_IS_JOB(term_p) );
+    g_return_if_fail( data_p != NULL );
+
+    if ( s->is_ok && job_should_be_saved( GNC_JOB(term_p) ) )
+    {
+        s->is_ok = save_job( s->be, term_p );
+    }
+}
+
+static gboolean
+write_jobs( GncSqlBackend* be )
+{
+    write_objects_t data;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    data.be = be;
+    data.is_ok = TRUE;
+    qof_object_foreach( GNC_ID_JOB, be->primary_book, write_single_job, &data );
+
+    return data.is_ok;
+}
+
+/* ================================================================= */
+void
+gnc_job_sql_initialize( void )
+{
+    static GncSqlObjectBackend be_data =
+    {
+        GNC_SQL_BACKEND_VERSION,
+        GNC_ID_JOB,
+        save_job,						/* commit */
+        load_all_jobs,					/* initial_load */
+        create_job_tables,				/* create_tables */
+        NULL, NULL, NULL,
+        write_jobs						/* write */
+    };
+
+    qof_object_register_backend( GNC_ID_JOB, GNC_SQL_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Copied: gnucash/trunk/src/backend/sql/gnc-job-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-job-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-job-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-job-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,35 @@
+/*
+ * gnc-job-sql.h -- job sql backend
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-job-sql.h
+ *  @brief load and save job data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_JOB_SQL_H
+#define GNC_JOB_SQL_H
+
+void gnc_job_sql_initialize( void );
+
+#endif /* GNC_JOB_SQL_H */

Copied: gnucash/trunk/src/backend/sql/gnc-order-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-order-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-order-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-order-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,264 @@
+/********************************************************************\
+ * gnc-order-sql.c -- order sql backend                             *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-order-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-backend-sql.h"
+#include "gnc-slots-sql.h"
+
+#include "gncOrderP.h"
+
+#include "gnc-order-sql.h"
+#include "gnc-owner-sql.h"
+
+#define _GNC_MOD_NAME	GNC_ID_ORDER
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+#define TABLE_NAME "orders"
+#define TABLE_VERSION 1
+
+#define MAX_ID_LEN 2048
+#define MAX_NOTES_LEN 2048
+#define MAX_REFERENCE_LEN 2048
+
+static GncSqlColumnTableEntry col_table[] =
+{
+    { "guid",        CT_GUID,     0,                 COL_NNUL | COL_PKEY, "guid" },
+    { "id",          CT_STRING,   MAX_ID_LEN,        COL_NNUL,          NULL, ORDER_ID },
+    { "notes",       CT_STRING,   MAX_NOTES_LEN,     COL_NNUL,          "notes" },
+    { "reference",   CT_STRING,   MAX_REFERENCE_LEN, COL_NNUL,          NULL, ORDER_REFERENCE },
+    { "active",      CT_BOOLEAN,  0,                 COL_NNUL,          NULL, QOF_PARAM_ACTIVE },
+    { "date_opened", CT_TIMESPEC, 0,                 COL_NNUL,          NULL, ORDER_OPENED },
+    { "date_closed", CT_TIMESPEC, 0,                 COL_NNUL,          NULL, ORDER_CLOSED },
+    { "owner",       CT_OWNERREF, 0,                 COL_NNUL,          NULL, ORDER_OWNER },
+    { NULL },
+};
+
+static GncOrder*
+load_single_order( GncSqlBackend* be, GncSqlRow* row )
+{
+    const GncGUID* guid;
+    GncOrder* pOrder;
+
+    g_return_val_if_fail( be != NULL, NULL );
+    g_return_val_if_fail( row != NULL, NULL );
+
+    guid = gnc_sql_load_guid( be, row );
+    pOrder = gncOrderLookup( be->primary_book, guid );
+    if ( pOrder == NULL )
+    {
+        pOrder = gncOrderCreate( be->primary_book );
+    }
+    gnc_sql_load_object( be, row, GNC_ID_ORDER, pOrder, col_table );
+    qof_instance_mark_clean( QOF_INSTANCE(pOrder) );
+
+    return pOrder;
+}
+
+static void
+load_all_orders( GncSqlBackend* be )
+{
+    GncSqlStatement* stmt;
+    GncSqlResult* result;
+    QofBook* pBook;
+
+    g_return_if_fail( be != NULL );
+
+    pBook = be->primary_book;
+
+    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
+    result = gnc_sql_execute_select_statement( be, stmt );
+    gnc_sql_statement_dispose( stmt );
+    if ( result != NULL )
+    {
+        GncSqlRow* row;
+        GList* list = NULL;
+
+        row = gnc_sql_result_get_first_row( result );
+        while ( row != NULL )
+        {
+            GncOrder* pOrder = load_single_order( be, row );
+            if ( pOrder != NULL )
+            {
+                list = g_list_append( list, pOrder );
+            }
+            row = gnc_sql_result_get_next_row( result );
+        }
+        gnc_sql_result_dispose( result );
+
+        if ( list != NULL )
+        {
+            gnc_sql_slots_load_for_list( be, list );
+        }
+    }
+}
+
+/* ================================================================= */
+static void
+create_order_tables( GncSqlBackend* be )
+{
+    gint version;
+
+    g_return_if_fail( be != NULL );
+
+    version = gnc_sql_get_table_version( be, TABLE_NAME );
+    if ( version == 0 )
+    {
+        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
+    }
+}
+
+/* ================================================================= */
+static gboolean
+save_order( GncSqlBackend* be, QofInstance* inst )
+{
+    g_return_val_if_fail( inst != NULL, FALSE );
+    g_return_val_if_fail( GNC_IS_ORDER(inst), FALSE );
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_ORDER, col_table );
+}
+
+/* ================================================================= */
+static gboolean
+order_should_be_saved( GncOrder *order )
+{
+    const char *id;
+
+    g_return_val_if_fail( order != NULL, FALSE );
+
+    /* make sure this is a valid order before we save it -- should have an ID */
+    id = gncOrderGetID( order );
+    if ( id == NULL || *id == '\0' )
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static void
+write_single_order( QofInstance *term_p, gpointer data_p )
+{
+    write_objects_t* s = (write_objects_t*)data_p;
+
+    g_return_if_fail( term_p != NULL );
+    g_return_if_fail( GNC_IS_ORDER(term_p) );
+    g_return_if_fail( data_p != NULL );
+
+    if ( s->is_ok && order_should_be_saved( GNC_ORDER(term_p) ) )
+    {
+        s->is_ok = save_order( s->be, term_p );
+    }
+}
+
+static gboolean
+write_orders( GncSqlBackend* be )
+{
+    write_objects_t data;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    data.be = be;
+    data.is_ok = TRUE;
+    qof_object_foreach( GNC_ID_ORDER, be->primary_book, write_single_order, &data );
+
+    return data.is_ok;
+}
+
+/* ================================================================= */
+static void
+load_order_guid( const GncSqlBackend* be, GncSqlRow* row,
+                 QofSetterFunc setter, gpointer pObject,
+                 const GncSqlColumnTableEntry* table_row )
+{
+    const GValue* val;
+    GncGUID guid;
+    GncOrder* order = NULL;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( row != NULL );
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( table_row != NULL );
+
+    val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
+    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
+    {
+        string_to_guid( g_value_get_string( val ), &guid );
+        order = gncOrderLookup( be->primary_book, &guid );
+        if ( order != NULL )
+        {
+            if ( table_row->gobj_param_name != NULL )
+            {
+                g_object_set( pObject, table_row->gobj_param_name, order, NULL );
+            }
+            else
+            {
+                (*setter)( pObject, (const gpointer)order );
+            }
+        }
+        else
+        {
+            PWARN( "Order ref '%s' not found", g_value_get_string( val ) );
+        }
+    }
+}
+
+static GncSqlColumnTypeHandler order_guid_handler
+= { load_order_guid,
+    gnc_sql_add_objectref_guid_col_info_to_list,
+    gnc_sql_add_colname_to_list,
+    gnc_sql_add_gvalue_objectref_guid_to_slist
+  };
+/* ================================================================= */
+void
+gnc_order_sql_initialize( void )
+{
+    static GncSqlObjectBackend be_data =
+    {
+        GNC_SQL_BACKEND_VERSION,
+        GNC_ID_ORDER,
+        save_order,						/* commit */
+        load_all_orders,				/* initial_load */
+        create_order_tables,			/* create_tables */
+        NULL, NULL, NULL,
+        write_orders					/* write */
+    };
+
+    qof_object_register_backend( GNC_ID_ORDER, GNC_SQL_BACKEND, &be_data );
+
+    gnc_sql_register_col_type_handler( CT_ORDERREF, &order_guid_handler );
+}
+/* ========================== END OF FILE ===================== */

Copied: gnucash/trunk/src/backend/sql/gnc-order-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-order-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-order-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-order-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,37 @@
+/*
+ * gnc-order-sql.h -- order sql backend
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-order-sql.h
+ *  @brief load and save order data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_ORDER_SQL_H
+#define GNC_ORDER_SQL_H
+
+#define CT_ORDERREF "order"
+
+void gnc_order_sql_initialize( void );
+
+#endif /* GNC_ORDER_SQL_H */

Copied: gnucash/trunk/src/backend/sql/gnc-owner-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-owner-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-owner-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,304 @@
+/********************************************************************\
+ * gnc-owner-sql.c -- owner sql implementation                      *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-owner-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-backend-sql.h"
+
+#include "gnc-owner-sql.h"
+#include "gncCustomerP.h"
+#include "gncJobP.h"
+#include "gncEmployeeP.h"
+#include "gncVendorP.h"
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+typedef void (*OwnerSetterFunc)( gpointer, GncOwner* );
+typedef GncOwner* (*OwnerGetterFunc)( const gpointer );
+
+static void
+load_owner( const GncSqlBackend* be, GncSqlRow* row,
+            QofSetterFunc setter, gpointer pObject,
+            const GncSqlColumnTableEntry* table_row )
+{
+    const GValue* val;
+    gchar* buf;
+    GncOwnerType type;
+    GncGUID guid;
+    QofBook* book;
+    GncOwner owner;
+    GncGUID* pGuid = NULL;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( row != NULL );
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( table_row != NULL );
+
+    book = be->primary_book;
+    buf = g_strdup_printf( "%s_type", table_row->col_name );
+    val = gnc_sql_row_get_value_at_col_name( row, buf );
+    type = (GncOwnerType)gnc_sql_get_integer_value( val );
+    g_free( buf );
+    buf = g_strdup_printf( "%s_guid", table_row->col_name );
+    val = gnc_sql_row_get_value_at_col_name( row, buf );
+    g_free( buf );
+
+    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
+    {
+        string_to_guid( g_value_get_string( val ), &guid );
+        pGuid = &guid;
+    }
+
+    switch ( type )
+    {
+    case GNC_OWNER_CUSTOMER:
+    {
+        GncCustomer *cust = NULL;
+
+        if ( pGuid != NULL )
+        {
+            cust = gncCustomerLookup( book, pGuid );
+            if ( cust == NULL )
+            {
+                cust = gncCustomerCreate( book );
+                gncCustomerSetGUID( cust, &guid );
+            }
+        }
+        gncOwnerInitCustomer( &owner, cust );
+        break;
+    }
+
+    case GNC_OWNER_JOB:
+    {
+        GncJob *job = NULL;
+
+        if ( pGuid != NULL )
+        {
+            job = gncJobLookup( book, pGuid );
+            if ( job == NULL )
+            {
+                job = gncJobCreate( book );
+                gncJobSetGUID( job, &guid );
+            }
+        }
+        gncOwnerInitJob( &owner, job );
+        break;
+    }
+
+    case GNC_OWNER_VENDOR:
+    {
+        GncVendor *vendor = NULL;
+
+        if ( pGuid != NULL )
+        {
+            vendor = gncVendorLookup( book, pGuid );
+            if ( vendor == NULL )
+            {
+                vendor = gncVendorCreate( book );
+                gncVendorSetGUID( vendor, &guid );
+            }
+        }
+        gncOwnerInitVendor( &owner, vendor );
+        break;
+    }
+
+    case GNC_OWNER_EMPLOYEE:
+    {
+        GncEmployee *employee = NULL;
+
+        if ( pGuid != NULL )
+        {
+            employee = gncEmployeeLookup( book, pGuid );
+            if ( employee == NULL )
+            {
+                employee = gncEmployeeCreate( book );
+                gncEmployeeSetGUID( employee, &guid );
+            }
+        }
+        gncOwnerInitEmployee( &owner, employee );
+        break;
+    }
+
+    default:
+        PWARN("Invalid owner type: %d\n", type );
+    }
+
+    if ( table_row->gobj_param_name != NULL )
+    {
+        g_object_set( pObject, table_row->gobj_param_name, &owner, NULL );
+    }
+    else
+    {
+        (*setter)( pObject, &owner );
+    }
+}
+
+static void
+add_owner_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,
+                            GList** pList )
+{
+    GncSqlColumnInfo* info;
+    gchar* buf;
+    const gchar* type;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( table_row != NULL );
+    g_return_if_fail( pList != NULL );
+
+    buf = g_strdup_printf( "%s_type", table_row->col_name );
+    info = g_new0( GncSqlColumnInfo, 1 );
+    info->name = buf;
+    info->type = BCT_INT;
+    info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
+    info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
+    info->size = table_row->size;
+    info->is_unicode = FALSE;
+    *pList = g_list_append( *pList, info );
+
+    buf = g_strdup_printf( "%s_guid", table_row->col_name );
+    info = g_new0( GncSqlColumnInfo, 1 );
+    info->name = buf;
+    info->type = BCT_STRING;
+    info->size = GUID_ENCODING_LENGTH;
+    info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
+    info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
+    info->is_unicode = FALSE;
+    *pList = g_list_append( *pList, info );
+}
+
+static void
+add_colname_to_list( const GncSqlColumnTableEntry* table_row, GList** pList )
+{
+    gchar* buf;
+
+    buf = g_strdup_printf( "%s_type", table_row->col_name );
+    (*pList) = g_list_append( (*pList), buf );
+    buf = g_strdup_printf( "%s_guid", table_row->col_name );
+    (*pList) = g_list_append( (*pList), buf );
+}
+
+static void
+add_gvalue_owner_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
+                           const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList )
+{
+    GValue* subfield_value;
+    GncOwner* owner;
+    gchar* buf;
+    const GncGUID* guid;
+    gchar guid_buf[GUID_ENCODING_LENGTH+1];
+    GncOwnerType type;
+    QofInstance* inst = NULL;
+    OwnerGetterFunc getter;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( obj_name != NULL );
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( table_row != NULL );
+
+    getter = (OwnerGetterFunc)gnc_sql_get_getter( obj_name, table_row );
+    owner = (*getter)( pObject );
+
+    if ( owner != NULL )
+    {
+        buf = g_strdup_printf( "%s_type", table_row->col_name );
+        subfield_value = g_new0( GValue, 1 );
+        g_value_init( subfield_value, G_TYPE_INT );
+        type = gncOwnerGetType( owner );
+        g_value_set_int( subfield_value, type );
+        (*pList) = g_slist_append( (*pList), subfield_value );
+        g_free( buf );
+
+        buf = g_strdup_printf( "%s_guid", table_row->col_name );
+        subfield_value = g_new0( GValue, 1 );
+        switch ( type )
+        {
+        case GNC_OWNER_CUSTOMER:
+            inst = QOF_INSTANCE(gncOwnerGetCustomer( owner ));
+            break;
+
+        case GNC_OWNER_JOB:
+            inst = QOF_INSTANCE(gncOwnerGetJob( owner ));
+            break;
+
+        case GNC_OWNER_VENDOR:
+            inst = QOF_INSTANCE(gncOwnerGetVendor( owner ));
+            break;
+
+        case GNC_OWNER_EMPLOYEE:
+            inst = QOF_INSTANCE(gncOwnerGetEmployee( owner ));
+            break;
+
+        default:
+            PWARN("Invalid owner type: %d\n", type );
+        }
+        g_value_init( subfield_value, G_TYPE_STRING );
+        if ( inst != NULL )
+        {
+            guid = qof_instance_get_guid( inst );
+            if ( guid != NULL )
+            {
+                (void)guid_to_string_buff( guid, guid_buf );
+                g_value_take_string( subfield_value, g_strdup_printf( "%s", guid_buf ) );
+            }
+        }
+        (*pList) = g_slist_append( (*pList), subfield_value );
+        g_free( buf );
+    }
+    else
+    {
+        subfield_value = g_new0( GValue, 1 );
+        g_value_init( subfield_value, G_TYPE_STRING );
+        g_value_set_string( subfield_value, "NULL" );
+        (*pList) = g_slist_append( (*pList), subfield_value );
+        subfield_value = g_new0( GValue, 1 );
+        g_value_init( subfield_value, G_TYPE_STRING );
+        g_value_set_string( subfield_value, "NULL" );
+        (*pList) = g_slist_append( (*pList), subfield_value );
+    }
+}
+
+static GncSqlColumnTypeHandler owner_handler
+= { load_owner,
+    add_owner_col_info_to_list,
+    add_colname_to_list,
+    add_gvalue_owner_to_slist
+  };
+
+/* ================================================================= */
+void
+gnc_owner_sql_initialize( void )
+{
+    gnc_sql_register_col_type_handler( CT_OWNERREF, &owner_handler );
+}
+/* ========================== END OF FILE ===================== */

Copied: gnucash/trunk/src/backend/sql/gnc-owner-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-owner-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-owner-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,39 @@
+/* gnc-owner-sql.h -- Owner SQL header
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-owner-sql.h
+ *  @brief load and save owner data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_OWNER_SQL_H
+#define GNC_OWNER_SQL_H
+
+#include "gncOwner.h"
+#include "qof.h"
+
+#define CT_OWNERREF "owner"
+
+void gnc_owner_sql_initialize( void );
+
+#endif /* GNC_OWNER_SQL_H */

Copied: gnucash/trunk/src/backend/sql/gnc-tax-table-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-tax-table-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-tax-table-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,598 @@
+/********************************************************************\
+ * gnc-tax-table-sql.c -- tax table sql implementation              *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-tax-table-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-backend-sql.h"
+#include "gnc-slots-sql.h"
+
+#include "gncEntry.h"
+#include "gncTaxTableP.h"
+
+#include "gnc-tax-table-sql.h"
+
+#define _GNC_MOD_NAME	GNC_ID_TAXTABLE
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+static void set_invisible( gpointer data, gboolean value );
+
+typedef struct
+{
+    GncSqlBackend* be;
+    const GncGUID* guid;
+} guid_info_t;
+
+static gpointer get_obj_guid( gpointer pObject, const QofParam* param );
+static void set_obj_guid( gpointer pObject, gpointer pValue );
+static gpointer get_child( gpointer pObject, const QofParam* param );
+static gpointer bt_get_parent( gpointer pObject );
+static void tt_set_parent( gpointer pObject, gpointer pValue );
+static void tt_set_parent_guid( gpointer pObject, gpointer pValue );
+
+#define MAX_NAME_LEN 50
+
+#define TT_TABLE_NAME "taxtables"
+#define TT_TABLE_VERSION 2
+
+static GncSqlColumnTableEntry tt_col_table[] =
+{
+    { "guid",      CT_GUID,        0,            COL_NNUL | COL_PKEY, "guid" },
+    { "name",      CT_STRING,      MAX_NAME_LEN, COL_NNUL,          "name" },
+    { "refcount",  CT_INT64,       0,            COL_NNUL,          NULL, GNC_TT_REFCOUNT },
+    {
+        "invisible", CT_BOOLEAN,     0,            COL_NNUL,          NULL, NULL,
+        (QofAccessFunc)gncTaxTableGetInvisible, (QofSetterFunc)set_invisible
+    },
+    /*	{ "child",     CT_TAXTABLEREF, 0,			 0,                 NULL, NULL,
+    			get_child, (QofSetterFunc)gncTaxTableSetChild }, */
+    {
+        "parent",    CT_GUID,        0,			 0,                 NULL, NULL,
+        (QofAccessFunc)bt_get_parent, tt_set_parent
+    },
+    { NULL }
+};
+
+static GncSqlColumnTableEntry tt_parent_col_table[] =
+{
+    { "parent", CT_GUID, 0, 0, NULL, NULL, NULL, tt_set_parent_guid },
+    { NULL }
+};
+
+#define TTENTRIES_TABLE_NAME "taxtable_entries"
+#define TTENTRIES_TABLE_VERSION 3
+
+static GncSqlColumnTableEntry ttentries_col_table[] =
+{
+    { "id",       CT_INT,         0, COL_PKEY | COL_NNUL | COL_AUTOINC },
+    {
+        "taxtable", CT_TAXTABLEREF, 0, COL_NNUL, NULL, NULL,
+        (QofAccessFunc)gncTaxTableEntryGetTable, set_obj_guid
+    },
+    {
+        "account",  CT_ACCOUNTREF,  0, COL_NNUL, NULL, NULL,
+        (QofAccessFunc)gncTaxTableEntryGetAccount, (QofSetterFunc)gncTaxTableEntrySetAccount
+    },
+    {
+        "amount",   CT_NUMERIC,     0, COL_NNUL, NULL, NULL,
+        (QofAccessFunc)gncTaxTableEntryGetAmount, (QofSetterFunc)gncTaxTableEntrySetAmount
+    },
+    {
+        "type",     CT_INT,         0, COL_NNUL, NULL, NULL,
+        (QofAccessFunc)gncTaxTableEntryGetType, (QofSetterFunc)gncTaxTableEntrySetType
+    },
+    { NULL }
+};
+
+/* Special column table because we need to be able to access the table by
+a column other than the primary key */
+static GncSqlColumnTableEntry guid_col_table[] =
+{
+    { "taxtable", CT_GUID, 0, 0, NULL, NULL, get_obj_guid, set_obj_guid },
+    { NULL }
+};
+
+typedef struct
+{
+    /*@ dependent @*/ GncTaxTable* tt;
+    GncGUID guid;
+    gboolean have_guid;
+} taxtable_parent_guid_struct;
+
+static gpointer
+get_obj_guid( gpointer pObject, const QofParam* param )
+{
+    guid_info_t* pInfo = (guid_info_t*)pObject;
+
+    g_return_val_if_fail( pInfo != NULL, NULL );
+
+    return (gpointer)pInfo->guid;
+}
+
+static void
+set_obj_guid( gpointer pObject, gpointer pValue )
+{
+    // Nowhere to put the GncGUID
+}
+
+static void
+set_invisible( gpointer data, gboolean value )
+{
+    GncTaxTable* tt = GNC_TAXTABLE(data);
+
+    g_return_if_fail( data != NULL );
+    g_return_if_fail( GNC_IS_TAXTABLE(data) );
+
+    if ( value )
+    {
+        gncTaxTableMakeInvisible( tt );
+    }
+}
+
+static gpointer
+get_child( gpointer pObject, const QofParam* param )
+{
+    GncTaxTable* tt = GNC_TAXTABLE(pObject);
+
+    g_return_val_if_fail( pObject != NULL, NULL );
+    g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );
+
+    return gncTaxTableGetChild( tt );
+}
+
+static /*@ null @*//*@ dependent @*/ gpointer
+bt_get_parent( gpointer pObject )
+{
+    const GncTaxTable* tt;
+    const GncTaxTable* pParent;
+    const GncGUID* parent_guid;
+
+    g_return_val_if_fail( pObject != NULL, NULL );
+    g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );
+
+    tt = GNC_TAXTABLE(pObject);
+    pParent = gncTaxTableGetParent( tt );
+    if ( pParent == NULL )
+    {
+        parent_guid = NULL;
+    }
+    else
+    {
+        parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
+    }
+
+    return (gpointer)parent_guid;
+}
+
+static void
+tt_set_parent( gpointer data, gpointer value )
+{
+    GncTaxTable* tt;
+    GncTaxTable* parent;
+    QofBook* pBook;
+    GncGUID* guid = (GncGUID*)value;
+
+    g_return_if_fail( data != NULL );
+    g_return_if_fail( GNC_IS_TAXTABLE(data) );
+
+    tt = GNC_TAXTABLE(data);
+    pBook = qof_instance_get_book( QOF_INSTANCE(tt) );
+    if ( guid != NULL )
+    {
+        parent = gncTaxTableLookup( pBook, guid );
+        if ( parent != NULL )
+        {
+            gncTaxTableSetParent( tt, parent );
+            gncTaxTableSetChild( parent, tt );
+        }
+    }
+}
+
+static void
+tt_set_parent_guid( gpointer pObject, /*@ null @*/ gpointer pValue )
+{
+    taxtable_parent_guid_struct* s = (taxtable_parent_guid_struct*)pObject;
+    GncGUID* guid = (GncGUID*)pValue;
+
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( pValue != NULL );
+
+    s->guid = *guid;
+    s->have_guid = TRUE;
+}
+
+static void
+load_single_ttentry( GncSqlBackend* be, GncSqlRow* row, GncTaxTable* tt )
+{
+    GncTaxTableEntry* e = gncTaxTableEntryCreate();
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( row != NULL );
+    g_return_if_fail( tt != NULL );
+
+    gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, e, ttentries_col_table );
+    gncTaxTableAddEntry( tt, e );
+}
+
+static void
+load_taxtable_entries( GncSqlBackend* be, GncTaxTable* tt )
+{
+    GncSqlResult* result;
+    gchar guid_buf[GUID_ENCODING_LENGTH+1];
+    GValue value;
+    gchar* buf;
+    GncSqlStatement* stmt;
+    GError* error = NULL;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( tt != NULL );
+
+    guid_to_string_buff( qof_instance_get_guid( QOF_INSTANCE(tt) ), guid_buf );
+    memset( &value, 0, sizeof( GValue ) );
+    g_value_init( &value, G_TYPE_STRING );
+    g_value_set_string( &value, guid_buf );
+    buf = g_strdup_printf( "SELECT * FROM %s WHERE taxtable='%s'", TTENTRIES_TABLE_NAME, guid_buf );
+    stmt = gnc_sql_connection_create_statement_from_sql( be->conn, buf );
+    g_free( buf );
+    result = gnc_sql_execute_select_statement( be, stmt );
+    gnc_sql_statement_dispose( stmt );
+    if ( result != NULL )
+    {
+        GncSqlRow* row;
+
+        row = gnc_sql_result_get_first_row( result );
+        while ( row != NULL )
+        {
+            load_single_ttentry( be, row, tt );
+            row = gnc_sql_result_get_next_row( result );
+        }
+        gnc_sql_result_dispose( result );
+    }
+}
+
+static void
+load_single_taxtable( GncSqlBackend* be, GncSqlRow* row,
+                      GList** l_tt_needing_parents )
+{
+    const GncGUID* guid;
+    GncTaxTable* tt;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( row != NULL );
+
+    guid = gnc_sql_load_guid( be, row );
+    tt = gncTaxTableLookup( be->primary_book, guid );
+    if ( tt == NULL )
+    {
+        tt = gncTaxTableCreate( be->primary_book );
+    }
+    gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, tt, tt_col_table );
+    gnc_sql_slots_load( be, QOF_INSTANCE(tt) );
+    load_taxtable_entries( be, tt );
+
+    /* If the tax table doesn't have a parent, it might be because it hasn't been loaded yet.
+       If so, add this tax table to the list of tax tables with no parent, along with the parent
+       GncGUID so that after they are all loaded, the parents can be fixed up. */
+    if ( gncTaxTableGetParent( tt ) == NULL )
+    {
+        taxtable_parent_guid_struct* s = g_malloc( (gsize)sizeof(taxtable_parent_guid_struct) );
+        g_assert( s != NULL );
+
+        s->tt = tt;
+        s->have_guid = FALSE;
+        gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, s, tt_parent_col_table );
+        if ( s->have_guid )
+        {
+            *l_tt_needing_parents = g_list_prepend( *l_tt_needing_parents, s );
+        }
+        else
+        {
+            g_free( s );
+        }
+    }
+
+    qof_instance_mark_clean( QOF_INSTANCE(tt) );
+}
+
+static void
+load_all_taxtables( GncSqlBackend* be )
+{
+    GncSqlStatement* stmt;
+    GncSqlResult* result;
+
+    g_return_if_fail( be != NULL );
+
+    /* First time, create the query */
+    stmt = gnc_sql_create_select_statement( be, TT_TABLE_NAME );
+    result = gnc_sql_execute_select_statement( be, stmt );
+    gnc_sql_statement_dispose( stmt );
+    if ( result != NULL )
+    {
+        GncSqlRow* row;
+        GList* tt_needing_parents = NULL;
+
+        row = gnc_sql_result_get_first_row( result );
+        while ( row != NULL )
+        {
+            load_single_taxtable( be, row, &tt_needing_parents );
+            row = gnc_sql_result_get_next_row( result );
+        }
+        gnc_sql_result_dispose( result );
+
+        /* While there are items on the list of taxtables needing parents,
+           try to see if the parent has now been loaded.  Theory says that if
+           items are removed from the front and added to the back if the
+           parent is still not available, then eventually, the list will
+           shrink to size 0. */
+        if ( tt_needing_parents != NULL )
+        {
+            gboolean progress_made = TRUE;
+            GncTaxTable* root;
+            Account* pParent;
+            GList* elem;
+
+            while ( progress_made )
+            {
+                progress_made = FALSE;
+                for ( elem = tt_needing_parents; elem != NULL; elem = g_list_next( elem ) )
+                {
+                    taxtable_parent_guid_struct* s = (taxtable_parent_guid_struct*)elem->data;
+                    tt_set_parent( s->tt, &s->guid );
+                    tt_needing_parents = g_list_delete_link( tt_needing_parents, elem );
+                    progress_made = TRUE;
+                }
+            }
+        }
+    }
+}
+
+/* ================================================================= */
+static void
+create_taxtable_tables( GncSqlBackend* be )
+{
+    gint version;
+
+    g_return_if_fail( be != NULL );
+
+    version = gnc_sql_get_table_version( be, TT_TABLE_NAME );
+    if ( version == 0 )
+    {
+        gnc_sql_create_table( be, TT_TABLE_NAME, TT_TABLE_VERSION, tt_col_table );
+    }
+    else if ( version == 1 )
+    {
+        /* Upgrade 64 bit int handling */
+        gnc_sql_upgrade_table( be, TT_TABLE_NAME, tt_col_table );
+        gnc_sql_set_table_version( be, TT_TABLE_NAME, TT_TABLE_VERSION );
+    }
+
+    version = gnc_sql_get_table_version( be, TTENTRIES_TABLE_NAME );
+    if ( version == 0 )
+    {
+        gnc_sql_create_table( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION, ttentries_col_table );
+    }
+    else if ( version == 1 )
+    {
+        /* Upgrade 64 bit int handling */
+        gnc_sql_upgrade_table( be, TTENTRIES_TABLE_NAME, ttentries_col_table );
+        gnc_sql_set_table_version( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION );
+    }
+}
+
+/* ================================================================= */
+static gboolean
+delete_all_tt_entries( GncSqlBackend* be, const GncGUID* guid )
+{
+    guid_info_t guid_info;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+    g_return_val_if_fail( guid != NULL, FALSE );
+
+    guid_info.be = be;
+    guid_info.guid = guid;
+    return gnc_sql_do_db_operation( be, OP_DB_DELETE, TTENTRIES_TABLE_NAME,
+                                    TTENTRIES_TABLE_NAME, &guid_info, guid_col_table );
+}
+
+static gboolean
+save_tt_entries( GncSqlBackend* be, const GncGUID* guid, GList* entries )
+{
+    GList* entry;
+    gboolean is_ok;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+    g_return_val_if_fail( guid != NULL, FALSE );
+
+    /* First, delete the old entries for this object */
+    is_ok = delete_all_tt_entries( be, guid );
+
+    for ( entry = entries; entry != NULL && is_ok; entry = entry->next )
+    {
+        GncTaxTableEntry* e = (GncTaxTableEntry*)entry->data;
+        is_ok = gnc_sql_do_db_operation( be,
+                                         OP_DB_INSERT,
+                                         TTENTRIES_TABLE_NAME,
+                                         GNC_ID_TAXTABLE, e,
+                                         ttentries_col_table );
+    }
+
+    return is_ok;
+}
+
+static gboolean
+save_taxtable( GncSqlBackend* be, QofInstance* inst )
+{
+    GncTaxTable* tt;
+    const GncGUID* guid;
+    gint op;
+    gboolean is_infant;
+    gboolean is_ok;
+
+    g_return_val_if_fail( inst != NULL, FALSE );
+    g_return_val_if_fail( GNC_IS_TAXTABLE(inst), FALSE );
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    tt = GNC_TAXTABLE(inst);
+
+    is_infant = qof_instance_get_infant( inst );
+    if ( qof_instance_get_destroying( inst ) )
+    {
+        op = OP_DB_DELETE;
+    }
+    else if ( be->is_pristine_db || is_infant )
+    {
+        op = OP_DB_INSERT;
+    }
+    else
+    {
+        op = OP_DB_UPDATE;
+    }
+    is_ok = gnc_sql_do_db_operation( be, op, TT_TABLE_NAME, GNC_ID_TAXTABLE, tt, tt_col_table );
+
+    if ( is_ok )
+    {
+        // Now, commit or delete any slots and tax table entries
+        guid = qof_instance_get_guid( inst );
+        if ( !qof_instance_get_destroying(inst) )
+        {
+            is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
+            if ( is_ok )
+            {
+                is_ok = save_tt_entries( be, guid, gncTaxTableGetEntries( tt ) );
+            }
+        }
+        else
+        {
+            is_ok = gnc_sql_slots_delete( be, guid );
+            if ( is_ok )
+            {
+                is_ok = delete_all_tt_entries( be, guid );
+            }
+        }
+    }
+
+    return is_ok;
+}
+
+/* ================================================================= */
+static void
+save_next_taxtable( QofInstance* inst, gpointer data )
+{
+    write_objects_t* s = (write_objects_t*)data;
+
+    if ( s->is_ok )
+    {
+        s->is_ok = save_taxtable( s->be, inst );
+    }
+}
+
+static gboolean
+write_taxtables( GncSqlBackend* be )
+{
+    write_objects_t data;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    data.be = be;
+    data.is_ok = TRUE;
+    qof_object_foreach( GNC_ID_TAXTABLE, be->primary_book, save_next_taxtable, &data );
+
+    return data.is_ok;
+}
+
+/* ================================================================= */
+static void
+load_taxtable_guid( const GncSqlBackend* be, GncSqlRow* row,
+                    QofSetterFunc setter, gpointer pObject,
+                    const GncSqlColumnTableEntry* table_row )
+{
+    const GValue* val;
+    GncGUID guid;
+    GncTaxTable* taxtable = NULL;
+
+    g_return_if_fail( be != NULL );
+    g_return_if_fail( row != NULL );
+    g_return_if_fail( pObject != NULL );
+    g_return_if_fail( table_row != NULL );
+
+    val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
+    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
+    {
+        string_to_guid( g_value_get_string( val ), &guid );
+        taxtable = gncTaxTableLookup( be->primary_book, &guid );
+        if ( taxtable != NULL )
+        {
+            if ( table_row->gobj_param_name != NULL )
+            {
+                g_object_set( pObject, table_row->gobj_param_name, taxtable, NULL );
+            }
+            else
+            {
+                (*setter)( pObject, (const gpointer)taxtable );
+            }
+        }
+        else
+        {
+            PWARN( "Taxtable ref '%s' not found", g_value_get_string( val ) );
+        }
+    }
+}
+
+static GncSqlColumnTypeHandler taxtable_guid_handler
+= { load_taxtable_guid,
+    gnc_sql_add_objectref_guid_col_info_to_list,
+    gnc_sql_add_colname_to_list,
+    gnc_sql_add_gvalue_objectref_guid_to_slist
+  };
+/* ================================================================= */
+void
+gnc_taxtable_sql_initialize( void )
+{
+    static GncSqlObjectBackend be_data =
+    {
+        GNC_SQL_BACKEND_VERSION,
+        GNC_ID_TAXTABLE,
+        save_taxtable,						/* commit */
+        load_all_taxtables,					/* initial_load */
+        create_taxtable_tables,				/* create_tables */
+        NULL, NULL, NULL,
+        write_taxtables						/* write */
+    };
+
+    qof_object_register_backend( GNC_ID_TAXTABLE, GNC_SQL_BACKEND, &be_data );
+
+    gnc_sql_register_col_type_handler( CT_TAXTABLEREF, &taxtable_guid_handler );
+}
+/* ========================== END OF FILE ===================== */
+

Copied: gnucash/trunk/src/backend/sql/gnc-tax-table-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-tax-table-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-tax-table-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,37 @@
+/*
+ * gnc-tax-table-sql.h -- tax table sql backend
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-tax-table-sql.h
+ *  @brief load and save tax table data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_TAXTABLE_SQL_H
+#define GNC_TAXTABLE_SQL_H
+
+#define CT_TAXTABLEREF "tax-table"
+
+void gnc_taxtable_sql_initialize( void );
+
+#endif /* GNC_TAXTABLE_SQL_H */

Copied: gnucash/trunk/src/backend/sql/gnc-vendor-sql.c (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.c)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-vendor-sql.c	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-vendor-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,280 @@
+/********************************************************************\
+ * gnc-vendor-sql.c -- vendor sql backend                           *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/** @file gnc-vendor-sql.c
+ *  @brief load and save address data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gnc-commodity.h"
+
+#include "gnc-backend-sql.h"
+#include "gnc-commodity-sql.h"
+#include "gnc-slots-sql.h"
+
+#include "gnc-commodity.h"
+#include "gncBillTermP.h"
+#include "gncVendorP.h"
+#include "gncTaxTableP.h"
+#include "gnc-vendor-sql.h"
+#include "gnc-address-sql.h"
+#include "gnc-bill-term-sql.h"
+#include "gnc-tax-table-sql.h"
+
+#define _GNC_MOD_NAME	GNC_ID_VENDOR
+
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+#define MAX_NAME_LEN 2048
+#define MAX_ID_LEN 2048
+#define MAX_NOTES_LEN 2048
+#define MAX_TAX_INC_LEN 2048
+
+#define TABLE_NAME "vendors"
+#define TABLE_VERSION 1
+
+static GncSqlColumnTableEntry col_table[] =
+{
+    { "guid",         CT_GUID,          0,               COL_NNUL | COL_PKEY, "guid" },
+    { "name",         CT_STRING,        MAX_NAME_LEN,    COL_NNUL,          "name" },
+    { "id",           CT_STRING,        MAX_ID_LEN,      COL_NNUL,          NULL, VENDOR_ID },
+    { "notes",        CT_STRING,        MAX_NOTES_LEN,   COL_NNUL,          NULL, VENDOR_NOTES },
+    {
+        "currency",     CT_COMMODITYREF,  0,               COL_NNUL,          NULL, NULL,
+        (QofAccessFunc)gncVendorGetCurrency, (QofSetterFunc)gncVendorSetCurrency
+    },
+    {
+        "active",       CT_BOOLEAN,       0,               COL_NNUL,          NULL, NULL,
+        (QofAccessFunc)gncVendorGetActive, (QofSetterFunc)gncVendorSetActive
+    },
+    { "tax_override", CT_BOOLEAN,       0,               COL_NNUL,          NULL, VENDOR_TAX_OVERRIDE },
+    { "addr",         CT_ADDRESS,       0,               0,                 NULL, VENDOR_ADDR },
+    { "terms",        CT_BILLTERMREF,   0,               0,                 NULL, VENDOR_TERMS },
+    { "tax_inc",      CT_STRING,        MAX_TAX_INC_LEN, 0,                 NULL, VENDOR_TAX_INC },
+    { "tax_table",    CT_TAXTABLEREF,   0,               0,                 NULL, VENDOR_TAX_TABLE },
+    { NULL }
+};
+
+static GncVendor*
+load_single_vendor( GncSqlBackend* be, GncSqlRow* row )
+{
+    const GncGUID* guid;
+    GncVendor* pVendor;
+
+    g_return_val_if_fail( be != NULL, NULL );
+    g_return_val_if_fail( row != NULL, NULL );
+
+    guid = gnc_sql_load_guid( be, row );
+    pVendor = gncVendorLookup( be->primary_book, guid );
+    if ( pVendor == NULL )
+    {
+        pVendor = gncVendorCreate( be->primary_book );
+    }
+    gnc_sql_load_object( be, row, GNC_ID_VENDOR, pVendor, col_table );
+    qof_instance_mark_clean( QOF_INSTANCE(pVendor) );
+
+    return pVendor;
+}
+
+static void
+load_all_vendors( GncSqlBackend* be )
+{
+    GncSqlStatement* stmt;
+    GncSqlResult* result;
+    QofBook* pBook;
+
+    g_return_if_fail( be != NULL );
+
+    pBook = be->primary_book;
+
+    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
+    result = gnc_sql_execute_select_statement( be, stmt );
+    gnc_sql_statement_dispose( stmt );
+    if ( result != NULL )
+    {
+        GncSqlRow* row;
+        GList* list = NULL;
+
+        row = gnc_sql_result_get_first_row( result );
+        while ( row != NULL )
+        {
+            GncVendor* pVendor = load_single_vendor( be, row );
+            if ( pVendor != NULL )
+            {
+                list = g_list_append( list, pVendor );
+            }
+            row = gnc_sql_result_get_next_row( result );
+        }
+        gnc_sql_result_dispose( result );
+
+        if ( list != NULL )
+        {
+            gnc_sql_slots_load_for_list( be, list );
+        }
+    }
+}
+
+/* ================================================================= */
+static void
+create_vendor_tables( GncSqlBackend* be )
+{
+    gint version;
+
+    g_return_if_fail( be != NULL );
+
+    version = gnc_sql_get_table_version( be, TABLE_NAME );
+    if ( version == 0 )
+    {
+        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
+    }
+}
+
+/* ================================================================= */
+static gboolean
+save_vendor( GncSqlBackend* be, QofInstance* inst )
+{
+    GncVendor* v;
+    const GncGUID* guid;
+    gint op;
+    gboolean is_infant;
+    gboolean is_ok = TRUE;
+
+    g_return_val_if_fail( inst != NULL, FALSE );
+    g_return_val_if_fail( GNC_IS_VENDOR(inst), FALSE );
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    v = GNC_VENDOR(inst);
+
+    is_infant = qof_instance_get_infant( inst );
+    if ( qof_instance_get_destroying( inst ) )
+    {
+        op = OP_DB_DELETE;
+    }
+    else if ( be->is_pristine_db || is_infant )
+    {
+        op = OP_DB_INSERT;
+    }
+    else
+    {
+        op = OP_DB_UPDATE;
+    }
+    if ( op != OP_DB_DELETE )
+    {
+        // Ensure the commodity is in the db
+        is_ok = gnc_sql_save_commodity( be, gncVendorGetCurrency( v ) );
+    }
+    if ( is_ok )
+    {
+        is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_VENDOR, v, col_table );
+    }
+
+    if ( is_ok )
+    {
+        // Now, commit or delete any slots
+        guid = qof_instance_get_guid( inst );
+        if ( !qof_instance_get_destroying(inst) )
+        {
+            is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
+        }
+        else
+        {
+            is_ok = gnc_sql_slots_delete( be, guid );
+        }
+    }
+
+    return is_ok;
+}
+
+/* ================================================================= */
+static gboolean
+vendor_should_be_saved( GncVendor *vendor )
+{
+    const char *id;
+
+    g_return_val_if_fail( vendor != NULL, FALSE );
+
+    /* make sure this is a valid vendor before we save it -- should have an ID */
+    id = gncVendorGetID( vendor );
+    if ( id == NULL || *id == '\0' )
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static void
+write_single_vendor( QofInstance *term_p, gpointer data_p )
+{
+    write_objects_t* s = (write_objects_t*)data_p;
+
+    g_return_if_fail( term_p != NULL );
+    g_return_if_fail( GNC_IS_VENDOR(term_p) );
+    g_return_if_fail( data_p != NULL );
+
+    if ( s->is_ok && vendor_should_be_saved( GNC_VENDOR(term_p) ) )
+    {
+        s->is_ok = save_vendor( s->be, term_p );
+    }
+}
+
+static gboolean
+write_vendors( GncSqlBackend* be )
+{
+    write_objects_t data;
+
+    g_return_val_if_fail( be != NULL, FALSE );
+
+    data.be = be;
+    data.is_ok = TRUE;
+    qof_object_foreach( GNC_ID_VENDOR, be->primary_book, write_single_vendor, &data );
+
+    return data.is_ok;
+}
+
+/* ================================================================= */
+void
+gnc_vendor_sql_initialize( void )
+{
+    static GncSqlObjectBackend be_data =
+    {
+        GNC_SQL_BACKEND_VERSION,
+        GNC_ID_VENDOR,
+        save_vendor,						/* commit */
+        load_all_vendors,					/* initial_load */
+        create_vendor_tables,				/* create_tables */
+        NULL, NULL, NULL,
+        write_vendors						/* write */
+    };
+
+    qof_object_register_backend( GNC_ID_VENDOR, GNC_SQL_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Copied: gnucash/trunk/src/backend/sql/gnc-vendor-sql.h (from rev 19363, gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.h)
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-vendor-sql.h	                        (rev 0)
+++ gnucash/trunk/src/backend/sql/gnc-vendor-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -0,0 +1,35 @@
+/*
+ * gnc-vendor-sql.h -- vendor sql backend
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-vendor-sql.h
+ *  @brief load and save vendor data to SQL
+ *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database
+ */
+
+#ifndef GNC_VENDOR_SQL_H
+#define GNC_VENDOR_SQL_H
+
+void gnc_vendor_sql_initialize( void );
+
+#endif /* GNC_VENDOR_SQL_H */

Modified: gnucash/trunk/src/backend/sql/test/Makefile.am
===================================================================
--- gnucash/trunk/src/backend/sql/test/Makefile.am	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/backend/sql/test/Makefile.am	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,18 +1,6 @@
 SUBDIRS = .
 
 test_column_types_SOURCES = \
-  ${top_srcdir}/src/backend/sql/gnc-backend-sql.c \
-  ${top_srcdir}/src/backend/sql/gnc-account-sql.c \
-  ${top_srcdir}/src/backend/sql/gnc-book-sql.c \
-  ${top_srcdir}/src/backend/sql/gnc-budget-sql.c \
-  ${top_srcdir}/src/backend/sql/gnc-commodity-sql.c \
-  ${top_srcdir}/src/backend/sql/gnc-lots-sql.c \
-  ${top_srcdir}/src/backend/sql/gnc-price-sql.c \
-  ${top_srcdir}/src/backend/sql/gnc-recurrence-sql.c \
-  ${top_srcdir}/src/backend/sql/gnc-schedxaction-sql.c \
-  ${top_srcdir}/src/backend/sql/gnc-slots-sql.c \
-  ${top_srcdir}/src/backend/sql/gnc-transaction-sql.c \
-  ${top_srcdir}/src/backend/sql/escape.c \
   test-column-types.c
 
 TESTS = \
@@ -39,6 +27,7 @@
 
 LDADD = ${top_builddir}/src/test-core/libtest-core.la \
         ${top_builddir}/src/gnc-module/libgnc-module.la \
+        ${top_builddir}/src/backend/sql/libgnc-backend-sql.la \
         ${top_builddir}/src/engine/libgncmod-engine.la \
         ${top_builddir}/src/engine/test-core/libgncmod-test-engine.la \
         ${top_builddir}/src/core-utils/libgnc-core-utils.la \

Modified: gnucash/trunk/src/business/business-core/Makefile.am
===================================================================
--- gnucash/trunk/src/business/business-core/Makefile.am	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/Makefile.am	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,4 +1,4 @@
-SUBDIRS = . sql test
+SUBDIRS = . test
 
 pkglib_LTLIBRARIES = libgncmod-business-core.la
 

Deleted: gnucash/trunk/src/business/business-core/sql/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/business/business-core/sql/CMakeLists.txt	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/CMakeLists.txt	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,54 +0,0 @@
-# CMakeLists.txt for src/backend/dbi
-
-ADD_DEFINITIONS (-DG_LOG_DOMAIN=\"gnc.backend.sql\")
-
-INCLUDE_DIRECTORIES (${GCONF2_INCLUDE_DIRS})
-INCLUDE_DIRECTORIES (${GLIB2_INCLUDE_DIRS})
-INCLUDE_DIRECTORIES (${LIBINTL_INCLUDE_PATH})
-INCLUDE_DIRECTORIES (${GUILE_INCLUDE_DIRS})
-INCLUDE_DIRECTORIES (${REGEX_INCLUDE_PATH})
-INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/src ) # for config.h
-INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/src ) # for gnc-ui.h
-INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/lib/libc) # for gnc-ui.h
-INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/src/libqof/qof)
-INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/src/gnc-module)
-INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/src/engine)
-INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/src/business/business-core)
-INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/src/backend/sql)
-
-SET (libgnc_business_backend_sql_SOURCES
-  gncmod-business-backend-sql.c
-  gnc-address-sql.c
-  gnc-bill-term-sql.c
-  gnc-customer-sql.c
-  gnc-employee-sql.c
-  gnc-entry-sql.c
-  gnc-invoice-sql.c
-  gnc-job-sql.c
-  gnc-order-sql.c
-  gnc-owner-sql.c
-  gnc-tax-table-sql.c
-  gnc-vendor-sql.c
-)
-SET (libgnc_business_backend_sql_HEADERS
-  gncmod-business-backend-sql.h
-  gnc-address-sql.h
-  gnc-bill-term-sql.h
-  gnc-customer-sql.h
-  gnc-employee-sql.h
-  gnc-entry-sql.h
-  gnc-invoice-sql.h
-  gnc-job-sql.h
-  gnc-order-sql.h
-  gnc-owner-sql.h
-  gnc-tax-table-sql.h
-  gnc-vendor-sql.h
-)
-
-# Add dependency on config.h
-SET_SOURCE_FILES_PROPERTIES (${libgnc_business_backend_sql_SOURCES} PROPERTIES OBJECT_DEPENDS ${CONFIG_H})
-
-ADD_LIBRARY	(gnc-business-backend-sql
-  ${libgnc_business_backend_sql_SOURCES}
-  ${libgnc_business_backend_sql_HEADERS}
-  )

Deleted: gnucash/trunk/src/business/business-core/sql/Makefile.am
===================================================================
--- gnucash/trunk/src/business/business-core/sql/Makefile.am	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/Makefile.am	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,55 +0,0 @@
-SUBDIRS = . test
-
-pkglib_LTLIBRARIES = libgncmod-business-backend-sql.la
-
-AM_CFLAGS = \
-  -I${top_srcdir}/src \
-  -I${top_srcdir}/src/backend \
-  -I${top_srcdir}/src/backend/sql \
-  -I${top_srcdir}/src/engine \
-  -I${top_srcdir}/src/gnc-module \
-  -I${top_srcdir}/src/business/business-core \
-  -I${top_srcdir}/src/libqof/qof \
-  ${GLIB_CFLAGS} \
-  ${LIBGDA_CFLAGS}
-
-libgncmod_business_backend_sql_la_SOURCES = \
-  gncmod-business-backend-sql.c \
-  gnc-address-sql.c \
-  gnc-bill-term-sql.c \
-  gnc-customer-sql.c \
-  gnc-employee-sql.c \
-  gnc-entry-sql.c \
-  gnc-invoice-sql.c \
-  gnc-job-sql.c \
-  gnc-order-sql.c \
-  gnc-owner-sql.c \
-  gnc-tax-table-sql.c \
-  gnc-vendor-sql.c
-
-noinst_HEADERS = \
-  gncmod-business-backend-sql.h \
-  gnc-address-sql.h \
-  gnc-bill-term-sql.h \
-  gnc-customer-sql.h \
-  gnc-employee-sql.h \
-  gnc-entry-sql.h \
-  gnc-invoice-sql.h \
-  gnc-job-sql.h \
-  gnc-order-sql.h \
-  gnc-owner-sql.h \
-  gnc-tax-table-sql.h \
-  gnc-vendor-sql.h
-
-libgncmod_business_backend_sql_la_LDFLAGS = -module -avoid-version
-
-libgncmod_business_backend_sql_la_LIBADD = \
-  ${top_builddir}/src/business/business-core/libgncmod-business-core.la \
-  ${top_builddir}/src/backend/sql/libgnc-backend-sql.la \
-  ${top_builddir}/src/engine/libgncmod-engine.la \
-  ${top_builddir}/src/gnc-module/libgnc-module.la \
-  ${top_builddir}/src/libqof/qof/libgnc-qof.la \
-  ${GLIB_LIBS} \
-  ${LIBGDA_LIBS}
-
-INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.sql\"

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-address-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-address-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-address-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,232 +0,0 @@
-/********************************************************************\
- * gnc-address-sql.c -- address sql backend implementation          *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-address-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-engine.h"
-
-#include "gnc-backend-sql.h"
-#include "gnc-address-sql.h"
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-#define ADDRESS_MAX_NAME_LEN 1024
-#define ADDRESS_MAX_ADDRESS_LINE_LEN 1024
-#define ADDRESS_MAX_PHONE_LEN 128
-#define ADDRESS_MAX_FAX_LEN 128
-#define ADDRESS_MAX_EMAIL_LEN 256
-
-static GncSqlColumnTableEntry col_table[] =
-{
-    { "name",  CT_STRING, ADDRESS_MAX_NAME_LEN,         COL_NNUL, "name" },
-    { "addr1", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_ONE },
-    { "addr2", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_TWO },
-    { "addr3", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_THREE },
-    { "addr4", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_FOUR },
-    { "phone", CT_STRING, ADDRESS_MAX_PHONE_LEN,        COL_NNUL, NULL, ADDRESS_PHONE },
-    { "fax",   CT_STRING, ADDRESS_MAX_FAX_LEN,          COL_NNUL, NULL, ADDRESS_FAX },
-    { "email", CT_STRING, ADDRESS_MAX_EMAIL_LEN,        COL_NNUL, NULL, ADDRESS_EMAIL },
-    { NULL }
-};
-
-typedef void (*AddressSetterFunc)( gpointer, GncAddress* );
-typedef GncAddress* (*AddressGetterFunc)( const gpointer );
-
-static void
-load_address( const GncSqlBackend* be, GncSqlRow* row,
-              QofSetterFunc setter, gpointer pObject,
-              const GncSqlColumnTableEntry* table_row )
-{
-    const GValue* val;
-    gchar* buf;
-    GncAddress* addr;
-    AddressSetterFunc a_setter = (AddressSetterFunc)setter;
-    const GncSqlColumnTableEntry* subtable;
-    const gchar* s;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( row != NULL );
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( table_row != NULL );
-
-    addr = gncAddressCreate( be->primary_book, NULL );
-    for ( subtable = col_table; subtable->col_name != NULL; subtable++ )
-    {
-        buf = g_strdup_printf( "%s_%s", table_row->col_name, subtable->col_name );
-        val = gnc_sql_row_get_value_at_col_name( row, buf );
-        g_free( buf );
-        if ( val == NULL )
-        {
-            s = NULL;
-        }
-        else
-        {
-            s = g_value_get_string( val );
-        }
-        if ( subtable->gobj_param_name != NULL )
-        {
-            g_object_set( addr, subtable->gobj_param_name, s, NULL );
-        }
-        else
-        {
-            if ( subtable->qof_param_name != NULL )
-            {
-                setter = qof_class_get_parameter_setter( GNC_ID_ADDRESS, subtable->qof_param_name );
-            }
-            else
-            {
-                setter = subtable->setter;
-            }
-            (*setter)( addr, (const gpointer)s );
-        }
-    }
-    (*a_setter)( pObject, addr );
-}
-
-static void
-add_address_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,
-                              GList** pList )
-{
-    GncSqlColumnInfo* info;
-    gchar* buf;
-    const GncSqlColumnTableEntry* subtable_row;
-    const gchar* type;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( table_row != NULL );
-    g_return_if_fail( pList != NULL );
-
-    for ( subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++ )
-    {
-        buf = g_strdup_printf( "%s_%s", table_row->col_name, subtable_row->col_name );
-        info = g_new0( GncSqlColumnInfo, 1 );
-        info->name = buf;
-        info->type = BCT_STRING;
-        info->size = subtable_row->size;
-        info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
-        info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
-        info->is_unicode = TRUE;
-        *pList = g_list_append( *pList, info );
-    }
-}
-
-static void
-add_address_colname_to_list( const GncSqlColumnTableEntry* table_row, GList** pList )
-{
-    gnc_sql_add_subtable_colnames_to_list( table_row, col_table, pList );
-}
-
-static void
-get_gvalue_address( const GncSqlBackend* be, QofIdTypeConst obj_name, const gpointer pObject,
-                    const GncSqlColumnTableEntry* table_row, GValue* value )
-{
-    AddressGetterFunc getter;
-    GncAddress* addr;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( obj_name != NULL );
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( table_row != NULL );
-    g_return_if_fail( value != NULL );
-
-    memset( value, 0, sizeof( GValue ) );
-
-    getter = (AddressGetterFunc)gnc_sql_get_getter( obj_name, table_row );
-    addr = (*getter)( pObject );
-    g_value_init( value, gnc_address_get_type() );
-    g_value_set_object( value, addr );
-}
-
-static void
-add_gvalue_address_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
-                             const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList )
-{
-    GValue value;
-    GValue* subfield_value;
-    GncAddress* addr;
-    gchar* s;
-    QofAccessFunc getter;
-    const GncSqlColumnTableEntry* subtable_row;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( obj_name != NULL );
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( table_row != NULL );
-
-    memset( &value, 0, sizeof( GValue ) );
-    get_gvalue_address( be, obj_name, pObject, table_row, &value );
-
-    if ( G_VALUE_TYPE(&value) != 0 )
-    {
-        addr = g_value_get_object( &value );
-        for ( subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++ )
-        {
-            subfield_value = g_new0( GValue, 1 );
-            if ( subtable_row->gobj_param_name != NULL )
-            {
-                g_object_get( addr, subtable_row->gobj_param_name, &s, NULL );
-            }
-            else
-            {
-                getter = gnc_sql_get_getter( GNC_ID_ADDRESS, subtable_row );
-                s = (gchar*)(*getter)( addr, NULL );
-            }
-            g_value_init( subfield_value, G_TYPE_STRING );
-            if ( s )
-            {
-                g_value_set_string( subfield_value, s );
-            }
-            else
-            {
-                g_value_set_string( subfield_value, "NULL" );
-            }
-            (*pList) = g_slist_append( (*pList), subfield_value );
-        }
-    }
-}
-
-static GncSqlColumnTypeHandler address_handler
-= { load_address,
-    add_address_col_info_to_list,
-    add_address_colname_to_list,
-    add_gvalue_address_to_slist
-  };
-
-/* ================================================================= */
-void
-gnc_address_sql_initialize( void )
-{
-    gnc_sql_register_col_type_handler( CT_ADDRESS, &address_handler );
-}
-/* ========================== END OF FILE ===================== */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-address-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-address-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-address-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,38 +0,0 @@
-/* gnc-address-sql.h -- Address SQL header
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-address-sql.h
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_ADDRESS_SQL_H
-#define GNC_ADDRESS_SQL_H
-
-#include "gncAddress.h"
-
-#define CT_ADDRESS "address"
-
-void gnc_address_sql_initialize( void );
-
-#endif /* GNC_ADDRESS_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,413 +0,0 @@
-/********************************************************************\
- * gnc-bill-term-sql.c -- billing term sql backend                  *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-bill-term-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-backend-sql.h"
-#include "gnc-slots-sql.h"
-
-#include "gncBillTermP.h"
-#include "gncInvoice.h"
-#include "gnc-bill-term-sql.h"
-#include "qof.h"
-
-#define _GNC_MOD_NAME	GNC_ID_BILLTERM
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-#define MAX_NAME_LEN 2048
-#define MAX_DESCRIPTION_LEN 2048
-#define MAX_TYPE_LEN 2048
-
-static void set_invisible( gpointer data, gboolean value );
-static gpointer bt_get_parent( gpointer data );
-static void bt_set_parent( gpointer data, gpointer value );
-static void bt_set_parent_guid( gpointer data, gpointer value );
-
-#define TABLE_NAME "billterms"
-#define TABLE_VERSION 2
-
-static GncSqlColumnTableEntry col_table[] =
-{
-    { "guid",         CT_GUID,        0,                   COL_NNUL | COL_PKEY, "guid" },
-    { "name",         CT_STRING,      MAX_NAME_LEN,        COL_NNUL,          "name" },
-    { "description",  CT_STRING,      MAX_DESCRIPTION_LEN, COL_NNUL,          NULL, GNC_BILLTERM_DESC },
-    {
-        "refcount",     CT_INT,         0,                   COL_NNUL,          NULL, NULL,
-        (QofAccessFunc)gncBillTermGetRefcount,  (QofSetterFunc)gncBillTermSetRefcount
-    },
-    {
-        "invisible",    CT_BOOLEAN,     0,                   COL_NNUL,          NULL, NULL,
-        (QofAccessFunc)gncBillTermGetInvisible, (QofSetterFunc)set_invisible
-    },
-    {
-        "parent",       CT_GUID,       0,                   0,                 NULL, NULL,
-        (QofAccessFunc)bt_get_parent,    (QofSetterFunc)bt_set_parent
-    },
-#if 0
-    {
-        "child",        CT_BILLTERMREF, 0,                   0,                 NULL, NULL,
-        (QofAccessFunc)gncBillTermReturnChild,  (QofSetterFunc)gncBillTermSetChild
-    },
-#endif
-    { "type",         CT_STRING,      MAX_TYPE_LEN,        COL_NNUL,          NULL, GNC_BILLTERM_TYPE },
-    { "duedays",      CT_INT,         0,                   0,                 0,    GNC_BILLTERM_DUEDAYS },
-    { "discountdays", CT_INT,         0,                   0,                 0,    GNC_BILLTERM_DISCDAYS },
-    { "discount",     CT_NUMERIC,     0,                   0,                 0,    GNC_BILLTERM_DISCOUNT },
-    { "cutoff",       CT_INT,         0,                   0,                 0,    GNC_BILLTERM_CUTOFF },
-    { NULL }
-};
-
-static GncSqlColumnTableEntry billterm_parent_col_table[] =
-{
-    { "parent", CT_GUID, 0, 0, NULL, NULL, NULL, (QofSetterFunc)bt_set_parent_guid },
-    { NULL }
-};
-
-typedef struct
-{
-    /*@ dependent @*/ GncBillTerm* billterm;
-    GncGUID guid;
-    gboolean have_guid;
-} billterm_parent_guid_struct;
-
-static void
-set_invisible( gpointer data, gboolean value )
-{
-    GncBillTerm* term = GNC_BILLTERM(data);
-
-    g_return_if_fail( term != NULL );
-
-    if ( value )
-    {
-        gncBillTermMakeInvisible( term );
-    }
-}
-
-static /*@ null @*//*@ dependent @*/ gpointer
-bt_get_parent( gpointer pObject )
-{
-    const GncBillTerm* billterm;
-    const GncBillTerm* pParent;
-    const GncGUID* parent_guid;
-
-    g_return_val_if_fail( pObject != NULL, NULL );
-    g_return_val_if_fail( GNC_IS_BILLTERM(pObject), NULL );
-
-    billterm = GNC_BILLTERM(pObject);
-    pParent = gncBillTermGetParent( billterm );
-    if ( pParent == NULL )
-    {
-        parent_guid = NULL;
-    }
-    else
-    {
-        parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
-    }
-
-    return (gpointer)parent_guid;
-}
-
-static void
-bt_set_parent( gpointer data, gpointer value )
-{
-    GncBillTerm* billterm;
-    GncBillTerm* parent;
-    QofBook* pBook;
-    GncGUID* guid = (GncGUID*)value;
-
-    g_return_if_fail( data != NULL );
-    g_return_if_fail( GNC_IS_BILLTERM(data) );
-
-    billterm = GNC_BILLTERM(data);
-    pBook = qof_instance_get_book( QOF_INSTANCE(billterm) );
-    if ( guid != NULL )
-    {
-        parent = gncBillTermLookup( pBook, guid );
-        if ( parent != NULL )
-        {
-            gncBillTermSetParent( billterm, parent );
-            gncBillTermSetChild( parent, billterm );
-        }
-    }
-}
-
-static void
-bt_set_parent_guid( gpointer pObject, /*@ null @*/ gpointer pValue )
-{
-    billterm_parent_guid_struct* s = (billterm_parent_guid_struct*)pObject;
-    GncGUID* guid = (GncGUID*)pValue;
-
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( pValue != NULL );
-
-    s->guid = *guid;
-    s->have_guid = TRUE;
-}
-
-static GncBillTerm*
-load_single_billterm( GncSqlBackend* be, GncSqlRow* row,
-                      GList** l_billterms_needing_parents )
-{
-    const GncGUID* guid;
-    GncBillTerm* pBillTerm;
-
-    g_return_val_if_fail( be != NULL, NULL );
-    g_return_val_if_fail( row != NULL, NULL );
-
-    guid = gnc_sql_load_guid( be, row );
-    pBillTerm = gncBillTermLookup( be->primary_book, guid );
-    if ( pBillTerm == NULL )
-    {
-        pBillTerm = gncBillTermCreate( be->primary_book );
-    }
-    gnc_sql_load_object( be, row, GNC_ID_BILLTERM, pBillTerm, col_table );
-
-    /* If the billterm doesn't have a parent, it might be because it hasn't been loaded yet.
-       If so, add this billterm to the list of billterms with no parent, along with the parent
-       GncGUID so that after they are all loaded, the parents can be fixed up. */
-    if ( gncBillTermGetParent( pBillTerm ) == NULL )
-    {
-        billterm_parent_guid_struct* s = g_malloc( (gsize)sizeof(billterm_parent_guid_struct) );
-        g_assert( s != NULL );
-
-        s->billterm = pBillTerm;
-        s->have_guid = FALSE;
-        gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, s, billterm_parent_col_table );
-        if ( s->have_guid )
-        {
-            *l_billterms_needing_parents = g_list_prepend( *l_billterms_needing_parents, s );
-        }
-        else
-        {
-            g_free( s );
-        }
-    }
-
-    qof_instance_mark_clean( QOF_INSTANCE(pBillTerm) );
-
-    return pBillTerm;
-}
-
-static void
-load_all_billterms( GncSqlBackend* be )
-{
-    GncSqlStatement* stmt;
-    GncSqlResult* result;
-    QofBook* pBook;
-
-    g_return_if_fail( be != NULL );
-
-    pBook = be->primary_book;
-
-    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
-    result = gnc_sql_execute_select_statement( be, stmt );
-    gnc_sql_statement_dispose( stmt );
-    if ( result != NULL )
-    {
-        GncSqlRow* row;
-        GList* list = NULL;
-        GList* l_billterms_needing_parents = NULL;
-
-        row = gnc_sql_result_get_first_row( result );
-        while ( row != NULL )
-        {
-            GncBillTerm* pBillTerm = load_single_billterm( be, row, &l_billterms_needing_parents );
-            if ( pBillTerm != NULL )
-            {
-                list = g_list_append( list, pBillTerm );
-            }
-            row = gnc_sql_result_get_next_row( result );
-        }
-        gnc_sql_result_dispose( result );
-
-        if ( list != NULL )
-        {
-            gnc_sql_slots_load_for_list( be, list );
-        }
-
-        /* While there are items on the list of billterms needing parents,
-           try to see if the parent has now been loaded.  Theory says that if
-           items are removed from the front and added to the back if the
-           parent is still not available, then eventually, the list will
-           shrink to size 0. */
-        if ( l_billterms_needing_parents != NULL )
-        {
-            gboolean progress_made = TRUE;
-            GncTaxTable* root;
-            Account* pParent;
-            GList* elem;
-
-            while ( progress_made )
-            {
-                progress_made = FALSE;
-                for ( elem = l_billterms_needing_parents; elem != NULL; elem = g_list_next( elem ) )
-                {
-                    billterm_parent_guid_struct* s = (billterm_parent_guid_struct*)elem->data;
-                    bt_set_parent( s->billterm, &s->guid );
-                    l_billterms_needing_parents = g_list_delete_link( l_billterms_needing_parents, elem );
-                    progress_made = TRUE;
-                }
-            }
-        }
-    }
-}
-
-/* ================================================================= */
-typedef struct
-{
-    GncSqlBackend* be;
-    gboolean is_ok;
-} write_billterms_t;
-
-static void
-do_save_billterm( QofInstance* inst, gpointer p2 )
-{
-    write_billterms_t* data = (write_billterms_t*)p2;
-
-    if ( data->is_ok )
-    {
-        data->is_ok = gnc_sql_save_billterm( data->be, inst );
-    }
-}
-
-static gboolean
-write_billterms( GncSqlBackend* be )
-{
-    write_billterms_t data;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    data.be = be;
-    data.is_ok = TRUE;
-    qof_object_foreach( GNC_ID_BILLTERM, be->primary_book, do_save_billterm, &data );
-    return data.is_ok;
-}
-
-/* ================================================================= */
-static void
-create_billterm_tables( GncSqlBackend* be )
-{
-    gint version;
-
-    g_return_if_fail( be != NULL );
-
-    version = gnc_sql_get_table_version( be, TABLE_NAME );
-    if ( version == 0 )
-    {
-        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
-    }
-    else if ( version == 1 )
-    {
-        /* Upgrade 64 bit int handling */
-        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
-        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
-    }
-}
-
-/* ================================================================= */
-gboolean
-gnc_sql_save_billterm( GncSqlBackend* be, QofInstance* inst )
-{
-    g_return_val_if_fail( inst != NULL, FALSE );
-    g_return_val_if_fail( GNC_IS_BILLTERM(inst), FALSE );
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_BILLTERM, col_table );
-}
-
-/* ================================================================= */
-static void
-load_billterm_guid( const GncSqlBackend* be, GncSqlRow* row,
-                    QofSetterFunc setter, gpointer pObject,
-                    const GncSqlColumnTableEntry* table_row )
-{
-    const GValue* val;
-    GncGUID guid;
-    GncBillTerm* term = NULL;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( row != NULL );
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( table_row != NULL );
-
-    val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
-    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
-    {
-        string_to_guid( g_value_get_string( val ), &guid );
-        term = gncBillTermLookup( be->primary_book, &guid );
-        if ( term != NULL )
-        {
-            if ( table_row->gobj_param_name != NULL )
-            {
-                g_object_set( pObject, table_row->gobj_param_name, term, NULL );
-            }
-            else
-            {
-                (*setter)( pObject, (const gpointer)term );
-            }
-        }
-        else
-        {
-            PWARN( "Billterm ref '%s' not found", g_value_get_string( val ) );
-        }
-    }
-}
-
-static GncSqlColumnTypeHandler billterm_guid_handler
-= { load_billterm_guid,
-    gnc_sql_add_objectref_guid_col_info_to_list,
-    gnc_sql_add_colname_to_list,
-    gnc_sql_add_gvalue_objectref_guid_to_slist
-  };
-/* ================================================================= */
-void
-gnc_billterm_sql_initialize( void )
-{
-    static GncSqlObjectBackend be_data =
-    {
-        GNC_SQL_BACKEND_VERSION,
-        GNC_ID_BILLTERM,
-        gnc_sql_save_billterm,				/* commit */
-        load_all_billterms,					/* initial_load */
-        create_billterm_tables,				/* create_tables */
-        NULL, NULL, NULL,
-        write_billterms						/* write */
-    };
-
-    qof_object_register_backend( GNC_ID_BILLTERM, GNC_SQL_BACKEND, &be_data );
-
-    gnc_sql_register_col_type_handler( CT_BILLTERMREF, &billterm_guid_handler );
-}
-/* ========================== END OF FILE ===================== */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,40 +0,0 @@
-/*
- * gnc-bill-term-sql.h -- billing term sql backend
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-bill-term-sql.h
- *  @brief load and save accounts data to SQL
- *  @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_BILLTERM_SQL_H
-#define GNC_BILLTERM_SQL_H
-
-#include "gncBillTerm.h"
-
-#define CT_BILLTERMREF "billterm"
-
-void gnc_billterm_sql_initialize( void );
-gboolean gnc_sql_save_billterm( GncSqlBackend* be, QofInstance* inst );
-
-#endif /* GNC_BILLTERM_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,247 +0,0 @@
-/********************************************************************\
- * gnc-customer-sql.c -- customer sql backend                       *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-customer-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-backend-sql.h"
-#include "gnc-slots-sql.h"
-
-#include "gncBillTermP.h"
-#include "gncCustomerP.h"
-#include "gncTaxTableP.h"
-#include "gnc-customer-sql.h"
-#include "gnc-address-sql.h"
-#include "gnc-bill-term-sql.h"
-#include "gnc-tax-table-sql.h"
-
-#define _GNC_MOD_NAME	GNC_ID_CUSTOMER
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-#define TABLE_NAME "customers"
-#define TABLE_VERSION 2
-
-#define MAX_NAME_LEN 2048
-#define MAX_ID_LEN 2048
-#define MAX_NOTES_LEN 2048
-
-static GncSqlColumnTableEntry col_table[] =
-{
-    { "guid",         CT_GUID,          0,             COL_NNUL | COL_PKEY, "guid" },
-    { "name",         CT_STRING,        MAX_NAME_LEN,  COL_NNUL,          "name" },
-    { "id",           CT_STRING,        MAX_ID_LEN,    COL_NNUL,          NULL, CUSTOMER_ID },
-    { "notes",        CT_STRING,        MAX_NOTES_LEN, COL_NNUL,          NULL, CUSTOMER_NOTES },
-    { "active",       CT_BOOLEAN,       0,             COL_NNUL,          NULL, QOF_PARAM_ACTIVE },
-    { "discount",     CT_NUMERIC,       0,             COL_NNUL,          NULL, CUSTOMER_DISCOUNT },
-    { "credit",       CT_NUMERIC,       0,             COL_NNUL,          NULL, CUSTOMER_CREDIT },
-    {
-        "currency",     CT_COMMODITYREF,  0,             COL_NNUL,          NULL, NULL,
-        (QofAccessFunc)gncCustomerGetCurrency, (QofSetterFunc)gncCustomerSetCurrency
-    },
-    { "tax_override", CT_BOOLEAN,       0,             COL_NNUL,          NULL, CUSTOMER_TT_OVER },
-    { "addr",         CT_ADDRESS,       0,             0,                 NULL, CUSTOMER_ADDR },
-    { "shipaddr",     CT_ADDRESS,       0,             0,                 NULL, CUSTOMER_SHIPADDR },
-    { "terms",        CT_BILLTERMREF,   0,             0,                 NULL, CUSTOMER_TERMS },
-    {
-        "tax_included", CT_INT,           0,             0,                 NULL, NULL,
-        (QofAccessFunc)gncCustomerGetTaxIncluded, (QofSetterFunc)gncCustomerSetTaxIncluded
-    },
-    {
-        "taxtable",     CT_TAXTABLEREF,   0,             0,                 NULL, NULL,
-        (QofAccessFunc)gncCustomerGetTaxTable, (QofSetterFunc)gncCustomerSetTaxTable
-    },
-    { NULL }
-};
-
-static GncCustomer*
-load_single_customer( GncSqlBackend* be, GncSqlRow* row )
-{
-    const GncGUID* guid;
-    GncCustomer* pCustomer;
-
-    g_return_val_if_fail( be != NULL, NULL );
-    g_return_val_if_fail( row != NULL, NULL );
-
-    guid = gnc_sql_load_guid( be, row );
-    pCustomer = gncCustomerLookup( be->primary_book, guid );
-    if ( pCustomer == NULL )
-    {
-        pCustomer = gncCustomerCreate( be->primary_book );
-    }
-    gnc_sql_load_object( be, row, GNC_ID_CUSTOMER, pCustomer, col_table );
-    qof_instance_mark_clean( QOF_INSTANCE(pCustomer) );
-
-    return pCustomer;
-}
-
-static void
-load_all_customers( GncSqlBackend* be )
-{
-    GncSqlStatement* stmt;
-    GncSqlResult* result;
-    QofBook* pBook;
-
-    g_return_if_fail( be != NULL );
-
-    pBook = be->primary_book;
-
-    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
-    result = gnc_sql_execute_select_statement( be, stmt );
-    gnc_sql_statement_dispose( stmt );
-    if ( result != NULL )
-    {
-        GList* list = NULL;
-        GncSqlRow* row;
-
-        row = gnc_sql_result_get_first_row( result );
-        while ( row != NULL )
-        {
-            GncCustomer* pCustomer = load_single_customer( be, row );
-            if ( pCustomer != NULL )
-            {
-                list = g_list_append( list, pCustomer );
-            }
-            row = gnc_sql_result_get_next_row( result );
-        }
-        gnc_sql_result_dispose( result );
-
-        if ( list != NULL )
-        {
-            gnc_sql_slots_load_for_list( be, list );
-        }
-    }
-}
-
-/* ================================================================= */
-static void
-create_customer_tables( GncSqlBackend* be )
-{
-    gint version;
-
-    g_return_if_fail( be != NULL );
-
-    version = gnc_sql_get_table_version( be, TABLE_NAME );
-    if ( version == 0 )
-    {
-        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
-    }
-    else if ( version == 1 )
-    {
-        /* Upgrade 64 bit int handling */
-        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
-        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
-    }
-}
-
-/* ================================================================= */
-static gboolean
-save_customer( GncSqlBackend* be, QofInstance* inst )
-{
-    g_return_val_if_fail( inst != NULL, FALSE );
-    g_return_val_if_fail( GNC_CUSTOMER(inst), FALSE );
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_CUSTOMER, col_table );
-}
-
-/* ================================================================= */
-typedef struct
-{
-    GncSqlBackend* be;
-    gboolean is_ok;
-} write_customers_t;
-
-static gboolean
-customer_should_be_saved( GncCustomer *customer )
-{
-    const char *id;
-
-    g_return_val_if_fail( customer != NULL, FALSE );
-
-    /* Make sure this is a valid customer before we save it -- should have an ID */
-    id = gncCustomerGetID( customer );
-    if ( id == NULL || *id == '\0' )
-    {
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-static void
-write_single_customer( QofInstance *term_p, gpointer data_p )
-{
-    write_customers_t* data = (write_customers_t*)data_p;
-
-    g_return_if_fail( term_p != NULL );
-    g_return_if_fail( GNC_IS_CUSTOMER(term_p) );
-    g_return_if_fail( data_p != NULL );
-
-    if ( customer_should_be_saved( GNC_CUSTOMER(term_p) ) && data->is_ok )
-    {
-        data->is_ok = save_customer( data->be, term_p );
-    }
-}
-
-static gboolean
-write_customers( GncSqlBackend* be )
-{
-    write_customers_t data;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    data.be = be;
-    data.is_ok = TRUE;
-    qof_object_foreach( GNC_ID_CUSTOMER, be->primary_book, write_single_customer, (gpointer)&data );
-    return data.is_ok;
-}
-
-/* ================================================================= */
-void
-gnc_customer_sql_initialize( void )
-{
-    static GncSqlObjectBackend be_data =
-    {
-        GNC_SQL_BACKEND_VERSION,
-        GNC_ID_CUSTOMER,
-        save_customer,						/* commit */
-        load_all_customers,					/* initial_load */
-        create_customer_tables,				/* create_tables */
-        NULL, NULL, NULL,
-        write_customers						/* write */
-    };
-
-    qof_object_register_backend( GNC_ID_CUSTOMER, GNC_SQL_BACKEND, &be_data );
-}
-/* ========================== END OF FILE ===================== */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,35 +0,0 @@
-/*
- * gnc-customer-sql.h -- customer sql backend
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-customer-sql.h
- *  @brief load and save customer data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_CUSTOMER_SQL_H
-#define GNC_CUSTOMER_SQL_H
-
-void gnc_customer_sql_initialize( void );
-
-#endif /* GNC_CUSTOMER_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,281 +0,0 @@
-/********************************************************************\
- * gnc-employee-sql.c -- employee sql implementation                *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-employee-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-commodity.h"
-
-#include "gnc-backend-sql.h"
-#include "gnc-slots-sql.h"
-#include "gnc-commodity-sql.h"
-
-#include "gncEmployeeP.h"
-#include "gnc-employee-sql.h"
-#include "gnc-address-sql.h"
-
-#define _GNC_MOD_NAME	GNC_ID_EMPLOYEE
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-#define MAX_USERNAME_LEN 2048
-#define MAX_ID_LEN 2048
-#define MAX_LANGUAGE_LEN 2048
-#define MAX_ACL_LEN 2048
-
-#define TABLE_NAME "employees"
-#define TABLE_VERSION 2
-
-static GncSqlColumnTableEntry col_table[] =
-{
-    { "guid",       CT_GUID,          0,                COL_NNUL | COL_PKEY, "guid" },
-    { "username",   CT_STRING,        MAX_USERNAME_LEN, COL_NNUL,          "username" },
-    { "id",         CT_STRING,        MAX_ID_LEN,       COL_NNUL,          NULL, EMPLOYEE_ID },
-    { "language",   CT_STRING,        MAX_LANGUAGE_LEN, COL_NNUL,          NULL, EMPLOYEE_LANGUAGE },
-    { "acl",        CT_STRING,        MAX_ACL_LEN,      COL_NNUL,          NULL, EMPLOYEE_ACL },
-    { "active",     CT_BOOLEAN,       0,                COL_NNUL,          NULL, QOF_PARAM_ACTIVE },
-    {
-        "currency",   CT_COMMODITYREF,  0,                COL_NNUL,          NULL, NULL,
-        (QofAccessFunc)gncEmployeeGetCurrency, (QofSetterFunc)gncEmployeeSetCurrency
-    },
-    { "ccard_guid", CT_ACCOUNTREF,    0,                0,                 NULL, EMPLOYEE_CC },
-    { "workday",    CT_NUMERIC,       0,                COL_NNUL,          NULL, EMPLOYEE_WORKDAY },
-    { "rate",       CT_NUMERIC,       0,                COL_NNUL,          NULL, EMPLOYEE_RATE },
-    { "addr",       CT_ADDRESS,       0,                0,                 NULL, EMPLOYEE_ADDR },
-    { NULL }
-};
-
-static GncEmployee*
-load_single_employee( GncSqlBackend* be, GncSqlRow* row )
-{
-    const GncGUID* guid;
-    GncEmployee* pEmployee;
-
-    g_return_val_if_fail( be != NULL, NULL );
-    g_return_val_if_fail( row != NULL, NULL );
-
-    guid = gnc_sql_load_guid( be, row );
-    pEmployee = gncEmployeeLookup( be->primary_book, guid );
-    if ( pEmployee == NULL )
-    {
-        pEmployee = gncEmployeeCreate( be->primary_book );
-    }
-    gnc_sql_load_object( be, row, GNC_ID_EMPLOYEE, pEmployee, col_table );
-    qof_instance_mark_clean( QOF_INSTANCE(pEmployee) );
-
-    return pEmployee;
-}
-
-static void
-load_all_employees( GncSqlBackend* be )
-{
-    GncSqlStatement* stmt;
-    GncSqlResult* result;
-    QofBook* pBook;
-    gnc_commodity_table* pTable;
-
-    g_return_if_fail( be != NULL );
-
-    pBook = be->primary_book;
-    pTable = gnc_commodity_table_get_table( pBook );
-
-    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
-    result = gnc_sql_execute_select_statement( be, stmt );
-    gnc_sql_statement_dispose( stmt );
-    if ( result != NULL )
-    {
-        GncSqlRow* row;
-        GList* list = NULL;
-
-        row = gnc_sql_result_get_first_row( result );
-        while ( row != NULL )
-        {
-            GncEmployee* pEmployee = load_single_employee( be, row );
-            if ( pEmployee != NULL )
-            {
-                list = g_list_append( list, pEmployee );
-            }
-            row = gnc_sql_result_get_next_row( result );
-        }
-        gnc_sql_result_dispose( result );
-
-        if ( list != NULL )
-        {
-            gnc_sql_slots_load_for_list( be, list );
-        }
-    }
-}
-
-/* ================================================================= */
-static void
-create_employee_tables( GncSqlBackend* be )
-{
-    gint version;
-
-    g_return_if_fail( be != NULL );
-
-    version = gnc_sql_get_table_version( be, TABLE_NAME );
-    if ( version == 0 )
-    {
-        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
-    }
-    else if ( version == 1 )
-    {
-        /* Upgrade 64 bit int handling */
-        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
-        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
-    }
-}
-
-/* ================================================================= */
-static gboolean
-save_employee( GncSqlBackend* be, QofInstance* inst )
-{
-    GncEmployee* emp;
-    const GncGUID* guid;
-    gint op;
-    gboolean is_infant;
-    gboolean is_ok = TRUE;
-
-    g_return_val_if_fail( inst != NULL, FALSE );
-    g_return_val_if_fail( GNC_IS_EMPLOYEE(inst), FALSE );
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    emp = GNC_EMPLOYEE(inst);
-
-    is_infant = qof_instance_get_infant( inst );
-    if ( qof_instance_get_destroying( inst ) )
-    {
-        op = OP_DB_DELETE;
-    }
-    else if ( be->is_pristine_db || is_infant )
-    {
-        op = OP_DB_INSERT;
-    }
-    else
-    {
-        op = OP_DB_UPDATE;
-    }
-    if ( op != OP_DB_DELETE )
-    {
-        // Ensure the commodity is in the db
-        is_ok = gnc_sql_save_commodity( be, gncEmployeeGetCurrency( emp ) );
-    }
-
-    if ( is_ok )
-    {
-        is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_EMPLOYEE, emp, col_table );
-    }
-
-    if ( is_ok )
-    {
-        // Now, commit or delete any slots
-        guid = qof_instance_get_guid( inst );
-        if ( !qof_instance_get_destroying(inst) )
-        {
-            is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
-        }
-        else
-        {
-            is_ok = gnc_sql_slots_delete( be, guid );
-        }
-    }
-
-    return is_ok;
-}
-
-/* ================================================================= */
-static gboolean
-employee_should_be_saved( GncEmployee *employee )
-{
-    const char *id;
-
-    g_return_val_if_fail( employee != NULL, FALSE );
-
-    /* make sure this is a valid employee before we save it -- should have an ID */
-    id = gncEmployeeGetID( employee );
-    if ( id == NULL || *id == '\0' )
-    {
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-static void
-write_single_employee( QofInstance *term_p, gpointer data_p )
-{
-    write_objects_t* s = (write_objects_t*)data_p;
-
-    g_return_if_fail( term_p != NULL );
-    g_return_if_fail( GNC_IS_EMPLOYEE(term_p) );
-    g_return_if_fail( data_p != NULL );
-
-    if ( s->is_ok && employee_should_be_saved( GNC_EMPLOYEE(term_p) ) )
-    {
-        s->is_ok = save_employee( s->be, term_p );
-    }
-}
-
-static gboolean
-write_employees( GncSqlBackend* be )
-{
-    write_objects_t data;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    data.be = be;
-    data.is_ok = TRUE;
-    qof_object_foreach( GNC_ID_EMPLOYEE, be->primary_book, write_single_employee, &data );
-
-    return data.is_ok;
-}
-
-/* ================================================================= */
-void
-gnc_employee_sql_initialize( void )
-{
-    static GncSqlObjectBackend be_data =
-    {
-        GNC_SQL_BACKEND_VERSION,
-        GNC_ID_EMPLOYEE,
-        save_employee,						/* commit */
-        load_all_employees,					/* initial_load */
-        create_employee_tables,				/* create_tables */
-        NULL, NULL, NULL,
-        write_employees						/* write */
-    };
-
-    qof_object_register_backend( GNC_ID_EMPLOYEE, GNC_SQL_BACKEND, &be_data );
-}
-/* ========================== END OF FILE ===================== */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,35 +0,0 @@
-/*
- * gnc-employee-sql.h -- employee sql backend
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-employee-sql.h
- *  @brief load and save employee data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_EMPLOYEE_SQL_H
-#define GNC_EMPLOYEE_SQL_H
-
-void gnc_employee_sql_initialize( void );
-
-#endif /* GNC_EMPLOYEE_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,296 +0,0 @@
-/********************************************************************\
- * gnc-entry-sql.c -- entry sql backend                             *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-entry-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-backend-sql.h"
-#include "gnc-slots-sql.h"
-
-#include "gncEntryP.h"
-#include "gncOrderP.h"
-#include "gncInvoiceP.h"
-#include "gncTaxTableP.h"
-#include "gnc-bill-term-sql.h"
-#include "gnc-entry-sql.h"
-#include "gnc-invoice-sql.h"
-#include "gnc-order-sql.h"
-#include "gnc-owner-sql.h"
-#include "gnc-tax-table-sql.h"
-
-#define _GNC_MOD_NAME	GNC_ID_ENTRY
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-#define TABLE_NAME "entries"
-#define TABLE_VERSION 3
-#define MAX_DESCRIPTION_LEN 2048
-#define MAX_ACTION_LEN 2048
-#define MAX_NOTES_LEN 2048
-#define MAX_DISCTYPE_LEN 2048
-#define MAX_DISCHOW_LEN 2048
-
-static void entry_set_invoice( gpointer pObject, gpointer val );
-static void entry_set_bill( gpointer pObject, gpointer val );
-
-static GncSqlColumnTableEntry col_table[] =
-{
-    { "guid",          CT_GUID,        0,                   COL_NNUL | COL_PKEY, "guid" },
-    { "date",          CT_TIMESPEC,    0,                   COL_NNUL,          NULL, ENTRY_DATE },
-    { "date_entered",  CT_TIMESPEC,    0,                   0,                 NULL, ENTRY_DATE_ENTERED },
-    { "description",   CT_STRING,      MAX_DESCRIPTION_LEN, 0,                 "description" },
-    { "action",        CT_STRING,      MAX_ACTION_LEN,      0,                 NULL, ENTRY_ACTION },
-    { "notes",         CT_STRING,      MAX_NOTES_LEN,       0,                 NULL, ENTRY_NOTES },
-    { "quantity",      CT_NUMERIC,     0,                   0,                 NULL, ENTRY_QTY },
-    { "i_acct",        CT_ACCOUNTREF,  0,                   0,                 NULL, ENTRY_IACCT },
-    { "i_price",       CT_NUMERIC,     0,                   0,                 NULL, ENTRY_IPRICE },
-    {
-        "i_discount",    CT_NUMERIC,     0,                   0,                 NULL, NULL,
-        (QofAccessFunc)gncEntryGetInvDiscount, (QofSetterFunc)gncEntrySetInvDiscount
-    },
-    {
-        "invoice",       CT_INVOICEREF,  0,                   0,                 NULL, NULL,
-        (QofAccessFunc)gncEntryGetInvoice, (QofSetterFunc)entry_set_invoice
-    },
-    { "i_disc_type",   CT_STRING,      MAX_DISCTYPE_LEN,    0,        			NULL, ENTRY_INV_DISC_TYPE },
-    { "i_disc_how",    CT_STRING,      MAX_DISCHOW_LEN,     0,        			NULL, ENTRY_INV_DISC_HOW },
-    { "i_taxable",     CT_BOOLEAN,     0,                   0,        			NULL, ENTRY_INV_TAXABLE },
-    { "i_taxincluded", CT_BOOLEAN,     0,                   0,        			NULL, ENTRY_INV_TAX_INC },
-    {
-        "i_taxtable",    CT_TAXTABLEREF, 0,                   0,        			NULL, NULL,
-        (QofAccessFunc)gncEntryGetInvTaxTable, (QofSetterFunc)gncEntrySetInvTaxTable
-    },
-    { "b_acct",        CT_ACCOUNTREF,  0,                   0,        			NULL, ENTRY_BACCT },
-    { "b_price",       CT_NUMERIC,     0,                   0,        			NULL, ENTRY_BPRICE },
-    {
-        "bill",          CT_INVOICEREF,  0,                   0,        			NULL, NULL,
-        (QofAccessFunc)gncEntryGetBill, (QofSetterFunc)entry_set_bill
-    },
-    { "b_taxable",     CT_BOOLEAN,     0,                   0,        			NULL, ENTRY_BILL_TAXABLE },
-    { "b_taxincluded", CT_BOOLEAN,     0,                   0,        			NULL, ENTRY_BILL_TAX_INC },
-    {
-        "b_taxtable",    CT_TAXTABLEREF, 0,                   0,        			NULL, NULL,
-        (QofAccessFunc)gncEntryGetBillTaxTable, (QofSetterFunc)gncEntrySetBillTaxTable
-    },
-    {
-        "b_paytype",     CT_INT,         0,                   0,        			NULL, NULL,
-        (QofAccessFunc)gncEntryGetBillPayment, (QofSetterFunc)gncEntrySetBillPayment
-    },
-    { "billable",      CT_BOOLEAN,     0,                   0,        			NULL, ENTRY_BILLABLE },
-    { "billto",        CT_OWNERREF,    0,                   0,        			NULL, ENTRY_BILLTO },
-    {
-        "order_guid",    CT_ORDERREF,    0,                   0,        			NULL, NULL,
-        (QofAccessFunc)gncEntryGetOrder, (QofSetterFunc)gncEntrySetOrder
-    },
-    { NULL }
-};
-
-static void
-entry_set_invoice( gpointer pObject, gpointer val )
-{
-    GncEntry* entry;
-    GncInvoice* invoice;
-
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( GNC_IS_ENTRY(pObject) );
-    g_return_if_fail( val != NULL );
-    g_return_if_fail( GNC_IS_INVOICE(val) );
-
-    entry = GNC_ENTRY(pObject);
-    invoice = GNC_INVOICE(val);
-
-    gncInvoiceAddEntry( invoice, entry );
-}
-
-static void
-entry_set_bill( gpointer pObject, gpointer val )
-{
-    GncEntry* entry;
-    GncInvoice* bill;
-
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( GNC_IS_ENTRY(pObject) );
-    g_return_if_fail( val != NULL );
-    g_return_if_fail( GNC_IS_INVOICE(val) );
-
-    entry = GNC_ENTRY(pObject);
-    bill = GNC_INVOICE(val);
-
-    gncBillAddEntry( bill, entry );
-}
-
-static GncEntry*
-load_single_entry( GncSqlBackend* be, GncSqlRow* row )
-{
-    const GncGUID* guid;
-    GncEntry* pEntry;
-
-    g_return_val_if_fail( be != NULL, NULL );
-    g_return_val_if_fail( row != NULL, NULL );
-
-    guid = gnc_sql_load_guid( be, row );
-    pEntry = gncEntryLookup( be->primary_book, guid );
-    if ( pEntry == NULL )
-    {
-        pEntry = gncEntryCreate( be->primary_book );
-    }
-    gnc_sql_load_object( be, row, GNC_ID_ENTRY, pEntry, col_table );
-    qof_instance_mark_clean( QOF_INSTANCE(pEntry) );
-
-    return pEntry;
-}
-
-static void
-load_all_entries( GncSqlBackend* be )
-{
-    GncSqlStatement* stmt;
-    GncSqlResult* result;
-    QofBook* pBook;
-
-    g_return_if_fail( be != NULL );
-
-    pBook = be->primary_book;
-
-    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
-    result = gnc_sql_execute_select_statement( be, stmt );
-    gnc_sql_statement_dispose( stmt );
-    if ( result != NULL )
-    {
-        GncSqlRow* row;
-        GList* list = NULL;
-
-        row = gnc_sql_result_get_first_row( result );
-        while ( row != NULL )
-        {
-            GncEntry* pEntry = load_single_entry( be, row );
-            if ( pEntry != NULL )
-            {
-                list = g_list_append( list, pEntry );
-            }
-            row = gnc_sql_result_get_next_row( result );
-        }
-        gnc_sql_result_dispose( result );
-
-        if ( list != NULL )
-        {
-            gnc_sql_slots_load_for_list( be, list );
-        }
-    }
-}
-
-/* ================================================================= */
-static void
-create_entry_tables( GncSqlBackend* be )
-{
-    gint version;
-
-    g_return_if_fail( be != NULL );
-
-    version = gnc_sql_get_table_version( be, TABLE_NAME );
-    if ( version == 0 )
-    {
-        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
-    }
-    else if ( version < TABLE_VERSION )
-    {
-        /* Upgrade:
-            1->2: 64 bit int handling
-        	2->3: "entered" -> "date_entered", and it can be NULL
-        */
-        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
-        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
-    }
-}
-
-/* ================================================================= */
-static gboolean
-save_entry( GncSqlBackend* be, QofInstance* inst )
-{
-    g_return_val_if_fail( inst != NULL, FALSE );
-    g_return_val_if_fail( GNC_IS_ENTRY(inst), FALSE );
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_ENTRY, col_table );
-}
-
-/* ================================================================= */
-static void
-write_single_entry( QofInstance *term_p, gpointer data_p )
-{
-    write_objects_t* s = (write_objects_t*)data_p;
-    GncEntry* entry = GNC_ENTRY(term_p);
-
-    g_return_if_fail( term_p != NULL );
-    g_return_if_fail( GNC_IS_ENTRY(term_p) );
-    g_return_if_fail( data_p != NULL );
-
-    /* Only save if attached */
-    if ( s->is_ok && (gncEntryGetOrder( entry ) != NULL || gncEntryGetInvoice( entry ) != NULL ||
-                      gncEntryGetBill( entry ) != NULL) )
-    {
-        s->is_ok = save_entry( s->be, term_p );
-    }
-}
-
-static gboolean
-write_entries( GncSqlBackend* be )
-{
-    write_objects_t data;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    data.be = be;
-    data.is_ok = TRUE;
-    qof_object_foreach( GNC_ID_ENTRY, be->primary_book, write_single_entry, &data );
-
-    return data.is_ok;
-}
-
-/* ================================================================= */
-void
-gnc_entry_sql_initialize( void )
-{
-    static GncSqlObjectBackend be_data =
-    {
-        GNC_SQL_BACKEND_VERSION,
-        GNC_ID_ENTRY,
-        save_entry,							/* commit */
-        load_all_entries,					/* initial_load */
-        create_entry_tables,				/* create_tables */
-        NULL, NULL, NULL,
-        write_entries						/* write */
-    };
-
-    qof_object_register_backend( GNC_ID_ENTRY, GNC_SQL_BACKEND, &be_data );
-}
-/* ========================== END OF FILE ===================== */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,35 +0,0 @@
-/*
- * gnc-entry-sql.h -- entry sql backend
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-entry-sql.h
- *  @brief load and save entry data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_ENTRY_SQL_H
-#define GNC_ENTRY_SQL_H
-
-void gnc_entry_sql_initialize( void );
-
-#endif /* GNC_ENTRY_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,345 +0,0 @@
-/********************************************************************\
- * gnc-invoice-sql.c - invoice sql backend                          *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-invoice-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-commodity.h"
-
-#include "gnc-backend-sql.h"
-#include "gnc-commodity-sql.h"
-#include "gnc-slots-sql.h"
-
-#include "gncBillTermP.h"
-#include "gncInvoiceP.h"
-#include "gnc-invoice-sql.h"
-#include "gnc-owner-sql.h"
-#include "gnc-bill-term-sql.h"
-
-#define _GNC_MOD_NAME	GNC_ID_INVOICE
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-#define TABLE_NAME "invoices"
-#define TABLE_VERSION 3
-
-#define MAX_ID_LEN 2048
-#define MAX_NOTES_LEN 2048
-#define MAX_BILLING_ID_LEN 2048
-
-static GncSqlColumnTableEntry col_table[] =
-{
-    { "guid",         CT_GUID,         0,                  COL_NNUL | COL_PKEY, "guid" },
-    { "id",           CT_STRING,       MAX_ID_LEN,         COL_NNUL,          NULL, INVOICE_ID },
-    { "date_opened",  CT_TIMESPEC,     0,                  0,                 NULL, INVOICE_OPENED },
-    { "date_posted",  CT_TIMESPEC,     0,                  0,                 NULL, INVOICE_POSTED },
-    { "notes",        CT_STRING,       MAX_NOTES_LEN,      COL_NNUL,          "notes" },
-    { "active",       CT_BOOLEAN,      0,                  COL_NNUL,          NULL, QOF_PARAM_ACTIVE },
-    {
-        "currency",     CT_COMMODITYREF, 0,                  COL_NNUL,          NULL, NULL,
-        (QofAccessFunc)gncInvoiceGetCurrency, (QofSetterFunc)gncInvoiceSetCurrency
-    },
-    {
-        "owner",        CT_OWNERREF,     0,                  0,                 NULL, NULL,
-        (QofAccessFunc)gncInvoiceGetOwner, (QofSetterFunc)gncInvoiceSetOwner
-    },
-    { "terms",        CT_BILLTERMREF,  0,                  0,                 NULL, INVOICE_TERMS },
-    { "billing_id",   CT_STRING,       MAX_BILLING_ID_LEN, 0,                 NULL, INVOICE_BILLINGID },
-    { "post_txn",     CT_TXREF,        0,                  0,                 NULL, INVOICE_POST_TXN },
-    {
-        "post_lot",     CT_LOTREF,       0,                  0,                 NULL, NULL,
-        (QofAccessFunc)gncInvoiceGetPostedLot, (QofSetterFunc)gncInvoiceSetPostedLot
-    },
-    { "post_acc",     CT_ACCOUNTREF,   0,                  0,                 NULL, INVOICE_ACC },
-    {
-        "billto",       CT_OWNERREF,     0,                  0,                 NULL, NULL,
-        (QofAccessFunc)gncInvoiceGetBillTo, (QofSetterFunc)gncInvoiceSetBillTo
-    },
-    {
-        "charge_amt",   CT_NUMERIC,      0,                  0,                 NULL, NULL,
-        (QofAccessFunc)gncInvoiceGetToChargeAmount, (QofSetterFunc)gncInvoiceSetToChargeAmount
-    },
-    { NULL }
-};
-
-static GncInvoice*
-load_single_invoice( GncSqlBackend* be, GncSqlRow* row )
-{
-    const GncGUID* guid;
-    GncInvoice* pInvoice;
-
-    g_return_val_if_fail( be != NULL, NULL );
-    g_return_val_if_fail( row != NULL, NULL );
-
-    guid = gnc_sql_load_guid( be, row );
-    pInvoice = gncInvoiceLookup( be->primary_book, guid );
-    if ( pInvoice == NULL )
-    {
-        pInvoice = gncInvoiceCreate( be->primary_book );
-    }
-    gnc_sql_load_object( be, row, GNC_ID_INVOICE, pInvoice, col_table );
-    qof_instance_mark_clean( QOF_INSTANCE(pInvoice) );
-
-    return pInvoice;
-}
-
-static void
-load_all_invoices( GncSqlBackend* be )
-{
-    GncSqlStatement* stmt;
-    GncSqlResult* result;
-    QofBook* pBook;
-
-    g_return_if_fail( be != NULL );
-
-    pBook = be->primary_book;
-
-    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
-    result = gnc_sql_execute_select_statement( be, stmt );
-    gnc_sql_statement_dispose( stmt );
-    if ( result != NULL )
-    {
-        GncSqlRow* row;
-        GList* list = NULL;
-
-        row = gnc_sql_result_get_first_row( result );
-        while ( row != NULL )
-        {
-            GncInvoice* pInvoice = load_single_invoice( be, row );
-            if ( pInvoice != NULL )
-            {
-                list = g_list_append( list, pInvoice );
-            }
-            row = gnc_sql_result_get_next_row( result );
-        }
-        gnc_sql_result_dispose( result );
-
-        if ( list != NULL )
-        {
-            gnc_sql_slots_load_for_list( be, list );
-        }
-    }
-}
-
-/* ================================================================= */
-static void
-create_invoice_tables( GncSqlBackend* be )
-{
-    gint version;
-
-    g_return_if_fail( be != NULL );
-
-    version = gnc_sql_get_table_version( be, TABLE_NAME );
-    if ( version == 0 )
-    {
-        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
-    }
-    else if ( version < TABLE_VERSION )
-    {
-        /* Upgrade:
-             1->2: 64 bit int handling
-        	 2->3: invoice open date can be NULL
-        */
-        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
-        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
-    }
-}
-
-/* ================================================================= */
-static gboolean
-save_invoice( GncSqlBackend* be, QofInstance* inst )
-{
-    const GncGUID* guid;
-    GncInvoice* invoice;
-    gint op;
-    gboolean is_infant;
-    gboolean is_ok = TRUE;
-
-    g_return_val_if_fail( inst != NULL, FALSE );
-    g_return_val_if_fail( GNC_IS_INVOICE(inst), FALSE );
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    invoice = GNC_INVOICE(inst);
-
-    is_infant = qof_instance_get_infant( inst );
-    if ( qof_instance_get_destroying( inst ) )
-    {
-        op = OP_DB_DELETE;
-    }
-    else if ( be->is_pristine_db || is_infant )
-    {
-        op = OP_DB_INSERT;
-    }
-    else
-    {
-        op = OP_DB_UPDATE;
-    }
-    if ( op != OP_DB_DELETE )
-    {
-        // Ensure the commodity is in the db
-        is_ok = gnc_sql_save_commodity( be, gncInvoiceGetCurrency( invoice ) );
-    }
-
-    if ( is_ok )
-    {
-        is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_INVOICE, inst, col_table );
-    }
-
-    if ( is_ok )
-    {
-        // Now, commit or delete any slots
-        guid = qof_instance_get_guid( inst );
-        if ( !qof_instance_get_destroying(inst) )
-        {
-            is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
-        }
-        else
-        {
-            is_ok = gnc_sql_slots_delete( be, guid );
-        }
-    }
-
-    return is_ok;
-}
-
-/* ================================================================= */
-static gboolean
-invoice_should_be_saved( GncInvoice *invoice )
-{
-    const char *id;
-
-    g_return_val_if_fail( invoice != NULL, FALSE );
-
-    /* make sure this is a valid invoice before we save it -- should have an ID */
-    id = gncInvoiceGetID( invoice );
-    if ( id == NULL || *id == '\0' )
-    {
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-static void
-write_single_invoice( QofInstance *term_p, gpointer data_p )
-{
-    write_objects_t* s = (write_objects_t*)data_p;
-
-    g_return_if_fail( term_p != NULL );
-    g_return_if_fail( GNC_IS_INVOICE(term_p) );
-    g_return_if_fail( data_p != NULL );
-
-    if ( s->is_ok && invoice_should_be_saved( GNC_INVOICE(term_p) ) )
-    {
-        s->is_ok = save_invoice( s->be, term_p );
-    }
-}
-
-static gboolean
-write_invoices( GncSqlBackend* be )
-{
-    write_objects_t data;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    data.be = be;
-    data.is_ok = TRUE;
-    qof_object_foreach( GNC_ID_INVOICE, be->primary_book, write_single_invoice, &data );
-
-    return data.is_ok;
-}
-
-/* ================================================================= */
-static void
-load_invoice_guid( const GncSqlBackend* be, GncSqlRow* row,
-                   QofSetterFunc setter, gpointer pObject,
-                   const GncSqlColumnTableEntry* table_row )
-{
-    const GValue* val;
-    GncGUID guid;
-    GncInvoice* invoice = NULL;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( row != NULL );
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( table_row != NULL );
-
-    val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
-    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
-    {
-        string_to_guid( g_value_get_string( val ), &guid );
-        invoice = gncInvoiceLookup( be->primary_book, &guid );
-        if ( invoice != NULL )
-        {
-            if ( table_row->gobj_param_name != NULL )
-            {
-                g_object_set( pObject, table_row->gobj_param_name, invoice, NULL );
-            }
-            else
-            {
-                (*setter)( pObject, (const gpointer)invoice );
-            }
-        }
-        else
-        {
-            PWARN( "Invoice ref '%s' not found", g_value_get_string( val ) );
-        }
-    }
-}
-
-static GncSqlColumnTypeHandler invoice_guid_handler
-= { load_invoice_guid,
-    gnc_sql_add_objectref_guid_col_info_to_list,
-    gnc_sql_add_colname_to_list,
-    gnc_sql_add_gvalue_objectref_guid_to_slist
-  };
-/* ================================================================= */
-void
-gnc_invoice_sql_initialize( void )
-{
-    static GncSqlObjectBackend be_data =
-    {
-        GNC_SQL_BACKEND_VERSION,
-        GNC_ID_INVOICE,
-        save_invoice,						/* commit */
-        load_all_invoices,					/* initial_load */
-        create_invoice_tables,				/* create_tables */
-        NULL, NULL, NULL,
-        write_invoices						/* write */
-    };
-
-    qof_object_register_backend( GNC_ID_INVOICE, GNC_SQL_BACKEND, &be_data );
-
-    gnc_sql_register_col_type_handler( CT_INVOICEREF, &invoice_guid_handler );
-}
-/* ========================== END OF FILE ===================== */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,37 +0,0 @@
-/*
- * gnc-invoice-sql.h -- invoice sql backend
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-invoice-sql.h
- *  @brief load and save invoice data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_INVOICE_SQL_H
-#define GNC_INVOICE_SQL_H
-
-#define CT_INVOICEREF "invoice"
-
-void gnc_invoice_sql_initialize( void );
-
-#endif /* GNC_INVOICE_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-job-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-job-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-job-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,221 +0,0 @@
-/********************************************************************\
- * gnc-job-sql.c -- job sql backend                                 *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-job-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-backend-sql.h"
-#include "gnc-slots-sql.h"
-
-#include "gncJobP.h"
-#include "gnc-job-sql.h"
-#include "gnc-owner-sql.h"
-
-#define _GNC_MOD_NAME	GNC_ID_JOB
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-#define TABLE_NAME "jobs"
-#define TABLE_VERSION 1
-
-#define MAX_ID_LEN 2048
-#define MAX_NAME_LEN 2048
-#define MAX_REFERENCE_LEN 2048
-
-static GncSqlColumnTableEntry col_table[] =
-{
-    { "guid",      CT_GUID,     0,                 COL_NNUL | COL_PKEY, "guid" },
-    { "id",        CT_STRING,   MAX_ID_LEN,        COL_NNUL,          NULL, JOB_ID },
-    { "name",      CT_STRING,   MAX_NAME_LEN,      COL_NNUL,          "name" },
-    { "reference", CT_STRING,   MAX_REFERENCE_LEN, COL_NNUL,          NULL, JOB_REFERENCE },
-    {
-        "active",    CT_BOOLEAN,  0,                 COL_NNUL,          NULL, NULL,
-        (QofAccessFunc)gncJobGetActive, (QofSetterFunc)gncJobSetActive
-    },
-    {
-        "owner",     CT_OWNERREF, 0,                 0,                 NULL, NULL,
-        (QofAccessFunc)gncJobGetOwner, (QofSetterFunc)gncJobSetOwner
-    },
-    { NULL }
-};
-
-static GncJob*
-load_single_job( GncSqlBackend* be, GncSqlRow* row )
-{
-    const GncGUID* guid;
-    GncJob* pJob;
-
-    g_return_val_if_fail( be != NULL, NULL );
-    g_return_val_if_fail( row != NULL, NULL );
-
-    guid = gnc_sql_load_guid( be, row );
-    pJob = gncJobLookup( be->primary_book, guid );
-    if ( pJob == NULL )
-    {
-        pJob = gncJobCreate( be->primary_book );
-    }
-    gnc_sql_load_object( be, row, GNC_ID_JOB, pJob, col_table );
-    qof_instance_mark_clean( QOF_INSTANCE(pJob) );
-
-    return pJob;
-}
-
-static void
-load_all_jobs( GncSqlBackend* be )
-{
-    GncSqlStatement* stmt;
-    GncSqlResult* result;
-    QofBook* pBook;
-
-    g_return_if_fail( be != NULL );
-
-    pBook = be->primary_book;
-
-    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
-    result = gnc_sql_execute_select_statement( be, stmt );
-    gnc_sql_statement_dispose( stmt );
-    if ( result != NULL )
-    {
-        GncSqlRow* row;
-        GList* list = NULL;
-
-        row = gnc_sql_result_get_first_row( result );
-        while ( row != NULL )
-        {
-            GncJob* pJob = load_single_job( be, row );
-            if ( pJob != NULL )
-            {
-                list = g_list_append( list, pJob );
-            }
-            row = gnc_sql_result_get_next_row( result );
-        }
-        gnc_sql_result_dispose( result );
-
-        if ( list != NULL )
-        {
-            gnc_sql_slots_load_for_list( be, list );
-        }
-    }
-}
-
-/* ================================================================= */
-static void
-create_job_tables( GncSqlBackend* be )
-{
-    gint version;
-
-    g_return_if_fail( be != NULL );
-
-    version = gnc_sql_get_table_version( be, TABLE_NAME );
-    if ( version == 0 )
-    {
-        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
-    }
-}
-
-/* ================================================================= */
-static gboolean
-save_job( GncSqlBackend* be, QofInstance* inst )
-{
-    g_return_val_if_fail( inst != NULL, FALSE );
-    g_return_val_if_fail( GNC_IS_JOB(inst), FALSE );
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_JOB, col_table );
-}
-
-/* ================================================================= */
-static gboolean
-job_should_be_saved( GncJob *job )
-{
-    const char *id;
-
-    g_return_val_if_fail( job != NULL, FALSE );
-
-    /* make sure this is a valid job before we save it -- should have an ID */
-    id = gncJobGetID( job );
-    if ( id == NULL || *id == '\0' )
-    {
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-static void
-write_single_job( QofInstance *term_p, gpointer data_p )
-{
-    write_objects_t* s = (write_objects_t*)data_p;
-
-    g_return_if_fail( term_p != NULL );
-    g_return_if_fail( GNC_IS_JOB(term_p) );
-    g_return_if_fail( data_p != NULL );
-
-    if ( s->is_ok && job_should_be_saved( GNC_JOB(term_p) ) )
-    {
-        s->is_ok = save_job( s->be, term_p );
-    }
-}
-
-static gboolean
-write_jobs( GncSqlBackend* be )
-{
-    write_objects_t data;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    data.be = be;
-    data.is_ok = TRUE;
-    qof_object_foreach( GNC_ID_JOB, be->primary_book, write_single_job, &data );
-
-    return data.is_ok;
-}
-
-/* ================================================================= */
-void
-gnc_job_sql_initialize( void )
-{
-    static GncSqlObjectBackend be_data =
-    {
-        GNC_SQL_BACKEND_VERSION,
-        GNC_ID_JOB,
-        save_job,						/* commit */
-        load_all_jobs,					/* initial_load */
-        create_job_tables,				/* create_tables */
-        NULL, NULL, NULL,
-        write_jobs						/* write */
-    };
-
-    qof_object_register_backend( GNC_ID_JOB, GNC_SQL_BACKEND, &be_data );
-}
-/* ========================== END OF FILE ===================== */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-job-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-job-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-job-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,35 +0,0 @@
-/*
- * gnc-job-sql.h -- job sql backend
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-job-sql.h
- *  @brief load and save job data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_JOB_SQL_H
-#define GNC_JOB_SQL_H
-
-void gnc_job_sql_initialize( void );
-
-#endif /* GNC_JOB_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-order-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-order-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-order-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,264 +0,0 @@
-/********************************************************************\
- * gnc-order-sql.c -- order sql backend                             *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-order-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-backend-sql.h"
-#include "gnc-slots-sql.h"
-
-#include "gncOrderP.h"
-
-#include "gnc-order-sql.h"
-#include "gnc-owner-sql.h"
-
-#define _GNC_MOD_NAME	GNC_ID_ORDER
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-#define TABLE_NAME "orders"
-#define TABLE_VERSION 1
-
-#define MAX_ID_LEN 2048
-#define MAX_NOTES_LEN 2048
-#define MAX_REFERENCE_LEN 2048
-
-static GncSqlColumnTableEntry col_table[] =
-{
-    { "guid",        CT_GUID,     0,                 COL_NNUL | COL_PKEY, "guid" },
-    { "id",          CT_STRING,   MAX_ID_LEN,        COL_NNUL,          NULL, ORDER_ID },
-    { "notes",       CT_STRING,   MAX_NOTES_LEN,     COL_NNUL,          "notes" },
-    { "reference",   CT_STRING,   MAX_REFERENCE_LEN, COL_NNUL,          NULL, ORDER_REFERENCE },
-    { "active",      CT_BOOLEAN,  0,                 COL_NNUL,          NULL, QOF_PARAM_ACTIVE },
-    { "date_opened", CT_TIMESPEC, 0,                 COL_NNUL,          NULL, ORDER_OPENED },
-    { "date_closed", CT_TIMESPEC, 0,                 COL_NNUL,          NULL, ORDER_CLOSED },
-    { "owner",       CT_OWNERREF, 0,                 COL_NNUL,          NULL, ORDER_OWNER },
-    { NULL },
-};
-
-static GncOrder*
-load_single_order( GncSqlBackend* be, GncSqlRow* row )
-{
-    const GncGUID* guid;
-    GncOrder* pOrder;
-
-    g_return_val_if_fail( be != NULL, NULL );
-    g_return_val_if_fail( row != NULL, NULL );
-
-    guid = gnc_sql_load_guid( be, row );
-    pOrder = gncOrderLookup( be->primary_book, guid );
-    if ( pOrder == NULL )
-    {
-        pOrder = gncOrderCreate( be->primary_book );
-    }
-    gnc_sql_load_object( be, row, GNC_ID_ORDER, pOrder, col_table );
-    qof_instance_mark_clean( QOF_INSTANCE(pOrder) );
-
-    return pOrder;
-}
-
-static void
-load_all_orders( GncSqlBackend* be )
-{
-    GncSqlStatement* stmt;
-    GncSqlResult* result;
-    QofBook* pBook;
-
-    g_return_if_fail( be != NULL );
-
-    pBook = be->primary_book;
-
-    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
-    result = gnc_sql_execute_select_statement( be, stmt );
-    gnc_sql_statement_dispose( stmt );
-    if ( result != NULL )
-    {
-        GncSqlRow* row;
-        GList* list = NULL;
-
-        row = gnc_sql_result_get_first_row( result );
-        while ( row != NULL )
-        {
-            GncOrder* pOrder = load_single_order( be, row );
-            if ( pOrder != NULL )
-            {
-                list = g_list_append( list, pOrder );
-            }
-            row = gnc_sql_result_get_next_row( result );
-        }
-        gnc_sql_result_dispose( result );
-
-        if ( list != NULL )
-        {
-            gnc_sql_slots_load_for_list( be, list );
-        }
-    }
-}
-
-/* ================================================================= */
-static void
-create_order_tables( GncSqlBackend* be )
-{
-    gint version;
-
-    g_return_if_fail( be != NULL );
-
-    version = gnc_sql_get_table_version( be, TABLE_NAME );
-    if ( version == 0 )
-    {
-        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
-    }
-}
-
-/* ================================================================= */
-static gboolean
-save_order( GncSqlBackend* be, QofInstance* inst )
-{
-    g_return_val_if_fail( inst != NULL, FALSE );
-    g_return_val_if_fail( GNC_IS_ORDER(inst), FALSE );
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_ORDER, col_table );
-}
-
-/* ================================================================= */
-static gboolean
-order_should_be_saved( GncOrder *order )
-{
-    const char *id;
-
-    g_return_val_if_fail( order != NULL, FALSE );
-
-    /* make sure this is a valid order before we save it -- should have an ID */
-    id = gncOrderGetID( order );
-    if ( id == NULL || *id == '\0' )
-    {
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-static void
-write_single_order( QofInstance *term_p, gpointer data_p )
-{
-    write_objects_t* s = (write_objects_t*)data_p;
-
-    g_return_if_fail( term_p != NULL );
-    g_return_if_fail( GNC_IS_ORDER(term_p) );
-    g_return_if_fail( data_p != NULL );
-
-    if ( s->is_ok && order_should_be_saved( GNC_ORDER(term_p) ) )
-    {
-        s->is_ok = save_order( s->be, term_p );
-    }
-}
-
-static gboolean
-write_orders( GncSqlBackend* be )
-{
-    write_objects_t data;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    data.be = be;
-    data.is_ok = TRUE;
-    qof_object_foreach( GNC_ID_ORDER, be->primary_book, write_single_order, &data );
-
-    return data.is_ok;
-}
-
-/* ================================================================= */
-static void
-load_order_guid( const GncSqlBackend* be, GncSqlRow* row,
-                 QofSetterFunc setter, gpointer pObject,
-                 const GncSqlColumnTableEntry* table_row )
-{
-    const GValue* val;
-    GncGUID guid;
-    GncOrder* order = NULL;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( row != NULL );
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( table_row != NULL );
-
-    val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
-    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
-    {
-        string_to_guid( g_value_get_string( val ), &guid );
-        order = gncOrderLookup( be->primary_book, &guid );
-        if ( order != NULL )
-        {
-            if ( table_row->gobj_param_name != NULL )
-            {
-                g_object_set( pObject, table_row->gobj_param_name, order, NULL );
-            }
-            else
-            {
-                (*setter)( pObject, (const gpointer)order );
-            }
-        }
-        else
-        {
-            PWARN( "Order ref '%s' not found", g_value_get_string( val ) );
-        }
-    }
-}
-
-static GncSqlColumnTypeHandler order_guid_handler
-= { load_order_guid,
-    gnc_sql_add_objectref_guid_col_info_to_list,
-    gnc_sql_add_colname_to_list,
-    gnc_sql_add_gvalue_objectref_guid_to_slist
-  };
-/* ================================================================= */
-void
-gnc_order_sql_initialize( void )
-{
-    static GncSqlObjectBackend be_data =
-    {
-        GNC_SQL_BACKEND_VERSION,
-        GNC_ID_ORDER,
-        save_order,						/* commit */
-        load_all_orders,				/* initial_load */
-        create_order_tables,			/* create_tables */
-        NULL, NULL, NULL,
-        write_orders					/* write */
-    };
-
-    qof_object_register_backend( GNC_ID_ORDER, GNC_SQL_BACKEND, &be_data );
-
-    gnc_sql_register_col_type_handler( CT_ORDERREF, &order_guid_handler );
-}
-/* ========================== END OF FILE ===================== */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-order-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-order-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-order-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,37 +0,0 @@
-/*
- * gnc-order-sql.h -- order sql backend
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-order-sql.h
- *  @brief load and save order data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_ORDER_SQL_H
-#define GNC_ORDER_SQL_H
-
-#define CT_ORDERREF "order"
-
-void gnc_order_sql_initialize( void );
-
-#endif /* GNC_ORDER_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,304 +0,0 @@
-/********************************************************************\
- * gnc-owner-sql.c -- owner sql implementation                      *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-owner-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-backend-sql.h"
-
-#include "gnc-owner-sql.h"
-#include "gncCustomerP.h"
-#include "gncJobP.h"
-#include "gncEmployeeP.h"
-#include "gncVendorP.h"
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-typedef void (*OwnerSetterFunc)( gpointer, GncOwner* );
-typedef GncOwner* (*OwnerGetterFunc)( const gpointer );
-
-static void
-load_owner( const GncSqlBackend* be, GncSqlRow* row,
-            QofSetterFunc setter, gpointer pObject,
-            const GncSqlColumnTableEntry* table_row )
-{
-    const GValue* val;
-    gchar* buf;
-    GncOwnerType type;
-    GncGUID guid;
-    QofBook* book;
-    GncOwner owner;
-    GncGUID* pGuid = NULL;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( row != NULL );
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( table_row != NULL );
-
-    book = be->primary_book;
-    buf = g_strdup_printf( "%s_type", table_row->col_name );
-    val = gnc_sql_row_get_value_at_col_name( row, buf );
-    type = (GncOwnerType)gnc_sql_get_integer_value( val );
-    g_free( buf );
-    buf = g_strdup_printf( "%s_guid", table_row->col_name );
-    val = gnc_sql_row_get_value_at_col_name( row, buf );
-    g_free( buf );
-
-    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
-    {
-        string_to_guid( g_value_get_string( val ), &guid );
-        pGuid = &guid;
-    }
-
-    switch ( type )
-    {
-    case GNC_OWNER_CUSTOMER:
-    {
-        GncCustomer *cust = NULL;
-
-        if ( pGuid != NULL )
-        {
-            cust = gncCustomerLookup( book, pGuid );
-            if ( cust == NULL )
-            {
-                cust = gncCustomerCreate( book );
-                gncCustomerSetGUID( cust, &guid );
-            }
-        }
-        gncOwnerInitCustomer( &owner, cust );
-        break;
-    }
-
-    case GNC_OWNER_JOB:
-    {
-        GncJob *job = NULL;
-
-        if ( pGuid != NULL )
-        {
-            job = gncJobLookup( book, pGuid );
-            if ( job == NULL )
-            {
-                job = gncJobCreate( book );
-                gncJobSetGUID( job, &guid );
-            }
-        }
-        gncOwnerInitJob( &owner, job );
-        break;
-    }
-
-    case GNC_OWNER_VENDOR:
-    {
-        GncVendor *vendor = NULL;
-
-        if ( pGuid != NULL )
-        {
-            vendor = gncVendorLookup( book, pGuid );
-            if ( vendor == NULL )
-            {
-                vendor = gncVendorCreate( book );
-                gncVendorSetGUID( vendor, &guid );
-            }
-        }
-        gncOwnerInitVendor( &owner, vendor );
-        break;
-    }
-
-    case GNC_OWNER_EMPLOYEE:
-    {
-        GncEmployee *employee = NULL;
-
-        if ( pGuid != NULL )
-        {
-            employee = gncEmployeeLookup( book, pGuid );
-            if ( employee == NULL )
-            {
-                employee = gncEmployeeCreate( book );
-                gncEmployeeSetGUID( employee, &guid );
-            }
-        }
-        gncOwnerInitEmployee( &owner, employee );
-        break;
-    }
-
-    default:
-        PWARN("Invalid owner type: %d\n", type );
-    }
-
-    if ( table_row->gobj_param_name != NULL )
-    {
-        g_object_set( pObject, table_row->gobj_param_name, &owner, NULL );
-    }
-    else
-    {
-        (*setter)( pObject, &owner );
-    }
-}
-
-static void
-add_owner_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,
-                            GList** pList )
-{
-    GncSqlColumnInfo* info;
-    gchar* buf;
-    const gchar* type;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( table_row != NULL );
-    g_return_if_fail( pList != NULL );
-
-    buf = g_strdup_printf( "%s_type", table_row->col_name );
-    info = g_new0( GncSqlColumnInfo, 1 );
-    info->name = buf;
-    info->type = BCT_INT;
-    info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
-    info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
-    info->size = table_row->size;
-    info->is_unicode = FALSE;
-    *pList = g_list_append( *pList, info );
-
-    buf = g_strdup_printf( "%s_guid", table_row->col_name );
-    info = g_new0( GncSqlColumnInfo, 1 );
-    info->name = buf;
-    info->type = BCT_STRING;
-    info->size = GUID_ENCODING_LENGTH;
-    info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
-    info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
-    info->is_unicode = FALSE;
-    *pList = g_list_append( *pList, info );
-}
-
-static void
-add_colname_to_list( const GncSqlColumnTableEntry* table_row, GList** pList )
-{
-    gchar* buf;
-
-    buf = g_strdup_printf( "%s_type", table_row->col_name );
-    (*pList) = g_list_append( (*pList), buf );
-    buf = g_strdup_printf( "%s_guid", table_row->col_name );
-    (*pList) = g_list_append( (*pList), buf );
-}
-
-static void
-add_gvalue_owner_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
-                           const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList )
-{
-    GValue* subfield_value;
-    GncOwner* owner;
-    gchar* buf;
-    const GncGUID* guid;
-    gchar guid_buf[GUID_ENCODING_LENGTH+1];
-    GncOwnerType type;
-    QofInstance* inst = NULL;
-    OwnerGetterFunc getter;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( obj_name != NULL );
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( table_row != NULL );
-
-    getter = (OwnerGetterFunc)gnc_sql_get_getter( obj_name, table_row );
-    owner = (*getter)( pObject );
-
-    if ( owner != NULL )
-    {
-        buf = g_strdup_printf( "%s_type", table_row->col_name );
-        subfield_value = g_new0( GValue, 1 );
-        g_value_init( subfield_value, G_TYPE_INT );
-        type = gncOwnerGetType( owner );
-        g_value_set_int( subfield_value, type );
-        (*pList) = g_slist_append( (*pList), subfield_value );
-        g_free( buf );
-
-        buf = g_strdup_printf( "%s_guid", table_row->col_name );
-        subfield_value = g_new0( GValue, 1 );
-        switch ( type )
-        {
-        case GNC_OWNER_CUSTOMER:
-            inst = QOF_INSTANCE(gncOwnerGetCustomer( owner ));
-            break;
-
-        case GNC_OWNER_JOB:
-            inst = QOF_INSTANCE(gncOwnerGetJob( owner ));
-            break;
-
-        case GNC_OWNER_VENDOR:
-            inst = QOF_INSTANCE(gncOwnerGetVendor( owner ));
-            break;
-
-        case GNC_OWNER_EMPLOYEE:
-            inst = QOF_INSTANCE(gncOwnerGetEmployee( owner ));
-            break;
-
-        default:
-            PWARN("Invalid owner type: %d\n", type );
-        }
-        g_value_init( subfield_value, G_TYPE_STRING );
-        if ( inst != NULL )
-        {
-            guid = qof_instance_get_guid( inst );
-            if ( guid != NULL )
-            {
-                (void)guid_to_string_buff( guid, guid_buf );
-                g_value_take_string( subfield_value, g_strdup_printf( "%s", guid_buf ) );
-            }
-        }
-        (*pList) = g_slist_append( (*pList), subfield_value );
-        g_free( buf );
-    }
-    else
-    {
-        subfield_value = g_new0( GValue, 1 );
-        g_value_init( subfield_value, G_TYPE_STRING );
-        g_value_set_string( subfield_value, "NULL" );
-        (*pList) = g_slist_append( (*pList), subfield_value );
-        subfield_value = g_new0( GValue, 1 );
-        g_value_init( subfield_value, G_TYPE_STRING );
-        g_value_set_string( subfield_value, "NULL" );
-        (*pList) = g_slist_append( (*pList), subfield_value );
-    }
-}
-
-static GncSqlColumnTypeHandler owner_handler
-= { load_owner,
-    add_owner_col_info_to_list,
-    add_colname_to_list,
-    add_gvalue_owner_to_slist
-  };
-
-/* ================================================================= */
-void
-gnc_owner_sql_initialize( void )
-{
-    gnc_sql_register_col_type_handler( CT_OWNERREF, &owner_handler );
-}
-/* ========================== END OF FILE ===================== */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,39 +0,0 @@
-/* gnc-owner-sql.h -- Owner SQL header
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-owner-sql.h
- *  @brief load and save owner data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_OWNER_SQL_H
-#define GNC_OWNER_SQL_H
-
-#include "gncOwner.h"
-#include "qof.h"
-
-#define CT_OWNERREF "owner"
-
-void gnc_owner_sql_initialize( void );
-
-#endif /* GNC_OWNER_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,598 +0,0 @@
-/********************************************************************\
- * gnc-tax-table-sql.c -- tax table sql implementation              *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-tax-table-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-backend-sql.h"
-#include "gnc-slots-sql.h"
-
-#include "gncEntry.h"
-#include "gncTaxTableP.h"
-
-#include "gnc-tax-table-sql.h"
-
-#define _GNC_MOD_NAME	GNC_ID_TAXTABLE
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-static void set_invisible( gpointer data, gboolean value );
-
-typedef struct
-{
-    GncSqlBackend* be;
-    const GncGUID* guid;
-} guid_info_t;
-
-static gpointer get_obj_guid( gpointer pObject, const QofParam* param );
-static void set_obj_guid( gpointer pObject, gpointer pValue );
-static gpointer get_child( gpointer pObject, const QofParam* param );
-static gpointer bt_get_parent( gpointer pObject );
-static void tt_set_parent( gpointer pObject, gpointer pValue );
-static void tt_set_parent_guid( gpointer pObject, gpointer pValue );
-
-#define MAX_NAME_LEN 50
-
-#define TT_TABLE_NAME "taxtables"
-#define TT_TABLE_VERSION 2
-
-static GncSqlColumnTableEntry tt_col_table[] =
-{
-    { "guid",      CT_GUID,        0,            COL_NNUL | COL_PKEY, "guid" },
-    { "name",      CT_STRING,      MAX_NAME_LEN, COL_NNUL,          "name" },
-    { "refcount",  CT_INT64,       0,            COL_NNUL,          NULL, GNC_TT_REFCOUNT },
-    {
-        "invisible", CT_BOOLEAN,     0,            COL_NNUL,          NULL, NULL,
-        (QofAccessFunc)gncTaxTableGetInvisible, (QofSetterFunc)set_invisible
-    },
-    /*	{ "child",     CT_TAXTABLEREF, 0,			 0,                 NULL, NULL,
-    			get_child, (QofSetterFunc)gncTaxTableSetChild }, */
-    {
-        "parent",    CT_GUID,        0,			 0,                 NULL, NULL,
-        (QofAccessFunc)bt_get_parent, tt_set_parent
-    },
-    { NULL }
-};
-
-static GncSqlColumnTableEntry tt_parent_col_table[] =
-{
-    { "parent", CT_GUID, 0, 0, NULL, NULL, NULL, tt_set_parent_guid },
-    { NULL }
-};
-
-#define TTENTRIES_TABLE_NAME "taxtable_entries"
-#define TTENTRIES_TABLE_VERSION 3
-
-static GncSqlColumnTableEntry ttentries_col_table[] =
-{
-    { "id",       CT_INT,         0, COL_PKEY | COL_NNUL | COL_AUTOINC },
-    {
-        "taxtable", CT_TAXTABLEREF, 0, COL_NNUL, NULL, NULL,
-        (QofAccessFunc)gncTaxTableEntryGetTable, set_obj_guid
-    },
-    {
-        "account",  CT_ACCOUNTREF,  0, COL_NNUL, NULL, NULL,
-        (QofAccessFunc)gncTaxTableEntryGetAccount, (QofSetterFunc)gncTaxTableEntrySetAccount
-    },
-    {
-        "amount",   CT_NUMERIC,     0, COL_NNUL, NULL, NULL,
-        (QofAccessFunc)gncTaxTableEntryGetAmount, (QofSetterFunc)gncTaxTableEntrySetAmount
-    },
-    {
-        "type",     CT_INT,         0, COL_NNUL, NULL, NULL,
-        (QofAccessFunc)gncTaxTableEntryGetType, (QofSetterFunc)gncTaxTableEntrySetType
-    },
-    { NULL }
-};
-
-/* Special column table because we need to be able to access the table by
-a column other than the primary key */
-static GncSqlColumnTableEntry guid_col_table[] =
-{
-    { "taxtable", CT_GUID, 0, 0, NULL, NULL, get_obj_guid, set_obj_guid },
-    { NULL }
-};
-
-typedef struct
-{
-    /*@ dependent @*/ GncTaxTable* tt;
-    GncGUID guid;
-    gboolean have_guid;
-} taxtable_parent_guid_struct;
-
-static gpointer
-get_obj_guid( gpointer pObject, const QofParam* param )
-{
-    guid_info_t* pInfo = (guid_info_t*)pObject;
-
-    g_return_val_if_fail( pInfo != NULL, NULL );
-
-    return (gpointer)pInfo->guid;
-}
-
-static void
-set_obj_guid( gpointer pObject, gpointer pValue )
-{
-    // Nowhere to put the GncGUID
-}
-
-static void
-set_invisible( gpointer data, gboolean value )
-{
-    GncTaxTable* tt = GNC_TAXTABLE(data);
-
-    g_return_if_fail( data != NULL );
-    g_return_if_fail( GNC_IS_TAXTABLE(data) );
-
-    if ( value )
-    {
-        gncTaxTableMakeInvisible( tt );
-    }
-}
-
-static gpointer
-get_child( gpointer pObject, const QofParam* param )
-{
-    GncTaxTable* tt = GNC_TAXTABLE(pObject);
-
-    g_return_val_if_fail( pObject != NULL, NULL );
-    g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );
-
-    return gncTaxTableGetChild( tt );
-}
-
-static /*@ null @*//*@ dependent @*/ gpointer
-bt_get_parent( gpointer pObject )
-{
-    const GncTaxTable* tt;
-    const GncTaxTable* pParent;
-    const GncGUID* parent_guid;
-
-    g_return_val_if_fail( pObject != NULL, NULL );
-    g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );
-
-    tt = GNC_TAXTABLE(pObject);
-    pParent = gncTaxTableGetParent( tt );
-    if ( pParent == NULL )
-    {
-        parent_guid = NULL;
-    }
-    else
-    {
-        parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
-    }
-
-    return (gpointer)parent_guid;
-}
-
-static void
-tt_set_parent( gpointer data, gpointer value )
-{
-    GncTaxTable* tt;
-    GncTaxTable* parent;
-    QofBook* pBook;
-    GncGUID* guid = (GncGUID*)value;
-
-    g_return_if_fail( data != NULL );
-    g_return_if_fail( GNC_IS_TAXTABLE(data) );
-
-    tt = GNC_TAXTABLE(data);
-    pBook = qof_instance_get_book( QOF_INSTANCE(tt) );
-    if ( guid != NULL )
-    {
-        parent = gncTaxTableLookup( pBook, guid );
-        if ( parent != NULL )
-        {
-            gncTaxTableSetParent( tt, parent );
-            gncTaxTableSetChild( parent, tt );
-        }
-    }
-}
-
-static void
-tt_set_parent_guid( gpointer pObject, /*@ null @*/ gpointer pValue )
-{
-    taxtable_parent_guid_struct* s = (taxtable_parent_guid_struct*)pObject;
-    GncGUID* guid = (GncGUID*)pValue;
-
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( pValue != NULL );
-
-    s->guid = *guid;
-    s->have_guid = TRUE;
-}
-
-static void
-load_single_ttentry( GncSqlBackend* be, GncSqlRow* row, GncTaxTable* tt )
-{
-    GncTaxTableEntry* e = gncTaxTableEntryCreate();
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( row != NULL );
-    g_return_if_fail( tt != NULL );
-
-    gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, e, ttentries_col_table );
-    gncTaxTableAddEntry( tt, e );
-}
-
-static void
-load_taxtable_entries( GncSqlBackend* be, GncTaxTable* tt )
-{
-    GncSqlResult* result;
-    gchar guid_buf[GUID_ENCODING_LENGTH+1];
-    GValue value;
-    gchar* buf;
-    GncSqlStatement* stmt;
-    GError* error = NULL;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( tt != NULL );
-
-    guid_to_string_buff( qof_instance_get_guid( QOF_INSTANCE(tt) ), guid_buf );
-    memset( &value, 0, sizeof( GValue ) );
-    g_value_init( &value, G_TYPE_STRING );
-    g_value_set_string( &value, guid_buf );
-    buf = g_strdup_printf( "SELECT * FROM %s WHERE taxtable='%s'", TTENTRIES_TABLE_NAME, guid_buf );
-    stmt = gnc_sql_connection_create_statement_from_sql( be->conn, buf );
-    g_free( buf );
-    result = gnc_sql_execute_select_statement( be, stmt );
-    gnc_sql_statement_dispose( stmt );
-    if ( result != NULL )
-    {
-        GncSqlRow* row;
-
-        row = gnc_sql_result_get_first_row( result );
-        while ( row != NULL )
-        {
-            load_single_ttentry( be, row, tt );
-            row = gnc_sql_result_get_next_row( result );
-        }
-        gnc_sql_result_dispose( result );
-    }
-}
-
-static void
-load_single_taxtable( GncSqlBackend* be, GncSqlRow* row,
-                      GList** l_tt_needing_parents )
-{
-    const GncGUID* guid;
-    GncTaxTable* tt;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( row != NULL );
-
-    guid = gnc_sql_load_guid( be, row );
-    tt = gncTaxTableLookup( be->primary_book, guid );
-    if ( tt == NULL )
-    {
-        tt = gncTaxTableCreate( be->primary_book );
-    }
-    gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, tt, tt_col_table );
-    gnc_sql_slots_load( be, QOF_INSTANCE(tt) );
-    load_taxtable_entries( be, tt );
-
-    /* If the tax table doesn't have a parent, it might be because it hasn't been loaded yet.
-       If so, add this tax table to the list of tax tables with no parent, along with the parent
-       GncGUID so that after they are all loaded, the parents can be fixed up. */
-    if ( gncTaxTableGetParent( tt ) == NULL )
-    {
-        taxtable_parent_guid_struct* s = g_malloc( (gsize)sizeof(taxtable_parent_guid_struct) );
-        g_assert( s != NULL );
-
-        s->tt = tt;
-        s->have_guid = FALSE;
-        gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, s, tt_parent_col_table );
-        if ( s->have_guid )
-        {
-            *l_tt_needing_parents = g_list_prepend( *l_tt_needing_parents, s );
-        }
-        else
-        {
-            g_free( s );
-        }
-    }
-
-    qof_instance_mark_clean( QOF_INSTANCE(tt) );
-}
-
-static void
-load_all_taxtables( GncSqlBackend* be )
-{
-    GncSqlStatement* stmt;
-    GncSqlResult* result;
-
-    g_return_if_fail( be != NULL );
-
-    /* First time, create the query */
-    stmt = gnc_sql_create_select_statement( be, TT_TABLE_NAME );
-    result = gnc_sql_execute_select_statement( be, stmt );
-    gnc_sql_statement_dispose( stmt );
-    if ( result != NULL )
-    {
-        GncSqlRow* row;
-        GList* tt_needing_parents = NULL;
-
-        row = gnc_sql_result_get_first_row( result );
-        while ( row != NULL )
-        {
-            load_single_taxtable( be, row, &tt_needing_parents );
-            row = gnc_sql_result_get_next_row( result );
-        }
-        gnc_sql_result_dispose( result );
-
-        /* While there are items on the list of taxtables needing parents,
-           try to see if the parent has now been loaded.  Theory says that if
-           items are removed from the front and added to the back if the
-           parent is still not available, then eventually, the list will
-           shrink to size 0. */
-        if ( tt_needing_parents != NULL )
-        {
-            gboolean progress_made = TRUE;
-            GncTaxTable* root;
-            Account* pParent;
-            GList* elem;
-
-            while ( progress_made )
-            {
-                progress_made = FALSE;
-                for ( elem = tt_needing_parents; elem != NULL; elem = g_list_next( elem ) )
-                {
-                    taxtable_parent_guid_struct* s = (taxtable_parent_guid_struct*)elem->data;
-                    tt_set_parent( s->tt, &s->guid );
-                    tt_needing_parents = g_list_delete_link( tt_needing_parents, elem );
-                    progress_made = TRUE;
-                }
-            }
-        }
-    }
-}
-
-/* ================================================================= */
-static void
-create_taxtable_tables( GncSqlBackend* be )
-{
-    gint version;
-
-    g_return_if_fail( be != NULL );
-
-    version = gnc_sql_get_table_version( be, TT_TABLE_NAME );
-    if ( version == 0 )
-    {
-        gnc_sql_create_table( be, TT_TABLE_NAME, TT_TABLE_VERSION, tt_col_table );
-    }
-    else if ( version == 1 )
-    {
-        /* Upgrade 64 bit int handling */
-        gnc_sql_upgrade_table( be, TT_TABLE_NAME, tt_col_table );
-        gnc_sql_set_table_version( be, TT_TABLE_NAME, TT_TABLE_VERSION );
-    }
-
-    version = gnc_sql_get_table_version( be, TTENTRIES_TABLE_NAME );
-    if ( version == 0 )
-    {
-        gnc_sql_create_table( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION, ttentries_col_table );
-    }
-    else if ( version == 1 )
-    {
-        /* Upgrade 64 bit int handling */
-        gnc_sql_upgrade_table( be, TTENTRIES_TABLE_NAME, ttentries_col_table );
-        gnc_sql_set_table_version( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION );
-    }
-}
-
-/* ================================================================= */
-static gboolean
-delete_all_tt_entries( GncSqlBackend* be, const GncGUID* guid )
-{
-    guid_info_t guid_info;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-    g_return_val_if_fail( guid != NULL, FALSE );
-
-    guid_info.be = be;
-    guid_info.guid = guid;
-    return gnc_sql_do_db_operation( be, OP_DB_DELETE, TTENTRIES_TABLE_NAME,
-                                    TTENTRIES_TABLE_NAME, &guid_info, guid_col_table );
-}
-
-static gboolean
-save_tt_entries( GncSqlBackend* be, const GncGUID* guid, GList* entries )
-{
-    GList* entry;
-    gboolean is_ok;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-    g_return_val_if_fail( guid != NULL, FALSE );
-
-    /* First, delete the old entries for this object */
-    is_ok = delete_all_tt_entries( be, guid );
-
-    for ( entry = entries; entry != NULL && is_ok; entry = entry->next )
-    {
-        GncTaxTableEntry* e = (GncTaxTableEntry*)entry->data;
-        is_ok = gnc_sql_do_db_operation( be,
-                                         OP_DB_INSERT,
-                                         TTENTRIES_TABLE_NAME,
-                                         GNC_ID_TAXTABLE, e,
-                                         ttentries_col_table );
-    }
-
-    return is_ok;
-}
-
-static gboolean
-save_taxtable( GncSqlBackend* be, QofInstance* inst )
-{
-    GncTaxTable* tt;
-    const GncGUID* guid;
-    gint op;
-    gboolean is_infant;
-    gboolean is_ok;
-
-    g_return_val_if_fail( inst != NULL, FALSE );
-    g_return_val_if_fail( GNC_IS_TAXTABLE(inst), FALSE );
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    tt = GNC_TAXTABLE(inst);
-
-    is_infant = qof_instance_get_infant( inst );
-    if ( qof_instance_get_destroying( inst ) )
-    {
-        op = OP_DB_DELETE;
-    }
-    else if ( be->is_pristine_db || is_infant )
-    {
-        op = OP_DB_INSERT;
-    }
-    else
-    {
-        op = OP_DB_UPDATE;
-    }
-    is_ok = gnc_sql_do_db_operation( be, op, TT_TABLE_NAME, GNC_ID_TAXTABLE, tt, tt_col_table );
-
-    if ( is_ok )
-    {
-        // Now, commit or delete any slots and tax table entries
-        guid = qof_instance_get_guid( inst );
-        if ( !qof_instance_get_destroying(inst) )
-        {
-            is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
-            if ( is_ok )
-            {
-                is_ok = save_tt_entries( be, guid, gncTaxTableGetEntries( tt ) );
-            }
-        }
-        else
-        {
-            is_ok = gnc_sql_slots_delete( be, guid );
-            if ( is_ok )
-            {
-                is_ok = delete_all_tt_entries( be, guid );
-            }
-        }
-    }
-
-    return is_ok;
-}
-
-/* ================================================================= */
-static void
-save_next_taxtable( QofInstance* inst, gpointer data )
-{
-    write_objects_t* s = (write_objects_t*)data;
-
-    if ( s->is_ok )
-    {
-        s->is_ok = save_taxtable( s->be, inst );
-    }
-}
-
-static gboolean
-write_taxtables( GncSqlBackend* be )
-{
-    write_objects_t data;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    data.be = be;
-    data.is_ok = TRUE;
-    qof_object_foreach( GNC_ID_TAXTABLE, be->primary_book, save_next_taxtable, &data );
-
-    return data.is_ok;
-}
-
-/* ================================================================= */
-static void
-load_taxtable_guid( const GncSqlBackend* be, GncSqlRow* row,
-                    QofSetterFunc setter, gpointer pObject,
-                    const GncSqlColumnTableEntry* table_row )
-{
-    const GValue* val;
-    GncGUID guid;
-    GncTaxTable* taxtable = NULL;
-
-    g_return_if_fail( be != NULL );
-    g_return_if_fail( row != NULL );
-    g_return_if_fail( pObject != NULL );
-    g_return_if_fail( table_row != NULL );
-
-    val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
-    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
-    {
-        string_to_guid( g_value_get_string( val ), &guid );
-        taxtable = gncTaxTableLookup( be->primary_book, &guid );
-        if ( taxtable != NULL )
-        {
-            if ( table_row->gobj_param_name != NULL )
-            {
-                g_object_set( pObject, table_row->gobj_param_name, taxtable, NULL );
-            }
-            else
-            {
-                (*setter)( pObject, (const gpointer)taxtable );
-            }
-        }
-        else
-        {
-            PWARN( "Taxtable ref '%s' not found", g_value_get_string( val ) );
-        }
-    }
-}
-
-static GncSqlColumnTypeHandler taxtable_guid_handler
-= { load_taxtable_guid,
-    gnc_sql_add_objectref_guid_col_info_to_list,
-    gnc_sql_add_colname_to_list,
-    gnc_sql_add_gvalue_objectref_guid_to_slist
-  };
-/* ================================================================= */
-void
-gnc_taxtable_sql_initialize( void )
-{
-    static GncSqlObjectBackend be_data =
-    {
-        GNC_SQL_BACKEND_VERSION,
-        GNC_ID_TAXTABLE,
-        save_taxtable,						/* commit */
-        load_all_taxtables,					/* initial_load */
-        create_taxtable_tables,				/* create_tables */
-        NULL, NULL, NULL,
-        write_taxtables						/* write */
-    };
-
-    qof_object_register_backend( GNC_ID_TAXTABLE, GNC_SQL_BACKEND, &be_data );
-
-    gnc_sql_register_col_type_handler( CT_TAXTABLEREF, &taxtable_guid_handler );
-}
-/* ========================== END OF FILE ===================== */
-

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,37 +0,0 @@
-/*
- * gnc-tax-table-sql.h -- tax table sql backend
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-tax-table-sql.h
- *  @brief load and save tax table data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_TAXTABLE_SQL_H
-#define GNC_TAXTABLE_SQL_H
-
-#define CT_TAXTABLEREF "tax-table"
-
-void gnc_taxtable_sql_initialize( void );
-
-#endif /* GNC_TAXTABLE_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,280 +0,0 @@
-/********************************************************************\
- * gnc-vendor-sql.c -- vendor sql backend                           *
- *                                                                  *
- * This program is free software; you can redistribute it and/or    *
- * modify it under the terms of the GNU General Public License as   *
- * published by the Free Software Foundation; either version 2 of   *
- * the License, or (at your option) any later version.              *
- *                                                                  *
- * This program is distributed in the hope that it will be useful,  *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
- * GNU General Public License for more details.                     *
- *                                                                  *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact:                        *
- *                                                                  *
- * Free Software Foundation           Voice:  +1-617-542-5942       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/** @file gnc-vendor-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gnc-commodity.h"
-
-#include "gnc-backend-sql.h"
-#include "gnc-commodity-sql.h"
-#include "gnc-slots-sql.h"
-
-#include "gnc-commodity.h"
-#include "gncBillTermP.h"
-#include "gncVendorP.h"
-#include "gncTaxTableP.h"
-#include "gnc-vendor-sql.h"
-#include "gnc-address-sql.h"
-#include "gnc-bill-term-sql.h"
-#include "gnc-tax-table-sql.h"
-
-#define _GNC_MOD_NAME	GNC_ID_VENDOR
-
-static QofLogModule log_module = G_LOG_DOMAIN;
-
-#define MAX_NAME_LEN 2048
-#define MAX_ID_LEN 2048
-#define MAX_NOTES_LEN 2048
-#define MAX_TAX_INC_LEN 2048
-
-#define TABLE_NAME "vendors"
-#define TABLE_VERSION 1
-
-static GncSqlColumnTableEntry col_table[] =
-{
-    { "guid",         CT_GUID,          0,               COL_NNUL | COL_PKEY, "guid" },
-    { "name",         CT_STRING,        MAX_NAME_LEN,    COL_NNUL,          "name" },
-    { "id",           CT_STRING,        MAX_ID_LEN,      COL_NNUL,          NULL, VENDOR_ID },
-    { "notes",        CT_STRING,        MAX_NOTES_LEN,   COL_NNUL,          NULL, VENDOR_NOTES },
-    {
-        "currency",     CT_COMMODITYREF,  0,               COL_NNUL,          NULL, NULL,
-        (QofAccessFunc)gncVendorGetCurrency, (QofSetterFunc)gncVendorSetCurrency
-    },
-    {
-        "active",       CT_BOOLEAN,       0,               COL_NNUL,          NULL, NULL,
-        (QofAccessFunc)gncVendorGetActive, (QofSetterFunc)gncVendorSetActive
-    },
-    { "tax_override", CT_BOOLEAN,       0,               COL_NNUL,          NULL, VENDOR_TAX_OVERRIDE },
-    { "addr",         CT_ADDRESS,       0,               0,                 NULL, VENDOR_ADDR },
-    { "terms",        CT_BILLTERMREF,   0,               0,                 NULL, VENDOR_TERMS },
-    { "tax_inc",      CT_STRING,        MAX_TAX_INC_LEN, 0,                 NULL, VENDOR_TAX_INC },
-    { "tax_table",    CT_TAXTABLEREF,   0,               0,                 NULL, VENDOR_TAX_TABLE },
-    { NULL }
-};
-
-static GncVendor*
-load_single_vendor( GncSqlBackend* be, GncSqlRow* row )
-{
-    const GncGUID* guid;
-    GncVendor* pVendor;
-
-    g_return_val_if_fail( be != NULL, NULL );
-    g_return_val_if_fail( row != NULL, NULL );
-
-    guid = gnc_sql_load_guid( be, row );
-    pVendor = gncVendorLookup( be->primary_book, guid );
-    if ( pVendor == NULL )
-    {
-        pVendor = gncVendorCreate( be->primary_book );
-    }
-    gnc_sql_load_object( be, row, GNC_ID_VENDOR, pVendor, col_table );
-    qof_instance_mark_clean( QOF_INSTANCE(pVendor) );
-
-    return pVendor;
-}
-
-static void
-load_all_vendors( GncSqlBackend* be )
-{
-    GncSqlStatement* stmt;
-    GncSqlResult* result;
-    QofBook* pBook;
-
-    g_return_if_fail( be != NULL );
-
-    pBook = be->primary_book;
-
-    stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
-    result = gnc_sql_execute_select_statement( be, stmt );
-    gnc_sql_statement_dispose( stmt );
-    if ( result != NULL )
-    {
-        GncSqlRow* row;
-        GList* list = NULL;
-
-        row = gnc_sql_result_get_first_row( result );
-        while ( row != NULL )
-        {
-            GncVendor* pVendor = load_single_vendor( be, row );
-            if ( pVendor != NULL )
-            {
-                list = g_list_append( list, pVendor );
-            }
-            row = gnc_sql_result_get_next_row( result );
-        }
-        gnc_sql_result_dispose( result );
-
-        if ( list != NULL )
-        {
-            gnc_sql_slots_load_for_list( be, list );
-        }
-    }
-}
-
-/* ================================================================= */
-static void
-create_vendor_tables( GncSqlBackend* be )
-{
-    gint version;
-
-    g_return_if_fail( be != NULL );
-
-    version = gnc_sql_get_table_version( be, TABLE_NAME );
-    if ( version == 0 )
-    {
-        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
-    }
-}
-
-/* ================================================================= */
-static gboolean
-save_vendor( GncSqlBackend* be, QofInstance* inst )
-{
-    GncVendor* v;
-    const GncGUID* guid;
-    gint op;
-    gboolean is_infant;
-    gboolean is_ok = TRUE;
-
-    g_return_val_if_fail( inst != NULL, FALSE );
-    g_return_val_if_fail( GNC_IS_VENDOR(inst), FALSE );
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    v = GNC_VENDOR(inst);
-
-    is_infant = qof_instance_get_infant( inst );
-    if ( qof_instance_get_destroying( inst ) )
-    {
-        op = OP_DB_DELETE;
-    }
-    else if ( be->is_pristine_db || is_infant )
-    {
-        op = OP_DB_INSERT;
-    }
-    else
-    {
-        op = OP_DB_UPDATE;
-    }
-    if ( op != OP_DB_DELETE )
-    {
-        // Ensure the commodity is in the db
-        is_ok = gnc_sql_save_commodity( be, gncVendorGetCurrency( v ) );
-    }
-    if ( is_ok )
-    {
-        is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_VENDOR, v, col_table );
-    }
-
-    if ( is_ok )
-    {
-        // Now, commit or delete any slots
-        guid = qof_instance_get_guid( inst );
-        if ( !qof_instance_get_destroying(inst) )
-        {
-            is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
-        }
-        else
-        {
-            is_ok = gnc_sql_slots_delete( be, guid );
-        }
-    }
-
-    return is_ok;
-}
-
-/* ================================================================= */
-static gboolean
-vendor_should_be_saved( GncVendor *vendor )
-{
-    const char *id;
-
-    g_return_val_if_fail( vendor != NULL, FALSE );
-
-    /* make sure this is a valid vendor before we save it -- should have an ID */
-    id = gncVendorGetID( vendor );
-    if ( id == NULL || *id == '\0' )
-    {
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-static void
-write_single_vendor( QofInstance *term_p, gpointer data_p )
-{
-    write_objects_t* s = (write_objects_t*)data_p;
-
-    g_return_if_fail( term_p != NULL );
-    g_return_if_fail( GNC_IS_VENDOR(term_p) );
-    g_return_if_fail( data_p != NULL );
-
-    if ( s->is_ok && vendor_should_be_saved( GNC_VENDOR(term_p) ) )
-    {
-        s->is_ok = save_vendor( s->be, term_p );
-    }
-}
-
-static gboolean
-write_vendors( GncSqlBackend* be )
-{
-    write_objects_t data;
-
-    g_return_val_if_fail( be != NULL, FALSE );
-
-    data.be = be;
-    data.is_ok = TRUE;
-    qof_object_foreach( GNC_ID_VENDOR, be->primary_book, write_single_vendor, &data );
-
-    return data.is_ok;
-}
-
-/* ================================================================= */
-void
-gnc_vendor_sql_initialize( void )
-{
-    static GncSqlObjectBackend be_data =
-    {
-        GNC_SQL_BACKEND_VERSION,
-        GNC_ID_VENDOR,
-        save_vendor,						/* commit */
-        load_all_vendors,					/* initial_load */
-        create_vendor_tables,				/* create_tables */
-        NULL, NULL, NULL,
-        write_vendors						/* write */
-    };
-
-    qof_object_register_backend( GNC_ID_VENDOR, GNC_SQL_BACKEND, &be_data );
-}
-/* ========================== END OF FILE ===================== */

Deleted: gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,35 +0,0 @@
-/*
- * gnc-vendor-sql.h -- vendor sql backend
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @file gnc-vendor-sql.h
- *  @brief load and save vendor data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#ifndef GNC_VENDOR_SQL_H
-#define GNC_VENDOR_SQL_H
-
-void gnc_vendor_sql_initialize( void );
-
-#endif /* GNC_VENDOR_SQL_H */

Deleted: gnucash/trunk/src/business/business-core/sql/gncmod-business-backend-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gncmod-business-backend-sql.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gncmod-business-backend-sql.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,137 +0,0 @@
-/*********************************************************************
- * gncmod-business-backend-sql.c
- * module definition/initialization for the sql backend module
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- *
- *********************************************************************/
-
-/** @file gncmod-business-backend-sql.c
- *  @brief load and save address data to SQL
- *  @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff at rogers.com>
- *
- * This file implements the top-level QofBackend API for saving/
- * restoring data to/from an SQL database
- */
-
-#include "config.h"
-#include <gmodule.h>
-
-#include "gnc-module.h"
-#include "gnc-module-api.h"
-#include "gnc-engine.h"
-
-#include "gnc-backend-sql.h"
-
-#include "gnc-address-sql.h"
-#include "gnc-bill-term-sql.h"
-#include "gnc-customer-sql.h"
-#include "gnc-employee-sql.h"
-#include "gnc-entry-sql.h"
-#include "gnc-invoice-sql.h"
-#include "gnc-job-sql.h"
-#include "gnc-order-sql.h"
-#include "gnc-owner-sql.h"
-#include "gnc-tax-table-sql.h"
-#include "gnc-vendor-sql.h"
-#include "gncmod-business-backend-sql.h"
-
-GNC_MODULE_API_DECL(libgncmod_business_backend_sql)
-
-/* version of the gnc module system interface we require */
-int libgncmod_business_backend_sql_gnc_module_system_interface = 0;
-
-/* module versioning uses libtool semantics. */
-int libgncmod_business_backend_sql_gnc_module_current  = 0;
-int libgncmod_business_backend_sql_gnc_module_revision = 0;
-int libgncmod_business_backend_sql_gnc_module_age      = 0;
-
-static GNCModule bus_core;
-
-
-gchar *
-libgncmod_business_backend_sql_gnc_module_path(void)
-{
-    return g_strdup( "gnucash/business-core-sql" );
-}
-
-gchar *
-libgncmod_business_backend_sql_gnc_module_description(void)
-{
-    return g_strdup( "The SQL backend for GnuCash business objects" );
-}
-
-/* Order in which business objects need to be loaded */
-static const gchar* fixed_load_order[] =
-{ GNC_ID_BILLTERM, GNC_ID_TAXTABLE, NULL };
-
-void
-gnc_module_init_business_core_sql_init(void)
-{
-    /* Initialize our pointers into the backend subsystem */
-    gnc_address_sql_initialize();
-    gnc_billterm_sql_initialize();
-    gnc_customer_sql_initialize();
-    gnc_employee_sql_initialize();
-    gnc_entry_sql_initialize();
-    gnc_invoice_sql_initialize();
-    gnc_job_sql_initialize();
-    gnc_order_sql_initialize();
-    gnc_owner_sql_initialize();
-    gnc_taxtable_sql_initialize();
-    gnc_vendor_sql_initialize();
-
-    gnc_sql_set_load_order( fixed_load_order );
-}
-
-int
-libgncmod_business_backend_sql_gnc_module_init(int refcount)
-{
-    if (!gnc_engine_is_initialized())
-    {
-        return FALSE;
-    }
-
-    bus_core = gnc_module_load( "gnucash/business-core", 0 );
-    if ( !bus_core ) return FALSE;
-
-    if ( refcount == 0 )
-    {
-        gnc_module_init_business_core_sql_init();
-    }
-
-    return TRUE;
-}
-
-int
-libgncmod_business_backend_sql_gnc_module_end(int refcount)
-{
-    int unload = TRUE;
-
-    if ( bus_core )
-    {
-        unload = gnc_module_unload( bus_core );
-    }
-
-    if ( refcount == 0 )
-    {
-        bus_core = NULL;
-    }
-
-    return unload;
-}

Deleted: gnucash/trunk/src/business/business-core/sql/gncmod-business-backend-sql.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gncmod-business-backend-sql.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/gncmod-business-backend-sql.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,32 +0,0 @@
-/*********************************************************************
- * gncmod-business-backend-sql.h
- * module definition/initialization for the sql backend module
- *
- * Copyright (c) 2010 Christian Stimming <stimming at tuhh.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- *
- *********************************************************************/
-
-#ifndef GNCMOD_BUSINESS_BACKEND_SQL_H
-#define GNCMOD_BUSINESS_BACKEND_SQL_H
-
-void
-gnc_module_init_business_core_sql_init(void);
-
-#endif

Deleted: gnucash/trunk/src/business/business-core/sql/test/Makefile.am
===================================================================
--- gnucash/trunk/src/business/business-core/sql/test/Makefile.am	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/test/Makefile.am	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,65 +0,0 @@
-SUBDIRS = .
-
-test_dbi_business_SOURCES = \
-  test-dbi-business.c \
-  test-dbi-business-stuff.c
-
-TESTS = \
-  test-dbi-business
-
-GNC_TEST_DEPS = \
-  --gnc-module-dir ${top_builddir}/src/engine \
-  --guile-load-dir ${top_builddir}/src/engine \
-  --library-dir    ${top_builddir}/lib/libqof/qof \
-  --library-dir    ${top_builddir}/src/core-utils \
-  --library-dir    ${top_builddir}/src/gnc-module \
-  --library-dir    ${top_builddir}/src/engine \
-  --library-dir    ${top_builddir}/src/backend/sql
-
-if CUSTOM_GNC_DBD_DIR
-gnc_dbd_dir_override="GNC_DBD_DIR=@GNC_DBD_DIR@"
-endif
-
-TESTS_ENVIRONMENT = \
-  GNC_ACCOUNT_PATH=${top_srcdir}/accounts/C \
-  SRCDIR=${srcdir} \
-  ${gnc_dbd_dir_override} \
-  $(shell ${top_srcdir}/src/gnc-test-env --no-exports ${GNC_TEST_DEPS})
-
-check_PROGRAMS = \
-  test-dbi-business
-
-LDADD = ${top_builddir}/src/test-core/libtest-core.la \
-        ${top_builddir}/src/gnc-module/libgnc-module.la \
-        ${top_builddir}/src/engine/libgncmod-engine.la \
-        ${top_builddir}/src/engine/test-core/libgncmod-test-engine.la \
-        ${top_builddir}/src/core-utils/libgnc-core-utils.la \
-        ${top_builddir}/src/libqof/qof/libgnc-qof.la \
-        ${top_builddir}/src/backend/dbi/test/libgncmod-test-dbi.la \
-        ${top_builddir}/src/backend/sql/libgnc-backend-sql.la \
-        ${top_builddir}/src/business/business-core/libgncmod-business-core.la \
-        ${top_builddir}/src/business/business-core/sql/libgncmod-business-backend-sql.la \
-        ${top_builddir}/lib/libc/libc-missing.la
-
-AM_CFLAGS = \
-  -I${top_srcdir}/lib/libc \
-  -I${top_srcdir}/src \
-  -I${top_srcdir}/src/core-utils \
-  -I${top_srcdir}/src/test-core \
-  -I${top_srcdir}/src/engine \
-  -I${top_srcdir}/src/engine/test-core \
-  -I${top_srcdir}/src/libqof/qof \
-  -I${top_srcdir}/src/backend/dbi/test \
-  -I${top_srcdir}/src/backend/sql \
-  -I${top_srcdir}/src/business/business-core \
-  -I${top_srcdir}/src/business/business-core/sql \
-  -DTEST_MYSQL_URL=\"${TEST_MYSQL_URL}\" \
-  -DTEST_PGSQL_URL=\"${TEST_PGSQL_URL}\" \
-  ${GLIB_CFLAGS} \
-  ${GUILE_INCS} \
-  ${GCONF_CFLAGS}
-
-EXTRA_DIST = \
-    test-dbi-business-stuff.h
-
-INCLUDES = -DG_LOG_DOMAIN=\"gnc.business.sql\"

Deleted: gnucash/trunk/src/business/business-core/sql/test/test-dbi-business-stuff.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/test/test-dbi-business-stuff.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/test/test-dbi-business-stuff.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,218 +0,0 @@
-/***************************************************************************
- *            test-dbi-business-stuff.c
- *
- *  Tests saving and loading business objects to a dbi/sqlite3 db
- *
- *  Copyright (C) 2010  Phil Longstaff <plongstaff at rogers.com>
- ****************************************************************************/
-
-/*
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- *  02110-1301, USA.
- */
-
-#include "config.h"
-#include "qof.h"
-#include "cashobjects.h"
-#include "test-engine-stuff.h"
-#include "test-stuff.h"
-#include "test-dbi-stuff.h"
-#include "test-dbi-business-stuff.h"
-
-#include "Account.h"
-#include "Split.h"
-#include "Transaction.h"
-#include "gnc-commodity.h"
-#include "gncCustomer.h"
-#include "gncInvoice.h"
-#include "gncEmployee.h"
-#include "gncVendor.h"
-
-static QofLogModule log_module = "test-dbi";
-
-static void
-compare_single_customer( QofInstance* inst, gpointer user_data )
-{
-    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
-    GncCustomer* cust_1 = GNC_CUSTOMER(inst);
-    GncCustomer* cust_2 = gncCustomerLookup( info->book_2, qof_instance_get_guid(inst) );
-
-    if (!gncCustomerEqual( cust_1, cust_2 ))
-    {
-        info->result = FALSE;
-    }
-}
-
-static void
-compare_customers( QofBook* book_1, QofBook* book_2 )
-{
-    do_compare( book_1, book_2, GNC_ID_CUSTOMER, compare_single_customer, "Customer lists match" );
-}
-
-static void
-compare_single_employee( QofInstance* inst, gpointer user_data )
-{
-    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
-    GncEmployee* emp_1 = GNC_EMPLOYEE(inst);
-    GncEmployee* emp_2 = gncEmployeeLookup( info->book_2, qof_instance_get_guid(inst) );
-
-    if (!gncEmployeeEqual( emp_1, emp_2 ))
-    {
-        info->result = FALSE;
-    }
-}
-
-static void
-compare_employees( QofBook* book_1, QofBook* book_2 )
-{
-    do_compare( book_1, book_2, GNC_ID_EMPLOYEE, compare_single_employee, "Employee lists match" );
-}
-
-static void
-compare_single_invoice( QofInstance* inst, gpointer user_data )
-{
-    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
-    GncInvoice* inv_1 = GNC_INVOICE(inst);
-    GncInvoice* inv_2 = gncInvoiceLookup( info->book_2, qof_instance_get_guid(inst) );
-
-    if (!gncInvoiceEqual( inv_1, inv_2 ))
-    {
-        info->result = FALSE;
-    }
-}
-
-static void
-compare_invoices( QofBook* book_1, QofBook* book_2 )
-{
-    do_compare( book_1, book_2, GNC_ID_INVOICE, compare_single_invoice, "Invoice lists match" );
-}
-
-static void
-compare_single_job( QofInstance* inst, gpointer user_data )
-{
-    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
-    GncJob* job_1 = GNC_JOB(inst);
-    GncJob* job_2 = gncJobLookup( info->book_2, qof_instance_get_guid(inst) );
-
-    if (!gncJobEqual( job_1, job_2 ))
-    {
-        info->result = FALSE;
-    }
-}
-
-static void
-compare_jobs( QofBook* book_1, QofBook* book_2 )
-{
-    do_compare( book_1, book_2, GNC_ID_JOB, compare_single_job, "Job lists match" );
-}
-
-static void
-compare_single_vendor( QofInstance* inst, gpointer user_data )
-{
-    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
-    GncVendor* vendor_1 = GNC_VENDOR(inst);
-    GncVendor* vendor_2 = gncVendorLookup( info->book_2, qof_instance_get_guid(inst) );
-
-    if (!gncVendorEqual( vendor_1, vendor_2 ))
-    {
-        info->result = FALSE;
-    }
-}
-
-static void
-compare_vendors( QofBook* book_1, QofBook* book_2 )
-{
-    do_compare( book_1, book_2, GNC_ID_VENDOR, compare_single_vendor, "Vendor lists match" );
-}
-
-static void
-compare_single_billterm( QofInstance* inst, gpointer user_data )
-{
-    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
-    GncBillTerm* bt_1 = GNC_BILLTERM(inst);
-    GncBillTerm* bt_2 = gncBillTermLookup( info->book_2, qof_instance_get_guid(inst) );
-
-    if (!gncBillTermEqual( bt_1, bt_2 ))
-    {
-        info->result = FALSE;
-    }
-}
-
-static void
-compare_billterms( QofBook* book_1, QofBook* book_2 )
-{
-    do_compare( book_1, book_2, GNC_ID_BILLTERM, compare_single_billterm, "Billterms lists match" );
-}
-
-static void
-compare_single_taxtable( QofInstance* inst, gpointer user_data )
-{
-    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
-    GncTaxTable* tt_1 = GNC_TAXTABLE(inst);
-    GncTaxTable* tt_2 = gncTaxTableLookup( info->book_2, qof_instance_get_guid(inst) );
-
-    if (!gncTaxTableEqual( tt_1, tt_2 ))
-    {
-        info->result = FALSE;
-    }
-}
-
-static void
-compare_taxtables( QofBook* book_1, QofBook* book_2 )
-{
-    do_compare( book_1, book_2, GNC_ID_TAXTABLE, compare_single_taxtable, "TaxTable lists match" );
-}
-
-static void
-compare_books( QofBook* book_1, QofBook* book_2 )
-{
-    compare_billterms( book_1, book_2 );
-    compare_taxtables( book_1, book_2 );
-
-    compare_customers( book_1, book_2 );
-    compare_employees( book_1, book_2 );
-    compare_invoices( book_1, book_2 );
-    compare_jobs( book_1, book_2 );
-    compare_vendors( book_1, book_2 );
-}
-
-void
-test_dbi_business_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url )
-{
-    QofSession* session_2;
-    QofSession* session_3;
-
-    printf( "Testing %s\n", driver );
-
-    // Save the session data
-    session_2 = qof_session_new();
-    qof_session_begin( session_2, url, TRUE, TRUE );
-    qof_session_swap_data( session_1, session_2 );
-    qof_session_save( session_2, NULL );
-
-    // Reload the session data
-    session_3 = qof_session_new();
-    qof_session_begin( session_3, url, FALSE, FALSE );
-    qof_session_load( session_3, NULL );
-
-    // Compare with the original data
-    compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) );
-    qof_session_end( session_1 );
-    qof_session_destroy( session_1 );
-    qof_session_end( session_2 );
-    qof_session_destroy( session_2 );
-    qof_session_end( session_3 );
-    qof_session_destroy( session_3 );
-}

Deleted: gnucash/trunk/src/business/business-core/sql/test/test-dbi-business-stuff.h
===================================================================
--- gnucash/trunk/src/business/business-core/sql/test/test-dbi-business-stuff.h	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/test/test-dbi-business-stuff.h	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,39 +0,0 @@
-/***************************************************************************
- *            test-dbi-stuff.h
- *
- *  Tests saving and loading to a dbi/sqlite3 db
- *
- *  Copyright (C) 2009  Phil Longstaff <plongstaff at rogers.com>
- ****************************************************************************/
-
-/*
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- *  02110-1301, USA.
- */
-
-#ifndef _TEST_DBI_BUSINESS_STUFF_H_
-#define _TEST_DBI_BUSINESS_STUFF_H_
-
-/**
- * Test storing a session contents to a db, reloading into a new session, then comparing the
- * two sessions.
- *
- * @param driver Driver name
- * @param session_1 Session to test
- * @param url Database URL
- */
-void test_dbi_business_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url );
-
-#endif

Deleted: gnucash/trunk/src/business/business-core/sql/test/test-dbi-business.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/test/test-dbi-business.c	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-core/sql/test/test-dbi-business.c	2010-07-14 19:39:19 UTC (rev 19364)
@@ -1,189 +0,0 @@
-/***************************************************************************
- *            test-dbi-business.c
- *
- *  Tests saving and loading business objects to a dbi/sqlite3 db
- *
- *  Copyright (C) 2010  Phil Longstaff <plongstaff at rogers.com>
- ****************************************************************************/
-
-/*
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- *  02110-1301, USA.
- */
-
-#include "config.h"
-#include "qof.h"
-#include "cashobjects.h"
-#include "test-engine-stuff.h"
-#include "test-stuff.h"
-#include "test-dbi-business-stuff.h"
-
-#include "Account.h"
-#include "Transaction.h"
-#include "Split.h"
-#include "gnc-commodity.h"
-#include "gncAddress.h"
-#include "gncCustomer.h"
-#include "gncInvoice.h"
-
-#include "gnc-backend-sql.h"
-
-#include "gnc-address-sql.h"
-#include "gnc-bill-term-sql.h"
-#include "gnc-customer-sql.h"
-#include "gnc-employee-sql.h"
-#include "gnc-entry-sql.h"
-#include "gnc-invoice-sql.h"
-#include "gnc-job-sql.h"
-#include "gnc-order-sql.h"
-#include "gnc-owner-sql.h"
-#include "gnc-tax-table-sql.h"
-#include "gnc-vendor-sql.h"
-
-#define FILE_NAME "sqlite3:///tmp/test-sqlite3-file"
-#define GNC_LIB_NAME "gncmod-backend-dbi"
-
-static QofSession*
-create_session(void)
-{
-    QofSession* session = qof_session_new();
-    QofBook* book = qof_session_get_book( session );
-    Account* root = gnc_book_get_root_account( book );
-    Account* acct1;
-    Account* acct2;
-    gnc_commodity_table* table;
-    gnc_commodity* currency;
-    GncAddress* addr;
-    GncCustomer* cust;
-    GncEmployee* emp;
-    GncVendor* v;
-    GncInvoice* inv;
-    GncJob* job;
-    GncTaxTable* tt;
-    GncTaxTableEntry* tte;
-
-    table = gnc_commodity_table_get_table( book );
-    currency = gnc_commodity_table_lookup( table, GNC_COMMODITY_NS_CURRENCY, "CAD" );
-
-    acct1 = xaccMallocAccount( book );
-    xaccAccountSetType( acct1, ACCT_TYPE_BANK );
-    xaccAccountSetName( acct1, "Bank 1" );
-    xaccAccountSetCommodity( acct1, currency );
-    xaccAccountSetHidden( acct1, FALSE );
-    xaccAccountSetPlaceholder( acct1, FALSE );
-    gnc_account_append_child( root, acct1 );
-
-    acct2 = xaccMallocAccount( book );
-    xaccAccountSetType( acct2, ACCT_TYPE_BANK );
-    xaccAccountSetName( acct2, "Bank 2" );
-    xaccAccountSetCommodity( acct2, currency );
-    xaccAccountSetHidden( acct2, FALSE );
-    xaccAccountSetPlaceholder( acct2, FALSE );
-    gnc_account_append_child( root, acct2 );
-
-    tt = gncTaxTableCreate( book );
-    gncTaxTableSetName( tt, "tt" );
-    tte = gncTaxTableEntryCreate();
-    gncTaxTableEntrySetAccount( tte, acct1 );
-    gncTaxTableEntrySetType( tte, GNC_AMT_TYPE_VALUE );
-    gncTaxTableEntrySetAmount( tte, gnc_numeric_zero() );
-    gncTaxTableAddEntry( tt, tte );
-    tte = gncTaxTableEntryCreate();
-    gncTaxTableEntrySetAccount( tte, acct2 );
-    gncTaxTableEntrySetType( tte, GNC_AMT_TYPE_PERCENT );
-    gncTaxTableEntrySetAmount( tte, gnc_numeric_zero() );
-    gncTaxTableAddEntry( tt, tte );
-
-    cust = gncCustomerCreate( book );
-    gncCustomerSetID( cust, "0001" );
-    gncCustomerSetName( cust, "MyCustomer" );
-    gncCustomerSetNotes( cust, "Here are some notes" );
-    gncCustomerSetCurrency( cust, currency );
-    addr = gncAddressCreate( book, QOF_INSTANCE(cust) );
-    gncAddressSetName( addr, "theAddress" );
-    gncAddressSetAddr1( addr, "Address line #1" );
-    gncAddressSetAddr2( addr, "Address line #2" );
-    gncAddressSetAddr3( addr, "Address line #3" );
-    gncAddressSetAddr4( addr, "Address line #4" );
-    gncAddressSetPhone( addr, "(123) 555-1212" );
-    gncAddressSetPhone( addr, "(123) 555-2121" );
-    gncAddressSetEmail( addr, "cust at mycustomer.com" );
-
-    emp = gncEmployeeCreate( book );
-    gncEmployeeSetID( emp, "0001" );
-    gncEmployeeSetUsername( emp, "gnucash" );
-    gncEmployeeSetLanguage( emp, "english" );
-    gncEmployeeSetCurrency( emp, currency );
-
-    return session;
-}
-
-/* Order in which business objects need to be loaded */
-static const gchar* fixed_load_order[] =
-{ GNC_ID_BILLTERM, GNC_ID_TAXTABLE, NULL };
-
-static void
-init_business_sql(void)
-{
-    /* Initialize our pointers into the backend subsystem */
-    gnc_address_sql_initialize();
-    gnc_billterm_sql_initialize();
-    gnc_customer_sql_initialize();
-    gnc_employee_sql_initialize();
-    gnc_entry_sql_initialize();
-    gnc_invoice_sql_initialize();
-    gnc_job_sql_initialize();
-    gnc_order_sql_initialize();
-    gnc_owner_sql_initialize();
-    gnc_taxtable_sql_initialize();
-    gnc_vendor_sql_initialize();
-
-    gnc_sql_set_load_order( fixed_load_order );
-}
-
-int main (int argc, char ** argv)
-{
-    gchar* filename;
-    QofSession* session_1;
-
-    qof_init();
-    cashobjects_register();
-    qof_load_backend_library ("../../../../backend/dbi/.libs/", GNC_LIB_NAME);
-    init_business_sql();
-
-    // Create a session with data
-    session_1 = create_session();
-    filename = tempnam( "/tmp", "test-sqlite3-" );
-    printf( "Using filename: %s\n", filename );
-    test_dbi_business_store_and_reload( "sqlite3", session_1, filename );
-#if 0
-    printf( "TEST_MYSQL_URL='%s'\n", TEST_MYSQL_URL );
-    if ( strlen( TEST_MYSQL_URL ) > 0 )
-    {
-        session_1 = create_session();
-        test_dbi_store_and_reload( "mysql", session_1, TEST_MYSQL_URL );
-    }
-    printf( "TEST_PGSQL_URL='%s'\n", TEST_PGSQL_URL );
-    if ( strlen( TEST_PGSQL_URL ) > 0 )
-    {
-        session_1 = create_session();
-        test_dbi_store_and_reload( "pgsql", session_1, TEST_PGSQL_URL );
-    }
-#endif
-    print_test_results();
-    qof_close();
-    exit(get_rv());
-}
-

Modified: gnucash/trunk/src/business/business-gnome/business-gnome.scm
===================================================================
--- gnucash/trunk/src/business/business-gnome/business-gnome.scm	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/business/business-gnome/business-gnome.scm	2010-07-14 19:39:19 UTC (rev 19364)
@@ -5,7 +5,6 @@
 (gnc:module-load "gnucash/business-core" 0)
 (gnc:module-load "gnucash/business-utils" 0)
 (gnc:module-load "gnucash/gnome-search" 0)
-(gnc:module-load "gnucash/business-core-sql" 0)
 (gnc:module-load "gnucash/dialog-tax-table" 0)
 
 (gnc:module-load "gnucash/report/report-gnome" 0)

Modified: gnucash/trunk/src/gnc/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/gnc/CMakeLists.txt	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/gnc/CMakeLists.txt	2010-07-14 19:39:19 UTC (rev 19364)
@@ -98,7 +98,6 @@
 TARGET_LINK_LIBRARIES (cutecash gnc-backend-xml)
 TARGET_LINK_LIBRARIES (cutecash app-utils calculation)
 IF (WITH_SQL)
-  TARGET_LINK_LIBRARIES (cutecash gnc-business-backend-sql)
   TARGET_LINK_LIBRARIES (cutecash gnc-backend-dbi gnc-backend-sql)
   TARGET_LINK_LIBRARIES (cutecash ${LIBDBI_LIBRARY})
 ENDIF (WITH_SQL)

Modified: gnucash/trunk/src/optional/python-bindings/gnucash_core.i
===================================================================
--- gnucash/trunk/src/optional/python-bindings/gnucash_core.i	2010-07-13 09:56:24 UTC (rev 19363)
+++ gnucash/trunk/src/optional/python-bindings/gnucash_core.i	2010-07-14 19:39:19 UTC (rev 19364)
@@ -40,7 +40,6 @@
 #include "engine/gnc-engine.h"
 #include "backend/xml/gnc-backend-xml.h"
 #include "backend/dbi/gnc-backend-dbi.h"
-#include "sql/gncmod-business-backend-sql.h"
 #include "Transaction.h"
 #include "Split.h"
 #include "Account.h"
@@ -186,5 +185,4 @@
 
 gnc_module_init_backend_xml();
 gnc_module_init_backend_dbi();
-gnc_module_init_business_core_sql_init();
 %}



More information about the gnucash-changes mailing list