Ensure that the root account is saved to the SQL backend.

The root account is created during DB load if it doesn't already exist.
The DB wasn't saving it because it wasn't marked dirty and because
the loading flag was set, so temprarily unset the loading flag when
creating the book.
This commit is contained in:
John Ralls 2014-09-27 13:57:54 -07:00
parent 2a7ad6867c
commit c61366b82e
3 changed files with 7 additions and 1 deletions

View File

@ -178,10 +178,14 @@ load_all_books( GncSqlBackend* be )
{ {
GncSqlRow* row = gnc_sql_result_get_first_row( result ); GncSqlRow* row = gnc_sql_result_get_first_row( result );
// If there are no rows, try committing the book /* If there are no rows, try committing the book; unset
* loading so that it will actually get saved.
*/
if ( row == NULL ) if ( row == NULL )
{ {
be->loading = FALSE;
(void)gnc_sql_save_book( be, QOF_INSTANCE(be->book) ); (void)gnc_sql_save_book( be, QOF_INSTANCE(be->book) );
be->loading = TRUE;
} }
else else
{ {

View File

@ -951,6 +951,7 @@ gnc_account_create_root (QofBook *book)
xaccAccountBeginEdit(root); xaccAccountBeginEdit(root);
rpriv->type = ACCT_TYPE_ROOT; rpriv->type = ACCT_TYPE_ROOT;
CACHE_REPLACE(rpriv->accountName, "Root Account"); CACHE_REPLACE(rpriv->accountName, "Root Account");
mark_account (root);
xaccAccountCommitEdit(root); xaccAccountCommitEdit(root);
gnc_book_set_root_account(book, root); gnc_book_set_root_account(book, root);
return root; return root;

View File

@ -118,6 +118,7 @@ sxtg_book_begin (QofBook *book)
xaccAccountBeginEdit(root); xaccAccountBeginEdit(root);
xaccAccountSetType(root, ACCT_TYPE_ROOT); xaccAccountSetType(root, ACCT_TYPE_ROOT);
xaccAccountSetName(root, "Template Root"); xaccAccountSetName(root, "Template Root");
qof_instance_set_dirty (QOF_INSTANCE (root));
xaccAccountCommitEdit(root); xaccAccountCommitEdit(root);
gnc_book_set_template_root (book, root); gnc_book_set_template_root (book, root);
} }