r18444 - gnucash/trunk/src/backend/sql - Fix bug 600486 - Unable to open sqllite file on Win7 64 bit

Phil Longstaff plongstaff at code.gnucash.org
Sat Nov 28 10:51:50 EST 2009


Author: plongstaff
Date: 2009-11-28 10:51:49 -0500 (Sat, 28 Nov 2009)
New Revision: 18444
Trac: http://svn.gnucash.org/trac/changeset/18444

Modified:
   gnucash/trunk/src/backend/sql/gnc-transaction-sql.c
Log:
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.


Modified: gnucash/trunk/src/backend/sql/gnc-transaction-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-transaction-sql.c	2009-11-27 03:13:41 UTC (rev 18443)
+++ gnucash/trunk/src/backend/sql/gnc-transaction-sql.c	2009-11-28 15:51:49 UTC (rev 18444)
@@ -1274,6 +1274,7 @@
     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 @@
 
     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 );
+	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 the transaction is not found, try loading it
-	if( tx == NULL ) {
-		gchar* buf;
-		GncSqlStatement* stmt;
+	    // 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 );
-	}
+		    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 );
+	    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 );
+			}
 		}
     }
 }



More information about the gnucash-changes mailing list