r15190 - gnucash/branches/gda-dev/src/backend/gda - 1) Use GObject-style macros instead of casts

Phil Longstaff plongstaff at cvs.gnucash.org
Thu Dec 7 09:35:08 EST 2006


Author: plongstaff
Date: 2006-12-07 09:35:07 -0500 (Thu, 07 Dec 2006)
New Revision: 15190
Trac: http://svn.gnucash.org/trac/changeset/15190

Modified:
   gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
   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-commodity-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c
Log:
1) Use GObject-style macros instead of casts
2) Prevent nested queries to solve problem where a split query triggers
rerunning the same query


Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c	2006-12-07 14:32:46 UTC (rev 15189)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c	2006-12-07 14:35:07 UTC (rev 15190)
@@ -74,17 +74,17 @@
 static gpointer
 get_commodity( gpointer pObject )
 {
-	Account* pAccount = (Account*)pObject;
+	const Account* pAccount = GNC_ACCOUNT(pObject);
 
 	return (gpointer)qof_instance_get_guid(
-						(QofInstance*)xaccAccountGetCommodity( pAccount ) );
+						QOF_INSTANCE(xaccAccountGetCommodity( pAccount )) );
 }
 
 static void 
 set_commodity( gpointer pObject, const gpointer pValue )
 {
-	Account* pAccount = (Account*)pObject;
-	QofBook* pBook = qof_instance_get_book( (QofInstance*)pAccount );
+	Account* pAccount = GNC_ACCOUNT(pObject);
+	QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pAccount) );
 	gnc_commodity* pCommodity;
 	GUID* guid = (GUID*)pValue;
 
@@ -95,14 +95,14 @@
 static gpointer
 get_parent( gpointer pObject )
 {
-	const Account* pAccount = (const Account*)pObject;
-	Account* pParent = xaccAccountGetParentAccount( pAccount );
+	const Account* pAccount = GNC_ACCOUNT(pObject);
+	const Account* pParent = xaccAccountGetParentAccount( pAccount );
 	const GUID* parent_guid;
 
 	if( pParent == NULL ) {
 		parent_guid = NULL;
 	} else {
-		parent_guid = qof_instance_get_guid( (QofInstance*)pParent );
+		parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
 	}
 
 	return (gpointer)parent_guid;
@@ -111,8 +111,8 @@
 static void 
 set_parent( gpointer pObject, const gpointer pValue )
 {
-	Account* pAccount = (Account*)pObject;
-	QofBook* pBook = qof_instance_get_book( (QofInstance*)pAccount );
+	Account* pAccount = GNC_ACCOUNT(pObject);
+	QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pAccount) );
 	GUID* guid = (GUID*)pValue;
 	Account* pParent;
 	
@@ -142,9 +142,9 @@
 	}
 	gnc_gda_load_object( pModel, row, GNC_ID_ACCOUNT, pAccount, col_table );
 	gnc_gda_slots_load( be, xaccAccountGetGUID( pAccount ),
-							qof_instance_get_slots( (QofInstance*)pAccount ) );
+							qof_instance_get_slots( QOF_INSTANCE(pAccount) ) );
 
-	qof_instance_mark_clean( (QofInstance*)pAccount );
+	qof_instance_mark_clean( QOF_INSTANCE(pAccount) );
 
 	return pAccount;
 }
@@ -164,13 +164,12 @@
 
 	ret = gnc_gda_execute_query( be, query );
 	if( GDA_IS_DATA_MODEL( ret ) ) {
-		GdaDataModel* pModel = (GdaDataModel*)ret;
+		GdaDataModel* pModel = GDA_DATA_MODEL(ret);
 		int numRows = gda_data_model_get_n_rows( pModel );
 		int r;
 		Account* pAccount;
 
 		for( r = 0; r < numRows; r++ ) {
-
 			pAccount = load_account( be, pModel, r, NULL );
 
 			if( pAccount != NULL ) {
@@ -195,17 +194,17 @@
 static void
 commit_account( GncGdaBackend* be, QofInstance* inst )
 {
-	Account* pAcc = (Account*)inst;
+	Account* pAcc = GNC_ACCOUNT(inst);
 	const GUID* guid;
 
 	// Ensure the commodity is in the db
 	gnc_gda_save_commodity( be, xaccAccountGetCommodity( pAcc ) );
 
 	(void)gnc_gda_do_db_operation( be,
-							(inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
-							TABLE_NAME,
-							GNC_ID_ACCOUNT, pAcc,
-							col_table );
+						(inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+						TABLE_NAME,
+						GNC_ID_ACCOUNT, pAcc,
+						col_table );
 
 	// Delete old slot info
 	guid = qof_instance_get_guid( inst );

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c	2006-12-07 14:32:46 UTC (rev 15189)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c	2006-12-07 14:35:07 UTC (rev 15190)
@@ -30,18 +30,18 @@
 
 #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 <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"
@@ -50,7 +50,7 @@
 #include "TransLog.h"
 #include "gnc-engine.h"
 
-#include "gnc-filepath-utils.h"
+//#include "gnc-filepath-utils.h"
 
 #include "gnc-backend-gda.h"
 #include "gnc-gconf-utils.h"
@@ -64,9 +64,9 @@
 #include "gnc-slots-gda.h"
 #include "gnc-transaction-gda.h"
 
-#ifndef HAVE_STRPTIME
-# include "strptime.h"
-#endif
+//#ifndef HAVE_STRPTIME
+//# include "strptime.h"
+//#endif
 
 static const gchar* convert_search_obj( QofIdType objType );
 static void gnc_gda_init_object_handlers( void );
@@ -132,8 +132,9 @@
 	g_object_unref( G_OBJECT(field) );
 }
 
-static GdaQueryCondition*
-create_cond_from_field( GdaQuery* query, const gchar* col_name, const GValue* value )
+GdaQueryCondition*
+gnc_gda_create_condition_from_field( GdaQuery* query, const gchar* col_name,
+								const GValue* value )
 {
 	GdaQueryCondition* cond;
 	GdaQueryField* key;
@@ -214,7 +215,8 @@
 	GValue value;
 
 	get_gvalue_string( be, obj_name, pObject, table_row, &value );
-	return create_cond_from_field( query, table_row->col_name, &value );
+	return gnc_gda_create_condition_from_field( query, table_row->col_name,
+											&value );
 }
 
 static void
@@ -288,7 +290,7 @@
 	GValue value;
 
 	get_gvalue_int( be, obj_name, pObject, table_row, &value );
-	return create_cond_from_field( query, table_row->col_name, &value );
+	return gnc_gda_create_condition_from_field( query, table_row->col_name, &value );
 }
 
 static void
@@ -360,7 +362,7 @@
 	GValue value;
 
 	get_gvalue_int64( be, obj_name, pObject, table_row, &value );
-	return create_cond_from_field( query, table_row->col_name, &value );
+	return gnc_gda_create_condition_from_field( query, table_row->col_name, &value );
 }
 
 static void
@@ -431,7 +433,7 @@
 	GValue value;
 
 	get_gvalue_double( be, obj_name, pObject, table_row, &value );
-	return create_cond_from_field( query, table_row->col_name, &value );
+	return gnc_gda_create_condition_from_field( query, table_row->col_name, &value );
 }
 
 static void
@@ -508,7 +510,7 @@
 	GValue value;
 
 	get_gvalue_guid( be, obj_name, pObject, table_row, &value );
-	return create_cond_from_field( query, table_row->col_name, &value );
+	return gnc_gda_create_condition_from_field( query, table_row->col_name, &value );
 }
 
 static void
