gnucash master: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Fri Mar 28 20:45:25 EDT 2014
Updated via https://github.com/Gnucash/gnucash/commit/9293f480 (commit)
via https://github.com/Gnucash/gnucash/commit/bbd26525 (commit)
from https://github.com/Gnucash/gnucash/commit/b73c7740 (commit)
commit 9293f480634f07e831ae3e1eaa21caf2aaf270ed
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Mar 28 11:32:36 2014 -0700
Bug 724995 - Gnucash crashes due to assertion failed when opening sqlite file
Rather than asserting (and therefore crashing) on a bad split or transaction,
write an error description and raise an ERR_BACKEND_DATA_CORRUPT error.
Fix bad GUIDs in splits at write.
diff --git a/src/backend/sql/gnc-transaction-sql.c b/src/backend/sql/gnc-transaction-sql.c
index d563b55..0ea2189 100644
--- a/src/backend/sql/gnc-transaction-sql.c
+++ b/src/backend/sql/gnc-transaction-sql.c
@@ -191,19 +191,29 @@ load_single_split( GncSqlBackend* be, GncSqlRow* row )
{
const GncGUID* guid;
GncGUID split_guid;
- Split* pSplit;
+ Split* pSplit = NULL;
+ gboolean bad_guid = FALSE;
g_return_val_if_fail( be != NULL, NULL );
g_return_val_if_fail( row != NULL, NULL );
guid = gnc_sql_load_guid( be, row );
if ( guid == NULL ) return NULL;
- split_guid = *guid;
+ if (guid_equal(guid, guid_null()))
+ {
+ PWARN("Bad GUID, creating new");
+ bad_guid = TRUE;
+ split_guid = guid_new_return();
+ }
+ else
+ {
+ split_guid = *guid;
+ pSplit = xaccSplitLookup( &split_guid, be->book );
+ }
- pSplit = xaccSplitLookup( &split_guid, be->book );
if ( pSplit == NULL )
{
- pSplit = xaccMallocSplit( be->book );
+ pSplit = xaccMallocSplit( be->book );
}
/* If the split is dirty, don't overwrite it */
@@ -212,8 +222,14 @@ load_single_split( GncSqlBackend* be, GncSqlRow* row )
gnc_sql_load_object( be, row, GNC_ID_SPLIT, pSplit, split_col_table );
}
- /*# -ifempty */g_assert( pSplit == xaccSplitLookup( &split_guid, be->book ) );
-
+ /*# -ifempty */
+ if (pSplit != xaccSplitLookup( &split_guid, be->book ))
+ {
+ PERR("A malformed split with id %s was found in the dataset.",
+ guid_to_string(qof_instance_get_guid(pSplit)));
+ qof_backend_set_error( &be->be, ERR_BACKEND_DATA_CORRUPT);
+ pSplit = NULL;
+ }
return pSplit;
}
@@ -287,7 +303,13 @@ load_single_tx( GncSqlBackend* be, GncSqlRow* row )
xaccTransBeginEdit( pTx );
gnc_sql_load_object( be, row, GNC_ID_TRANS, pTx, tx_col_table );
- g_assert( pTx == xaccTransLookup( &tx_guid, be->book ) );
+ if (pTx != xaccTransLookup( &tx_guid, be->book ))
+ {
+ PERR("A malformed transaction with id %s was found in the dataset.",
+ guid_to_string(qof_instance_get_guid(pTx)));
+ qof_backend_set_error( &be->be, ERR_BACKEND_DATA_CORRUPT);
+ pTx = NULL;
+ }
return pTx;
}
@@ -570,6 +592,7 @@ commit_split( GncSqlBackend* be, QofInstance* inst )
gint op;
gboolean is_infant;
gboolean is_ok;
+ GncGUID *guid = (GncGUID*)qof_instance_get_guid(inst);
g_return_val_if_fail( inst != NULL, FALSE );
g_return_val_if_fail( be != NULL, FALSE );
@@ -587,11 +610,20 @@ commit_split( GncSqlBackend* be, QofInstance* inst )
{
op = OP_DB_UPDATE;
}
- is_ok = gnc_sql_do_db_operation( be, op, SPLIT_TABLE, GNC_ID_SPLIT, inst, split_col_table );
+
+ if (guid_equal (guid, guid_null ()))
+ {
+ *guid = guid_new_return ();
+ qof_instance_set_guid (inst, guid);
+ }
+
+ is_ok = gnc_sql_do_db_operation( be, op, SPLIT_TABLE, GNC_ID_SPLIT,
+ inst, split_col_table );
+
if ( is_ok && !qof_instance_get_destroying (inst))
{
is_ok = gnc_sql_slots_save( be,
- qof_instance_get_guid( inst ),
+ guid,
is_infant,
qof_instance_get_slots( inst ) );
}
commit bbd26525fc8ca23bfa997c9ac1a20c774e347d27
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Mar 28 11:30:14 2014 -0700
Set Gnucash version and GNUCASH_RESAVE_VERSION in init_version_info
And reset_version_info. This is a better solution than setting it in load
after calling init_version_info because in load it would over-write the
values stored in the database.
diff --git a/src/backend/dbi/gnc-backend-dbi.c b/src/backend/dbi/gnc-backend-dbi.c
index fb93e06..8347679 100644
--- a/src/backend/dbi/gnc-backend-dbi.c
+++ b/src/backend/dbi/gnc-backend-dbi.c
@@ -1412,10 +1412,6 @@ gnc_dbi_load( QofBackend* qbe, /*@ dependent @*/ QofBook *book, QofBackendLoadTy
// Set up table version information
gnc_sql_init_version_info (&be->sql_be);
- gnc_sql_set_table_version (&be->sql_be, "Gnucash",
- gnc_prefs_get_long_version());
- gnc_sql_set_table_version (&be->sql_be, "Gnucash-Resave",
- GNUCASH_RESAVE_VERSION);
// Call all object backends to create any required tables
qof_object_foreach_backend( GNC_SQL_BACKEND, create_tables_cb, be );
diff --git a/src/backend/sql/gnc-backend-sql.c b/src/backend/sql/gnc-backend-sql.c
index e6518bb..6169388 100644
--- a/src/backend/sql/gnc-backend-sql.c
+++ b/src/backend/sql/gnc-backend-sql.c
@@ -439,8 +439,6 @@ gnc_sql_sync_all( GncSqlBackend* be, /*@ dependent @*/ QofBook *book )
ENTER( "book=%p, be->book=%p", book, be->book );
update_progress( be );
(void)reset_version_info( be );
- gnc_sql_set_table_version( be, "Gnucash", gnc_prefs_get_long_version() );
- gnc_sql_set_table_version( be, "Gnucash-Resave", GNUCASH_RESAVE_VERSION );
/* Create new tables */
be->is_pristine_db = TRUE;
@@ -3231,6 +3229,10 @@ gnc_sql_init_version_info( GncSqlBackend* be )
else
{
do_create_table( be, VERSION_TABLE_NAME, version_table );
+ gnc_sql_set_table_version( be, "Gnucash",
+ gnc_prefs_get_long_version() );
+ gnc_sql_set_table_version( be, "Gnucash-Resave",
+ GNUCASH_RESAVE_VERSION );
}
}
@@ -3258,6 +3260,8 @@ reset_version_info( GncSqlBackend* be )
g_hash_table_remove_all( be->versions );
}
+ gnc_sql_set_table_version( be, "Gnucash", gnc_prefs_get_long_version() );
+ gnc_sql_set_table_version( be, "Gnucash-Resave", GNUCASH_RESAVE_VERSION );
return ok;
}
Summary of changes:
src/backend/dbi/gnc-backend-dbi.c | 4 ---
src/backend/sql/gnc-backend-sql.c | 8 ++++--
src/backend/sql/gnc-transaction-sql.c | 50 ++++++++++++++++++++++++++++-------
3 files changed, 47 insertions(+), 15 deletions(-)
More information about the gnucash-changes
mailing list