gnucash maint: Ensure that the root account is saved to the SQL backend.

John Ralls jralls at code.gnucash.org
Sat Sep 27 16:40:59 EDT 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/c61366b8 (commit)
	from  https://github.com/Gnucash/gnucash/commit/2a7ad686 (commit)



commit c61366b82e35109dfca56f7977cec6acab0d758b
Author: John Ralls <jralls at ceridwen.us>
Date:   Sat Sep 27 13:57:54 2014 -0700

    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.

diff --git a/src/backend/sql/gnc-book-sql.c b/src/backend/sql/gnc-book-sql.c
index 85b1a59..a9e312d 100644
--- a/src/backend/sql/gnc-book-sql.c
+++ b/src/backend/sql/gnc-book-sql.c
@@ -178,10 +178,14 @@ load_all_books( GncSqlBackend* be )
         {
             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 )
             {
+                be->loading = FALSE;
                 (void)gnc_sql_save_book( be, QOF_INSTANCE(be->book) );
+                be->loading = TRUE;
             }
             else
             {
diff --git a/src/engine/Account.c b/src/engine/Account.c
index 3e842ce..c0f120b 100644
--- a/src/engine/Account.c
+++ b/src/engine/Account.c
@@ -951,6 +951,7 @@ gnc_account_create_root (QofBook *book)
     xaccAccountBeginEdit(root);
     rpriv->type = ACCT_TYPE_ROOT;
     CACHE_REPLACE(rpriv->accountName, "Root Account");
+    mark_account (root);
     xaccAccountCommitEdit(root);
     gnc_book_set_root_account(book, root);
     return root;
diff --git a/src/engine/SX-book.c b/src/engine/SX-book.c
index 57ee618..8d433ae 100644
--- a/src/engine/SX-book.c
+++ b/src/engine/SX-book.c
@@ -118,6 +118,7 @@ sxtg_book_begin (QofBook *book)
     xaccAccountBeginEdit(root);
     xaccAccountSetType(root, ACCT_TYPE_ROOT);
     xaccAccountSetName(root, "Template Root");
+    qof_instance_set_dirty (QOF_INSTANCE (root));
     xaccAccountCommitEdit(root);
     gnc_book_set_template_root (book, root);
 }



Summary of changes:
 src/backend/sql/gnc-book-sql.c | 6 +++++-
 src/engine/Account.c           | 1 +
 src/engine/SX-book.c           | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)



More information about the gnucash-changes mailing list