@@ -537,10 +539,12 @@
 		(*setter)( pObject, NULL );
 	} else {
 		date = (GDate*)g_value_get_boxed( val );
-		ts = gnc_dmy2timespec( g_date_get_day( date ),
+		if( date != NULL ) {
+			ts = gnc_dmy2timespec( g_date_get_day( date ),
 								g_date_get_month( date ),
 								g_date_get_year( date ) );
-		(*setter)( pObject, &ts );
+			(*setter)( pObject, &ts );
+		}
 	}
 }
 
@@ -585,7 +589,7 @@
 	GValue value;
 
 	get_gvalue_timespec( be, obj_name, pObject, table_row, &value );
-	return create_cond_from_field( query, table_row->col_name, &value );
+	return gnc_gda_create_condition_from_field( query, table_row->col_name, &value );
 }
 
 static void
@@ -653,7 +657,7 @@
 	GValue value;
 
 	get_gvalue_date( be, obj_name, pObject, table_row, &value );
-	return create_cond_from_field( query, table_row->col_name, &value );
+	return gnc_gda_create_condition_from_field( query, table_row->col_name, &value );
 }
 
 static col_type_handler_t date_handler =
@@ -770,10 +774,10 @@
 	}
 
 	s = g_strdup_printf( "%s_num", table_row->col_name );
-	num_cond = create_cond_from_field( query, table_row->col_name, &value );
+	num_cond = gnc_gda_create_condition_from_field( query, table_row->col_name, &value );
 	g_free( s );
 	s = g_strdup_printf( "%s_denom", table_row->col_name );
-	denom_cond = create_cond_from_field( query, table_row->col_name, &value );
+	denom_cond = gnc_gda_create_condition_from_field( query, table_row->col_name, &value );
 	g_free( s );
 
 	cond = gda_query_condition_new( query, GDA_QUERY_CONDITION_NODE_AND );
@@ -783,51 +787,6 @@
 	return cond;
 }
 
-static gchar*
-render_numeric( GncGdaBackend* be, QofIdTypeConst obj_name, gpointer pObject,
-				const col_cvt_t* table_row, gboolean include_name )
-{
-	gchar* buf;
-	gnc_numeric* pNumeric;
-	gnc_numeric v;
-
-	pNumeric = (gnc_numeric*)(*table_row->getter) (pObject );
-	if( pNumeric != NULL ) {
-		gchar* s_num;
-		gchar* s_denom;
-		GValue value_num;
-		GValue value_denom;
-
-		v = *pNumeric;
-		memset( &value_num, 0, sizeof( value_num ) );
-		g_value_init( &value_num, G_TYPE_INT64 );
-		g_value_set_int64( &value_num, gnc_numeric_num( v ) );
-		memset( &value_denom, 0, sizeof( value_denom ) );
-		g_value_init( &value_denom, G_TYPE_INT64 );
-		g_value_set_int64( &value_denom, gnc_numeric_denom( v ) );
-		s_num = gda_data_handler_get_sql_from_value( be->pNumHandler, &value_num );
-		s_denom = gda_data_handler_get_sql_from_value( be->pNumHandler, &value_denom );
-		if( include_name ) {
-			buf = g_strdup_printf( "%s_num=%s, %s_denom=%s",
-							table_row->col_name, s_num,
-							table_row->col_name, s_denom );
-		} else {
-			buf = g_strdup_printf( "%s, %s", s_num, s_denom );
-		}
-		g_free( s_num );
-		g_free( s_denom );
-	} else {
-		if( include_name ) {
-			buf = g_strdup_printf( "%s_num=NULL, %s_denom=NULL",
-							table_row->col_name, table_row->col_name );
-		} else {
-			buf = g_strdup( "NULL" );
-		}
-	}
-
-	return buf;
-}
-
 static void
 create_numeric_col( GdaServerProvider* server, GdaConnection* cnn,
 			xmlNodePtr array_data, const col_cvt_t* table_row )
@@ -1015,7 +974,7 @@
 
 	ret = gnc_gda_execute_sql( be, sql );
 	if( GDA_IS_DATA_MODEL(ret) ) {
-		GdaDataModel* pModel = (GdaDataModel*)ret;
+		GdaDataModel* pModel = GDA_DATA_MODEL(ret);
 		count = gda_data_model_get_n_rows( pModel );
 	}
 
@@ -1035,7 +994,7 @@
 
 	ret = gnc_gda_execute_query( be, query );
 	if( GDA_IS_DATA_MODEL(ret) ) {
-		GdaDataModel* pModel = (GdaDataModel*)ret;
+		GdaDataModel* pModel = GDA_DATA_MODEL(ret);
 		count = gda_data_model_get_n_rows( pModel );
 	}
 
