Fix bug 600486 - Unable to open sqllite file on Win7 64 bit

Unposted invoice has NULL tx guid, which wasn't being handled correctly.  Doesn't crash
on linux but does on windows.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18444 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2009-11-28 15:51:49 +00:00
parent d0f22524ee
commit 5b49c70ed2

View File

@ -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 );
}
}
}
}