r18239 - gnucash/trunk/src/backend/sql - Fix bug 589418: commodities were not being stored properly. The old code used an INSERT if a

Phil Longstaff plongstaff at code.gnucash.org
Sat Aug 8 12:19:57 EDT 2009


Author: plongstaff
Date: 2009-08-08 12:19:57 -0400 (Sat, 08 Aug 2009)
New Revision: 18239
Trac: http://svn.gnucash.org/trac/changeset/18239

Modified:
   gnucash/trunk/src/backend/sql/gnc-commodity-sql.c
Log:
Fix bug 589418: commodities were not being stored properly.  The old code used an INSERT if a
completely new db was being saved or if the object was a new object.  This didn't handle the case
where a currency (all of which are created at startup time) is used for the first time in an
existing file.  In this case, the commodity would *not* be stored.  This was an attempt to avoid
testing each time to see whether the commodity needed to be stored or not.  For now, the test
every time is re-instated.


Modified: gnucash/trunk/src/backend/sql/gnc-commodity-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-commodity-sql.c	2009-08-05 20:52:46 UTC (rev 18238)
+++ gnucash/trunk/src/backend/sql/gnc-commodity-sql.c	2009-08-08 16:19:57 UTC (rev 18239)
@@ -174,13 +174,44 @@
 
 /* ================================================================= */
 static gboolean
+do_commit_commodity( GncSqlBackend* be, QofInstance* inst, gboolean force_insert )
+{
+	const GUID* guid;
+	gboolean is_infant;
+	gint op;
+	gboolean is_ok;
+
+	is_infant = qof_instance_get_infant( inst );
+	if( qof_instance_get_destroying( inst ) ) {
+		op = OP_DB_DELETE;
+	} else if( be->is_pristine_db || is_infant || force_insert ) {
+		op = OP_DB_INSERT;
+	} else {
+		op = OP_DB_UPDATE;
+	}
+    is_ok = gnc_sql_do_db_operation( be, op, COMMODITIES_TABLE, GNC_ID_COMMODITY, inst, col_table );
+
+	if( is_ok ) {
+    	// Now, commit any slots
+    	guid = qof_instance_get_guid( inst );
+    	if( !qof_instance_get_destroying(inst) ) {
+        	is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
+    	} else {
+        	is_ok = gnc_sql_slots_delete( be, guid );
+    	}
+	}
+
+	return is_ok;
+}
+
+static gboolean
 commit_commodity( GncSqlBackend* be, QofInstance* inst )
 {
 	g_return_val_if_fail( be != NULL, FALSE );
 	g_return_val_if_fail( inst != NULL, FALSE );
 	g_return_val_if_fail( GNC_IS_COMMODITY(inst), FALSE );
 
-    return gnc_sql_commit_standard_item( be, inst, COMMODITIES_TABLE, GNC_ID_COMMODITY, col_table );
+    return do_commit_commodity( be, inst, FALSE );
 }
 
 static gboolean
@@ -202,7 +233,7 @@
 	g_return_val_if_fail( pCommodity != NULL, FALSE );
 
     if( !is_commodity_in_db( be, pCommodity ) ) {
-        is_ok = commit_commodity( be, QOF_INSTANCE(pCommodity) );
+        is_ok = do_commit_commodity( be, QOF_INSTANCE(pCommodity), TRUE );
     }
 
 	return is_ok;



More information about the gnucash-changes mailing list