r17307 - gnucash/branches/gda-dev2 - 1) Move code from qof into the file backend which was marking the books

Phil Longstaff plongstaff at cvs.gnucash.org
Fri Jul 11 21:12:51 EDT 2008


Author: plongstaff
Date: 2008-07-11 21:12:50 -0400 (Fri, 11 Jul 2008)
New Revision: 17307
Trac: http://svn.gnucash.org/trac/changeset/17307

Modified:
   gnucash/branches/gda-dev2/lib/libqof/qof/qofinstance.c
   gnucash/branches/gda-dev2/src/backend/dbi/gnc-backend-dbi.c
   gnucash/branches/gda-dev2/src/backend/file/gnc-backend-file.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c
   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-transaction-sql.c
   gnucash/branches/gda-dev2/src/gnome-utils/gnc-main-window.c
Log:
1) Move code from qof into the file backend which was marking the books
dirty after a commit was finished.  This worked for the xml backend but not
for the sql backend.
2) Simplify some code sql backend - when loading the file, often, a list of
the objects loaded was needed.  This list is now generated more simply and
regularly.
3) Change how transactions are saved.  Originally, when a clean transaction
was saved, this was a signal to save the splits.  Now, the splits are saved
because of their own commits.  Note that the order in which a transaction is
deleted (tx first, then splits) will need to be changed if we want referential
integrity between the splits and tx tables.
4) At DEBUG level, log all sql statements executed



Modified: gnucash/branches/gda-dev2/lib/libqof/qof/qofinstance.c
===================================================================
--- gnucash/branches/gda-dev2/lib/libqof/qof/qofinstance.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/lib/libqof/qof/qofinstance.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -970,11 +970,11 @@
         /* XXX the backend commit code should clear dirty!! */
         priv->dirty = FALSE;
     }
-    if (dirty && qof_get_alt_dirty_mode() && 
-        !(priv->infant && priv->do_free)) {
-      qof_collection_mark_dirty(priv->collection);
-      qof_book_mark_dirty(priv->book);
-    }
+//    if (dirty && qof_get_alt_dirty_mode() && 
+//        !(priv->infant && priv->do_free)) {
+//      qof_collection_mark_dirty(priv->collection);
+//      qof_book_mark_dirty(priv->book);
+//    }
     priv->infant = FALSE;
 
     if (priv->do_free) {

Modified: gnucash/branches/gda-dev2/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/dbi/gnc-backend-dbi.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/backend/dbi/gnc-backend-dbi.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -654,6 +654,7 @@
 		PERR( "Error executing SQL %s\n", dbi_stmt->sql->str );
 		return NULL;
 	}
+	DEBUG( "SQL: %s\n", dbi_stmt->sql->str );
 	return create_dbi_result( result );
 }
 
@@ -670,6 +671,7 @@
 		PERR( "Error executing SQL %s\n", dbi_stmt->sql->str );
 		return 0;
 	}
+	DEBUG( "SQL: %s\n", dbi_stmt->sql->str );
 	num_rows = dbi_result_get_numrows_affected( result );
 	dbi_result_free( result );
 	return num_rows;

Modified: gnucash/branches/gda-dev2/src/backend/file/gnc-backend-file.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/file/gnc-backend-file.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/backend/file/gnc-backend-file.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -860,6 +860,11 @@
 static void
 file_commit_edit (QofBackend *be, QofInstance *inst)
 {
+    if (qof_instance_get_dirty(inst) && qof_get_alt_dirty_mode() && 
+        !(qof_instance_get_infant(inst) && qof_instance_get_destroying(inst))) {
+      qof_collection_mark_dirty(qof_instance_get_collection(inst));
+      qof_book_mark_dirty(qof_instance_get_book(inst));
+    }
 #if BORKEN_FOR_NOW
     FileBackend *fbe = (FileBackend *) be;
     QofBook *book = gp;

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-account-sql.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -136,17 +136,17 @@
 	s->guid = *guid;
 }
 
