diff --git a/src/backend/sql/gnc-transaction-sql.c b/src/backend/sql/gnc-transaction-sql.c index 30f8431da2..e5c7a974ff 100644 --- a/src/backend/sql/gnc-transaction-sql.c +++ b/src/backend/sql/gnc-transaction-sql.c @@ -1274,6 +1274,7 @@ load_tx_guid( const GncSqlBackend* be, GncSqlRow* row, const GValue* val; GUID guid; Transaction* tx; + const gchar* guid_str; g_return_if_fail( be != NULL ); g_return_if_fail( row != NULL ); @@ -1282,28 +1283,31 @@ load_tx_guid( const GncSqlBackend* be, GncSqlRow* row, val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name ); g_assert( val != NULL ); - (void)string_to_guid( g_value_get_string( val ), &guid ); - tx = xaccTransLookup( &guid, be->primary_book ); - - // If the transaction is not found, try loading it - if( tx == NULL ) { - gchar* buf; - GncSqlStatement* stmt; - - buf = g_strdup_printf( "SELECT * FROM %s WHERE guid='%s'", - TRANSACTION_TABLE, g_value_get_string( val ) ); - stmt = gnc_sql_create_statement_from_sql( (GncSqlBackend*)be, buf ); - g_free( buf ); - query_transactions( (GncSqlBackend*)be, stmt ); + guid_str = g_value_get_string(val); + if( guid_str != NULL ) { + (void)string_to_guid( guid_str, &guid ); tx = xaccTransLookup( &guid, be->primary_book ); - } - if( tx != NULL ) { - if( table_row->gobj_param_name != NULL ) { - g_object_set( pObject, table_row->gobj_param_name, tx, NULL ); - } else { - g_return_if_fail( setter != NULL ); - (*setter)( pObject, (const gpointer)tx ); + // If the transaction is not found, try loading it + if( tx == NULL ) { + gchar* buf; + GncSqlStatement* stmt; + + buf = g_strdup_printf( "SELECT * FROM %s WHERE guid='%s'", + TRANSACTION_TABLE, guid_str ); + stmt = gnc_sql_create_statement_from_sql( (GncSqlBackend*)be, buf ); + g_free( buf ); + query_transactions( (GncSqlBackend*)be, stmt ); + tx = xaccTransLookup( &guid, be->primary_book ); + } + + if( tx != NULL ) { + if( table_row->gobj_param_name != NULL ) { + g_object_set( pObject, table_row->gobj_param_name, tx, NULL ); + } else { + g_return_if_fail( setter != NULL ); + (*setter)( pObject, (const gpointer)tx ); + } } } }