r17323 - gnucash/branches/gda-dev2/src - Get dbi connection to postgres working.

Phil Longstaff plongstaff at cvs.gnucash.org
Sun Jul 13 15:58:11 EDT 2008


Author: plongstaff
Date: 2008-07-13 15:58:11 -0400 (Sun, 13 Jul 2008)
New Revision: 17323
Trac: http://svn.gnucash.org/trac/changeset/17323

Modified:
   gnucash/branches/gda-dev2/src/backend/dbi/gnc-backend-dbi.c
   gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c
   gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.c
   gnucash/branches/gda-dev2/src/gnome-utils/glade/dialog-database-connection.glade
Log:
Get dbi connection to postgres working.



Modified: gnucash/branches/gda-dev2/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/dbi/gnc-backend-dbi.c	2008-07-13 18:33:57 UTC (rev 17322)
+++ gnucash/branches/gda-dev2/src/backend/dbi/gnc-backend-dbi.c	2008-07-13 19:58:11 UTC (rev 17323)
@@ -157,7 +157,6 @@
 				       gboolean create_if_nonexistent )
 {
     GncDbiBackend *be = (GncDbiBackend*)qbe;
-    GError* error = NULL;
 	gchar* dsn;
 	gchar* host;
 	gchar* dbname;
@@ -216,15 +215,12 @@
 				       gboolean create_if_nonexistent )
 {
     GncDbiBackend *be = (GncDbiBackend*)qbe;
-    GError* error = NULL;
-    gchar* dsn;
+	gint result;
+	gchar* dsn;
+	gchar* host;
+	gchar* dbname;
     gchar* username;
     gchar* password;
-	gchar* provider;
-	gboolean uriOK;
-	gint result;
-	gchar* dirname;
-	gchar* basename;
 
 	g_return_if_fail( qbe != NULL );
 	g_return_if_fail( session != NULL );
@@ -232,23 +228,32 @@
 
     ENTER (" ");
 
-	dirname = g_path_get_dirname( book_id );
-	basename = g_path_get_basename( book_id );
+	/* Split the book-id (format host:dbname:username:password) */
+	dsn = g_strdup( book_id );
+	for( host = dsn; *host != '/'; host++ ) {}
+	host += 2;
+	for( dbname = host; *dbname != ':'; dbname++ ) {}
+	*dbname++ = '\0';
+	for( username = dbname; *username != ':'; username++ ) {}
+	*username++ = '\0';
+	for( password = username; *password != ':'; password++ ) {}
+	*password++ = '\0';
 
-	be->conn = dbi_conn_new( "sqlite3" );
+	be->conn = dbi_conn_new( "pgsql" );
 	if( be->conn == NULL ) {
-		PERR( "Unable to create sqlite3 dbi connection\n" );
+		PERR( "Unable to create pgsql dbi connection\n" );
         qof_backend_set_error( qbe, ERR_BACKEND_BAD_URL );
 		LEAVE( " " );
 		return;
 	}
 	dbi_conn_error_handler( be->conn, error_fn, be );
-	dbi_conn_set_option( be->conn, "host", "localhost" );
-	dbi_conn_set_option( be->conn, "dbname", basename );
-	dbi_conn_set_option( be->conn, "sqlite3_dbdir", dirname );
+	dbi_conn_set_option( be->conn, "host", host );
+	dbi_conn_set_option_numeric( be->conn, "port", 0 );
+	dbi_conn_set_option( be->conn, "dbname", dbname );
+	dbi_conn_set_option( be->conn, "username", username );
+	dbi_conn_set_option( be->conn, "password", password );
 	result = dbi_conn_connect( be->conn );
-	g_free( basename );
-	g_free( dirname );
+	g_free( dsn );
 	if( result < 0 ) {
 		PERR( "Unable to connect to %s: %d\n", book_id, result );
         qof_backend_set_error( qbe, ERR_BACKEND_BAD_URL );
@@ -959,6 +964,22 @@
 				PERR( "Unknown GType: %d\n", type );
 				return "";
 		}
+	} else if( dbi_conn->provider == GNC_DBI_PROVIDER_PGSQL ) {
+		switch( type ) {
+			case G_TYPE_INT:
+			case G_TYPE_INT64:
+				return "integer";
+				break;
+			case G_TYPE_DOUBLE:
+				return "double precision";
+				break;
+			case G_TYPE_STRING:
+				return "varchar";
+				break;
+			default:
+				PERR( "Unknown GType: %d\n", type );
+				return "";
+		}
 	} else {
 		PERR( "Unknown provider: %d\n", dbi_conn->provider );
 		return "";

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-13 18:33:57 UTC (rev 17322)
+++ gnucash/branches/gda-dev2/src/backend/sql/gnc-backend-sql.c	2008-07-13 19:58:11 UTC (rev 17323)
@@ -1306,8 +1306,8 @@
         g_value_init( value, G_TYPE_DOUBLE );
         g_value_set_double( value, d_value );
     } else {
-        g_value_init( value, G_TYPE_STRING );
-		g_value_set_string( value, "NULL" );
+        g_value_init( value, G_TYPE_DOUBLE );
+		g_value_set_double( value, 0 );
 	}
 
 	(*pList) = g_slist_append( (*pList), value );

