r17417 - gnucash/branches/gda-dev2/src - Fix saving and restoring of null owner values.

Phil Longstaff plongstaff at cvs.gnucash.org
Sun Jul 27 10:00:35 EDT 2008


Author: plongstaff
Date: 2008-07-27 10:00:35 -0400 (Sun, 27 Jul 2008)
New Revision: 17417
Trac: http://svn.gnucash.org/trac/changeset/17417

Modified:
   gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c
   gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-owner-sql.c
Log:
Fix saving and restoring of null owner values.



Modified: gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c	2008-07-27 13:08:22 UTC (rev 17416)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c	2008-07-27 14:00:35 UTC (rev 17417)
@@ -984,8 +984,6 @@
 	g_value_init( value, G_TYPE_STRING );
     if( s ) {
         g_value_set_string( value, s );
-    } else {
-		g_value_set_string( value, "NULL" );
 	}
 
 	(*pList) = g_slist_append( (*pList), value );
@@ -2135,15 +2133,19 @@
 {
 	if( value != NULL && G_IS_VALUE( value ) ) {
 		if( G_VALUE_HOLDS_STRING(value) ) {
-			gchar *before_str;
-			gchar* after_str;
-			before_str = g_value_dup_string( value );
-			after_str = gnc_sql_connection_quote_string( conn, before_str );
-			g_free( before_str );
-			return after_str;
+			if( g_value_get_string( value ) != NULL ) {
+				gchar* before_str;
+				gchar* after_str;
+				before_str = g_value_dup_string( value );
+				after_str = gnc_sql_connection_quote_string( conn, before_str );
+				g_free( before_str );
+				return after_str;
+			} else {
+				return g_strdup( "NULL" );
+			}
 		} else if( g_value_type_transformable( G_VALUE_TYPE(value), G_TYPE_STRING ) ) {
-			GValue *string;
-			gchar *str;
+			GValue* string;
+			gchar* str;
 			
 			string = g_value_init( g_new0( GValue, 1 ), G_TYPE_STRING );
 			g_value_transform( value, string );

Modified: gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-owner-sql.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-owner-sql.c	2008-07-27 13:08:22 UTC (rev 17416)
+++ gnucash/branches/gda-dev2/src/business/business-core/sql/gnc-owner-sql.c	2008-07-27 14:00:35 UTC (rev 17417)
@@ -58,7 +58,7 @@
     GUID guid;
 	QofBook* book;
 	GncOwner owner;
-	GUID* pGuid;
+	GUID* pGuid = NULL;
 
 	g_return_if_fail( be != NULL );
 	g_return_if_fail( row != NULL );
@@ -74,18 +74,22 @@
     val = gnc_sql_row_get_value_at_col_name( row, buf );
     g_free( buf );
 
-    if( val != NULL ) {
+    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;
+		pGuid = &guid;
+	}
 
     switch( type ) {
   	case GNC_OWNER_CUSTOMER:
   		{
-    		GncCustomer *cust = gncCustomerLookup( book, pGuid );
-    		if( cust == NULL ) {
-      			cust = gncCustomerCreate( book );
-      			gncCustomerSetGUID( cust, &guid );
+    		GncCustomer *cust = NULL;
+
+			if( pGuid != NULL ) {
+    			cust = gncCustomerLookup( book, pGuid );
+    			if( cust == NULL ) {
+      				cust = gncCustomerCreate( book );
+      				gncCustomerSetGUID( cust, &guid );
+				}
     		}
     		gncOwnerInitCustomer( &owner, cust );
     		break; 
@@ -93,10 +97,14 @@
 
   	case GNC_OWNER_JOB:
   		{
-    		GncJob *job = gncJobLookup( book, pGuid );
-    		if( job == NULL ) {
-      			job = gncJobCreate( book );
-      			gncJobSetGUID( job, &guid );
+    		GncJob *job = NULL;
+
+			if( pGuid != NULL ) {
+				job = gncJobLookup( book, pGuid );
+    			if( job == NULL ) {
+      				job = gncJobCreate( book );
+      				gncJobSetGUID( job, &guid );
+				}
     		}
     		gncOwnerInitJob( &owner, job );
     		break; 
@@ -104,10 +112,14 @@
 
   	case GNC_OWNER_VENDOR:
   		{
-    		GncVendor *vendor = gncVendorLookup( book, pGuid );
-    		if( vendor == NULL ) {
-      			vendor = gncVendorCreate( book );
-    		  	gncVendorSetGUID( vendor, &guid );
+    		GncVendor *vendor = NULL;
+
+			if( pGuid != NULL ) {
+    			vendor = gncVendorLookup( book, pGuid );
+    			if( vendor == NULL ) {
+      				vendor = gncVendorCreate( book );
+    		  		gncVendorSetGUID( vendor, &guid );
+				}
     		}
     		gncOwnerInitVendor( &owner, vendor );
     		break; 
@@ -115,10 +127,14 @@
 
   	case GNC_OWNER_EMPLOYEE:
   		{
-    		GncEmployee *employee = gncEmployeeLookup( book, pGuid );
-    		if( employee == NULL ) {
-      			employee = gncEmployeeCreate( book );
-      			gncEmployeeSetGUID( employee, &guid );
+    		GncEmployee *employee = NULL;
+
+			if( pGuid != NULL ) {
+    			employee = gncEmployeeLookup( book, pGuid );
+    			if( employee == NULL ) {
+      				employee = gncEmployeeCreate( book );
+      				gncEmployeeSetGUID( employee, &guid );
+				}
     		}
     		gncOwnerInitEmployee( &owner, employee );
     		break; 
@@ -237,11 +253,7 @@
     		if( guid != NULL ) {
         		(void)guid_to_string_buff( guid, guid_buf );
         		g_value_take_string( subfield_value, g_strdup_printf( "%s", guid_buf ) );
-    		} else {
-				g_value_set_string( subfield_value, "NULL" );
 			}
-    	} else {
-			g_value_set_string( subfield_value, "NULL" );
 		}
 		(*pList) = g_slist_append( (*pList), subfield_value );
 		g_free( buf );



More information about the gnucash-changes mailing list