r17251 - gnucash/branches/gda-dev2/src - 1) Reverse order of arguments for sql backend 'commit' function to put

Phil Longstaff plongstaff at cvs.gnucash.org
Wed Jun 25 14:29:58 EDT 2008


Author: plongstaff
Date: 2008-06-25 14:29:57 -0400 (Wed, 25 Jun 2008)
New Revision: 17251
Trac: http://svn.gnucash.org/trac/changeset/17251

Modified:
   gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.h
   gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.h
   gnucash/branches/gda-dev2/src/backend/sql/gnc-book-sql.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-book-sql.h
   gnucash/branches/gda-dev2/src/backend/sql/gnc-budget-sql.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-commodity-sql.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-lots-sql.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-price-sql.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.h
   gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.h
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-bill-term-sql.c
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-bill-term-sql.h
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-customer-sql.c
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-employee-sql.c
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-entry-sql.c
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-invoice-sql.c
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-job-sql.c
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-order-sql.c
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-tax-table-sql.c
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-vendor-sql.c
   gnucash/branches/gda-dev2/src/engine/Split.c
   gnucash/branches/gda-dev2/src/engine/Split.h
   gnucash/branches/gda-dev2/src/engine/gnc-lot.c
   gnucash/branches/gda-dev2/src/engine/gnc-lot.h
   gnucash/branches/gda-dev2/src/gnome/lot-viewer.c
Log:
1) Reverse order of arguments for sql backend 'commit' function to put
GncSqlBackend* first.
2) When deleting a lot, delete its slots as well.
3) Add 'lot_guid' field to a split.
4) When loading sql file, ensure lots are loaded before splits so that engine
already knows lot guids.
5) In sql commit routine, ensure LEAVE() balances ENTER()
6) In lot-viewer.c, when selecting a different lot in the list, lot title
and notes are set.  Put these inside begin_edit/commit_edit.
7) Add xaccSplitSetLot() function to Split.h and .c and use this in gnc-lot.c
instead of modifying the Split field directly.
8) Modify gnc_lot_destroy() to set the destroying flag and commit the lot.
The actual free is done in the qof_commit callback.



Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -261,7 +261,7 @@
 
 /* ================================================================= */
 void
-gnc_sql_save_account( QofInstance* inst, GncSqlBackend* be )
+gnc_sql_save_account( GncSqlBackend* be, QofInstance* inst )
 {
     Account* pAcc = GNC_ACCOUNT(inst);
     const GUID* guid;

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.h
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.h	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.h	2008-06-25 18:29:57 UTC (rev 17251)
@@ -33,6 +33,6 @@
 #include <gmodule.h>
 
 void gnc_sql_init_account_handler( void );
-void gnc_sql_save_account( QofInstance* inst, GncSqlBackend* be );
+void gnc_sql_save_account( GncSqlBackend* be, QofInstance* inst );
 
 #endif /* GNC_ACCOUNT_SQL_H_ */

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -127,7 +127,7 @@
 /* ================================================================= */
 
 static const gchar* fixed_load_order[] =
-{ GNC_ID_BOOK, GNC_ID_COMMODITY, GNC_ID_ACCOUNT, NULL };
+{ GNC_ID_BOOK, GNC_ID_COMMODITY, GNC_ID_ACCOUNT, GNC_ID_LOT, NULL };
 
 static void
 initial_load_cb( const gchar* type, gpointer data_p, gpointer be_p )
@@ -251,7 +251,7 @@
 
     descendants = gnc_account_get_descendants( root );
     for( node = descendants; node != NULL; node = g_list_next(node) ) {
-        gnc_sql_save_account( QOF_INSTANCE(GNC_ACCOUNT(node->data)), be );
+        gnc_sql_save_account( be, QOF_INSTANCE(GNC_ACCOUNT(node->data)) );
 		update_save_progress( be );
     }
     g_list_free( descendants );
@@ -273,7 +273,7 @@
 	g_return_val_if_fail( tx != NULL, 0 );
 	g_return_val_if_fail( data != NULL, 0 );
 
-    gnc_sql_save_transaction( QOF_INSTANCE(tx), be );
+    gnc_sql_save_transaction( be, QOF_INSTANCE(tx) );
 	update_save_progress( be );
 
     return 0;
@@ -315,7 +315,7 @@
 
     for( ; schedXactions != NULL; schedXactions = schedXactions->next ) {
         tmpSX = schedXactions->data;
-		gnc_sql_save_schedxaction( QOF_INSTANCE( tmpSX ), be );
+		gnc_sql_save_schedxaction( be, QOF_INSTANCE( tmpSX ) );
     }
 }
 
