r15094 - gnucash/branches/gda-dev - Initial commit of initial gda backend framework. See GDA_STATUS.

Phil Longstaff plongstaff at cvs.gnucash.org
Tue Nov 7 10:56:42 EST 2006


Author: plongstaff
Date: 2006-11-07 10:56:39 -0500 (Tue, 07 Nov 2006)
New Revision: 15094
Trac: http://svn.gnucash.org/trac/changeset/15094

Added:
   gnucash/branches/gda-dev/GDA_STATUS
   gnucash/branches/gda-dev/src/backend/gda/
   gnucash/branches/gda-dev/src/backend/gda/Makefile.am
   gnucash/branches/gda-dev/src/backend/gda/ddl/
   gnucash/branches/gda-dev/src/backend/gda/ddl/accounts.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/books.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/budgets.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/business.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/commodities.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/freq_specs.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/gnucash.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/lots.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/prices.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/sched_transactions.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/slots.ddl
   gnucash/branches/gda-dev/src/backend/gda/ddl/transactions.ddl
   gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.h
   gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h
   gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.h
   gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.h
   gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.h
   gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.h
   gnucash/branches/gda-dev/src/backend/gda/gncmod-backend-gda.c
Modified:
   gnucash/branches/gda-dev/configure.in
   gnucash/branches/gda-dev/src/engine/gnc-engine.c
   gnucash/branches/gda-dev/src/engine/gnc-filepath-utils.c
Log:
Initial commit of initial gda backend framework.  See GDA_STATUS.



Added: gnucash/branches/gda-dev/GDA_STATUS
===================================================================
--- gnucash/branches/gda-dev/GDA_STATUS	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/GDA_STATUS	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,23 @@
+GDA backend status - Nov 7, 2006
+
+Building:
+- I am currently building with libgda 1.99.1 installed in /opt/libgda-1.99.1.
+This location is hard wired into src/backend/gda/Makefile.am as LIBGDA_DIR
+
+Execution:
+- A basic GDA backend framework now exists.  This framework accepts URLs of
+the form gda://DSN:USERNAME:PASSWORD.  "gda" is required.  "DSN" represents
+a dataset configured in ~/.libgda/config.  USERNAME and PASSWORD are not
+required but can be specified.
+
+- The backend assumes that the database already exists and tables are set up
+according to src/backend/gda/ddl/gnucash.ddl.  Note that
+src/backend/gda/ddl/business.ddl has not been tried yet, so there are no
+guarantees that any database will accept it.
+
+- The backend will save commodities and load them on startup.  However, they
+will not have the correct GUIDs.
+
+- The backend will save accounts and load them on startup.  Any information
+in slots is not saved or loaded.  Also, because of the commodity GUID issue
+above, accounts will not have the correct commodity.

Modified: gnucash/branches/gda-dev/configure.in
===================================================================
--- gnucash/branches/gda-dev/configure.in	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/configure.in	2006-11-07 15:56:39 UTC (rev 15094)
@@ -2153,6 +2153,7 @@
           src/backend/file/test/Makefile
           src/backend/file/test/test-files/Makefile
           src/backend/file/test/test-files/xml2/Makefile
+		  src/backend/gda/Makefile
           src/backend/postgres/Makefile
           src/backend/postgres/test/Makefile
           src/bin/Makefile

