mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
If an object is being loaded that has a reference to a transaction, and the transaction
hasn't been loaded yet, load it. If an object has a reference to an account, commodity, budget or lot that hasn't been loaded yet, print a warning message in the trace file. The difference in handling is that these object types are always loaded at init time, whereas transactions are not. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18307 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
2bc336a874
commit
ca6a78b89d
@ -358,7 +358,6 @@ load_account_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
{
|
||||
const GValue* val;
|
||||
GUID guid;
|
||||
const GUID* pGuid;
|
||||
Account* account = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
@ -367,15 +366,9 @@ load_account_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val == NULL ) {
|
||||
pGuid = NULL;
|
||||
} else {
|
||||
if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
|
||||
(void)string_to_guid( g_value_get_string( val ), &guid );
|
||||
pGuid = &guid;
|
||||
}
|
||||
if( pGuid != NULL ) {
|
||||
account = xaccAccountLookup( pGuid, be->primary_book );
|
||||
}
|
||||
account = xaccAccountLookup( &guid, be->primary_book );
|
||||
if( account != NULL ) {
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, account, NULL );
|
||||
@ -383,6 +376,9 @@ load_account_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
g_return_if_fail( setter != NULL );
|
||||
(*setter)( pObject, (const gpointer)account );
|
||||
}
|
||||
} else {
|
||||
PWARN( "Account ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -446,7 +446,6 @@ load_budget_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
{
|
||||
const GValue* val;
|
||||
GUID guid;
|
||||
const GUID* pGuid;
|
||||
GncBudget* budget = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
@ -455,15 +454,9 @@ load_budget_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val == NULL ) {
|
||||
pGuid = NULL;
|
||||
} else {
|
||||
if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
|
||||
(void)string_to_guid( g_value_get_string( val ), &guid );
|
||||
pGuid = &guid;
|
||||
}
|
||||
if( pGuid != NULL ) {
|
||||
budget = gnc_budget_lookup( pGuid, be->primary_book );
|
||||
}
|
||||
budget = gnc_budget_lookup( &guid, be->primary_book );
|
||||
if( budget != NULL ) {
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, budget, NULL );
|
||||
@ -471,6 +464,9 @@ load_budget_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
g_return_if_fail( setter != NULL );
|
||||
(*setter)( pObject, (const gpointer)budget );
|
||||
}
|
||||
} else {
|
||||
PWARN( "Budget ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,7 +256,7 @@ load_commodity_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
g_assert( val != NULL );
|
||||
if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
|
||||
(void)string_to_guid( g_value_get_string( val ), &guid );
|
||||
commodity = gnc_commodity_find_commodity_by_guid( &guid, be->primary_book );
|
||||
if( commodity != NULL ) {
|
||||
@ -265,6 +265,9 @@ load_commodity_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
} else if( setter != NULL ) {
|
||||
(*setter)( pObject, (const gpointer)commodity );
|
||||
}
|
||||
} else {
|
||||
PWARN( "Commodity ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,17 +233,20 @@ load_lot_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
|
||||
g_return_if_fail( val != NULL );
|
||||
|
||||
if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
|
||||
(void)string_to_guid( g_value_get_string( val ), &guid );
|
||||
lot = gnc_lot_lookup( &guid, be->primary_book );
|
||||
if( lot != NULL ) {
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, lot, NULL );
|
||||
} else {
|
||||
g_return_if_fail( setter != NULL );
|
||||
(*setter)( pObject, (const gpointer)lot );
|
||||
}
|
||||
} else {
|
||||
PWARN( "Lot ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static GncSqlColumnTypeHandler lot_guid_handler
|
||||
|
@ -1266,12 +1266,28 @@ load_tx_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
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 );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static GncSqlColumnTypeHandler tx_guid_handler
|
||||
|
Loading…
Reference in New Issue
Block a user