@@ -413,7 +413,7 @@
 
 	// FIXME: should write the set of commodities that are used 
     //write_commodities( be, book );
-	gnc_sql_save_book( QOF_INSTANCE(book), be );
+	gnc_sql_save_book( be, QOF_INSTANCE(book) );
     write_accounts( be );
     write_transactions( be );
     write_template_transactions( be );
@@ -460,7 +460,7 @@
     if( be_data->ok ) return;
 
     if( pData->commit != NULL ) {
-        (pData->commit)( be_data->inst, be_data->be );
+        (pData->commit)( be_data->be, be_data->inst );
         be_data->ok = TRUE;
     }
 }
@@ -501,7 +501,10 @@
         gnc_sql_transaction_commit_splits( be, GNC_TRANS(inst) );
     }
 
-    if( !qof_instance_get_dirty_flag(inst) && !qof_instance_get_destroying(inst) ) return;
+    if( !qof_instance_get_dirty_flag(inst) && !qof_instance_get_destroying(inst) ) {
+		LEAVE( "!dirty OR !destroying" );
+		return;
+	}
 
 	error = NULL;
 	gnc_sql_connection_begin_transaction( be->conn );
@@ -518,6 +521,7 @@
 		// Don't let unknown items still mark the book as being dirty
     	qof_instance_mark_clean(inst);
     	qof_book_mark_saved( be->primary_book );
+		LEAVE( "Rolled back" );
         return;
     }
 	gnc_sql_connection_commit_transaction( be->conn );

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.h
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.h	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.h	2008-06-25 18:29:57 UTC (rev 17251)
@@ -252,7 +252,7 @@
   int		version;		/**< Backend version number */
   const gchar *	type_name;	/**< Engine object type name */
   /** Commit an instance of this object to the database */