-static void
-load_single_account( GncSqlBackend* be, GncSqlRow* row, GList** pList,
-				GList** l_accounts_needing_parents )
+static Account*
+load_single_account( GncSqlBackend* be, GncSqlRow* row,
+					GList** l_accounts_needing_parents )
 {
     const GUID* guid;
     GUID acc_guid;
 	Account* pAccount;
 
-	g_return_if_fail( be != NULL );
-	g_return_if_fail( row != NULL );
-	g_return_if_fail( l_accounts_needing_parents != NULL );
+	g_return_val_if_fail( be != NULL, NULL );
+	g_return_val_if_fail( row != NULL, NULL );
+	g_return_val_if_fail( l_accounts_needing_parents != NULL, NULL );
 
     guid = gnc_sql_load_guid( be, row );
     acc_guid = *guid;
@@ -157,10 +157,7 @@
     }
 	xaccAccountBeginEdit( pAccount );
     gnc_sql_load_object( be, row, GNC_ID_ACCOUNT, pAccount, col_table );
-	*pList = g_list_append( *pList, pAccount );
-
 	xaccAccountCommitEdit( pAccount );
-    qof_instance_mark_clean( QOF_INSTANCE(pAccount) );
 
 	/* If we don't have a parent, it might be because the parent account hasn't
 	   been loaded yet.  Remember the account and its parent guid for later. */
@@ -170,6 +167,8 @@
 		gnc_sql_load_object( be, row, GNC_ID_ACCOUNT, s, parent_col_table );
 		*l_accounts_needing_parents = g_list_prepend( *l_accounts_needing_parents, s );
 	}
+
+	return pAccount;
 }
 
 static void