Added: gnucash/branches/gda-dev/src/backend/gda/Makefile.am
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/Makefile.am	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/Makefile.am	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,46 @@
+SUBDIRS = .
+
+# Now a shared library AND a GModule
+lib_LTLIBRARIES = libgnc-backend-gda.la
+
+LIBGDA_DIR = /opt/libgda-1.99.1
+
+AM_CFLAGS = \
+  -I.. -I../.. \
+  -DLOCALE_DIR=\""$(datadir)/locale"\" \
+  -I${top_srcdir}/src/backend \
+  -I${top_srcdir}/src/engine \
+  -I${top_srcdir}/src/core-utils\
+  -I${top_srcdir}/lib/libc\
+  ${QOF_CFLAGS} \
+  ${GLIB_CFLAGS} \
+  ${GCONF_CFLAGS} \
+  -I/usr/include/libxml2 -I$(LIBGDA_DIR)
+
+libgnc_backend_gda_la_SOURCES = \
+  gnc-backend-gda.c \
+  gnc-account-gda.c \
+  gnc-budget-gda.c \
+  gnc-commodity-gda.c \
+  gnc-price-gda.c \
+  gnc-transaction-gda.c
+
+#noinst_HEADERS = \
+#  gnc-backend-file.h \
+#  gnc-xml.h \
+#  gnc-xml-helper.h \
+#  io-example-account.h \
+#  io-gncxml-gen.h \
+#  io-gncxml.h \
+#  io-gncxml-v2.h \
+#  io-utils.h \
+#  sixtp-dom-generators.h \
+#  sixtp-dom-parsers.h \
+#  sixtp.h \
+#  sixtp-parsers.h \
+#  sixtp-stack.h \
+#  sixtp-utils.h
+
+libgnc_backend_gda_la_LDFLAGS = -module -avoid-version
+libgnc_backend_gda_la_LIBADD = \
+	-L$(LIBGDA_DIR) -lgda-3 -lgda_handlers-3 -lgda_sql_delimiter-3 -lglib-2.0 -lxslt -lxml2 -lz -lm

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/accounts.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/accounts.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/accounts.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,15 @@
+CREATE TABLE accounts (
+	guid char(32) NOT NULL,
+	name varchar(50) NOT NULL,
+	account_type_id int NOT NULL,
+	commodity_guid char(32) NOT NULL,
+	parent_guid char(32),
+	code varchar(50),
+	description varchar(500),
+
+	PRIMARY KEY(guid),
+	CONSTRAINT c_account_parent
+			FOREIGN KEY(parent_guid) REFERENCES accounts(guid),
+	CONSTRAINT c_account_commodity
+			FOREIGN KEY(commodity_guid) REFERENCES commodities(guid)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/books.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/books.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/books.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,6 @@
+CREATE TABLE books (
+	guid char(32) NOT NULL,
+	is_open boolean,
+
+	PRIMARY KEY(guid)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/budgets.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/budgets.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/budgets.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,11 @@
+CREATE TABLE budgets (
+	guid char(32) NOT NULL,
+	name text NOT NULL,
+	description text,
+	num_periods int NOT NULL,
+	recur_mult int NOT NULL,
+	recur_type int NOT NULL,
+	recur_date date NOT NULL,
+	
+	PRIMARY KEY(guid)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/business.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/business.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/business.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,206 @@
+CREATE TABLE addresses (
+	address_id int NOT NULL,
+	name text NOT NULL,
+	addr1 text,
+	addr2 text,
+	addr3 text,
+	addr4 text,
+	phone text,
+	fax text,
+	email text,
+
+#	slots ???
+
+	PRIMARY KEY(address_id)
+);
+
+CREATE TABLE billterms (
+	billterm_id int NOT NULL,
+	guid_1 int NOT NULL,
+	guid_2 int NOT NULL,
+	guid_3 int NOT NULL,
+	guid_4 int NOT NULL,
+	name text,
+	desc text,
+	refcount int,
+	invisible int
+	parent_billterm_id int,
+	child_billterm_id int,
+	type int,
+	duedays int,
+	discdays int,
+	discount_num int,
+	discount_denom int,
+	prox_cutoff int,
+
+#	slots ???
+
+	PRIMARY KEY(billterm_id),
+	CONSTRAINT FOREIGN KEY(parent_billterm_id) REFERENCES billterms(billterm_id),
+	CONSTRAINT FOREIGN KEY(child_billterm_id) REFERENCES billterms(billterm_id)
+);
+
+CREATE TABLE customers (
+	customer_id int NOT NULL,
+	guid_1 int NOT NULL,
+	guid_2 int NOT NULL,
+	guid_3 int NOT NULL,
+	guid_4 int NOT NULL,
+	name text,
+	id text,
+	address --,
+	shipaddress --,
+	notes text,
+	terms_id int,
+	tax_included text,
+	active int,
+	discount_num int,
+	discount_denom int,
+	credit_num int,
+	credit_denom int,
+	currency_id int,
+	taxtable_override int,
+
+#	slots ???
+
+	PRIMARY KEY(customer_id),
+	CONSTRAINT FOREIGN KEY(currency_id) REFERENCES currencies(currency_id),
+	CONSTRAINT FOREIGN KEY(terms_id) REFERENCES billterms(billterm_id)
+);
+
+CREATE TABLE invoices (
+	invoice_id int NOT NULL,
+	guid_1 int NOT NULL,
+	guid_2 int NOT NULL,
+	guid_3 int NOT NULL,
+	guid_4 int NOT NULL,
+	id text,
+	owner ???
+	opened_date date,
+	posted_date date,
+	terms_id int,
+	billing_id text,
+	notes text,
+	active int,
+	posttxn_id int,
+	postlot_id int,
+	postacc_id int,
+	currency_id int,
+	bill_to ???
+	to_charge_num int,
+	to_charge_denom int,
+
+	PRIMARY KEY(invoice_id),
+	CONSTRAINT FOREIGN KEY(terms_id) REFERENCES billterms(billterm_id),
+	CONSTRAINT FOREIGN KEY(posttxn_id) REFERENCES transactions(trans_id),
+	CONSTRAINT FOREIGN KEY(postlot_id) REFERENCES lots(lot_id),
+	CONSTRAINT FOREIGN KEY(postacc_id) REFERENCES accounts(account_id),
+	CONSTRAINT FOREIGN KEY(currency_id) REFERENCES currencies(currency_id)
+);
+
+CREATE TABLE jobs (
+	job_id int NOT NULL,
+	guid_1 int NOT NULL,
+	guid_2 int NOT NULL,
+	guid_3 int NOT NULL,
+	guid_4 int NOT NULL,
+	id text,
+	name text,
+	reference text,
+	owner ???
+	active int,
+
+	PRIMARY KEY(job_id)
+);
+
+CREATE TABLE employees (
+	employee_id int NOT NULL,
+	guid_1 int NOT NULL,
+	guid_2 int NOT NULL,
+	guid_3 int NOT NULL,
+	guid_4 int NOT NULL,
+	username text,
+	id text,
+	address --,
+	language text,
+	acl text,
+	active int,
+	workday_num int,
+	workday_denom int,
+	rate_num int,
+	rate_denom int,
+	currency_id int,
+
+#	ccard ??? - it's a guid
+
+	PRIMARY KEY(customer_id),
+	CONSTRAINT FOREIGN KEY(currency_id) REFERENCES currencies(currency_id)
+);
+
+CREATE TABLE orders (
+	order_id int NOT NULL,
+	guid_1 int NOT NULL,
+	guid_2 int NOT NULL,
+	guid_3 int NOT NULL,
+	guid_4 int NOT NULL,
+	id text,
+	owner ???
+	date_opened date,
+	date_closed date,
+	notes text,
+	reference text,
+	active int,
+
+	PRIMARY KEY(order_id)
+);
+
+CREATE TABLE taxtables (
+	taxtable_id int NOT NULL,
+	guid_1 int NOT NULL,
+	guid_2 int NOT NULL,
+	guid_3 int NOT NULL,
+	guid_4 int NOT NULL,
+	name text,
+	refcount int,
+	invisible int,
+	parent_id int,
+	child_id int,
+
+	PRIMARY KEY(taxtable_id),
+	CONSTRAINT FOREIGN KEY(parent_id) REFERENCES taxtables(taxtable_id),
+	CONSTRAINT FOREIGN KEY(child_id) REFERENCES taxtables(taxtable_id)
+);
+
+CREATE TABLE taxtable_entries (
+	tt_entry_id int NOT NULL,
+	account_id int,
+	amount_num int,
+	amount_denom int,
+	type text,
+
+	PRIMARY KEY(tt_entry_id),
+	CONSTRAINT FOREIGN KEY(account_id) REFERENCES accounts(account_id)
+);
+
+CREATE TABLE vendors (
+	vendor_id int NOT NULL,
+	guid_1 int NOT NULL,
+	guid_2 int NOT NULL,
+	guid_3 int NOT NULL,
+	guid_4 int NOT NULL,
+	name text,
+	id text,
+	address --,
+	notes text,
+	terms_id int,
+	taxincluded text,
+	active int,
+	currency_id,
+	taxtable_override int,
+	taxtable_id int,
+
+	PRIMARY KEY(vendor_id),
+	CONSTRAINT FOREIGN KEY(terms_id) REFERENCES billterms(billterm_id),
+	CONSTRAINT FOREIGN KEY(currency_id) REFERENCES currencies(currency_id),
+	CONSTRAINT FOREIGN KEY(taxtable_id) REFERENCES taxtables(taxtable_id)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/commodities.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/commodities.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/commodities.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,16 @@
+-- Commodities table - stores currencies and stocks/mutual funds
+CREATE TABLE commodities (
+	guid char(32) NOT NULL,
+
+	namespace varchar(40) NOT NULL,
+	mnemonic varchar(40) NOT NULL,
+
+	fullname varchar(40),
+	cusip varchar(40),
+	fraction int,
+	use_quote_source int,
+	quote_source varchar(40),
+	quote_tz varchar(40),
+
+	PRIMARY KEY(guid)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/freq_specs.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/freq_specs.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/freq_specs.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,16 @@
+CREATE TABLE freq_specs (
+	guid char(32) NOT NULL,
+
+	fs_type int,
+	fs_interval int,
+	fs_offset int,
+	day int,
+	occurrence int,
+
+-- Parent used for composite fs's
+	parent_guid char(32),
+
+	PRIMARY KEY(guid),
+	CONSTRAINT c_fs_parent
+			FOREIGN KEY(parent_guid) REFERENCES freq_specs(guid)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/gnucash.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/gnucash.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/gnucash.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,10 @@
+source commodities.ddl
+source slots.ddl
+source accounts.ddl
+source lots.ddl
+source budgets.ddl
+source prices.ddl
+source freq_specs.ddl
+source sched_transactions.ddl
+source transactions.ddl
+source books.ddl

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/lots.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/lots.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/lots.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,10 @@
+-- Lots are tied to accounts.  The contents are slots
+CREATE TABLE lots (
+	guid char(32) NOT NULL,
+
+	account_guid char(32) NOT NULL,
+
+	PRIMARY KEY(guid),
+	CONSTRAINT c_lot_account
+			FOREIGN KEY(account_guid) REFERENCES accounts(guid)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/prices.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/prices.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/prices.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,16 @@
+CREATE TABLE prices (
+	guid char(32) NOT NULL,
+	commodity_guid char(32) NOT NULL,
+	currency_guid char(32) NOT NULL,
+	time date NOT NULL,
+	source text,
+	type text,
+	value_num int,
+	value_denom int,
+
+	PRIMARY KEY(guid),
+	CONSTRAINT c_price_commodity
+			FOREIGN KEY(commodity_guid) REFERENCES commodities(guid),
+	CONSTRAINT c_price_currency
+			FOREIGN KEY(currency_guid) REFERENCES commodities(guid)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/sched_transactions.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/sched_transactions.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/sched_transactions.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,47 @@
+CREATE TABLE sched_transactions (
+	sched_tx_guid char(32) NOT NULL,
+	name text NOT NULL,
+	autocreate boolean,
+	notify boolean,
+	create_days_in_advance int,
+	remind_days_in_advance int,
+	instance_count int,
+	start_date date,
+	last_occur_date date,
+	num_occur int,
+	rem_occur int,
+	end_date date,
+
+	fs_guid char(32),
+
+	PRIMARY KEY(sched_tx_guid),
+	CONSTRAINT c_sx_fs
+			FOREIGN KEY(fs_guid) REFERENCES freq_specs(guid)
+);
+
+CREATE TABLE sched_tx_deferred_instances (
+	id int NOT NULL,
+	sched_tx_guid char(32) NOT NULL,
+	last_date date,
+	num_occur_rem int,
+	num_inst int,
+
+	PRIMARY KEY(id),
+	CONSTRAINT c_sx_instance_tx
+			FOREIGN KEY(sched_tx_guid) REFERENCES sched_transactions(sched_tx_guid)
+);
+
+CREATE TABLE sched_tx_splits (
+	sched_tx_split_id int NOT NULL,
+	sched_tx_guid char(32) NOT NULL,
+	memo text,
+	action text,
+	account_guid char(32) NOT NULL,
+	value text,
+
+	PRIMARY KEY(sched_tx_split_id),
+	CONSTRAINT c_sx_split_tx
+			FOREIGN KEY(sched_tx_guid) REFERENCES sched_transactions(sched_tx_guid),
+	CONSTRAINT c_sx_split_account
+			FOREIGN KEY(account_guid) REFERENCES accounts(guid)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/slots.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/slots.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/slots.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,23 @@
+-- Slots table to store all slots
+CREATE TABLE slots (
+	slot_id int NOT NULL,
+
+	-- What type of object, and what guid, does this slot belong to
+	object_type int NOT NULL,
+	obj_guid char(32) NOT NULL,
+
+	-- Full name
+	name text NOT NULL,
+
+	-- Slot type and value.
+	slot_type int NOT NULL,
+	int64_val bigint,
+	string_val text,
+	timespec_val date,
+	guid_val char(32),
+	num_val_num int,
+	num_val_denom int,
+	double_val double precision,
+
+	PRIMARY KEY(slot_id)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/ddl/transactions.ddl
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/ddl/transactions.ddl	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/ddl/transactions.ddl	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,36 @@
+CREATE TABLE transactions (
+	guid char(32) NOT NULL,
+	currency_guid char(32) NOT NULL,
+	num text,
+	post_date date,
+	enter_date date,
+	description text,
+
+	PRIMARY KEY(guid),
+	CONSTRAINT c_tx_currency
+			FOREIGN KEY(currency_guid) REFERENCES commodities(guid)
+);
+
+CREATE TABLE splits (
+	guid char(32) NOT NULL,
+	tx_guid char(32) NOT NULL,
+	memo text,
+	action text,
+	reconcile_state char NOT NULL,
+	reconcile_date date,
+	value_num int NOT NULL,
+	value_denom int NOT NULL,
+	quantity_num int NOT NULL,
+	quantity_denom int NOT NULL,
+	account_guid char(32) NOT NULL,
+
+	lot_guid char(32),
+
+	PRIMARY KEY(guid),
+	CONSTRAINT c_split_tx
+			FOREIGN KEY(tx_guid) REFERENCES transactions(guid),
+	CONSTRAINT c_split_account
+			FOREIGN KEY(account_guid) REFERENCES accounts(guid),
+	CONSTRAINT c_split_lot
+			FOREIGN KEY(lot_guid) REFERENCES lots(guid)
+);

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,265 @@
+/********************************************************************
+ * gnc-account-gda.c: load and save data to SQL via libgda          *
+ *                                                                  *
+ * 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-account-gda.c
+ *  @brief load and save data to SQL 
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL db using libgda
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <libintl.h>
+#include <locale.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <dirent.h>
+#include <time.h>
+#include <libgda/libgda.h>
+
+#include "qof.h"
+#include "qofquery-p.h"
+#include "qofquerycore-p.h"
+#include "TransLog.h"
+#include "gnc-engine.h"
+#include "Group.h"
+#include "AccountP.h"
+
+#include "gnc-filepath-utils.h"
+
+#include "gnc-backend-gda.h"
+#include "gnc-gconf-utils.h"
+
+#include "gnc-account-gda.h"
+
+#ifndef HAVE_STRPTIME
+# include "strptime.h"
+#endif
+
+/* callback structure */
+typedef struct {
+	gboolean ok;
+	GdaConnection* pConnection;
+	QofInstance* inst;
+} gda_backend;
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+/* ================================================================= */
+static Account*
+load_account( QofBook* pBook, GdaDataModel* pModel, int row )
+{
+	int numCols = gda_data_model_get_n_columns( pModel );
+	int col;
+	const GValue* val;
+	Account* pAccount;
+	GUID guid;
+	const char* name = NULL;
+	int type = ACCT_TYPE_INVALID;
+	GUID commodity_guid;
+	GUID parent_guid;
+	Account* pParent = NULL;
+	const char* code = NULL;
+	const char* description = NULL;
+	const char* s;
+	gnc_commodity* pCommodity;
+
+	for( col = 0; col < numCols; col++ ) {
+		val = gda_data_model_get_value_at( pModel, col, row );
+		
+		switch( col ) {
+			case 0:	/* guid */
+				s = g_value_get_string( val );
+				string_to_guid( s, &guid );
+				break;
+			case 1: /* name */
+				name = g_value_get_string( val );
+				break;
+			case 2: /* type */
+				type = g_value_get_int( val );
+				break;
+			case 3: /* commodity_guid */
+				s = g_value_get_string( val );
+				string_to_guid( s, &commodity_guid );
+				pCommodity = gnc_commodity_find_commodity_by_guid( &commodity_guid, pBook );
+				break;
+			case 4: /* parent_guid */
+				s = g_value_get_string( val );
+				string_to_guid( s, &parent_guid );
+				pParent = xaccAccountLookup( &parent_guid, pBook );
+				break;
+			case 5: /* code */
+				code = g_value_get_string( val );
+				break;
+			case 6: /* description */
+				description = g_value_get_string( val );
+				break;
+			default:	/* too many cols */
+				*(char*)0 = 0;
+		}
+	}
+
+	pAccount = xaccMallocAccount( pBook );
+	xaccAccountSetGUID( pAccount, &guid );
+	xaccAccountSetName( pAccount, name );
+	xaccAccountSetType( pAccount, type );
+	xaccAccountSetCode( pAccount, code );
+	xaccAccountSetDescription( pAccount, description );
+	xaccAccountSetCommodity( pAccount, pCommodity );
+
+	if( pParent != NULL ) {
+		xaccAccountInsertSubAccount( pParent, pAccount );
+	}
+
+	return pAccount;
+}
+
+static void
+load_accounts( GncGdaBackend* be, QofBook* pBook )
+{
+	GError* error = NULL;
+
+	GdaQuery* query;
+	GdaObject* ret;
+	gnc_commodity_table* pTable = gnc_commodity_table_get_table( pBook );
+
+	query = gda_query_new_from_sql( be->pDict, "SELECT * FROM accounts", &error );
+	if( query == NULL ) {
+		printf( "SQL error: %s\n", error->message );
+		return;
+	}
+	error = NULL;
+	ret = gda_query_execute( query, NULL, FALSE, &error );
+
+	if( error != NULL ) {
+		printf( "SQL error: %s\n", error->message );
+	}
+	if( GDA_IS_DATA_MODEL( ret ) ) {
+		GdaDataModel* pModel = (GdaDataModel*)ret;
+		int numRows = gda_data_model_get_n_rows( pModel );
+		int r;
+		Account* pAccount;
+
+		for( r = 0; r < numRows; r++ ) {
+
+			pAccount = load_account( pBook, pModel, r );
+
+			if( pAccount != NULL ) {
+				if( xaccAccountGetParent( pAccount ) == NULL ) {
+        			xaccGroupInsertAccount(
+									gnc_book_get_group( pBook ),
+									pAccount );
+				}
+			}
+		}
+	}
+}
+
+/* ================================================================= */
+static gboolean
+account_exists_in_db( GncGdaBackend* be, const char* guid )
+{
+	char cmdbuf[400];
+	int count;
+
+	sprintf( cmdbuf, "SELECT * FROM accounts WHERE guid='%s';", guid );
+	count = gnc_gda_execute_select_get_count( be, cmdbuf );
+	if( count == 0 ) {
+		return FALSE;
+	} else {
+		return TRUE;
+	}
+}
+
+static void
+commit_account( GncGdaBackend* be, QofInstance* inst )
+{
+	Account* pAcc = (Account*)inst;
+	Account* pParent = xaccAccountGetParentAccount( pAcc );
+	gnc_commodity* c;
+	const GUID* guid = xaccAccountGetGUID( pAcc );
+	char guid_buf[GUID_ENCODING_LENGTH+1];
+	char commodity_guid_buf[GUID_ENCODING_LENGTH+1];
+	const GUID* parent_guid;
+	char parent_guid_buf[GUID_ENCODING_LENGTH+1];
+	char cmdbuf[300];
+	const char* name = xaccAccountGetName(pAcc);
+	const char* code = xaccAccountGetCode(pAcc);
+	const char* description = xaccAccountGetDescription(pAcc);
+	GNCAccountType type = xaccAccountGetType(pAcc);
+
+	c = xaccAccountGetCommodity(pAcc);
+
+	(void)guid_to_string_buff( guid, guid_buf );
+	(void)guid_to_string_buff( qof_instance_get_guid( (QofInstance*)c ),
+								commodity_guid_buf );
+	if( pParent == NULL ) {
+		parent_guid_buf[0] = '\0';
+	} else {
+		parent_guid = xaccAccountGetGUID( pParent );
+		(void)guid_to_string_buff( parent_guid, parent_guid_buf );
+	}
+
+	if( inst->do_free ) {
+		sprintf( cmdbuf, "DELETE FROM accounts WHERE guid='%s';", guid_buf );
+		printf( "%s\n", cmdbuf );
+		gnc_gda_execute_sql( be, cmdbuf );
+	} else {
+		if( account_exists_in_db( be, guid_buf ) ) {
+			sprintf( cmdbuf, "UPDATE accounts set name='%s',account_type_id=%d,commodity_guid='%s',parent_guid='%s',code='%s',description='%s' WHERE guid='%s';\n",
+				name, type, commodity_guid_buf, parent_guid_buf, code, description,
+				guid_buf );
+		} else {
+			sprintf( cmdbuf, "INSERT INTO accounts VALUES('%s','%s',%d,'%s','%s','%s','%s');\n",
+				guid_buf,name, type, commodity_guid_buf, parent_guid_buf, code, description );
+		}
+		printf( "%s\n", cmdbuf );
+		gnc_gda_execute_sql( be, cmdbuf );
+	}
+}
+
+/* ================================================================= */
+void
+gnc_gda_init_account_handler( void )
+{
+	static GncGdaDataType_t be_data =
+	{
+		GNC_GDA_BACKEND_VERSION,
+		GNC_ID_ACCOUNT,
+		commit_account,				/* commit */
+		load_accounts				/* initial_load */
+	};
+
+	qof_object_register_backend( GNC_ID_ACCOUNT, GNC_GDA_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.h	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.h	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,40 @@
+/********************************************************************
+ * gnc-account-gda.h: load and save data to SQL via libgda          *
+ *                                                                  *
+ * 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-account-gda.h
+ *  @brief load and save accounts data to SQL via libgda
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_ACCOUNT_GDA_H_
+#define GNC_ACCOUNT_GDA_H_
+
+#include "qof.h"
+#include <gmodule.h>
+
+void gnc_gda_init_account_handler( void );
+
+#endif /* GNC_ACCOUNT_GDA_H_ */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,565 @@
+/********************************************************************
+ * gnc-backend-gda.c: load and save data to SQL via libgda          *
+ *                                                                  *
+ * 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-backend-gda.c
+ *  @brief load and save data to SQL 
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL db using libgda
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <libintl.h>
+#include <locale.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <dirent.h>
+#include <time.h>
+#include <libgda/libgda.h>
+
+#include "qof.h"
+#include "qofquery-p.h"
+#include "qofquerycore-p.h"
+#include "TransLog.h"
+#include "gnc-engine.h"
+
+#include "gnc-filepath-utils.h"
+
+#include "gnc-backend-gda.h"
+#include "gnc-gconf-utils.h"
+
+#include "gnc-account-gda.h"
+#include "gnc-budget-gda.h"
+#include "gnc-commodity-gda.h"
+#include "gnc-price-gda.h"
+#include "gnc-transaction-gda.h"
+
+#ifndef HAVE_STRPTIME
+# include "strptime.h"
+#endif
+
+static const gchar* convert_search_obj( QofIdType objType );
+
+/* callback structure */
+typedef struct {
+	gboolean ok;
+	GncGdaBackend* be;
+	QofInstance* inst;
+	QofBook* book;
+} gda_backend;
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+/* ================================================================= */
+void
+gnc_gda_execute_sql( GncGdaBackend* be, const char* sql )
+{
+	GError* error = NULL;
+
+	GdaQuery* query;
+	GdaObject* ret;
+
+	query = gda_query_new_from_sql( be->pDict, sql, &error );
+	if( query == NULL ) {
+		printf( "SQL error: %s\n", error->message );
+		return;
+	}
+	error = NULL;
+	ret = gda_query_execute( query, NULL, FALSE, &error );
+
+	if( error != NULL ) {
+		printf( "SQL error: %s\n", error->message );
+	}
+}
+
+int
+gnc_gda_execute_select_get_count( GncGdaBackend* be, const char* sql )
+{
+	GError* error = NULL;
+	int count = 0;
+
+	GdaQuery* query;
+	GdaObject* ret;
+
+	query = gda_query_new_from_sql( be->pDict, sql, &error );
+	if( query == NULL ) {
+		printf( "SQL error: %s\n", error->message );
+		return 0;
+	}
+	error = NULL;
+	ret = gda_query_execute( query, NULL, FALSE, &error );
+	if( GDA_IS_DATA_MODEL(ret) ) {
+		GdaDataModel* pModel = (GdaDataModel*)ret;
+		count = gda_data_model_get_n_rows( pModel );
+	}
+
+	if( error != NULL ) {
+		printf( "SQL error: %s\n", error->message );
+	}
+
+	return count;
+}
+/* ================================================================= */
+
+static void
+gnc_gda_session_begin(QofBackend *be_start, QofSession *session, 
+                   const char *book_id,
+                   gboolean ignore_lock, gboolean create_if_nonexistent)
+{
+    GncGdaBackend *be = (GncGdaBackend*) be_start;
+	GError* error = NULL;
+	gda_backend be_data;
+	char book_info[300];
+	char* dsn;
+	char* username;
+	char* password;
+
+    ENTER (" ");
+
+	be->pClient = gda_client_new();
+
+	/* Split book_id into provider and connection string */
+	strcpy( book_info, book_id );
+	dsn = strchr( book_info, ':' );
+	*dsn = '\0';
+	dsn += 3;
+	username = strchr( dsn, ':' );
+	if( username != NULL ) {
+		*username++ = '\0';
+	} else {
+		username = "";
+	}
+	password = strchr( username, ':' );
+	if( password != NULL ) {
+		*password++ = '\0';
+	} else {
+		password = "";
+	}
+
+	be->pConnection = gda_client_open_connection( be->pClient,
+						dsn,
+						username, password,
+						0,
+						&error );
+
+	if( be->pConnection == NULL ) {
+		printf( "SQL error: %s\n", error->message );
+		qof_backend_set_error( be_start, ERR_BACKEND_NO_SUCH_DB );
+		return;
+	}
+
+	be->pDict = gda_dict_new();
+	gda_dict_set_connection( be->pDict, be->pConnection );
+	gda_dict_update_dbms_meta_data( be->pDict, 0, NULL, &error );
+	if( error != NULL ) {
+		printf( "SQL error: %s\n", error->message );
+	}
+
+    LEAVE (" ");
+}
+
+/* ================================================================= */
+
+static void
+gnc_gda_session_end(QofBackend *be_start)
+{
+    GncGdaBackend *be = (GncGdaBackend*)be_start;
+    ENTER (" ");
+
+	if( be->pDict != NULL ) {
+		g_object_unref( G_OBJECT(be->pDict) );
+		be->pDict = NULL;
+	}
+	if( be->pConnection != NULL && gda_connection_is_opened( be->pConnection ) ) {
+		gda_connection_close( be->pConnection );
+	}
+	be->pConnection = NULL;
+	if( be->pClient != NULL ) {
+		g_object_unref( G_OBJECT(be->pClient ) );
+		be->pClient = NULL;
+	}
+
+    LEAVE (" ");
+}
+
+static void
+gnc_gda_destroy_backend(QofBackend *be)
+{
+    g_free(be);
+}
+
+/* ================================================================= */
+
+static void
+initial_load_cb( const char* type, gpointer data_p, gpointer be_data_p )
+{
+	GncGdaDataType_t* pData = data_p;
+	gda_backend* be_data = be_data_p;
+
+	g_return_if_fail( type != NULL && pData != NULL && be_data != NULL );
+	g_return_if_fail( pData->version == GNC_GDA_BACKEND_VERSION );
+
+	if( pData->initial_load != NULL ) {
+		(pData->initial_load)( be_data->be, be_data->book );
+	}
+}
+
+static void
+gnc_gda_load(QofBackend* be_start, QofBook *book)
+{
+    GncGdaBackend *be = (GncGdaBackend*)be_start;
+	gda_backend be_data;
+
+    ENTER (" ");
+
+	/* Load any initial stuff */
+	be->loading = TRUE;
+
+	be_data.ok = FALSE;
+	be_data.be = be;
+	be_data.inst = NULL;
+	be_data.book = book;
+	qof_object_foreach_backend( GNC_GDA_BACKEND, initial_load_cb, &be_data );
+
+	be->loading = FALSE;
+
+	LEAVE( "" );
+}
+
+/* ================================================================= */
+
+static void
+gnc_gda_sync_all(QofBackend* be, QofBook *book)
+{
+    GncGdaBackend *fbe = (GncGdaBackend *) be;
+    ENTER ("book=%p, primary=%p", book, fbe->primary_book);
+
+    LEAVE ("book=%p", book);
+}
+
+/* ================================================================= */
+/* Routines to deal with the creation of multiple books. */
+
+
+static void
+gnc_gda_begin_edit (QofBackend *be, QofInstance *inst)
+{
+}
+
+static void
+gnc_gda_rollback_edit (QofBackend *be, QofInstance *inst)
+{
+}
+
+static void
+commit_cb( const char* type, gpointer data_p, gpointer be_data_p )
+{
+	GncGdaDataType_t* pData = data_p;
+	gda_backend* be_data = be_data_p;
+
+	g_return_if_fail( type != NULL && pData != NULL && be_data != NULL );
+	g_return_if_fail( pData->version == GNC_GDA_BACKEND_VERSION );
+
+	/* If this has already been handled, or is not the correct handler, return */
+	g_return_if_fail( strcmp( pData->type_name, be_data->inst->entity.e_type ) == 0 );
+	g_return_if_fail( !be_data->ok );
+
+	if( pData->commit != NULL ) {
+		(pData->commit)( be_data->be, be_data->inst );
+		be_data->ok = TRUE;
+	}
+}
+
+/* Commit_edit handler - find the correct backend handler for this object
+ * type and call its commit handler
+ */
+static void
+gnc_gda_commit_edit (QofBackend *be_start, QofInstance *inst)
+{
+    GncGdaBackend *be = (GncGdaBackend*)be_start;
+	gda_backend be_data;
+
+	/* During initial load where objects are being created, don't commit
+	anything */
+
+	if( be->loading ) return;
+
+	printf( "gda_commit_edit(): %s dirty = %d, do_free=%d\n", inst->entity.e_type, inst->dirty, inst->do_free );
+
+	if( !inst->dirty ) return;
+
+	be_data.ok = FALSE;
+	be_data.be = be;
+	be_data.inst = inst;
+	qof_object_foreach_backend( GNC_GDA_BACKEND, commit_cb, &be_data );
+
+	if( !be_data.ok ) {
+		*(char*)0 = 0;
+	}
+
+	qof_instance_mark_clean( inst );
+}
+/* ---------------------------------------------------------------------- */
+
+/* Query processing */
+
+static const gchar*
+convert_search_obj( QofIdType objType )
+{
+	return (gchar*)objType;
+}
+
+static void
+handle_and_term( QofQueryTerm* pTerm, char* sql )
+{
+	GSList* pParamPath = qof_query_term_get_param_path( pTerm );
+	QofQueryPredData* pPredData = qof_query_term_get_pred_data( pTerm );
+	gboolean isInverted = qof_query_term_is_inverted( pTerm );
+	GSList* name;
+	char val[33];
+
+	strcat( sql, "(" );
+	if( isInverted ) {
+		strcat( sql, "!" );
+	}
+
+	for( name = pParamPath; name != NULL; name = name->next ) {
+		if( name != pParamPath ) strcat( sql, "." );
+		strcat( sql, name->data );
+	}
+
+	if( pPredData->how == QOF_COMPARE_LT ) {
+		strcat( sql, "<" );
+	} else if( pPredData->how == QOF_COMPARE_LTE ) {
+		strcat( sql, "<=" );
+	} else if( pPredData->how == QOF_COMPARE_EQUAL ) {
+		strcat( sql, "=" );
+	} else if( pPredData->how == QOF_COMPARE_GT ) {
+		strcat( sql, ">" );
+	} else if( pPredData->how == QOF_COMPARE_GTE ) {
+		strcat( sql, ">=" );
+	} else if( pPredData->how == QOF_COMPARE_NEQ ) {
+		strcat( sql, "~=" );
+	} else {
+		strcat( sql, "??" );
+	}
+
+	if( strcmp( pPredData->type_name, "string" ) == 0 ) {
+		query_string_t pData = (query_string_t)pPredData;
+		strcat( sql, "'" );
+		strcat( sql, pData->matchstring );
+		strcat( sql, "'" );
+	} else if( strcmp( pPredData->type_name, "date" ) == 0 ) {
+		query_date_t pData = (query_date_t)pPredData;
+
+		(void)gnc_timespec_to_iso8601_buff( pData->date, val );
+		strcat( sql, "'" );
+		strncat( sql, val, 4+1+2+1+2 );
+		strcat( sql, "'" );
+	} else if( strcmp( pPredData->type_name, "numeric" ) == 0 ) {
+		query_numeric_t pData = (query_numeric_t)pPredData;
+
+		strcat( sql, "numeric" );
+	} else if( strcmp( pPredData->type_name, "guid" ) == 0 ) {
+		query_guid_t pData = (query_guid_t)pPredData;
+		(void)guid_to_string_buff( pData->guids->data, val );
+		strcat( sql, "'" );
+		strcat( sql, val );
+		strcat( sql, "'" );
+	} else if( strcmp( pPredData->type_name, "gint32" ) == 0 ) {
+		query_int32_t pData = (query_int32_t)pPredData;
+
+		sprintf( val, "%d", pData->val );
+		strcat( sql, val );
+	} else if( strcmp( pPredData->type_name, "gint64" ) == 0 ) {
+		query_int64_t pData = (query_int64_t)pPredData;
+
+		sprintf( val, "%lld", pData->val );
+		strcat( sql, val );
+	} else if( strcmp( pPredData->type_name, "double" ) == 0 ) {
+		query_double_t pData = (query_double_t)pPredData;
+
+		sprintf( val, "%f", pData->val );
+		strcat( sql, val );
+	} else if( strcmp( pPredData->type_name, "boolean" ) == 0 ) {
+		query_boolean_t pData = (query_boolean_t)pPredData;
+
+		sprintf( val, "%d", pData->val );
+		strcat( sql, val );
+	} else {
+		*(char*)0 = '\0';
+	}
+
+	strcat( sql, ")" );
+}
+
+static gpointer
+gnc_gda_compile_query(QofBackend* pBEnd, QofQuery* pQuery)
+{
+    GncGdaBackend *be = (GncGdaBackend*)pBEnd;
+	GList* pBookList;
+	QofIdType searchObj;
+	char sql[1000];
+
+	pBookList = qof_query_get_books( pQuery );
+	searchObj = qof_query_get_search_for( pQuery );
+
+	/* Convert search object type to table name */
+	sprintf( sql, "SELECT * from %s", convert_search_obj( searchObj ) );
+	if( !qof_query_has_terms( pQuery ) ) {
+		strcat( sql, ";" );
+	} else {
+		GList* pOrTerms = qof_query_get_terms( pQuery );
+		GList* orTerm;
+
+		strcat( sql, " WHERE " );
+
+		for( orTerm = pOrTerms; orTerm != NULL; orTerm = orTerm->next ) {
+			GList* pAndTerms = (GList*)orTerm->data;
+			GList* andTerm;
+
+			if( orTerm != pOrTerms ) strcat( sql, " OR " );
+			strcat( sql, "(" );
+			for( andTerm = pAndTerms; andTerm != NULL; andTerm = andTerm->next ) {
+				if( andTerm != pAndTerms ) strcat( sql, " AND " );
+				handle_and_term( (QofQueryTerm*)andTerm->data, sql );
+			}
+			strcat( sql, ")" );
+		}
+	}
+
+	printf( "Compiled: %s\n", sql );
+	return g_strdup( sql );
+}
+
+static void
+gnc_gda_free_query(QofBackend* pBEnd, gpointer pQuery)
+{
+    GncGdaBackend *be = (GncGdaBackend*)pBEnd;
+
+	printf( "gda_free_query(): %s\n", (char*)pQuery );
+}
+
+static void
+gnc_gda_run_query(QofBackend* pBEnd, gpointer pQuery)
+{
+    GncGdaBackend *be = (GncGdaBackend*)pBEnd;
+	printf( "gda_run_query(): %s\n", (char*)pQuery );
+}
+
+/* ================================================================= */
+void
+gnc_gda_init_object_handlers( void )
+{
+	gnc_gda_init_commodity_handler();
+	gnc_gda_init_account_handler();
+	gnc_gda_init_budget_handler();
+	gnc_gda_init_price_handler();
+	gnc_gda_init_transaction_handler();
+}
+
+/* ================================================================= */
+
+static QofBackend*
+gnc_gda_backend_new(void)
+{
+	GncGdaBackend *gnc_be;
+	QofBackend *be;
+
+	gnc_be = g_new0(GncGdaBackend, 1);
+	be = (QofBackend*) gnc_be;
+	qof_backend_init(be);
+
+	be->session_begin = gnc_gda_session_begin;
+	be->session_end = gnc_gda_session_end;
+	be->destroy_backend = gnc_gda_destroy_backend;
+
+	be->load = gnc_gda_load;
+	be->save_may_clobber_data = NULL;
+
+	/* The gda backend treats accounting periods transactionally. */
+	be->begin = gnc_gda_begin_edit;
+	be->commit = gnc_gda_commit_edit;
+	be->rollback = gnc_gda_rollback_edit;
+
+	/* The gda backend uses queries to load data ... */
+	be->compile_query = gnc_gda_compile_query;
+	be->free_query = gnc_gda_free_query;
+	be->run_query = gnc_gda_run_query;
+
+	be->counter = NULL;
+
+	/* The gda backend will not be multi-user (for now)... */
+	be->events_pending = NULL;
+	be->process_events = NULL;
+
+	be->sync = gnc_gda_sync_all;
+	be->load_config = NULL;
+	be->get_config = NULL;
+
+    be->export = NULL;
+
+	gnc_be->primary_book = NULL;
+
+	return be;
+}
+
+static void
+gnc_gda_provider_free (QofBackendProvider *prov)
+{
+    prov->provider_name = NULL;
+    prov->access_method = NULL;
+    g_free (prov);
+}
+
+G_MODULE_EXPORT const gchar *
+g_module_check_init(GModule *module)
+{
+	QofBackendProvider *prov;
+
+	prov = g_new0 (QofBackendProvider, 1);
+    prov->provider_name = "GnuCash LibGDA Backend (MySQL)";
+    prov->access_method = "gda";
+    prov->partial_book_supported = FALSE;
+    prov->backend_new = gnc_gda_backend_new;
+    prov->provider_free = gnc_gda_provider_free;
+	prov->check_data_type = NULL;
+    qof_backend_register_provider (prov);
+
+	gda_init( "gnucash", "2.0", 0, NULL );
+
+	gnc_gda_init_object_handlers();
+    return NULL;
+}
+
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,81 @@
+/********************************************************************
+ * gnc-backend-gda.h: load and save data to SQL via libgda          *
+ *                                                                  *
+ * 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-backend-gda.h
+ *  @brief load and save data to SQL via libgda
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_BACKEND_GDA_H_
+#define GNC_BACKEND_GDA_H_
+
+#include "qof.h"
+#include <gmodule.h>
+
+#include "qofbackend-p.h"
+struct GncGdaBackend_struct
+{
+  QofBackend be;
+
+  GdaClient* pClient;
+  GdaConnection* pConnection;
+  GdaDict* pDict;
+
+  QofBook *primary_book;	/* The primary, main open book */
+  gboolean	loading;		/* We are performing an initial load */
+};
+typedef struct GncGdaBackend_struct GncGdaBackend;
+
+/**
+ * Struct used to pass in a new data type for GDA storage.  This contains
+ * the set of callbacks to read and write GDA for new data objects..  New
+ * types should register an instance of this object with the engine.
+ *
+ * commit()			- commit an object to the db
+ * initial_load()	- load stuff when new db opened
+ */
+#define GNC_GDA_BACKEND	"gnc:gda:1"
+#define GNC_GDA_BACKEND_VERSION	1
+typedef struct
+{
+  int		version;	/* backend version number */
+  const char *	type_name;	/* The XML tag for this type */
+
+  void		(*commit)( GncGdaBackend* pBackend, QofInstance* inst );
+  void		(*initial_load)( GncGdaBackend* pBackend, QofBook* pBook );
+} GncGdaDataType_t;
+
+// This is now a static inside the module
+//QofBackend * libgncmod_backend_gda_LTX_gnc_backend_new(void);
+
+void gnc_gda_init_object_handlers( void );
+void gnc_gda_execute_sql( GncGdaBackend* pBackend, const char* sql );
+int gnc_gda_execute_select_get_count( GncGdaBackend* pBackend, const char* sql );
+
+G_MODULE_EXPORT const gchar *
+g_module_check_init(GModule *module);
+
+#endif /* GNC_BACKEND_GDA_H_ */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,81 @@
+/********************************************************************
+ * gnc-budget-gda.c: load and save data to SQL via libgda           *
+ *                                                                  *
+ * 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-budget-gda.c
+ *  @brief load and save data to SQL 
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL db using libgda
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <libintl.h>
+#include <locale.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <dirent.h>
+#include <time.h>
+#include <libgda/libgda.h>
+
+#include "qof.h"
+#include "qofquery-p.h"
+#include "qofquerycore-p.h"
+#include "TransLog.h"
+#include "gnc-engine.h"
+
+#include "gnc-filepath-utils.h"
+
+#include "gnc-backend-gda.h"
+#include "gnc-gconf-utils.h"
+
+#include "gnc-budget-gda.h"
+
+#ifndef HAVE_STRPTIME
+# include "strptime.h"
+#endif
+
+/* callback structure */
+typedef struct {
+	gboolean ok;
+	GdaConnection* pConnection;
+	QofInstance* inst;
+} gda_backend;
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+/* ================================================================= */
+void
+gnc_gda_init_budget_handler( void )
+{
+}
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.h	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.h	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,40 @@
+/********************************************************************
+ * gnc-budget-gda.h: load and save data to SQL via libgda           *
+ *                                                                  *
+ * 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-backend-gda.h
+ *  @brief load and save data to SQL via libgda
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_BUDGET_GDA_H_
+#define GNC_BUDGET_GDA_H_
+
+#include "qof.h"
+#include <gmodule.h>
+
+void gnc_gda_init_budget_handler( void );
+
+#endif /* GNC_BUDGET_GDA_H_ */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,256 @@
+/********************************************************************
+ * gnc-commodity-gda.c: load and save data to SQL via libgda        *
+ *                                                                  *
+ * 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-commodity-gda.c
+ *  @brief load and save data to SQL 
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL db using libgda
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <libintl.h>
+#include <locale.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <dirent.h>
+#include <time.h>
+#include <libgda/libgda.h>
+
+#include "qof.h"
+#include "qofquery-p.h"
+#include "qofquerycore-p.h"
+#include "qofinstance-p.h"
+#include "TransLog.h"
+#include "gnc-engine.h"
+
+#include "gnc-filepath-utils.h"
+
+#include "gnc-backend-gda.h"
+#include "gnc-gconf-utils.h"
+
+#include "gnc-commodity-gda.h"
+
+#ifndef HAVE_STRPTIME
+# include "strptime.h"
+#endif
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+/*
+-- Commodities table - stores currencies and stocks/mutual funds
+CREATE TABLE commodities (
+	guid char(32) NOT NULL,
+
+	namespace text NOT NULL,
+	mnemonic text NOT NULL,
+
+	fullname text,
+	cusip text,
+	fraction int,
+	use_quote_source boolean,
+	quote_source text,
+	quote_tz text,
+
+	PRIMARY KEY(guid)
+);
+*/
+/* ================================================================= */
+static gnc_commodity*
+load_commodity( QofBook* pBook, GdaDataModel* pModel, int row )
+{
+	int numCols = gda_data_model_get_n_columns( pModel );
+	int col;
+	const GValue* val;
+	gnc_commodity* pCommodity;
+	GUID guid;
+	const char* namespace = NULL;
+	const char* mnemonic = NULL;
+	const char* fullname = NULL;
+	const char* cusip = NULL;
+	int fraction = 1;
+	gboolean quote_flag = FALSE;
+	gnc_quote_source* quote_source = NULL;
+	const char* quote_tz = NULL;
+	const char* s;
+
+	for( col = 0; col < numCols; col++ ) {
+		val = gda_data_model_get_value_at( pModel, col, row );
+		
+		switch( col ) {
+			case 0:	/* guid */
+				s = g_value_get_string( val );
+				string_to_guid( s, &guid );
+				break;
+			case 1: /* namespace */
+				namespace = g_value_get_string( val );
+				break;
+			case 2: /* mnemonic */
+				mnemonic = g_value_get_string( val );
+				break;
+			case 3: /* fullname */
+				fullname = g_value_get_string( val );
+				break;
+			case 4: /* cusip */
+				cusip = g_value_get_string( val );
+				break;
+			case 5: /* fraction */
+				fraction = g_value_get_int( val );
+				break;
+			case 6: /* use_quote_source */
+				quote_flag = g_value_get_boolean( val );
+				break;
+			case 7: /* quote_source */
+				quote_source = gnc_quote_source_lookup_by_internal( g_value_get_string( val ) );
+				break;
+			case 8: /* quote_tz */
+				quote_tz = g_value_get_string( val );
+				break;
+			default:	/* too many cols */
+				*(char*)0 = 0;
+		}
+	}
+
+	pCommodity = gnc_commodity_new( pBook, fullname, namespace, mnemonic, cusip, fraction );
+	memcpy( &((QofInstance*)pCommodity)->entity.guid, &guid, sizeof( GUID ) );
+	gnc_commodity_set_quote_flag( pCommodity, quote_flag );
+	gnc_commodity_set_quote_source( pCommodity, quote_source );
+	gnc_commodity_set_quote_tz( pCommodity, quote_tz );
+
+	return pCommodity;
+}
+
+static void
+load_commodities( GncGdaBackend* be, QofBook* pBook )
+{
+	GError* error = NULL;
+
+	GdaQuery* query;
+	GdaObject* ret;
+	gnc_commodity_table* pTable = gnc_commodity_table_get_table( pBook );
+
+	query = gda_query_new_from_sql( be->pDict, "SELECT * FROM commodities", &error );
+	if( query == NULL ) {
+		printf( "SQL error: %s\n", error->message );
+		return;
+	}
+	error = NULL;
+	ret = gda_query_execute( query, NULL, FALSE, &error );
+
+	if( error != NULL ) {
+		printf( "SQL error: %s\n", error->message );
+	}
+	if( GDA_IS_DATA_MODEL( ret ) ) {
+		GdaDataModel* pModel = (GdaDataModel*)ret;
+		int numRows = gda_data_model_get_n_rows( pModel );
+		int r;
+		gnc_commodity* pCommodity;
+
+		for( r = 0; r < numRows; r++ ) {
+			gnc_commodity* c;
+
+			pCommodity = load_commodity( pBook, pModel, r );
+
+			if( pCommodity != NULL ) {
+				gnc_commodity_table_insert( pTable, pCommodity );
+			}
+		}
+	}
+}
+/* ================================================================= */
+static gboolean
+commodity_exists_in_db( GncGdaBackend* be, const char* guid )
+{
+	char cmdbuf[400];
+	int count;
+
+	sprintf( cmdbuf, "SELECT * FROM commodities WHERE guid='%s';", guid );
+	count = gnc_gda_execute_select_get_count( be, cmdbuf );
+	if( count == 0 ) {
+		return FALSE;
+	} else {
+		return TRUE;
+	}
+}
+
+static void
+commit_commodity( GncGdaBackend* be, QofInstance* inst )
+{
+	gnc_commodity* pCommodity = (gnc_commodity*)inst;
+	const char* mnemonic = gnc_commodity_get_mnemonic(pCommodity);
+	const char* namespace = gnc_commodity_get_namespace(pCommodity);
+	const char* fullname = gnc_commodity_get_fullname(pCommodity);
+	const char* cusip = gnc_commodity_get_cusip(pCommodity);
+	int fraction = gnc_commodity_get_fraction(pCommodity);
+	const char* quote_source = gnc_quote_source_get_user_name(gnc_commodity_get_quote_source(pCommodity));
+	const char* quote_tz = gnc_commodity_get_quote_tz(pCommodity);
+	char guid[GUID_ENCODING_LENGTH+1];
+	char cmdbuf[1000];
+	gboolean quote_flag = gnc_commodity_get_quote_flag(pCommodity);
+
+	guid_to_string_buff( qof_instance_get_guid( inst ), guid );
+
+	if( inst->do_free ) {
+		sprintf( cmdbuf, "DELETE FROM commodities WHERE guid='%s';\n", guid );
+		printf( "%s\n", cmdbuf );
+		gnc_gda_execute_sql( be, cmdbuf );
+	} else {
+		if( commodity_exists_in_db( be, guid ) ) {
+			sprintf( cmdbuf,
+				"UPDATE commodities set namespace='%s',mnemonic='%s',fullname='%s', cusip='%s',fraction=%d,use_quote_source=%d,quote_source='%s',quote_tz='%s' WHERE guid='%s';",
+			namespace, mnemonic, fullname, cusip, fraction, quote_flag, quote_source, quote_tz, guid );
+		} else {
+			sprintf( cmdbuf,
+				"INSERT INTO commodities VALUES('%s', '%s', '%s','%s','%s',%d,'%d','%s','%s')\n",
+				guid, namespace, mnemonic, fullname, cusip, fraction, quote_flag, quote_source, quote_tz );
+		}
+		printf( "%s\n", cmdbuf );
+		gnc_gda_execute_sql( be, cmdbuf );
+    }
+}
+
+/* ================================================================= */
+void
+gnc_gda_init_commodity_handler( void )
+{
+	static GncGdaDataType_t be_data =
+	{
+		GNC_GDA_BACKEND_VERSION,
+		GNC_ID_COMMODITY,
+		commit_commodity,			/* commit */
+		load_commodities			/* initial_load */
+	};
+
+	qof_object_register_backend( GNC_ID_COMMODITY, GNC_GDA_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.h	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.h	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,40 @@
+/********************************************************************
+ * gnc-commodity-gda.h: load and save data to SQL via libgda        *
+ *                                                                  *
+ * 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-commodity-gda.h
+ *  @brief load and save data to SQL via libgda
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_COMMODITY_GDA_H_
+#define GNC_COMMODITY_GDA_H_
+
+#include "qof.h"
+#include <gmodule.h>
+
+void gnc_gda_init_commodity_handler( void );
+
+#endif /* GNC_COMMODITY_GDA_H_ */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,86 @@
+/********************************************************************
+ * gnc-price-gda.c: load and save data to SQL via libgda            *
+ *                                                                  *
+ * 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-price-gda.c
+ *  @brief load and save data to SQL 
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL db using libgda
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <libintl.h>
+#include <locale.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <dirent.h>
+#include <time.h>
+#include <libgda/libgda.h>
+
+#include "qof.h"
+#include "qofquery-p.h"
+#include "qofquerycore-p.h"
+#include "TransLog.h"
+#include "gnc-engine.h"
+
+#include "gnc-filepath-utils.h"
+
+#include "gnc-backend-gda.h"
+#include "gnc-gconf-utils.h"
+
+#include "gnc-price-gda.h"
+
+#ifndef HAVE_STRPTIME
+# include "strptime.h"
+#endif
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+/* ================================================================= */
+void
+gnc_gda_init_price_handler( void )
+{
+#if 0
+	static GncGdaDataType_t be_data =
+	{
+		GNC_GDA_BACKEND_VERSION,
+		GNC_ID_ACCOUNT,
+		commit_account,		/* commit */
+		NULL				/* initial_load */
+	};
+
+	qof_object_register_backend( GNC_ID_ACCOUNT, GNC_GDA_BACKEND, &be_data );
+#endif
+}
+
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.h	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.h	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,40 @@
+/********************************************************************
+ * gnc-price-gda.h: load and save data to SQL via libgda            *
+ *                                                                  *
+ * 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-price-gda.h
+ *  @brief load and save data to SQL via libgda
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_PRICE_GDA_H_
+#define GNC_PRICE_GDA_H_
+
+#include "qof.h"
+#include <gmodule.h>
+
+void gnc_gda_init_price_handler( void );
+
+#endif /* GNC_PRICE_GDA_H_ */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,87 @@
+/********************************************************************
+ * gnc-transaction-gda.c: load and save data to SQL via libgda      *
+ *                                                                  *
+ * 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-transaction-gda.c
+ *  @brief load and save data to SQL 
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL db using libgda
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <libintl.h>
+#include <locale.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <dirent.h>
+#include <time.h>
+#include <libgda/libgda.h>
+
+#include "qof.h"
+#include "qofquery-p.h"
+#include "qofquerycore-p.h"
+#include "TransLog.h"
+#include "gnc-engine.h"
+
+#include "gnc-filepath-utils.h"
+
+#include "gnc-backend-gda.h"
+#include "gnc-gconf-utils.h"
+
+#include "gnc-transaction-gda.h"
+
+#ifndef HAVE_STRPTIME
+# include "strptime.h"
+#endif
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+/* ================================================================= */
+
+void
+gnc_gda_init_transaction_handler( void )
+{
+#if 0
+	static GncGdaDataType_t be_data =
+	{
+		GNC_GDA_BACKEND_VERSION,
+		GNC_ID_ACCOUNT,
+		commit_account,		/* commit */
+		NULL				/* initial_load */
+	};
+
+	qof_object_register_backend( GNC_ID_ACCOUNT, GNC_GDA_BACKEND, &be_data );
+#endif
+}
+
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.h	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.h	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,40 @@
+/********************************************************************
+ * gnc-transaction-gda.h: load and save data to SQL via libgda      *
+ *                                                                  *
+ * 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-transaction-gda.h
+ *  @brief load and save data to SQL via libgda
+ *  @author Copyright (c) 2000 Gnumatic Inc.
+ *  @author Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *  @author Copyright (c) 2003 Linas Vepstas <linas at linas.org>
+ *  @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_TRANSACTION_GDA_H_
+#define GNC_TRANSACTION_GDA_H_
+
+#include "qof.h"
+#include <gmodule.h>
+
+void gnc_gda_init_transaction_handler( void );
+
+#endif /* GNC_TRANSACTION_GDA_H_ */

Added: gnucash/branches/gda-dev/src/backend/gda/gncmod-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gncmod-backend-gda.c	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/backend/gda/gncmod-backend-gda.c	2006-11-07 15:56:39 UTC (rev 15094)
@@ -0,0 +1,72 @@
+/*********************************************************************
+ * gncmod-backend-gda.c
+ * module definition/initialization for the gda backend module
+ * 
+ * Copyright (c) 2001 Linux Developers Group, Inc. 
+ *********************************************************************/
+
+#include <stdio.h>
+#include <glib.h>
+#include <glib-gobject.h>
+
+#include "gnc-module.h"
+#include "gnc-module-api.h"
+
+#include "gnc-backend-gda.h"
+
+/* version of the gnc module system interface we require */
+int libgncmod_backend_gda_LTX_gnc_module_system_interface = 0;
+
+/* module versioning uses libtool semantics. */
+int libgncmod_backend_gda_LTX_gnc_module_current  = 0;
+int libgncmod_backend_gda_LTX_gnc_module_revision = 0;
+int libgncmod_backend_gda_LTX_gnc_module_age      = 0;
+
+static GNCModule engine;
+
+/* forward references */
+char *libgncmod_backend_gda_LTX_gnc_module_path(void);
+char *libgncmod_backend_gda_LTX_gnc_module_description(void);
+int libgncmod_backend_gda_LTX_gnc_module_init(int refcount);
+int libgncmod_backend_gda_LTX_gnc_module_end(int refcount);
+
+
+char *
+libgncmod_backend_gda_LTX_gnc_module_path(void) 
+{
+  return g_strdup("gnucash/backend/gda");
+}
+
+char * 
+libgncmod_backend_gda_LTX_gnc_module_description(void) 
+{
+  return g_strdup("The GDA/SQL backend for GnuCash");
+}
+
+int
+libgncmod_backend_gda_LTX_gnc_module_init(int refcount) 
+{  
+  engine = gnc_module_load("gnucash/engine", 0);
+  if(!engine) return FALSE;
+
+  /* Need to initialize g-type engine for gconf */
+  if (refcount == 0) {
+    g_type_init();
+  }
+
+  return TRUE;
+}
+
+int
+libgncmod_backend_gda_LTX_gnc_module_end(int refcount) 
+{
+  int unload = TRUE;
+
+  if (engine)
+    unload = gnc_module_unload(engine);
+
+  if (refcount == 0)
+    engine = NULL;
+
+  return unload;
+}

Modified: gnucash/branches/gda-dev/src/engine/gnc-engine.c
===================================================================
--- gnucash/branches/gda-dev/src/engine/gnc-engine.c	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/engine/gnc-engine.c	2006-11-07 15:56:39 UTC (rev 15094)
@@ -80,6 +80,7 @@
     gboolean required;
   } libs[] = {
     { GNC_LIB_NAME, TRUE },
+	{ "gnc-backend-gda", TRUE },
     /* shouldn't the PG gnc-module do this instead of US doing it? */
     { "gnc-backend-postgres", FALSE },
     { NULL, FALSE } }, *lib;

Modified: gnucash/branches/gda-dev/src/engine/gnc-filepath-utils.c
===================================================================
--- gnucash/branches/gda-dev/src/engine/gnc-filepath-utils.c	2006-11-07 00:23:53 UTC (rev 15093)
+++ gnucash/branches/gda-dev/src/engine/gnc-filepath-utils.c	2006-11-07 15:56:39 UTC (rev 15094)
@@ -298,6 +298,7 @@
 
   if (!g_ascii_strncasecmp (pathfrag, "http://", 7)      ||
       !g_ascii_strncasecmp (pathfrag, "https://", 8)     ||
+	  !g_ascii_strncasecmp (pathfrag, "gda://", 6)		 ||
       !g_ascii_strncasecmp (pathfrag, "postgres://", 11))
   {
     return g_strdup(pathfrag);



More information about the gnucash-changes mailing list