-  void		(*commit)( QofInstance* inst, GncSqlBackend* be );
+  void		(*commit)( GncSqlBackend* be, QofInstance* inst );
   /** Load all objects of this type from the database */
   void		(*initial_load)( GncSqlBackend* be );
   /** Create database tables for this object */

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-book-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-book-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-book-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -165,7 +165,7 @@
 
 		// If there are no rows, try committing the book
 		if( row == NULL ) {
-   	    	gnc_sql_save_book( QOF_INSTANCE(be->primary_book), be );
+   	    	gnc_sql_save_book( be, QOF_INSTANCE(be->primary_book) );
 		} else {
 			// Otherwise, load the 1st book.
         	load_single_book( be, row );
@@ -191,7 +191,7 @@
 
 /* ================================================================= */
 void
-gnc_sql_save_book( QofInstance* inst, GncSqlBackend* be )
+gnc_sql_save_book( GncSqlBackend* be, QofInstance* inst)
 {
     const GUID* guid;
 	gint op;

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-book-sql.h
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-book-sql.h	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-book-sql.h	2008-06-25 18:29:57 UTC (rev 17251)
@@ -33,6 +33,6 @@
 #include <gmodule.h>
 
 void gnc_sql_init_book_handler( void );
-void gnc_sql_save_book( QofInstance* inst, GncSqlBackend* be );
+void gnc_sql_save_book( GncSqlBackend* be, QofInstance* inst );
 
 #endif /* GNC_BOOK_SQL_H_ */

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-budget-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-budget-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-budget-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -131,7 +131,7 @@
 
 /* ================================================================= */
 static void
-save_budget( QofInstance* inst, GncSqlBackend* be )
+save_budget( GncSqlBackend* be, QofInstance* inst )
 {
     GncBudget* pBudget = GNC_BUDGET(inst);
     const GUID* guid;
@@ -162,12 +162,18 @@
 }
 
 static void
+do_save_budget( QofInstance* inst, gpointer data )
+{
+	save_budget( (GncSqlBackend*)data, inst );
+}
+
+static void
 write_budgets( GncSqlBackend* be )
 {
 	g_return_if_fail( be != NULL );
 
     qof_collection_foreach( qof_book_get_collection( be->primary_book, GNC_ID_BUDGET ),
-                            (QofInstanceForeachCB)save_budget, be );
+                            (QofInstanceForeachCB)do_save_budget, be );
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-commodity-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-commodity-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-commodity-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -183,7 +183,7 @@
 
 /* ================================================================= */
 static void
-commit_commodity( QofInstance* inst, GncSqlBackend* be )
+commit_commodity( GncSqlBackend* be, QofInstance* inst )
 {
     const GUID* guid;
 	gint op;
@@ -229,7 +229,7 @@
 	g_return_if_fail( pCommodity != NULL );
 
     if( !is_commodity_in_db( be, pCommodity ) ) {
-        commit_commodity( QOF_INSTANCE(pCommodity), be );
+        commit_commodity( be, QOF_INSTANCE(pCommodity) );
     }
 }
 
@@ -281,7 +281,7 @@
         GNC_SQL_BACKEND_VERSION,
         GNC_ID_COMMODITY,
         commit_commodity,            /* commit */
-        load_all_commodities,            /* initial_load */
+        load_all_commodities,        /* initial_load */
         create_commodities_tables    /* create_tables */
     };
 

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-lots-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-lots-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-lots-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -159,7 +159,7 @@
 /* ================================================================= */
 
 static void
-commit_lot( QofInstance* inst, GncSqlBackend* be )
+commit_lot( GncSqlBackend* be, QofInstance* inst )
 {
 	gint op;
 
@@ -177,8 +177,12 @@
     (void)gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_LOT, inst, col_table );
 
     // Now, commit any slots
-    gnc_sql_slots_save( be, qof_instance_get_guid( inst ),
-                        qof_instance_get_slots( inst ) );
+	if( !qof_instance_get_destroying( inst ) ) {
+    	gnc_sql_slots_save( be, qof_instance_get_guid( inst ),
+                        	qof_instance_get_slots( inst ) );
+	} else {
+    	gnc_sql_slots_delete( be, qof_instance_get_guid( inst ) );
+	}
 }
 
 /* ----------------------------------------------------------------- */
@@ -228,8 +232,8 @@
         GNC_SQL_BACKEND_VERSION,
         GNC_ID_LOT,
         commit_lot,            /* commit */
-        load_all_lots,            /* initial_load */
-        create_lots_tables    /* create tables */
+        load_all_lots,         /* initial_load */
+        create_lots_tables     /* create tables */
     };
 
     qof_object_register_backend( GNC_ID_LOT, GNC_SQL_BACKEND, &be_data );

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-price-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-price-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-price-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -133,7 +133,7 @@
 /* ================================================================= */
 
 static void
-save_price( QofInstance* inst, GncSqlBackend* be )
+save_price( GncSqlBackend* be, QofInstance* inst )
 {
     GNCPrice* pPrice = GNC_PRICE(inst);
 	gint op;
@@ -164,7 +164,7 @@
 	g_return_val_if_fail( p != NULL, FALSE );
 	g_return_val_if_fail( data != NULL, FALSE );
 
-    save_price( QOF_INSTANCE(p), be );
+    save_price( be, QOF_INSTANCE(p) );
 
     return TRUE;
 }

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -261,7 +261,7 @@
 
 /* ================================================================= */
 void