@@ -195,9 +194,13 @@
 	gnc_sql_statement_dispose( stmt );
 	if( result != NULL ) {
 	    GncSqlRow* row = gnc_sql_result_get_first_row( result );
+		Account* acc;
 
     	while( row != NULL ) {
-        	load_single_account( be, row, &list, &l_accounts_needing_parents );
+        	acc = load_single_account( be, row, &l_accounts_needing_parents );
+			if( acc != NULL ) {
+				list = g_list_append( list, acc );
+			}
 			row = gnc_sql_result_get_next_row( result );
     	}
 		gnc_sql_result_dispose( result );

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -474,34 +474,42 @@
     sql_backend be_data;
 	GError* error;
 	gboolean status;
+	gboolean is_dirty;
+	gboolean is_destroying;
 
 	g_return_if_fail( be != NULL );
 	g_return_if_fail( inst != NULL );
 
     /* During initial load where objects are being created, don't commit
-    anything */
+    anything, but do mark the object as clean. */
     if( be->loading ) {
+		qof_instance_mark_clean( inst );
 	    return;
 	}
 
 	// The engine has a PriceDB object but it isn't in the database
 	if( strcmp( inst->e_type, "PriceDB" ) == 0 ) {
-    	qof_instance_mark_clean(inst);
+    	qof_instance_mark_clean( inst );
     	qof_book_mark_saved( be->primary_book );
 		return;
 	}
 
     ENTER( " " );
 
-    DEBUG( "%s dirty = %d, do_free=%d\n",
+	is_dirty = qof_instance_get_dirty_flag( inst );
+	is_destroying = qof_instance_get_destroying( inst );
+
+    DEBUG( "%s dirty = %d, do_free = %d\n",
              (inst->e_type ? inst->e_type : "(null)"),
-             qof_instance_get_dirty_flag(inst), qof_instance_get_destroying(inst) );
+             is_dirty, is_destroying );
 
-    if( !qof_instance_get_dirty_flag(inst) && !qof_instance_get_destroying(inst) && GNC_IS_TRANS(inst) ) {
+#if 0
+    if( !is_dirty && !is_destroying && GNC_IS_TRANS(inst) ) {
         gnc_sql_transaction_commit_splits( be, GNC_TRANS(inst) );
     }
+#endif
 
-    if( !qof_instance_get_dirty_flag(inst) && !qof_instance_get_destroying(inst) ) {
+    if( !is_dirty && !is_destroying ) {
 		LEAVE( "!dirty OR !destroying" );
 		return;
 	}

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-budget-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-budget-sql.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-budget-sql.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -60,16 +60,16 @@
 };
 
 /* ================================================================= */
-static void
-load_single_budget( GncSqlBackend* be, GncSqlRow* row, GList** pList )
+static GncBudget*
+load_single_budget( GncSqlBackend* be, GncSqlRow* row )
 {
     const GUID* guid;
     GUID budget_guid;
 	GncBudget* pBudget;
 	Recurrence* r;
 
-	g_return_if_fail( be != NULL );
-	g_return_if_fail( row != NULL );
+	g_return_val_if_fail( be != NULL, NULL );
+	g_return_val_if_fail( row != NULL, NULL );
 
     guid = gnc_sql_load_guid( be, row );
     budget_guid = *guid;
@@ -79,12 +79,13 @@
         pBudget = gnc_budget_new( be->primary_book );
     }
 
+	gnc_budget_begin_edit( pBudget );
     gnc_sql_load_object( be, row, GNC_ID_BUDGET, pBudget, col_table );
 	r = g_new0( Recurrence, 1 );
 	gnc_sql_recurrence_load( be, gnc_budget_get_guid( pBudget ), r );
-	*pList = g_list_append( *pList, pBudget );
+	gnc_budget_commit_edit( pBudget );
 
-    qof_instance_mark_clean( QOF_INSTANCE(pBudget) );
+	return pBudget;
 }
 
 static void
@@ -102,9 +103,13 @@
 	gnc_sql_statement_dispose( stmt );
 	if( result != NULL ) {
 		GncSqlRow* row = gnc_sql_result_get_first_row( result );
+		GncBudget* b;
 
         while( row != NULL ) {
-            load_single_budget( be, row, &list );
+            b = load_single_budget( be, row );
+			if( b != NULL ) {
+				list = g_list_append( list, b );
+			}
 			row = gnc_sql_result_get_next_row( result );
         }
 		gnc_sql_result_dispose( result );

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-commodity-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-commodity-sql.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-commodity-sql.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -120,11 +120,10 @@
     gnc_commodity* pCommodity;
 
     pCommodity = gnc_commodity_new( pBook, NULL, NULL, NULL, NULL, 100 );
-
+	gnc_commodity_begin_edit( pCommodity );
     gnc_sql_load_object( be, row, GNC_ID_COMMODITY, pCommodity, col_table );
+	gnc_commodity_commit_edit( pCommodity );
 
-    qof_instance_mark_clean( QOF_INSTANCE(pCommodity) );
-
     return pCommodity;
 }
 

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-lots-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-lots-sql.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-lots-sql.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -98,20 +98,21 @@
     lot->is_closed = closed;
 }
 
-static void
-load_single_lot( GncSqlBackend* be, GncSqlRow* row, GList** pList )
+static GNCLot*
+load_single_lot( GncSqlBackend* be, GncSqlRow* row )
 {
 	GNCLot* lot;
 
-	g_return_if_fail( be != NULL );
-	g_return_if_fail( row != NULL );
+	g_return_val_if_fail( be != NULL, NULL );
+	g_return_val_if_fail( row != NULL, NULL );
 
     lot = gnc_lot_new( be->primary_book );
 
+	gnc_lot_begin_edit( lot );
     gnc_sql_load_object( be, row, GNC_ID_LOT, lot, col_table );
-	*pList = g_list_append( *pList, lot );
+	gnc_lot_commit_edit( lot );
 
-    qof_instance_mark_clean( QOF_INSTANCE(lot) );
+	return lot;
 }
 
 static void
@@ -129,9 +130,13 @@
         int r;
 		GList* list = NULL;
         GncSqlRow* row = gnc_sql_result_get_first_row( result );
