From f9822bd3340d3314a65c81cedf2f3bdaa2d0fd15 Mon Sep 17 00:00:00 2001 From: Phil Longstaff Date: Sun, 9 Aug 2009 17:26:16 +0000 Subject: [PATCH] Save and restore root account to SQL dbs git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18240 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/backend/sql/gnc-account-sql.c | 7 ++++--- src/backend/sql/gnc-backend-sql.c | 16 ++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/backend/sql/gnc-account-sql.c b/src/backend/sql/gnc-account-sql.c index 063ebd28b6..a43bab5f56 100644 --- a/src/backend/sql/gnc-account-sql.c +++ b/src/backend/sql/gnc-account-sql.c @@ -167,9 +167,10 @@ load_single_account( GncSqlBackend* be, GncSqlRow* row, gnc_sql_load_object( be, row, GNC_ID_ACCOUNT, pAccount, col_table ); xaccAccountCommitEdit( 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. */ - if( gnc_account_get_parent( pAccount ) == NULL ) { + /* If we don't have a parent and this isn't the root account, it might be because the parent + account hasn't been loaded yet. Remember the account and its parent guid for later. */ + if( gnc_account_get_parent( pAccount ) == NULL + && pAccount != gnc_book_get_root_account( be->primary_book ) ) { account_parent_guid_struct* s = g_malloc( (gsize)sizeof(account_parent_guid_struct) ); g_assert( s != NULL ); diff --git a/src/backend/sql/gnc-backend-sql.c b/src/backend/sql/gnc-backend-sql.c index d44f2149ab..32c9829a37 100644 --- a/src/backend/sql/gnc-backend-sql.c +++ b/src/backend/sql/gnc-backend-sql.c @@ -267,12 +267,16 @@ write_account_tree( GncSqlBackend* be, Account* root ) g_return_val_if_fail( be != NULL, FALSE ); g_return_val_if_fail( root != NULL, FALSE ); - descendants = gnc_account_get_descendants( root ); - for( node = descendants; node != NULL && is_ok; node = g_list_next(node) ) { - is_ok = gnc_sql_save_account( be, QOF_INSTANCE(GNC_ACCOUNT(node->data)) ); - update_save_progress( be ); - } - g_list_free( descendants ); + is_ok = gnc_sql_save_account( be, QOF_INSTANCE(root) ); + if( is_ok ) { + descendants = gnc_account_get_descendants( root ); + for( node = descendants; node != NULL && is_ok; node = g_list_next(node) ) { + is_ok = gnc_sql_save_account( be, QOF_INSTANCE(GNC_ACCOUNT(node->data)) ); + if( !is_ok ) break; + update_save_progress( be ); + } + g_list_free( descendants ); + } return is_ok; }