Merge branch 'maint'

This commit is contained in:
John Ralls 2014-09-04 17:01:12 -07:00
commit 1df569e98c
5 changed files with 42 additions and 0 deletions

View File

@ -99,6 +99,8 @@ static GncSqlStatement* build_delete_statement( GncSqlBackend* be,
QofIdTypeConst obj_name, gpointer pObject, QofIdTypeConst obj_name, gpointer pObject,
const GncSqlColumnTableEntry* table ); const GncSqlColumnTableEntry* table );
static GList *post_load_commodities = NULL;
#define TRANSACTION_NAME "trans" #define TRANSACTION_NAME "trans"
typedef struct typedef struct
@ -208,6 +210,20 @@ initial_load_cb( const gchar* type, gpointer data_p, gpointer be_p )
} }
} }
void
gnc_sql_push_commodity_for_postload_processing (GncSqlBackend *be,
gpointer *comm)
{
post_load_commodities = g_list_prepend(post_load_commodities, comm);
}
static void
commit_commodity (gpointer data)
{
gnc_commodity *comm = GNC_COMMODITY (data);
gnc_sql_commit_commodity (comm);
}
void void
gnc_sql_load( GncSqlBackend* be, /*@ dependent @*/ QofBook *book, QofBackendLoadType loadType ) gnc_sql_load( GncSqlBackend* be, /*@ dependent @*/ QofBook *book, QofBackendLoadType loadType )
{ {
@ -264,6 +280,8 @@ gnc_sql_load( GncSqlBackend* be, /*@ dependent @*/ QofBook *book, QofBackendLoad
} }
be->loading = FALSE; be->loading = FALSE;
g_list_free_full (post_load_commodities, commit_commodity);
post_load_commodities = NULL;
/* Mark the sessoion as clean -- though it should never be marked /* Mark the sessoion as clean -- though it should never be marked
* dirty with this backend * dirty with this backend

View File

@ -81,6 +81,16 @@ void gnc_sql_init( GncSqlBackend* be );
*/ */
void gnc_sql_load( GncSqlBackend* be, /*@ dependent @*/ QofBook *book, QofBackendLoadType loadType ); void gnc_sql_load( GncSqlBackend* be, /*@ dependent @*/ QofBook *book, QofBackendLoadType loadType );
/**
* Register a commodity to be committed after loading is complete.
*
* Necessary to save corrections made while loading.
* @param be SQL backend
* @param comm The commodity item to be committed.
*/
void gnc_sql_push_commodity_for_postload_processing (GncSqlBackend *be,
gpointer *comm);
/** /**
* Save the contents of a book to an SQL database. * Save the contents of a book to an SQL database.
* *

View File

@ -154,6 +154,8 @@ load_all_commodities( GncSqlBackend* be )
guid = *qof_instance_get_guid( QOF_INSTANCE(pCommodity) ); guid = *qof_instance_get_guid( QOF_INSTANCE(pCommodity) );
pCommodity = gnc_commodity_table_insert( pTable, pCommodity ); pCommodity = gnc_commodity_table_insert( pTable, pCommodity );
if (qof_instance_is_dirty (QOF_INSTANCE (pCommodity)))
gnc_sql_push_commodity_for_postload_processing (be, (gpointer)pCommodity);
qof_instance_set_guid( QOF_INSTANCE(pCommodity), &guid ); qof_instance_set_guid( QOF_INSTANCE(pCommodity), &guid );
} }
row = gnc_sql_result_get_next_row( result ); row = gnc_sql_result_get_next_row( result );
@ -258,6 +260,15 @@ gnc_sql_save_commodity( GncSqlBackend* be, gnc_commodity* pCommodity )
return is_ok; return is_ok;
} }
void
gnc_sql_commit_commodity (gnc_commodity *pCommodity)
{
g_return_if_fail (pCommodity != NULL);
g_return_if_fail (GNC_IS_COMMODITY (pCommodity));
gnc_commodity_begin_edit (pCommodity);
gnc_commodity_commit_edit (pCommodity);
}
/* ----------------------------------------------------------------- */ /* ----------------------------------------------------------------- */
static void static void

View File

@ -34,5 +34,6 @@
void gnc_sql_init_commodity_handler( void ); void gnc_sql_init_commodity_handler( void );
gboolean gnc_sql_save_commodity( GncSqlBackend* be, gnc_commodity* pCommodity ); gboolean gnc_sql_save_commodity( GncSqlBackend* be, gnc_commodity* pCommodity );
void gnc_sql_commit_commodity (gnc_commodity* pCommodity);
#endif /* GNC_COMMODITY_SQL_H */ #endif /* GNC_COMMODITY_SQL_H */

View File

@ -856,6 +856,7 @@ gnc_commodity_new(QofBook *book, const char * fullname,
gnc_commodity_set_mnemonic(retval, mnemonic); gnc_commodity_set_mnemonic(retval, mnemonic);
gnc_commodity_set_cusip(retval, cusip); gnc_commodity_set_cusip(retval, cusip);
gnc_commodity_set_fraction(retval, fraction); gnc_commodity_set_fraction(retval, fraction);
mark_commodity_dirty (retval);
gnc_commodity_commit_edit(retval); gnc_commodity_commit_edit(retval);
qof_event_gen (&retval->inst, QOF_EVENT_CREATE, NULL); qof_event_gen (&retval->inst, QOF_EVENT_CREATE, NULL);
@ -1925,6 +1926,7 @@ gnc_commodity_table_insert(gnc_commodity_table * table,
"namespace User", priv->mnemonic); "namespace User", priv->mnemonic);
gnc_commodity_set_namespace (comm, "User"); gnc_commodity_set_namespace (comm, "User");
ns_name = "User"; ns_name = "User";
mark_commodity_dirty (comm);
} }
book = qof_instance_get_book (&comm->inst); book = qof_instance_get_book (&comm->inst);