Modified: gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.c
===================================================================
--- gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.c	2008-07-13 18:33:57 UTC (rev 17322)
+++ gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.c	2008-07-13 19:58:11 UTC (rev 17323)
@@ -72,7 +72,7 @@
 	if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(dcw->rb_mysql) ) ) {
 		type = "mysql";
 	} else {
-		type = "postgresql";
+		type = "postgres";
 	}
 	url = g_strdup_printf( "%s://%s:%s:%s:%s",
 							type, host, database, username, password );

Modified: gnucash/branches/gda-dev2/src/gnome-utils/glade/dialog-database-connection.glade
===================================================================
--- gnucash/branches/gda-dev2/src/gnome-utils/glade/dialog-database-connection.glade	2008-07-13 18:33:57 UTC (rev 17322)
+++ gnucash/branches/gda-dev2/src/gnome-utils/glade/dialog-database-connection.glade	2008-07-13 19:58:11 UTC (rev 17323)
@@ -29,7 +29,6 @@
                 <child>
                   <widget class="GtkRadioButton" id="rb_postgresql">
                     <property name="visible">True</property>
-                    <property name="sensitive">False</property>
                     <property name="can_focus">True</property>
                     <property name="label" translatable="yes">PostgreSQL</property>
                     <property name="use_underline">True</property>
@@ -49,39 +48,39 @@
                 <property name="n_rows">4</property>
                 <property name="n_columns">2</property>
                 <child>
-                  <widget class="GtkLabel" id="label1">
+                  <widget class="GtkEntry" id="tf_password">
                     <property name="visible">True</property>
-                    <property name="label" translatable="yes">host</property>
+                    <property name="can_focus">True</property>
                   </widget>
-                </child>
-                <child>
-                  <widget class="GtkLabel" id="label2">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">database</property>
-                  </widget>
                   <packing>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkLabel" id="label3">
+                  <widget class="GtkEntry" id="tf_username">
                     <property name="visible">True</property>
-                    <property name="label" translatable="yes">username</property>
+                    <property name="can_focus">True</property>
                   </widget>
                   <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
                     <property name="top_attach">2</property>
                     <property name="bottom_attach">3</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkLabel" id="label4">
+                  <widget class="GtkEntry" id="tf_database">
                     <property name="visible">True</property>
-                    <property name="label" translatable="yes">password</property>
+                    <property name="can_focus">True</property>
                   </widget>
                   <packing>
-                    <property name="top_attach">3</property>
-                    <property name="bottom_attach">4</property>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
                   </packing>
                 </child>
                 <child>
@@ -95,41 +94,41 @@
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkEntry" id="tf_database">
+                  <widget class="GtkLabel" id="label4">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">password</property>
                   </widget>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkEntry" id="tf_username">
+                  <widget class="GtkLabel" id="label3">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">username</property>
                   </widget>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
                     <property name="top_attach">2</property>
                     <property name="bottom_attach">3</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkEntry" id="tf_password">
+                  <widget class="GtkLabel" id="label2">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">database</property>
                   </widget>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="top_attach">3</property>
-                    <property name="bottom_attach">4</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
                   </packing>
                 </child>
+                <child>
+                  <widget class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">host</property>
+                  </widget>
+                </child>
               </widget>
               <packing>
                 <property name="position">1</property>



More information about the gnucash-changes mailing list