@@ -1136,29 +1095,6 @@
 	GdaQuery* query;
 	int col;
 
-#if 0
-	GString* sql;
-	GError* error = NULL;
-	gchar* col_value;
-
-	sql = g_string_sized_new( INITIAL_SQL_BUF_LEN );
-	g_string_printf( sql, "INSERT INTO %s VALUES(", table_name );
-
-	for( col = 0; table[col].col_name != NULL; col++ ) {
-		if( col != 0 ) g_string_append( sql, "," );
-		col_value = render_col_value( be, obj_name, pObject, &table[col], FALSE );
-		g_string_append( sql, col_value );
-		g_free( col_value );
-	}
-
-	g_string_append( sql, ");" );
-
-	query = gda_query_new_from_sql( be->pDict, sql->str, &error );
-	g_string_free( sql, TRUE );
-	if( query == NULL ) {
-		printf( "SQL error: %s\n", error->message );
-	}
-#else
 	GdaQueryTarget* target;
 
 	/* INSERT */
@@ -1173,7 +1109,6 @@
 	for( col = 0; table[col].col_name != NULL; col++ ) {
 		get_col_gvalue_for_query( be, obj_name, pObject, &table[col], query );
 	}
-#endif
 
 	return query;
 }
@@ -1855,7 +1790,10 @@
 	gnc_gda_query_info* pQueryInfo = (gnc_gda_query_info*)pQuery;
 	gda_backend be_data;
 
+	g_return_if_fail( !be->in_query );
+
 	be->loading = TRUE;
+	be->in_query = TRUE;
 
 	// Try various objects first
 	be_data.ok = FALSE;
@@ -1865,6 +1803,7 @@
 
 	qof_object_foreach_backend( GNC_GDA_BACKEND, run_query_cb, &be_data );
 	be->loading = FALSE;
+	be->in_query = FALSE;
 	if( be_data.ok ) {
 		return;
 	}

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h	2006-12-07 14:32:46 UTC (rev 15189)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h	2006-12-07 14:35:07 UTC (rev 15190)
@@ -47,6 +47,7 @@
 
   QofBook *primary_book;	/* The primary, main open book */
   gboolean	loading;		/* We are performing an initial load */
+  gboolean  in_query;
 };
 typedef struct GncGdaBackend_struct GncGdaBackend;
 
@@ -151,6 +152,9 @@
 						const gchar* table_name, col_cvt_t* col_table );
 const GUID* gnc_gda_load_guid( GdaDataModel* pModel, int row );
 GdaQuery* gnc_gda_create_select_query( const GncGdaBackend* be, const gchar* table_name );
