From f110ce2c68505be8492621c00f097875febe0f60 Mon Sep 17 00:00:00 2001 From: Phil Longstaff Date: Fri, 11 Sep 2009 02:09:08 +0000 Subject: [PATCH] If an object is loaded with a reference to an invoice, order, tax table or bill term which has not been loaded yet, print a warning message into the trace file. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18308 57a11ea4-9604-0410-9ed3-97b8803252fd --- .../business-core/sql/gnc-bill-term-sql.c | 24 +++++++++---------- .../business-core/sql/gnc-invoice-sql.c | 24 +++++++++---------- .../business-core/sql/gnc-order-sql.c | 24 +++++++++---------- .../business-core/sql/gnc-tax-table-sql.c | 24 +++++++++---------- 4 files changed, 44 insertions(+), 52 deletions(-) diff --git a/src/business/business-core/sql/gnc-bill-term-sql.c b/src/business/business-core/sql/gnc-bill-term-sql.c index a32c739aaf..c4b2982b12 100644 --- a/src/business/business-core/sql/gnc-bill-term-sql.c +++ b/src/business/business-core/sql/gnc-bill-term-sql.c @@ -208,7 +208,6 @@ load_billterm_guid( const GncSqlBackend* be, GncSqlRow* row, { const GValue* val; GUID guid; - const GUID* pGuid; GncBillTerm* term = NULL; g_return_if_fail( be != NULL ); @@ -217,20 +216,19 @@ load_billterm_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 || !G_VALUE_HOLDS_STRING( val ) || g_value_get_string( val ) == NULL ) { - pGuid = NULL; - } else { + if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) { string_to_guid( g_value_get_string( val ), &guid ); - pGuid = &guid; - } - if( pGuid != NULL ) { - term = gncBillTermLookup( be->primary_book, pGuid ); + term = gncBillTermLookup( be->primary_book, &guid ); + if( term != NULL ) { + if( table_row->gobj_param_name != NULL ) { + g_object_set( pObject, table_row->gobj_param_name, term, NULL ); + } else { + (*setter)( pObject, (const gpointer)term ); + } + } else { + PWARN( "Billterm ref '%s' not found", g_value_get_string( val ) ); + } } - if( table_row->gobj_param_name != NULL ) { - g_object_set( pObject, table_row->gobj_param_name, term, NULL ); - } else { - (*setter)( pObject, (const gpointer)term ); - } } static GncSqlColumnTypeHandler billterm_guid_handler diff --git a/src/business/business-core/sql/gnc-invoice-sql.c b/src/business/business-core/sql/gnc-invoice-sql.c index 34e332f34c..6cc3918c09 100644 --- a/src/business/business-core/sql/gnc-invoice-sql.c +++ b/src/business/business-core/sql/gnc-invoice-sql.c @@ -253,7 +253,6 @@ load_invoice_guid( const GncSqlBackend* be, GncSqlRow* row, { const GValue* val; GUID guid; - const GUID* pGuid; GncInvoice* invoice = NULL; g_return_if_fail( be != NULL ); @@ -262,20 +261,19 @@ load_invoice_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 || !G_VALUE_HOLDS_STRING( val ) || g_value_get_string( val ) == NULL ) { - pGuid = NULL; - } else { + if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) { string_to_guid( g_value_get_string( val ), &guid ); - pGuid = &guid; - } - if( pGuid != NULL ) { - invoice = gncInvoiceLookup( be->primary_book, pGuid ); + invoice = gncInvoiceLookup( be->primary_book, &guid ); + if( invoice != NULL ) { + if( table_row->gobj_param_name != NULL ) { + g_object_set( pObject, table_row->gobj_param_name, invoice, NULL ); + } else { + (*setter)( pObject, (const gpointer)invoice ); + } + } else { + PWARN( "Invoice ref '%s' not found", g_value_get_string( val ) ); + } } - if( table_row->gobj_param_name != NULL ) { - g_object_set( pObject, table_row->gobj_param_name, invoice, NULL ); - } else { - (*setter)( pObject, (const gpointer)invoice ); - } } static GncSqlColumnTypeHandler invoice_guid_handler diff --git a/src/business/business-core/sql/gnc-order-sql.c b/src/business/business-core/sql/gnc-order-sql.c index b18c4037d3..dff7ac8d2c 100644 --- a/src/business/business-core/sql/gnc-order-sql.c +++ b/src/business/business-core/sql/gnc-order-sql.c @@ -198,7 +198,6 @@ load_order_guid( const GncSqlBackend* be, GncSqlRow* row, { const GValue* val; GUID guid; - const GUID* pGuid; GncOrder* order = NULL; g_return_if_fail( be != NULL ); @@ -207,20 +206,19 @@ load_order_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 || !G_VALUE_HOLDS_STRING( val ) || g_value_get_string( val ) == NULL ) { - pGuid = NULL; - } else { + if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) { string_to_guid( g_value_get_string( val ), &guid ); - pGuid = &guid; - } - if( pGuid != NULL ) { - order = gncOrderLookup( be->primary_book, pGuid ); + order = gncOrderLookup( be->primary_book, &guid ); + if( order != NULL ) { + if( table_row->gobj_param_name != NULL ) { + g_object_set( pObject, table_row->gobj_param_name, order, NULL ); + } else { + (*setter)( pObject, (const gpointer)order ); + } + } else { + PWARN( "Order ref '%s' not found", g_value_get_string( val ) ); + } } - if( table_row->gobj_param_name != NULL ) { - g_object_set( pObject, table_row->gobj_param_name, order, NULL ); - } else { - (*setter)( pObject, (const gpointer)order ); - } } static GncSqlColumnTypeHandler order_guid_handler diff --git a/src/business/business-core/sql/gnc-tax-table-sql.c b/src/business/business-core/sql/gnc-tax-table-sql.c index 44f7cc5c80..735356145a 100644 --- a/src/business/business-core/sql/gnc-tax-table-sql.c +++ b/src/business/business-core/sql/gnc-tax-table-sql.c @@ -393,7 +393,6 @@ load_taxtable_guid( const GncSqlBackend* be, GncSqlRow* row, { const GValue* val; GUID guid; - const GUID* pGuid; GncTaxTable* taxtable = NULL; g_return_if_fail( be != NULL ); @@ -402,19 +401,18 @@ load_taxtable_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 || !G_VALUE_HOLDS_STRING( val ) || g_value_get_string( val ) == NULL ) { - pGuid = NULL; - } else { + if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) { string_to_guid( g_value_get_string( val ), &guid ); - pGuid = &guid; - } - if( pGuid != NULL ) { - taxtable = gncTaxTableLookup( be->primary_book, pGuid ); - } - if( table_row->gobj_param_name != NULL ) { - g_object_set( pObject, table_row->gobj_param_name, taxtable, NULL ); - } else { - (*setter)( pObject, (const gpointer)taxtable ); + taxtable = gncTaxTableLookup( be->primary_book, &guid ); + if( taxtable != NULL ) { + if( table_row->gobj_param_name != NULL ) { + g_object_set( pObject, table_row->gobj_param_name, taxtable, NULL ); + } else { + (*setter)( pObject, (const gpointer)taxtable ); + } + } else { + PWARN( "Taxtable ref '%s' not found", g_value_get_string( val ) ); + } } }