-gnc_sql_save_schedxaction( QofInstance* inst, GncSqlBackend* be )
+gnc_sql_save_schedxaction( GncSqlBackend* be, QofInstance* inst )
 {
     SchedXaction* pSx = GNC_SX(inst);
     const GUID* guid;
@@ -298,9 +298,9 @@
     {
         GNC_SQL_BACKEND_VERSION,
         GNC_ID_SCHEDXACTION,
-        gnc_sql_save_schedxaction,                /* commit */
+        gnc_sql_save_schedxaction,    /* commit */
         load_all_sxes,                /* initial_load */
-        create_sx_tables        /* create_tables */
+        create_sx_tables              /* create_tables */
     };
 
     qof_object_register_backend( GNC_ID_SCHEDXACTION, GNC_SQL_BACKEND, &be_data );

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.h
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.h	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.h	2008-06-25 18:29:57 UTC (rev 17251)
@@ -33,6 +33,6 @@
 #include <gmodule.h>
 
 void gnc_sql_init_schedxaction_handler( void );
-void gnc_sql_save_schedxaction( QofInstance* inst, GncSqlBackend* be );
+void gnc_sql_save_schedxaction( GncSqlBackend* be, QofInstance* inst );
 
 #endif /* GNC_SCHEDXACTION_SQL_H_ */

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -36,6 +36,7 @@
 
 #include "Account.h"
 #include "Transaction.h"
+#include "gnc-lot.h"
 #include "engine-helpers.h"
 
 #include "gnc-backend-sql.h"
@@ -80,6 +81,7 @@
 static gpointer get_split_reconcile_state( gpointer pObject, const QofParam* param );
 static void set_split_reconcile_state( gpointer pObject, gpointer pValue );
 static void set_split_reconcile_date( gpointer pObject, Timespec ts );
+static void set_split_lot( gpointer pObject, gpointer pLot );
 
 #define SPLIT_MAX_MEMO_LEN 2048
 #define SPLIT_MAX_ACTION_LEN 2048
@@ -97,6 +99,8 @@
 			(QofAccessFunc)xaccSplitRetDateReconciledTS, (QofSetterFunc)set_split_reconcile_date },
     { "value",           CT_NUMERIC,      0,                    COL_NNUL,          NULL, SPLIT_VALUE },
     { "quantity",        CT_NUMERIC,      0,                    COL_NNUL,          NULL, SPLIT_AMOUNT },
+	{ "lot_guid",        CT_LOTREF,       0,                    0,                 NULL, NULL,
+			(QofAccessFunc)xaccSplitGetLot, set_split_lot },
     { NULL }
 };
 
@@ -156,7 +160,24 @@
     *pResult = value;
 }
 
+static void
+set_split_lot( gpointer pObject, gpointer pLot )
+{
+	GNCLot* lot;
+	Split* split;
 
+	g_return_if_fail( pObject != NULL );
+	g_return_if_fail( GNC_IS_SPLIT(pObject) );
+
+	if( pLot == NULL ) return;
+
+	g_return_if_fail( GNC_IS_LOT(pLot) );
+
+	split = GNC_SPLIT(pObject);
+	lot = GNC_LOT(pLot);
+	gnc_lot_add_split( lot, split );
+}
+
 // Table to retrieve just the quantity
 static GncSqlColumnTableEntry quantity_table[] =
 {
@@ -424,7 +445,7 @@
 }
 
 static void
-commit_split( QofInstance* inst, GncSqlBackend* be )
+commit_split( GncSqlBackend* be, QofInstance* inst )
 {
 	gint op;
 
@@ -454,7 +475,7 @@
 	g_return_if_fail( GNC_IS_SPLIT(data) );
 	g_return_if_fail( user_data != NULL );
 
-    commit_split( QOF_INSTANCE(pSplit), split_info->be );
+    commit_split( split_info->be, QOF_INSTANCE(pSplit) );
 }
 
 static void
@@ -472,7 +493,7 @@
 }
 
 void