+GdaQueryCondition* gnc_gda_create_condition_from_field( GdaQuery* query,
+														const gchar* col_name,
+														const GValue* value );
 
 G_MODULE_EXPORT const gchar *
 g_module_check_init(GModule *module);

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c	2006-12-07 14:32:46 UTC (rev 15189)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c	2006-12-07 14:35:07 UTC (rev 15190)
@@ -77,7 +77,7 @@
 static gpointer
 get_recurrence_mult( gpointer pObject )
 {
-	GncBudget* budget = (GncBudget*)pObject;
+	GncBudget* budget = GNC_BUDGET(pObject);
 	const Recurrence* r = gnc_budget_get_recurrence( budget );
 	guint m = r->mult;
 
@@ -87,7 +87,7 @@
 static void
 set_recurrence_mult( gpointer pObject, gpointer pValue )
 {
-	GncBudget* budget = (GncBudget*)pObject;
+	GncBudget* budget = GNC_BUDGET(pObject);
 	Recurrence* r = (Recurrence*)gnc_budget_get_recurrence( budget );
 	guint m = (guint)pValue;
 
@@ -97,7 +97,7 @@
 static gpointer
 get_recurrence_period_type( gpointer pObject )
 {
-	GncBudget* budget = (GncBudget*)pObject;
+	GncBudget* budget = GNC_BUDGET(pObject);
 	const Recurrence* r = gnc_budget_get_recurrence( budget );
 
 	return (gpointer)recurrencePeriodTypeToString(
@@ -107,7 +107,7 @@
 static void
 set_recurrence_period_type( gpointer pObject, gpointer pValue )
 {
-	GncBudget* budget = (GncBudget*)pObject;
+	GncBudget* budget = GNC_BUDGET(pObject);
 	Recurrence* r = (Recurrence*)gnc_budget_get_recurrence( budget );
 
 	r->ptype = recurrencePeriodTypeFromString( (gchar*)pValue );
@@ -116,7 +116,7 @@
 static gpointer
 get_recurrence_period_start( gpointer pObject )
 {
-	GncBudget* budget = (GncBudget*)pObject;
+	GncBudget* budget = GNC_BUDGET(pObject);
 	const Recurrence* r = gnc_budget_get_recurrence( budget );
 	static GDate date;
 
@@ -127,7 +127,7 @@
 static void
 set_recurrence_period_start( gpointer pObject, gpointer pValue )
 {
-	GncBudget* budget = (GncBudget*)pObject;
+	GncBudget* budget = GNC_BUDGET(pObject);
 	Recurrence* r = (Recurrence*)gnc_budget_get_recurrence( budget );
 	GDate* date = (GDate*)pValue;
 
@@ -154,9 +154,9 @@
 
 	gnc_gda_load_object( pModel, row, GNC_ID_BUDGET, pBudget, col_table );
 	gnc_gda_slots_load( be, gnc_budget_get_guid( pBudget ),
-							qof_instance_get_slots( (QofInstance*)pBudget ) );
+							qof_instance_get_slots( QOF_INSTANCE(pBudget) ) );
 
-	qof_instance_mark_clean( (QofInstance*)pBudget );
+	qof_instance_mark_clean( QOF_INSTANCE(pBudget) );
 
 	return pBudget;
 }
@@ -173,7 +173,7 @@
 	}
 	ret = gnc_gda_execute_query( be, query );
 	if( GDA_IS_DATA_MODEL( ret ) ) {
-		GdaDataModel* pModel = (GdaDataModel*)ret;
+		GdaDataModel* pModel = GDA_DATA_MODEL(ret);
 		int numRows = gda_data_model_get_n_rows( pModel );
 		int r;
 
@@ -194,14 +194,14 @@
 static void
 commit_budget( GncGdaBackend* be, QofInstance* inst )
 {
-	GncBudget* pBudget = (GncBudget*)inst;
+	GncBudget* pBudget = GNC_BUDGET(inst);
 	const GUID* guid;
 
 	(void)gnc_gda_do_db_operation( be,
-							(inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
-							BUDGET_TABLE,
-							GNC_ID_BUDGET, pBudget,
-							col_table );
+						inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE,
+						BUDGET_TABLE,
+						GNC_ID_BUDGET, pBudget,
+						col_table );
 
 	// Delete old slot info
 	guid = qof_instance_get_guid( inst );

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c	2006-12-07 14:32:46 UTC (rev 15189)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c	2006-12-07 14:35:07 UTC (rev 15190)
@@ -90,7 +90,7 @@
 static gpointer
 get_quote_source_name( gpointer pObject )
 {
-	gnc_commodity* pCommodity = (gnc_commodity*)pObject;
+	const gnc_commodity* pCommodity = GNC_COMMODITY(pObject);
 
 	return (gpointer)gnc_quote_source_get_internal_name(
 							gnc_commodity_get_quote_source(pCommodity));
@@ -99,7 +99,7 @@
 static void 
 set_quote_source_name( gpointer pObject, const gpointer pValue )
 {
-	gnc_commodity* pCommodity = (gnc_commodity*)pObject;
+	gnc_commodity* pCommodity = GNC_COMMODITY(pObject);
 	const gchar* quote_source_name = (const gchar*)pValue;
 	gnc_quote_source* quote_source;
 
@@ -121,7 +121,7 @@
 
 	gnc_gda_load_object( pModel, row, GNC_ID_COMMODITY, pCommodity, col_table );
 
-	qof_instance_mark_clean( (QofInstance*)pCommodity );
+	qof_instance_mark_clean( QOF_INSTANCE(pCommodity) );
 
 	return pCommodity;
 }
@@ -138,7 +138,7 @@
 	}
 	ret = gnc_gda_execute_query( be, query );
 	if( GDA_IS_DATA_MODEL( ret ) ) {
-		GdaDataModel* pModel = (GdaDataModel*)ret;
+		GdaDataModel* pModel = GDA_DATA_MODEL(ret);
 		int numRows = gda_data_model_get_n_rows( pModel );
 		int r;
 		gnc_commodity* pCommodity;
@@ -151,9 +151,9 @@
 			if( pCommodity != NULL ) {
 				GUID guid;
 
-				guid = *qof_entity_get_guid( (QofEntity*)pCommodity );
+				guid = *qof_entity_get_guid( QOF_ENTITY(pCommodity) );
 				pCommodity = gnc_commodity_table_insert( pTable, pCommodity );
-				qof_entity_set_guid( (QofEntity*)pCommodity, &guid );
+				qof_entity_set_guid( QOF_ENTITY(pCommodity), &guid );
 			}
 		}
 	}
@@ -186,7 +186,7 @@
 void gnc_gda_save_commodity( GncGdaBackend* be, gnc_commodity* pCommodity )
 {
 	if( !is_commodity_in_db( be, pCommodity ) ) {
-		commit_commodity( be, (QofInstance*)pCommodity );
+		commit_commodity( be, QOF_INSTANCE(pCommodity) );
 	}
 }
 

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c	2006-12-07 14:32:46 UTC (rev 15189)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c	2006-12-07 14:35:07 UTC (rev 15190)
@@ -76,7 +76,7 @@
 static gpointer
 get_value( gpointer pObject )
 {
-	GNCPrice* pPrice = (GNCPrice*)pObject;
+	const GNCPrice* pPrice = GNC_PRICE(pObject);
 	static gnc_numeric v;
 
 	v = gnc_price_get_value( pPrice );
@@ -86,7 +86,7 @@
 static void
 set_value( gpointer pObject, const gpointer pValue )
 {
-	GNCPrice* pPrice = (GNCPrice*)pObject;
+	GNCPrice* pPrice = GNC_PRICE(pObject);
 	const gnc_numeric* pNumeric = (const gnc_numeric*)pValue;
 
 	gnc_price_set_value( pPrice, *pNumeric );
@@ -95,7 +95,7 @@
 static gpointer
 get_date( gpointer pObject )
 {
-	GNCPrice* pPrice = (GNCPrice*)pObject;
+	const GNCPrice* pPrice = GNC_PRICE(pObject);
 	static Timespec t;
 
 	t = gnc_price_get_time( pPrice );
@@ -105,7 +105,7 @@
 static void
 set_date( gpointer pObject, const gpointer pValue )
 {
-	GNCPrice* pPrice = (GNCPrice*)pObject;
+	GNCPrice* pPrice = GNC_PRICE(pObject);
 	const Timespec* pTimespec = (const Timespec*)pValue;
 
 	gnc_price_set_time( pPrice, *pTimespec );
@@ -114,17 +114,17 @@
 static gpointer
 get_currency( gpointer pObject )
 {
-	GNCPrice* pPrice = (GNCPrice*)pObject;
+	const GNCPrice* pPrice = GNC_PRICE(pObject);
 
 	return (gpointer)qof_instance_get_guid(
-							(QofInstance*)gnc_price_get_currency( pPrice ) );
+							QOF_INSTANCE(gnc_price_get_currency( pPrice )) );
 }
 
 static void 
 set_currency( gpointer pObject, const gpointer pValue )
 {
-	GNCPrice* pPrice = (GNCPrice*)pObject;
-	QofBook* pBook = qof_instance_get_book( (QofInstance*)pPrice );
+	GNCPrice* pPrice = GNC_PRICE(pObject);
+	QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pPrice) );
 	gnc_commodity* pCurrency;
 	GUID* guid = (GUID*)pValue;
 
@@ -135,17 +135,17 @@
 static gpointer
 get_commodity( gpointer pObject )
 {
-	GNCPrice* pPrice = (GNCPrice*)pObject;
+	const GNCPrice* pPrice = GNC_PRICE(pObject);
 
 	return (gpointer)qof_instance_get_guid(
-						(QofInstance*)gnc_price_get_commodity( pPrice ) );
+						QOF_INSTANCE(gnc_price_get_commodity( pPrice )) );
 }
 
 static void 
 set_commodity( gpointer pObject, const gpointer pValue )
 {
-	GNCPrice* pPrice = (GNCPrice*)pObject;
-	QofBook* pBook = qof_instance_get_book( (QofInstance*)pPrice );
+	GNCPrice* pPrice = GNC_PRICE(pObject);
+	QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pPrice) );
 	gnc_commodity* pCommodity;
 	GUID* guid = (GUID*)pValue;
 
@@ -162,7 +162,7 @@
 
 	gnc_gda_load_object( pModel, row, GNC_ID_PRICE, pPrice, col_table );
 
-	qof_instance_mark_clean( (QofInstance*)pPrice );
+	qof_instance_mark_clean( QOF_INSTANCE(pPrice) );
 
 	return pPrice;
 }
@@ -180,13 +180,12 @@
 	}
 	ret = gnc_gda_execute_query( be, query );
 	if( GDA_IS_DATA_MODEL( ret ) ) {
-		GdaDataModel* pModel = (GdaDataModel*)ret;
+		GdaDataModel* pModel = GDA_DATA_MODEL(ret);
 		int numRows = gda_data_model_get_n_rows( pModel );
 		int r;
 		GNCPrice* pPrice;
 
 		for( r = 0; r < numRows; r++ ) {
-
 			pPrice = load_price( be, pModel, r, NULL );
 
 			if( pPrice != NULL ) {
@@ -208,17 +207,17 @@
 static void
 commit_price( GncGdaBackend* be, QofInstance* inst )
 {
-	GNCPrice* pPrice = (GNCPrice*)inst;
+	GNCPrice* pPrice = GNC_PRICE(inst);
 
 	/* Ensure commodity and currency are in the db */
 	gnc_gda_save_commodity( be, gnc_price_get_commodity( pPrice ) );
 	gnc_gda_save_commodity( be, gnc_price_get_currency( pPrice ) );
 
 	(void)gnc_gda_do_db_operation( be,
-							(inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
-							TABLE_NAME,
-							GNC_ID_PRICE, pPrice,
-							col_table );
+						(inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+						TABLE_NAME,
+						GNC_ID_PRICE, pPrice,
+						col_table );
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c	2006-12-07 14:32:46 UTC (rev 15189)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c	2006-12-07 14:35:07 UTC (rev 15190)
@@ -75,9 +75,9 @@
 
 	gnc_gda_load_object( pModel, row, GNC_ID_BUDGET, pBudget, col_table );
 	gnc_gda_slots_load( be, gnc_budget_get_guid( pBudget ),
-							qof_instance_get_slots( (QofInstance*)pBudget ) );
+							qof_instance_get_slots( QOF_INSTANCE(pBudget) ) );
 
-	qof_instance_mark_clean( (QofInstance*)pBudget );
+	qof_instance_mark_clean( QOF_INSTANCE(pBudget) );
 
 #endif
 	return pSx;
@@ -95,7 +95,7 @@
 	ret = gnc_gda_execute_sql( be, buf );
 	g_free( buf );
 	if( GDA_IS_DATA_MODEL( ret ) ) {
-		GdaDataModel* pModel = (GdaDataModel*)ret;
+		GdaDataModel* pModel = GDA_DATA_MODEL(ret);
 		int numRows = gda_data_model_get_n_rows( pModel );
 		int r;
 
@@ -124,10 +124,10 @@
 	const GUID* guid;
 
 	(void)gnc_gda_do_db_operation( be,
-							(inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
-							BUDGET_TABLE,
-							GNC_ID_BUDGET, pBudget,
-							col_table );
+						(inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+						BUDGET_TABLE,
+						GNC_ID_BUDGET, pBudget,
+						col_table );
 
 	// Delete old slot info
 	guid = qof_instance_get_guid( inst );

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c	2006-12-07 14:32:46 UTC (rev 15189)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c	2006-12-07 14:35:07 UTC (rev 15190)
@@ -135,13 +135,13 @@
 static gpointer
 get_guid( gpointer pObject )
 {
-	return (gpointer)qof_entity_get_guid( (QofEntity*)pObject );
+	return (gpointer)qof_entity_get_guid( QOF_ENTITY(pObject) );
 }
 
 static void 
 set_guid( gpointer pObject, const gpointer pValue )
 {
-	QofEntity* pEntity = (QofEntity*)pObject;
+	QofEntity* pEntity = QOF_ENTITY(pObject);
 	GUID* guid = (GUID*)pValue;
 
 	qof_entity_set_guid( pEntity, guid );
@@ -150,17 +150,17 @@
 static gpointer
 get_tx_currency( gpointer pObject )
 {
-	Transaction* pTx = (Transaction*)pObject;
+	const Transaction* pTx = GNC_TRANS(pObject);
 
 	return (gpointer)qof_instance_get_guid(
-						(QofInstance*)xaccTransGetCurrency( pTx ) );
+						QOF_INSTANCE(xaccTransGetCurrency( pTx )) );
 }
 
 static void 
 set_tx_currency( gpointer pObject, const gpointer pValue )
 {
-	Transaction* pTx = (Transaction*)pObject;
-	QofBook* pBook = qof_instance_get_book( (QofInstance*)pTx );
+	Transaction* pTx = GNC_TRANS(pObject);
+	QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pTx) );
 	gnc_commodity* pCurrency;
 	GUID* guid = (GUID*)pValue;
 
@@ -171,7 +171,7 @@
 static gpointer
 get_tx_num( gpointer pObject )
 {
-	Transaction* pTx = (Transaction*)pObject;
+	const Transaction* pTx = GNC_TRANS(pObject);
 	const gchar* s;
 
 	s = xaccTransGetNum( pTx );
@@ -181,7 +181,7 @@
 static void 
 set_tx_num( gpointer pObject, const gpointer pValue )
 {
-	Transaction* pTx = (Transaction*)pObject;
+	Transaction* pTx = GNC_TRANS(pObject);
 	const gchar* s = (const gchar*)pValue;
 
 	xaccTransSetNum( pTx, s );
@@ -190,7 +190,7 @@
 static gpointer
 get_tx_post_date( gpointer pObject )
 {
-	Transaction* pTx = (Transaction*)pObject;
+	const Transaction* pTx = GNC_TRANS(pObject);
 	static Timespec ts;
 
 	ts = xaccTransRetDatePostedTS( pTx );
@@ -200,7 +200,7 @@
 static void 
 set_tx_post_date( gpointer pObject, const gpointer pValue )
 {
-	Transaction* pTx = (Transaction*)pObject;
+	Transaction* pTx = GNC_TRANS(pObject);
 	Timespec* pTS = (Timespec*)pValue;
 
 	xaccTransSetDatePostedTS( pTx, pTS );
@@ -209,7 +209,7 @@
 static gpointer
 get_tx_enter_date( gpointer pObject )
 {
-	Transaction* pTx = (Transaction*)pObject;
+	const Transaction* pTx = GNC_TRANS(pObject);
 	static Timespec ts;
 
 	ts = xaccTransRetDateEnteredTS( pTx );
@@ -219,7 +219,7 @@
 static void 
 set_tx_enter_date( gpointer pObject, const gpointer pValue )
 {
-	Transaction* pTx = (Transaction*)pObject;
+	Transaction* pTx = GNC_TRANS(pObject);
 	Timespec* pTS = (Timespec*)pValue;
 
 	xaccTransSetDateEnteredTS( pTx, pTS );
@@ -228,17 +228,17 @@
 static gpointer
 get_split_tx_guid( gpointer pObject )
 {
-	Split* pSplit = (Split*)pObject;
+	const Split* pSplit = GNC_SPLIT(pObject);
 	Transaction* pTx = xaccSplitGetParent( pSplit );
 
-	return (gpointer)qof_instance_get_guid( (QofInstance*)pTx );
+	return (gpointer)qof_instance_get_guid( QOF_INSTANCE(pTx) );
 }
 
 static void 
 set_split_tx_guid( gpointer pObject, const gpointer pValue )
 {
-	Split* pSplit = (Split*)pObject;
-	QofBook* pBook = qof_instance_get_book( (QofInstance*)pSplit );
+	Split* pSplit = GNC_SPLIT(pObject);
+	QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pSplit) );
 	GUID* guid = (GUID*)pValue;
 	Transaction* pTx = xaccTransLookup( guid, pBook );
 
@@ -248,7 +248,7 @@
 static gpointer
 get_split_reconcile_state( gpointer pObject )
 {
-	Split* pSplit = (Split*)pObject;
+	const Split* pSplit = GNC_SPLIT(pObject);
 	static gchar c[2];
 
 	c[0] = xaccSplitGetReconcile( pSplit );
@@ -259,7 +259,7 @@
 static void 
 set_split_reconcile_state( gpointer pObject, const gpointer pValue )
 {
-	Split* pSplit = (Split*)pObject;
+	Split* pSplit = GNC_SPLIT(pObject);
 	const gchar* s = (const gchar*)pValue;
 
 	xaccSplitSetReconcile( pSplit, s[0] );
@@ -268,7 +268,7 @@
 static gpointer
 get_split_reconcile_date( gpointer pObject )
 {
-	Split* pSplit = (Split*)pObject;
+	const Split* pSplit = GNC_SPLIT(pObject);
 	static Timespec ts;
 
 	ts = xaccSplitRetDateReconciledTS( pSplit );
@@ -278,7 +278,7 @@
 static void 
 set_split_reconcile_date( gpointer pObject, const gpointer pValue )
 {
-	Split* pSplit = (Split*)pObject;
+	Split* pSplit = GNC_SPLIT(pObject);
 	Timespec* pTS = (Timespec*)pValue;
 
 	xaccSplitSetDateReconciledTS( pSplit, pTS );
@@ -287,7 +287,7 @@
 static gpointer
 get_split_value( gpointer pObject )
 {
-	Split* pSplit = (Split*)pObject;
+	const Split* pSplit = GNC_SPLIT(pObject);
 	static gnc_numeric v;
 
 	v = xaccSplitGetValue( pSplit );
@@ -297,7 +297,7 @@
 static void 
 set_split_value( gpointer pObject, const gpointer pValue )
 {
-	Split* pSplit = (Split*)pObject;
+	Split* pSplit = GNC_SPLIT(pObject);
 	gnc_numeric* pV = (gnc_numeric*)pValue;
 
 	xaccSplitSetValue( pSplit, *pV );
@@ -306,7 +306,7 @@
 static gpointer
 get_split_quantity( gpointer pObject )
 {
-	Split* pSplit = (Split*)pObject;
+	const Split* pSplit = GNC_SPLIT(pObject);
 	static gnc_numeric v;
 
 	v = xaccSplitGetAmount( pSplit );
@@ -316,7 +316,7 @@
 static void 
 set_split_quantity( gpointer pObject, const gpointer pValue )
 {
-	Split* pSplit = (Split*)pObject;
+	Split* pSplit = GNC_SPLIT(pObject);
 	gnc_numeric* pV = (gnc_numeric*)pValue;
 
 	xaccSplitSetAmount( pSplit, *pV );
@@ -325,17 +325,17 @@
 static gpointer
 get_split_account( gpointer pObject )
 {
-	Split* pSplit = (Split*)pObject;
+	const Split* pSplit = GNC_SPLIT(pObject);
 	Account* pAccount = xaccSplitGetAccount( pSplit );
 
-	return (gpointer)qof_instance_get_guid( (QofInstance*)pAccount );
+	return (gpointer)qof_instance_get_guid( QOF_INSTANCE(pAccount) );
 }
 
 static void 
 set_split_account( gpointer pObject, const gpointer pValue )
 {
-	Split* pSplit = (Split*)pObject;
-	QofBook* pBook = qof_instance_get_book( (QofInstance*)pSplit );
+	Split* pSplit = GNC_SPLIT(pObject);
+	QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pSplit) );
 	GUID* guid = (GUID*)pValue;
 	Account* pAccount = xaccAccountLookup( guid, pBook );
 
@@ -358,12 +358,12 @@
 		}
 	}
 	gnc_gda_load_object( pModel, row, GNC_ID_SPLIT, pSplit, split_col_table );
-	gnc_gda_slots_load( be, qof_instance_get_guid( (QofInstance*)pSplit ),
-							qof_instance_get_slots( (QofInstance*)pSplit ) );
+	gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE(pSplit) ),
+							qof_instance_get_slots( QOF_INSTANCE(pSplit) ) );
 
 	g_assert( pSplit == xaccSplitLookup( &split_guid, be->primary_book ) );
 
-	qof_instance_mark_clean( (QofInstance*)pSplit );
+	qof_instance_mark_clean( QOF_INSTANCE(pSplit) );
 
 	return pSplit;
 }
@@ -371,16 +371,25 @@
 static void
 load_splits( GncGdaBackend* be, const GUID* guid )
 {
-	gchar* buf;
 	GdaObject* ret;
 	gchar guid_buf[GUID_ENCODING_LENGTH+1];
+	GdaQuery* query;
+	GdaQueryCondition* cond;
+	GValue value;
 
 	guid_to_string_buff( guid, guid_buf );
-	buf = g_strdup_printf( "SELECT * FROM %s where tx_guid='%s'",
-						SPLIT_TABLE, guid_buf );
-	ret = gnc_gda_execute_sql( be, buf );
+	memset( &value, 0, sizeof( GValue ) );
+	g_value_init( &value, G_TYPE_STRING );
+	g_value_set_string( &value, guid_buf );
+	query = gnc_gda_create_select_query( be, SPLIT_TABLE );
+	cond = gnc_gda_create_condition_from_field( query, "tx_guid", &value );
+	gda_query_set_condition( query, cond );
+	g_object_unref( G_OBJECT(cond) );
+
+	ret = gnc_gda_execute_query( be, query );
+	g_object_unref( G_OBJECT(query) );
 	if( GDA_IS_DATA_MODEL( ret ) ) {
-		GdaDataModel* pModel = (GdaDataModel*)ret;
+		GdaDataModel* pModel = GDA_DATA_MODEL(ret);
 		int numRows = gda_data_model_get_n_rows( pModel );
 		int r;
 
@@ -407,11 +416,11 @@
 	}
 	xaccTransBeginEdit( pTx );
 	gnc_gda_load_object( pModel, row, GNC_ID_TRANS, pTx, tx_col_table );
-	gnc_gda_slots_load( be, qof_instance_get_guid( (QofInstance*)pTx ),
-							qof_instance_get_slots( (QofInstance*)pTx ) );
-	load_splits( be, qof_instance_get_guid( (QofInstance*)pTx ) );
+	gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE(pTx) ),
+							qof_instance_get_slots( QOF_INSTANCE(pTx) ) );
+	load_splits( be, qof_instance_get_guid( QOF_INSTANCE(pTx) ) );
 
-	qof_instance_mark_clean( (QofInstance*)pTx );
+	qof_instance_mark_clean( QOF_INSTANCE(pTx) );
 	xaccTransCommitEdit( pTx );
 
 	g_assert( pTx == xaccTransLookup( &tx_guid, be->primary_book ) );
@@ -419,32 +428,28 @@
 	return pTx;
 }
 
+#if 0
 static void
 load_transactions( GncGdaBackend* be, const GUID* guid )
 {
-	GError* error = NULL;
-	gchar* buf;
 	GdaQuery* query;
 	GdaObject* ret;
 	gchar guid_buf[GUID_ENCODING_LENGTH+1];
+	GValue value;
+	GdaQueryCondition* cond;
 
 	guid_to_string_buff( guid, guid_buf );
-	buf = g_strdup_printf( "SELECT * FROM %s where guid='%s'",
-						TRANSACTION_TABLE, guid_buf );
-	query = gda_query_new_from_sql( be->pDict, buf, &error );
-	g_free( buf );
-	if( query == NULL ) {
-		printf( "SQL error: %s\n", error->message );
-		return;
-	}
-	error = NULL;
-	ret = gda_query_execute( query, NULL, FALSE, &error );
+	memset( &value, 0, sizeof( GValue ) );
+	g_value_init( &value, G_TYPE_STRING );
+	g_value_set_string( &value, guid_buf );
+	query = gnc_gda_create_select_query( be, TRANSACTION_TABLE );
+	cond = gnc_gda_create_condition_from_field( query, "guid", &value );
+	gda_query_set_condition( query, cond );
+	g_object_unref( G_OBJECT(cond) );
 
-	if( error != NULL ) {
-		printf( "SQL error: %s\n", error->message );
-	}
+	ret = gnc_gda_execute_query( be, query );
 	if( GDA_IS_DATA_MODEL( ret ) ) {
-		GdaDataModel* pModel = (GdaDataModel*)ret;
+		GdaDataModel* pModel = GDA_DATA_MODEL(ret);
 		int numRows = gda_data_model_get_n_rows( pModel );
 		int r;
 
@@ -453,27 +458,16 @@
 		}
 	}
 }
+#endif
 
 static void
-query_transactions( GncGdaBackend* be, const gchar* sql )
+query_transactions( GncGdaBackend* be, GdaQuery* query )
 {
-	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 );
-	}
+	ret = gnc_gda_execute_query( be, query );
 	if( GDA_IS_DATA_MODEL( ret ) ) {
-		GdaDataModel* pModel = (GdaDataModel*)ret;
+		GdaDataModel* pModel = GDA_DATA_MODEL(ret);
 		int numRows = gda_data_model_get_n_rows( pModel );
 		int r;
 
@@ -495,9 +489,10 @@
 delete_split_slots_cb( gpointer data, gpointer user_data )
 {
 	split_info_t* split_info = (split_info_t*)user_data;
-	Split* pSplit = (Split*)data;
+	Split* pSplit = GNC_SPLIT(data);
 
-	gnc_gda_slots_delete( split_info->be, qof_instance_get_guid( (QofInstance*)pSplit ) );
+	gnc_gda_slots_delete( split_info->be,
+					qof_instance_get_guid( QOF_INSTANCE(pSplit) ) );
 }
 
 static void
@@ -516,12 +511,13 @@
 save_split_cb( gpointer data, gpointer user_data )
 {
 	split_info_t* split_info = (split_info_t*)user_data;
-	Split* pSplit = (Split*)data;
+	Split* pSplit = GNC_SPLIT(data);
 
 	(void)gnc_gda_do_db_operation( split_info->be, OP_DB_ADD, SPLIT_TABLE,
 									GNC_ID_SPLIT, pSplit, split_col_table );
-	gnc_gda_slots_save( split_info->be, qof_instance_get_guid( (QofInstance*)pSplit ),
-							qof_instance_get_slots( (QofInstance*)pSplit ) );
+	gnc_gda_slots_save( split_info->be,
+							qof_instance_get_guid( QOF_INSTANCE(pSplit) ),
+							qof_instance_get_slots( QOF_INSTANCE(pSplit) ) );
 }
 
 static void
@@ -537,17 +533,17 @@
 static void
 commit_transaction( GncGdaBackend* be, QofInstance* inst )
 {
-	Transaction* pTx = (Transaction*)inst;
+	Transaction* pTx = GNC_TRANS(inst);
 	const GUID* guid;
 
 	// Ensure the commodity is in the db
 	gnc_gda_save_commodity( be, xaccTransGetCurrency( pTx ) );
 
 	(void)gnc_gda_do_db_operation( be,
-							(inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
-							TRANSACTION_TABLE,
-							GNC_ID_TRANS, pTx,
-							tx_col_table );
+						(inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+						TRANSACTION_TABLE,
+						GNC_ID_TRANS, pTx,
+						tx_col_table );
 
 	guid = qof_instance_get_guid( inst );
 
@@ -596,25 +592,110 @@
 	const GUID* acct_guid;
 	gchar guid_buf[GUID_ENCODING_LENGTH+1];
 
+#if 1
 	acct_guid = get_guid_from_query( pQuery );
 	guid_to_string_buff( acct_guid, guid_buf );
 	buf = g_strdup_printf( "SELECT * FROM %s WHERE guid IN (SELECT DISTINCT tx_guid FROM %s WHERE account_guid = '%s')",
 							TRANSACTION_TABLE, SPLIT_TABLE, guid_buf );
 	return buf;
+#else
+	GdaQuery* query;
+	GdaQuery* subQuery;
+	GdaQueryTarget* target;
+	GdaQueryField* allFields;
+	GdaQueryField* field;
+	GValue value;
+	GdaQueryCondition* cond;
+	GdaQueryField* key;
+	GdaQueryField* key_value;
+
+	acct_guid = get_guid_from_query( pQuery );
+	guid_to_string_buff( acct_guid, guid_buf );
+
+	/* Subquery */
+
+	/* SELECT */
+	subQuery = gda_query_new( pBackend->pDict );
+	gda_query_set_query_type( subQuery, GDA_QUERY_TYPE_SELECT );
+
+	/* FROM splits */
+	target = gda_query_target_new( subQuery, SPLIT_TABLE );
+	gda_query_add_target( subQuery, target, NULL );
+	g_object_unref( G_OBJECT(target) );
+
+	/* tx_guid */
+	field = gda_query_field_field_new( subQuery, "tx_guid" );
+	gda_query_field_set_visible( field, TRUE );
+	gda_entity_add_field( GDA_ENTITY(subQuery), GDA_ENTITY_FIELD(field) );
+	g_object_unref( G_OBJECT(field) );
+
+	/* WHERE */
+	memset( &value, 0, sizeof( GValue ) );
+	g_value_init( &value, G_TYPE_STRING );
+	g_value_set_string( &value, guid_buf );
+	cond = gnc_gda_create_condition_from_field( subQuery, "account_guid", &value );
+	gda_query_set_condition( subQuery, cond );
+	g_object_unref( G_OBJECT(cond) );
+
+	/* Main query */
+
+	/* SELECT * FROM transactions */
+	query = gnc_gda_create_select_query( pBackend, TRANSACTION_TABLE );
+	gda_query_add_sub_query( query, subQuery );
+	g_object_unref( G_OBJECT(subQuery) );
+
+	/* WHERE */
+	cond = gda_query_condition_new( query, GDA_QUERY_CONDITION_LEAF_IN );
+	gda_query_set_condition( query, cond );
+	g_object_unref( G_OBJECT(cond) );
+
+	key = gda_query_field_field_new( query, "account_guid" );
+	gda_query_field_set_visible( key, TRUE );
+	gda_query_condition_leaf_set_operator( cond,
+											GDA_QUERY_CONDITION_OP_LEFT,
+											GDA_QUERY_FIELD(key) );
+	g_object_unref( G_OBJECT(key) );
+
+	key_value = gda_query_field_value_new( query, G_TYPE_STRING );
+	gda_query_field_set_visible( key_value, TRUE );
+	gda_query_field_value_set_is_parameter( GDA_QUERY_FIELD_VALUE(key_value), TRUE );
+
+	g_object_set( key_value, "value-provider", subQuery, NULL );
+	gda_query_condition_leaf_set_operator( cond, GDA_QUERY_CONDITION_OP_RIGHT,
+												GDA_QUERY_FIELD(key_value) );
+
+	return query;
+#endif
 }
 
 static void
-run_split_query( GncGdaBackend* pBackend, gpointer pQuery )
+run_split_query( GncGdaBackend* be, gpointer pQuery )
 {
+	GdaQuery* query;
+#if 1
+	GError* error = NULL;
 	const gchar* sql = (const gchar*)pQuery;
 
-	query_transactions( pBackend, sql );
+	query = gda_query_new_from_sql( be->pDict, sql, &error );
+	if( query == NULL ) {
+		printf( "SQL error: %s\n", error->message );
+		return;
+	}
+	error = NULL;
+#else
+	query = GDA_QUERY(pQuery);
+#endif
+	query_transactions( be, query );
 }
 
 static void
 free_split_query( GncGdaBackend* pBackend, gpointer pQuery )
 {
+#if 1
 	g_free( pQuery );
+#else
+	g_object_unref( G_OBJECT(pQuery) );
+#endif
 }
 
 /* ================================================================= */



More information about the gnucash-changes mailing list