mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add a mechanism so that the business sql backend module can provide the main sql backend with the order in which objects should be loaded. This will allow billterms and taxtables to be loaded before objects which contain references to those objects.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18852 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
5396817936
commit
0c944231f6
@ -137,9 +137,18 @@ create_tables_cb( const gchar* type, gpointer data_p, gpointer be_p )
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
/* Main object load order */
|
||||
static const gchar* fixed_load_order[] =
|
||||
{ GNC_ID_BOOK, GNC_ID_COMMODITY, GNC_ID_ACCOUNT, GNC_ID_LOT };
|
||||
#define NUM_FIXED_LOAD_ORDER (gint)(sizeof(fixed_load_order)/sizeof(fixed_load_order[0]))
|
||||
{ GNC_ID_BOOK, GNC_ID_COMMODITY, GNC_ID_ACCOUNT, GNC_ID_LOT, NULL };
|
||||
|
||||
/* Load order for objects from other modules */
|
||||
static const gchar** other_load_order = NULL;
|
||||
|
||||
void
|
||||
gnc_sql_set_load_order( const gchar** load_order )
|
||||
{
|
||||
other_load_order = load_order;
|
||||
}
|
||||
|
||||
static void
|
||||
initial_load_cb( const gchar* type, gpointer data_p, gpointer be_p )
|
||||
@ -152,9 +161,14 @@ initial_load_cb( const gchar* type, gpointer data_p, gpointer be_p )
|
||||
g_return_if_fail( pData->version == GNC_SQL_BACKEND_VERSION );
|
||||
|
||||
// Don't need to load anything if it has already been loaded with the fixed order
|
||||
for( i = 0; i < NUM_FIXED_LOAD_ORDER; i++ ) {
|
||||
for( i = 0; fixed_load_order[i] != NULL; i++ ) {
|
||||
if( g_ascii_strcasecmp( type, fixed_load_order[i] ) == 0 ) return;
|
||||
}
|
||||
if( other_load_order != NULL ) {
|
||||
for( i = 0; other_load_order[i] != NULL; i++ ) {
|
||||
if( g_ascii_strcasecmp( type, other_load_order[i] ) == 0 ) return;
|
||||
}
|
||||
}
|
||||
|
||||
if( pData->initial_load != NULL ) {
|
||||
(pData->initial_load)( be );
|
||||
@ -180,12 +194,20 @@ gnc_sql_load( GncSqlBackend* be, /*@ dependent @*/ QofBook *book, QofBackendLoad
|
||||
be->primary_book = book;
|
||||
|
||||
/* Load any initial stuff. Some of this needs to happen in a certain order */
|
||||
for( i = 0; i < NUM_FIXED_LOAD_ORDER; i++ ) {
|
||||
for( i = 0; fixed_load_order[i] != NULL; i++ ) {
|
||||
pData = qof_object_lookup_backend( fixed_load_order[i], GNC_SQL_BACKEND );
|
||||
if( pData->initial_load != NULL ) {
|
||||
(pData->initial_load)( be );
|
||||
}
|
||||
}
|
||||
if( other_load_order != NULL ) {
|
||||
for( i = 0; other_load_order[i] != NULL; i++ ) {
|
||||
pData = qof_object_lookup_backend( other_load_order[i], GNC_SQL_BACKEND );
|
||||
if( pData->initial_load != NULL ) {
|
||||
(pData->initial_load)( be );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
root = gnc_book_get_root_account( book );
|
||||
gnc_account_foreach_descendant( root, (AccountCb)xaccAccountBeginEdit, NULL );
|
||||
|
@ -716,6 +716,15 @@ gchar* gnc_sql_convert_timespec_to_string( const GncSqlBackend* be, Timespec ts
|
||||
void gnc_sql_upgrade_table( GncSqlBackend* be, const gchar* table_name,
|
||||
const GncSqlColumnTableEntry* col_table );
|
||||
|
||||
/**
|
||||
* Specifies the load order for a set of objects. When loading from a database, the
|
||||
* objects will be loaded in this order, so that when later objects have references to
|
||||
* objects, those objects will already have been loaded.
|
||||
*
|
||||
* @param load_order NULL-terminated array of object type ID strings
|
||||
*/
|
||||
void gnc_sql_set_load_order( const gchar** load_order );
|
||||
|
||||
void _retrieve_guid_( gpointer pObject, /*@ null @*/ gpointer pValue );
|
||||
|
||||
/*@ null @*/
|
||||
|
@ -75,6 +75,10 @@ libgncmod_business_backend_sql_gnc_module_description(void)
|
||||
return g_strdup( "The SQL backend for GnuCash business objects" );
|
||||
}
|
||||
|
||||
/* Order in which business objects need to be loaded */
|
||||
static const gchar* fixed_load_order[] =
|
||||
{ GNC_ID_BILLTERM, GNC_ID_TAXTABLE, NULL };
|
||||
|
||||
int
|
||||
libgncmod_business_backend_sql_gnc_module_init(int refcount)
|
||||
{
|
||||
@ -100,6 +104,8 @@ libgncmod_business_backend_sql_gnc_module_init(int refcount)
|
||||
gnc_owner_sql_initialize();
|
||||
gnc_taxtable_sql_initialize();
|
||||
gnc_vendor_sql_initialize();
|
||||
|
||||
gnc_sql_set_load_order( fixed_load_order );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
Loading…
Reference in New Issue
Block a user