[gnome-db] Postgres Transactions and clear error list in connections



Hi to everybody,

I've prepared two patches for libgda:

- postgresql_transaction_support.diff improves the support of
transactions of the postgres provider. Now the isolation levels
supported by postgres in postgres greater than 6.5 as serlializable and
read commited can be used, other ones now give an error. The read-only
mode is enabled in versions superrior of 7.4.

- connection_clear_errors.diff , creates a new gda-connection function
that enables to reset the errors list, it's usefull to reuse
connections, until it would be great to have a gda_connection_reset that
could reset a gdaconnection to the database engine, but this function
would need support for providers.

I'm thinking in getting libgda thread save, but i think that there is a
great job in this, most of it in testing :)

I hope this patches to be useful.

Best regards,

-- 

José María Casanova Crespo
Ingeniero en Informática
Telf:  +34 981 91 39 91 Ext. 14
Fax:   +34 981 91 39 49
mailto:jmcasanova igalia com
IGALIA, S.L. http://www.igalia.com
? providers/bdb/Makefile
? providers/bdb/Makefile.in
? providers/freetds/gda-freetds-provider.loT
Index: providers//postgres/gda-postgres-provider.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/postgres/gda-postgres-provider.c,v
retrieving revision 1.62
diff -u -r1.62 gda-postgres-provider.c
--- providers//postgres/gda-postgres-provider.c	1 May 2004 20:34:51 -0000	1.62
+++ providers//postgres/gda-postgres-provider.c	5 Aug 2004 16:08:34 -0000
@@ -772,12 +772,56 @@
 				         GdaConnection *cnc,
 					 GdaTransaction *xaction)
 {
+        gboolean result;
 	GdaPostgresProvider *pg_prv = (GdaPostgresProvider *) provider;
+	GdaPostgresConnectionData *priv_data;
+
+	gchar * write_option=NULL;
+	gchar * isolation_level=NULL;
 
 	g_return_val_if_fail (GDA_IS_POSTGRES_PROVIDER (pg_prv), FALSE);
 	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
+	g_return_val_if_fail (GDA_IS_TRANSACTION (xaction), FALSE);
+
+	priv_data = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE);
+	if (priv_data->version_float >= 6.5){
+	        if (gda_connection_get_options (cnc) & GDA_CONNECTION_OPTIONS_READ_ONLY) {
+	                if (priv_data->version_float >= 7.4){
+		                write_option="READ ONLY";
+           	        } 
+                        else {
+		                gda_connection_add_error_string (cnc, _("Transactions are not supported in read-only mode"));
+				return FALSE;
+			}
+		}
+		switch (gda_transaction_get_isolation_level (xaction)) {
+		case GDA_TRANSACTION_ISOLATION_READ_COMMITTED :
+		        isolation_level = g_strconcat("SET TRANSACTION ISOLATION LEVEL READ COMMITTED ",write_option,NULL);
+			g_message("Begin transaction read committed");
+		        break;
+		case GDA_TRANSACTION_ISOLATION_READ_UNCOMMITTED :
+		        gda_connection_add_error_string (cnc, _("Transactions are not supported in read uncommitted isolation level"));
+		        return FALSE;
+		case GDA_TRANSACTION_ISOLATION_REPEATABLE_READ :
+		        gda_connection_add_error_string (cnc, _("Transactions are not supported in repeatable read isolation level"));
+		        return FALSE;
+		case GDA_TRANSACTION_ISOLATION_SERIALIZABLE :
+		        isolation_level =g_strconcat("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE ",write_option,NULL);
+			g_message("Begin transaction serializable");
+		        break;
+		default: 
+		        isolation_level=NULL;
+		}
+	}
+
+	result=gda_postgres_provider_single_command (pg_prv, cnc, "BEGIN"); 
+	if (result&&isolation_level!=NULL) {
+	        result=gda_postgres_provider_single_command (pg_prv, cnc, isolation_level) ;
+		g_message(isolation_level);
+	} 
+	g_free(isolation_level);
 
-	return gda_postgres_provider_single_command (pg_prv, cnc, "BEGIN"); 
+	return result;
 }
 
 static gboolean 
Index: libgda/gda-connection.c
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-connection.c,v
retrieving revision 1.58
diff -u -r1.58 gda-connection.c
--- libgda/gda-connection.c	1 Aug 2004 10:21:33 -0000	1.58
+++ libgda/gda-connection.c	5 Aug 2004 16:08:14 -0000
@@ -593,6 +593,31 @@
 }
 
 /**
+ * gda_connection_clear_error_list
+ * @cnc: a #GdaConnection object.
+ *
+ * This function lets you clear the list of #GdaError's of the
+ * given connection. This is usefull to reuse a #GdaConnection 
+ * because next uses of #gda_connection_errors will return an empty
+ * list.
+ */
+void
+gda_connection_clear_error_list (GdaConnection *cnc)
+{
+	GList *l;
+
+	g_return_if_fail (GDA_IS_CONNECTION (cnc));
+
+	if (cnc->priv->error_list!=NULL) {
+	  l = cnc->priv->error_list;
+	  gda_error_list_free (l);
+	  
+	  cnc->priv->error_list =  NULL;
+	}
+}
+
+
+/**
  * gda_connection_change_database
  * @cnc: a #GdaConnection object.
  * @name: name of database to switch to.
Index: libgda/gda-connection.h
===================================================================
RCS file: /cvs/gnome/libgda/libgda/gda-connection.h,v
retrieving revision 1.39
diff -u -r1.39 gda-connection.h
--- libgda/gda-connection.h	5 May 2004 09:17:10 -0000	1.39
+++ libgda/gda-connection.h	5 Aug 2004 16:08:14 -0000
@@ -89,6 +89,7 @@
 void                 gda_connection_add_error (GdaConnection *cnc, GdaError *error);
 void                 gda_connection_add_error_string (GdaConnection *cnc, const gchar *str, ...);
 void                 gda_connection_add_error_list (GdaConnection *cnc, GList *error_list);
+void                 gda_connection_clear_error_list (GdaConnection *cnc);
 
 gboolean             gda_connection_change_database (GdaConnection *cnc, const gchar *name);
 gboolean             gda_connection_create_database (GdaConnection *cnc, const gchar *name);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]