-gnc_sql_save_transaction( QofInstance* inst, GncSqlBackend* be )
+gnc_sql_save_transaction( GncSqlBackend* be, QofInstance* inst )
 {
     Transaction* pTx = GNC_TRANS(inst);
     const GUID* guid;

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.h
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.h	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.h	2008-06-25 18:29:57 UTC (rev 17251)
@@ -34,7 +34,7 @@
 
 void gnc_sql_init_transaction_handler( void );
 void gnc_sql_transaction_commit_splits( GncSqlBackend* be, Transaction* pTx );
-void gnc_sql_save_transaction( QofInstance* inst, GncSqlBackend* be );
+void gnc_sql_save_transaction( GncSqlBackend* be, QofInstance* inst );
 void gnc_sql_get_account_balances( GncSqlBackend* be, Account* pAccount, 
 								    gnc_numeric* start_balance,
 								    gnc_numeric* cleared_balance,

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-bill-term-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-bill-term-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-bill-term-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -159,7 +159,7 @@
 
 /* ================================================================= */
 void
-gnc_sql_save_billterm( QofInstance* inst, GncSqlBackend* be )
+gnc_sql_save_billterm( GncSqlBackend* be, QofInstance* inst )
 {
     const GUID* guid;
 

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-bill-term-sql.h
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-bill-term-sql.h	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-bill-term-sql.h	2008-06-25 18:29:57 UTC (rev 17251)
@@ -35,6 +35,6 @@
 #define CT_BILLTERMREF "billterm"
 
 void gnc_billterm_sql_initialize( void );
-void gnc_sql_save_billterm( QofInstance* inst, GncSqlBackend* be );
+void gnc_sql_save_billterm( GncSqlBackend* be, QofInstance* inst );
 
 #endif /* GNC_BILLTERM_SQL_H */

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-customer-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-customer-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-customer-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -140,7 +140,7 @@
 
 /* ================================================================= */
 static void
-save_customer( QofInstance* inst, GncSqlBackend* be )
+save_customer( GncSqlBackend* be, QofInstance* inst )
 {
     const GUID* guid;
 
@@ -190,7 +190,7 @@
 	g_return_if_fail( be_p != NULL );
 
 	if( customer_should_be_saved( GNC_CUSTOMER(term_p) ) ) {
-    	save_customer( term_p, be );
+    	save_customer( be, term_p );
 	}
 }
 

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-employee-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-employee-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-employee-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -136,7 +136,7 @@
 
 /* ================================================================= */
 static void
-save_employee( QofInstance* inst, GncSqlBackend* be )
+save_employee( GncSqlBackend* be, QofInstance* inst )
 {
     GncEmployee* emp = GNC_EMPLOYEE(inst);
     const GUID* guid;
@@ -189,7 +189,7 @@
 	g_return_if_fail( be_p != NULL );
 
 	if( employee_should_be_saved( GNC_EMPLOYEE(term_p) ) ) {
-    	save_employee( term_p, be );
+    	save_employee( be, term_p );
 	}
 }
 

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-entry-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-entry-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-entry-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -159,7 +159,7 @@
 
 /* ================================================================= */
 static void
-save_entry( QofInstance* inst, GncSqlBackend* be )
+save_entry( GncSqlBackend* be, QofInstance* inst )
 {
     const GUID* guid;
 
@@ -196,7 +196,7 @@
   	/* Only save if attached */
   	if( gncEntryGetOrder( entry ) != NULL || gncEntryGetInvoice( entry ) != NULL ||
 			gncEntryGetBill( entry ) != NULL ) {
-    	save_entry( term_p, be );
+    	save_entry( be, term_p );
 	}
 }
 

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-invoice-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-invoice-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-invoice-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -144,7 +144,7 @@
 
 /* ================================================================= */
 static void
-save_invoice( QofInstance* inst, GncSqlBackend* be )
+save_invoice( GncSqlBackend* be, QofInstance* inst )
 {
     const GUID* guid;
 	GncInvoice* invoice = GNC_INVOICE(inst);
@@ -198,7 +198,7 @@
 	g_return_if_fail( be_p != NULL );
 
 	if( invoice_should_be_saved( GNC_INVOICE(term_p) ) ) {
-    	save_invoice( term_p, be );
+    	save_invoice( be, term_p );
 	}
 }
 

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-job-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-job-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-job-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -127,7 +127,7 @@
 
 /* ================================================================= */
 static void
-save_job( QofInstance* inst, GncSqlBackend* be )
+save_job( GncSqlBackend* be, QofInstance* inst )
 {
     const GUID* guid;
 
@@ -177,7 +177,7 @@
 	g_return_if_fail( be_p != NULL );
 
 	if( job_should_be_saved( GNC_JOB(term_p) ) ) {
-    	save_job( term_p, be );
+    	save_job( be, term_p );
 	}
 }
 

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-order-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-order-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-order-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -128,7 +128,7 @@
 
 /* ================================================================= */
 static void
-save_order( QofInstance* inst, GncSqlBackend* be )
+save_order( GncSqlBackend* be, QofInstance* inst )
 {
     const GUID* guid;
 
@@ -178,7 +178,7 @@
 	g_return_if_fail( be_p != NULL );
 
 	if( order_should_be_saved( GNC_ORDER(term_p) ) ) {
-    	save_order( term_p, be );
+    	save_order( be, term_p );
 	}
 }
 

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-tax-table-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-tax-table-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-tax-table-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -303,7 +303,7 @@
 }
 
 static void
-save_taxtable( QofInstance* inst, GncSqlBackend* be )
+save_taxtable( GncSqlBackend* be, QofInstance* inst )
 {
     GncTaxTable* tt = GNC_TAXTABLE(inst);
     const GUID* guid;
@@ -331,11 +331,17 @@
 
 /* ================================================================= */
 static void
+save_next_taxtable( QofInstance* inst, gpointer p2 )
+{
+	save_taxtable( (GncSqlBackend*)p2, inst );
+}
+
+static void
 write_taxtables( GncSqlBackend* be )
 {
 	g_return_if_fail( be != NULL );
 
-    qof_object_foreach( GNC_ID_TAXTABLE, be->primary_book, (QofInstanceForeachCB)save_taxtable, (gpointer)be );
+    qof_object_foreach( GNC_ID_TAXTABLE, be->primary_book, save_next_taxtable, be );
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-vendor-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-vendor-sql.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-vendor-sql.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -141,7 +141,7 @@
 
 /* ================================================================= */
 static void
-save_vendor( QofInstance* inst, GncSqlBackend* be )
+save_vendor( GncSqlBackend* be, QofInstance* inst )
 {
     GncVendor* v = GNC_VENDOR(inst);
     const GUID* guid;
@@ -195,7 +195,7 @@
 	g_return_if_fail( be_p != NULL );
 
 	if( vendor_should_be_saved( GNC_VENDOR(term_p) ) ) {
-    	save_vendor( term_p, be );
+    	save_vendor( be, term_p );
 	}
 }
 

Modified: gnucash/branches/gda-dev2/src/engine/Split.c
===================================================================
--- gnucash/branches/gda-dev2/src/engine/Split.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/engine/Split.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -1527,6 +1527,15 @@
    return split ? split->lot : NULL;
 }
 
+void
+xaccSplitSetLot(Split* split, GNCLot* lot)
+{
+   xaccTransBeginEdit (split->parent);
+   split->lot = lot;
+   qof_instance_set_dirty(QOF_INSTANCE(split));
+   xaccTransCommitEdit(split->parent);
+}
+
 const char *
 xaccSplitGetMemo (const Split *split)
 {

Modified: gnucash/branches/gda-dev2/src/engine/Split.h
===================================================================
--- gnucash/branches/gda-dev2/src/engine/Split.h	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/engine/Split.h	2008-06-25 18:29:57 UTC (rev 17251)
@@ -130,7 +130,10 @@
  * belongs to, or NULL if it doesn't belong to any. */
 GNCLot *      xaccSplitGetLot (const Split *split);
 
+/** Assigns the split to a specific Lot */
+void xaccSplitSetLot(Split* split, GNCLot* lot);
 
+
 /** Returns the KvpFrame slots of this split for direct editing. 
  *
  * Split slots are used to store arbitrary strings, numbers, and

Modified: gnucash/branches/gda-dev2/src/engine/gnc-lot.c
===================================================================
--- gnucash/branches/gda-dev2/src/engine/gnc-lot.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/engine/gnc-lot.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -99,8 +99,8 @@
    return lot;
 }
 
-void 
-gnc_lot_destroy (GNCLot *lot)
+static void
+gnc_lot_free(GNCLot* lot)
 {
    GList *node;
    if (!lot) return;
@@ -122,6 +122,16 @@
    g_object_unref (lot);
 }
 
+void 
+gnc_lot_destroy (GNCLot *lot)
+{
+   if (!lot) return;
+   
+   gnc_lot_begin_edit(lot);
+   qof_instance_set_destroying(lot, TRUE);
+   gnc_lot_commit_edit(lot);
+}
+
 /* ============================================================= */
 
 void
@@ -135,13 +145,20 @@
   PERR ("Failed to commit: %d", errcode);
 }
 
+static void lot_free(QofInstance* inst)
+{
+	GNCLot* lot = GNC_LOT(inst);
+
+	gnc_lot_free(lot);
+}
+
 static void noop (QofInstance *inst) {}
 
 void
 gnc_lot_commit_edit (GNCLot *lot)
 {
   if (!qof_commit_edit (QOF_INSTANCE(lot))) return;
-  qof_commit_edit_part2 (&lot->inst, commit_err, noop, noop);
+  qof_commit_edit_part2 (&lot->inst, commit_err, noop, lot_free);
 }
 
 /* ============================================================= */
@@ -356,7 +373,7 @@
    {
       gnc_lot_remove_split (split->lot, split);
    }
-   split->lot = lot;
+   xaccSplitSetLot(split, lot);
 
    lot->splits = g_list_append (lot->splits, split);
 
@@ -377,7 +394,7 @@
    gnc_lot_begin_edit(lot);
    qof_instance_set_dirty(QOF_INSTANCE(lot));
    lot->splits = g_list_remove (lot->splits, split);
-   split->lot = NULL;
+   xaccSplitSetLot(split, NULL);
    lot->is_closed = -1;   /* force an is-closed computation */
 
    if (NULL == lot->splits)

Modified: gnucash/branches/gda-dev2/src/engine/gnc-lot.h
===================================================================
--- gnucash/branches/gda-dev2/src/engine/gnc-lot.h	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/engine/gnc-lot.h	2008-06-25 18:29:57 UTC (rev 17251)
@@ -92,7 +92,7 @@
  *    that *all* splits in a lot must also be in the same account.
  *    Note that this routine adds the split unconditionally, with
  *    no regard for the accounting policy.  To enforce a particular
- *    accounting polciy, use the xaccSplitAssignToLot() routine 
+ *    accounting policy, use the xaccSplitAssignToLot() routine 
  *    instead.
  */
 void gnc_lot_add_split (GNCLot *, Split *);

Modified: gnucash/branches/gda-dev2/src/gnome/lot-viewer.c
===================================================================
--- gnucash/branches/gda-dev2/src/gnome/lot-viewer.c	2008-06-24 23:28:31 UTC (rev 17250)
+++ gnucash/branches/gda-dev2/src/gnome/lot-viewer.c	2008-06-25 18:29:57 UTC (rev 17251)
@@ -221,6 +221,8 @@
 
    if (lot)
    {
+	  gnc_lot_begin_edit(lot);
+
       /* Get the title, save_the_title */
       str = gtk_entry_get_text (lv->title_entry);
       gnc_lot_set_title (lot, str);
@@ -229,6 +231,8 @@
       notes = xxxgtk_textview_get_text (lv->lot_notes);
       gnc_lot_set_notes (lot, notes);
       g_free(notes);
+
+	  gnc_lot_commit_edit(lot);
    }
 }
 



More information about the gnucash-changes mailing list