+		GNCLot* lot;
 
         while( row != NULL ) {
-            load_single_lot( be, row, &list );
+            lot = load_single_lot( be, row );
+			if( lot != NULL ) {
+				list = g_list_append( list, lot );
+			}
 			row = gnc_sql_result_get_next_row( result );
         }
 		gnc_sql_result_dispose( result );

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-price-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-price-sql.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-price-sql.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -62,7 +62,7 @@
 /* ================================================================= */
 
 static GNCPrice*
-load_single_price( GncSqlBackend* be, GncSqlRow* row, GList** pList )
+load_single_price( GncSqlBackend* be, GncSqlRow* row )
 {
 	GNCPrice* pPrice;
 
@@ -71,11 +71,10 @@
 
     pPrice = gnc_price_create( be->primary_book );
 
+	gnc_price_begin_edit( pPrice );
     gnc_sql_load_object( be, row, GNC_ID_PRICE, pPrice, col_table );
-	*pList = g_list_append( *pList, pPrice );
+	gnc_price_commit_edit( pPrice );
 
-    qof_instance_mark_clean( QOF_INSTANCE(pPrice) );
-
     return pPrice;
 }
 
@@ -101,9 +100,10 @@
 		GncSqlRow* row = gnc_sql_result_get_first_row( result );
 
         while( row != NULL ) {
-            pPrice = load_single_price( be, row, &list );
+            pPrice = load_single_price( be, row );
 
             if( pPrice != NULL ) {
+				list = g_list_append( list, pPrice );
                 gnc_pricedb_add_price( pPriceDB, pPrice );
             }
 			row = gnc_sql_result_get_next_row( result );

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-schedxaction-sql.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -184,7 +184,7 @@
 
 /* ================================================================= */
 static SchedXaction*
-load_single_sx( GncSqlBackend* be, GncSqlRow* row, GList** pList )
+load_single_sx( GncSqlBackend* be, GncSqlRow* row )
 {
     const GUID* guid;
     GUID sx_guid;
@@ -199,13 +199,12 @@
 
     pSx = xaccSchedXactionMalloc( be->primary_book );
 
+	gnc_sx_begin_edit( pSx );
     gnc_sql_load_object( be, row, GNC_SX_ID, pSx, col_table );
 	gnc_sql_recurrence_load_list( be, guid, &schedule );
 	gnc_sx_set_schedule( pSx, schedule );
-	*pList = g_list_append( *pList, pSx );
+	gnc_sx_commit_edit( pSx );
 
-    qof_instance_mark_clean( QOF_INSTANCE(pSx) );
-
     return pSx;
 }
 
@@ -231,9 +230,10 @@
         while( row != NULL ) {
             SchedXaction* sx;
 			
-			sx = load_single_sx( be, row, &list );
+			sx = load_single_sx( be, row );
 			if( sx != NULL ) {
-		    	gnc_sxes_add_sx(sxes, sx);
+		    	gnc_sxes_add_sx( sxes, sx );
+				list = g_list_append( list, sx );
 			}
 			row = gnc_sql_result_get_next_row( result );
         }

Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-transaction-sql.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -198,15 +198,15 @@
     return val;
 }
 
-static void
-load_single_split( GncSqlBackend* be, GncSqlRow* row, GList** pList )
+static Split*
+load_single_split( GncSqlBackend* be, GncSqlRow* row )
 {
     const GUID* guid;
     GUID split_guid;
 	Split* pSplit;
 
-	g_return_if_fail( be != NULL );
-	g_return_if_fail( row != NULL );
+	g_return_val_if_fail( be != NULL, NULL );
+	g_return_val_if_fail( row != NULL, NULL );
 
     guid = gnc_sql_load_guid( be, row );
     split_guid = *guid;
@@ -219,10 +219,11 @@
     /* If the split is dirty, don't overwrite it */
     if( !qof_instance_is_dirty( QOF_INSTANCE(pSplit) ) ) {
     	gnc_sql_load_object( be, row, GNC_ID_SPLIT, pSplit, split_col_table );
-		*pList = g_list_append( *pList, pSplit );
 	}
 
     g_assert( pSplit == xaccSplitLookup( &split_guid, be->primary_book ) );
+
+	return pSplit;
 }
 
 static void
