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.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18239 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2009-08-08 16:19:57 +00:00
parent dc998a7408
commit 6356b0dcbf

View File

@ -173,6 +173,37 @@ create_commodities_tables( GncSqlBackend* be )
} }
/* ================================================================= */ /* ================================================================= */
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 static gboolean
commit_commodity( GncSqlBackend* be, QofInstance* inst ) commit_commodity( GncSqlBackend* be, QofInstance* inst )
{ {
@ -180,7 +211,7 @@ commit_commodity( GncSqlBackend* be, QofInstance* inst )
g_return_val_if_fail( inst != NULL, FALSE ); g_return_val_if_fail( inst != NULL, FALSE );
g_return_val_if_fail( GNC_IS_COMMODITY(inst), 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 static gboolean
@ -202,7 +233,7 @@ gnc_sql_save_commodity( GncSqlBackend* be, gnc_commodity* pCommodity )
g_return_val_if_fail( pCommodity != NULL, FALSE ); g_return_val_if_fail( pCommodity != NULL, FALSE );
if( !is_commodity_in_db( be, pCommodity ) ) { 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; return is_ok;