r18085 - gnucash/trunk/src/backend/dbi - Bug #583535: When selecting a db using dbi_conn_select_db(), change the "dbname" option which

Phil Longstaff plongstaff at code.gnucash.org
Fri May 22 21:02:37 EDT 2009


Author: plongstaff
Date: 2009-05-22 21:02:37 -0400 (Fri, 22 May 2009)
New Revision: 18085
Trac: http://svn.gnucash.org/trac/changeset/18085

Modified:
   gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
Log:
Bug #583535: When selecting a db using dbi_conn_select_db(), change the "dbname" option which
is used in other places to identify the current database name.


Modified: gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2009-05-21 01:52:47 UTC (rev 18084)
+++ gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2009-05-23 01:02:37 UTC (rev 18085)
@@ -340,6 +340,13 @@
 			if( be->sql_be.conn != NULL ) {
 				gnc_sql_connection_dispose( be->sql_be.conn );
 			}
+			result = dbi_conn_set_option( be->conn, "dbname", dbname );
+			if( result < 0 ) {
+				PERR( "Error setting 'dbname' option\n" );
+        		qof_backend_set_error( qbe, ERR_BACKEND_SERVER_ERR );
+        		LEAVE( " " );
+        		return;
+			}
 			be->sql_be.conn = create_dbi_connection( GNC_DBI_PROVIDER_MYSQL, qbe, be->conn );
 		} else {
 			if( create_if_nonexistent ) {
@@ -352,6 +359,13 @@
 						gnc_sql_connection_dispose( be->sql_be.conn );
 					}
 					be->sql_be.conn = create_dbi_connection( GNC_DBI_PROVIDER_MYSQL, qbe, be->conn );
+					result = dbi_conn_set_option( be->conn, "dbname", dbname );
+					if( result < 0 ) {
+						PERR( "Error setting 'dbname' option\n" );
+        				qof_backend_set_error( qbe, ERR_BACKEND_SERVER_ERR );
+        				LEAVE( " " );
+        				return;
+					}
 				} else {
 					PERR( "Unable to connect to %s: %d\n", book_id, result );
         			qof_backend_set_error( qbe, ERR_BACKEND_CANT_CONNECT );
@@ -579,10 +593,12 @@
 
 		table_name = dbi_result_get_string_idx( tables, 1 );
 		result = dbi_conn_queryf( be->conn, "DROP TABLE %s", table_name );
-		status = dbi_result_free( result );
-		if( status < 0 ) {
-			PERR( "Error in dbi_result_free() result\n" );
-			qof_backend_set_error( qbe, ERR_BACKEND_SERVER_ERR );
+		if( result != NULL ) {
+			status = dbi_result_free( result );
+			if( status < 0 ) {
+				PERR( "Error in dbi_result_free() result\n" );
+				qof_backend_set_error( qbe, ERR_BACKEND_SERVER_ERR );
+			}
 		}
 	}
 	status = dbi_result_free( tables );



More information about the gnucash-changes mailing list