@@ -256,7 +257,12 @@
 
 		row = gnc_sql_result_get_first_row( result );
         while( row != NULL ) {
-            load_single_split( be, row, &list );
+			Split* s;
+
+            s = load_single_split( be, row );
+			if( s != NULL ) {
+				list = g_list_append( list, s );
+			}
 			row = gnc_sql_result_get_next_row( result );
         }
 		gnc_sql_result_dispose( result );
@@ -292,7 +298,11 @@
 
 		row = gnc_sql_result_get_first_row( result );
         while( row != NULL ) {
-            load_single_split( be, row, &list );
+			Split* s;
+            s = load_single_split( be, row );
+			if( s != NULL ) {
+				list = g_list_append( list, s );
+			}
 			row = gnc_sql_result_get_next_row( result );
         }
 
@@ -305,15 +315,15 @@
 	g_string_free( sql, FALSE );
 }
 
-static void
-load_single_tx( GncSqlBackend* be, GncSqlRow* row, GList** pList )
+static Transaction*
+load_single_tx( GncSqlBackend* be, GncSqlRow* row )
 {
     const GUID* guid;
     GUID tx_guid;
 	Transaction* pTx;
 
-	g_return_if_fail( be != NULL );
-	g_return_if_fail( row != NULL );
+	g_return_val_if_fail( be != NULL, NULL );
+	g_return_val_if_fail( row != NULL, NULL );
 
     guid = gnc_sql_load_guid( be, row );
     tx_guid = *guid;
@@ -324,9 +334,10 @@
     }
     xaccTransBeginEdit( pTx );
     gnc_sql_load_object( be, row, GNC_ID_TRANS, pTx, tx_col_table );
-	*pList = g_list_append( *pList, pTx );
 
     g_assert( pTx == xaccTransLookup( &tx_guid, be->primary_book ) );
+
+	return pTx;
 }
 
 static void
@@ -342,10 +353,14 @@
 		GList* tx_list = NULL;
 		GList* node;
 		GncSqlRow* row;
+		Transaction* tx;
 
 		row = gnc_sql_result_get_first_row( result );
         while( row != NULL ) {
-            load_single_tx( be, row, &tx_list );
+            tx = load_single_tx( be, row );
+			if( tx != NULL ) {
+				tx_list = g_list_append( tx_list, tx );
+			}
 			row = gnc_sql_result_get_next_row( result );
         }
 		gnc_sql_result_dispose( result );
@@ -358,7 +373,6 @@
 		// Commit all of the transactions
 		for( node = tx_list; node != NULL; node = node->next ) {
 			Transaction* pTx = GNC_TRANSACTION(node->data);
-    		qof_instance_mark_clean( QOF_INSTANCE(pTx) );
     		xaccTransCommitEdit( pTx );
 		}
     }
@@ -528,6 +542,7 @@
 
         // Now, commit any slots and splits
         gnc_sql_slots_save( be, guid, qof_instance_get_slots( inst ) );
+#if 0
         splits = xaccTransGetSplitList( pTx );
         save_splits( be, guid, splits );
 
@@ -538,6 +553,7 @@
 
             qof_instance_mark_clean(inst);
         }
+#endif
     } else {
         gnc_sql_slots_delete( be, guid );
     }

Modified: gnucash/branches/gda-dev2/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/branches/gda-dev2/src/gnome-utils/gnc-main-window.c	2008-07-12 01:00:59 UTC (rev 17306)
+++ gnucash/branches/gda-dev2/src/gnome-utils/gnc-main-window.c	2008-07-12 01:12:50 UTC (rev 17307)
@@ -1203,6 +1203,9 @@
  *  window title and the title of the "Window" menu item associated
  *  with the window.
  *
+ *  As a side-effect, the save action is set sensitive iff the book
+ *  is dirty.
+ *
  *  @param window The window whose title should be generated.
  *
  *  @return The title for the window.  It is the callers



More information about the gnucash-changes mailing list