[gnome-db] Patch for postgres provider and SQL mini parser



	Hi, all!

	Rodrigo, can you, please, apply the patch attached? I sent it to
	you a few days ago, but it didn't seem to be applied. Thx!

	About the SQL mini parser... Have you considered to use/adapt
	the SQL parser already included in the SQLite provider?

	Bye!

	
Index: ChangeLog
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/ChangeLog,v
retrieving revision 1.2
diff -u -w -r1.2 ChangeLog
--- ChangeLog	20 Dec 2001 19:59:59 -0000	1.2
+++ ChangeLog	26 Dec 2001 18:59:14 -0000
@@ -1,3 +1,15 @@
+2001-12-26  Gonzalo Paniagua Javier <gonzalo gnome-db org>
+
+	* gda-postgres-provider.c: added the call to
+	gda_server_connection_add_error() where I forgot to put it.
+	Added gda_postgres_provider_supports().
+	Call PQfinish() if PQsetdbLogin() fails.
+	Always call PQfinish() in close_connection() to avoid memory leaks.
+	Handle the possible NULL return value in PQexec().
+
+	* utils.c: First version of a working gda_postgres_type_to_gda().
+	Added gda_postgres_set_type_value().
+
 2001-12-20  Gonzalo Paniagua Javier <gonzalo gnome-db org>
 
 	* gda-postgres-provider.c: some cosmetic changes, implementation of
Index: gda-postgres-provider.c
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/gda-postgres-provider.c,v
retrieving revision 1.2
diff -u -w -r1.2 gda-postgres-provider.c
--- gda-postgres-provider.c	20 Dec 2001 19:59:59 -0000	1.2
+++ gda-postgres-provider.c	26 Dec 2001 19:01:42 -0000
@@ -62,6 +62,9 @@
 						      GdaServerConnection *cnc,
 						      const gchar *command);
 
+static gboolean gda_postgres_provider_supports (GdaServerProvider *provider,
+						GdaServerConnection *cnc,
+						GNOME_Database_Feature feature);
 static GObjectClass *parent_class = NULL;
 
 /*
@@ -82,6 +85,7 @@
 	provider_class->begin_transaction = gda_postgres_provider_begin_transaction;
 	provider_class->commit_transaction = gda_postgres_provider_commit_transaction;
 	provider_class->rollback_transaction = gda_postgres_provider_rollback_transaction;
+	provider_class->supports = gda_postgres_provider_supports;
 }
 
 static void
@@ -163,7 +167,9 @@
 		      pq_login, pq_pwd);
 
 	if (PQstatus (pconn) != CONNECTION_OK) {
-		gda_postgres_make_error (pconn);
+		gda_server_connection_add_error (
+			cnc, gda_postgres_make_error (pconn));
+		PQfinish(pconn);
 		return FALSE;
 	}
 
@@ -197,11 +203,7 @@
 	if (!pconn)
 		return FALSE;
 
-	/* check connection status */
-	if (PQstatus (pconn) == CONNECTION_OK) {
 		PQfinish (pconn);
-		pconn = NULL;
-	}
 
 	g_object_set_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE, NULL);
 	return TRUE;
@@ -337,12 +339,34 @@
 		return FALSE;
 	}
 
+	result = FALSE;
 	pg_res = PQexec(pconn, command);
+	if (pg_res != NULL){
 	result = PQresultStatus(pg_res) == PGRES_COMMAND_OK;
 	PQclear (pg_res);
+	}
+
 	if (result == FALSE)
-		gda_postgres_make_error (pconn);
+		gda_server_connection_add_error (
+			cnc, gda_postgres_make_error (pconn));
 
 	return result;
+}
+
+static gboolean gda_postgres_provider_supports (GdaServerProvider *provider,
+						GdaServerConnection *cnc,
+						GNOME_Database_Feature feature)
+{
+	GdaPostgresProvider *pgprv = (GdaPostgresProvider *) provider;
+
+	g_return_val_if_fail (GDA_IS_POSTGRES_PROVIDER (pgprv), FALSE);
+
+	switch (feature) {
+	case GNOME_Database_FEATURE_TRANSACTIONS :
+		return TRUE;
+	default :
+	}
+ 
+	return FALSE;
 }
 
Index: gda-postgres-recordset.c
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/gda-postgres-recordset.c,v
retrieving revision 1.2
diff -u -w -r1.2 gda-postgres-recordset.c
--- gda-postgres-recordset.c	20 Dec 2001 19:59:59 -0000	1.2
+++ gda-postgres-recordset.c	26 Dec 2001 18:58:42 -0000
@@ -76,7 +76,7 @@
 	for (i = 0; i < field_count; i++) {
 		GdaField *field;
 		gchar *thevalue;
-		Oid ftype;
+		GdaType ftype;
 
 		field = gda_row_get_field (row, i);
 		//TODO: What do I do when PQfsize() returns -1 to show that the
@@ -94,57 +94,8 @@
 		//gda_field_set_scale (field, mysql_fields[i].decimals);
 		gda_field_set_scale (field, 0);
 		ftype = gda_postgres_type_to_gda (PQftype (pg_res, i));
-		gda_field_set_gdatype (field, ftype);
-
 		thevalue = PQgetvalue(pg_res, rownum, i);
-
-		//switch (ftype) {
-		//case FIELD_TYPE_DATE : /* FIXME */
-	/*		break;
-		case FIELD_TYPE_DECIMAL :
-		case FIELD_TYPE_DOUBLE :
-			gda_field_set_double_value (field, atof (thevalue));
-			break;
-		case FIELD_TYPE_FLOAT :
-			gda_field_set_single_value (field, atof (thevalue));
-			break;
-		case FIELD_TYPE_LONG :
-		case FIELD_TYPE_YEAR :
-			gda_field_set_integer_value (field, atol (thevalue));
-			break;
-		case FIELD_TYPE_LONGLONG :
-		case FIELD_TYPE_INT24 :
-			gda_field_set_bigint_value (field, atoll (thevalue));
-			break;
-		case FIELD_TYPE_SHORT :
-			gda_field_set_smallint_value (field, atoi (thevalue));
-			break;
-			*/
-		//case FIELD_TYPE_TIME : /* FIXME */
-		//	break;
-		//case FIELD_TYPE_TIMESTAMP :
-		//case FIELD_TYPE_DATETIME : /* FIXME */
-	//		break;
-//		case FIELD_TYPE_TINY :
-//			gda_field_set_tinyint_value (field, atoi (thevalue));
-//			break;
-//		case FIELD_TYPE_TINY_BLOB :
-//		case FIELD_TYPE_MEDIUM_BLOB :
-//		case FIELD_TYPE_LONG_BLOB :
-//		case FIELD_TYPE_BLOB :
-//			gda_field_set_binary_value (field, thevalue, PQgetlength(pg_res, rownum, i));
-//			break;
-//		case FIELD_TYPE_VAR_STRING :
-//		case FIELD_TYPE_STRING :
-//			gda_field_set_string_value (field, thevalue);
-//			break;
-//		case FIELD_TYPE_NULL :
-//		case FIELD_TYPE_NEWDATE :
-//		case FIELD_TYPE_ENUM :
-//		case FIELD_TYPE_SET : /* FIXME */
-//			gda_field_set_string_value (field, thevalue);
-//			break;
-//		}
+		gda_postgres_set_type_value(field, ftype, thevalue);
 	}
 
 	return row;
Index: gda-postgres.h
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/gda-postgres.h,v
retrieving revision 1.2
diff -u -w -r1.2 gda-postgres.h
--- gda-postgres.h	20 Dec 2001 19:59:59 -0000	1.2
+++ gda-postgres.h	26 Dec 2001 18:57:54 -0000
@@ -45,8 +45,10 @@
  */
 
 GdaError *gda_postgres_make_error (PGconn *cnc);
-//TODO: see utils.c
-GdaType gda_postgres_type_to_gda (int postgres_type);//(enum enum_field_types postgres_type);
+GdaType gda_postgres_type_to_gda (Oid postgres_type);
+void gda_postgres_set_type_value (GdaField *field,
+				GdaType type, 
+				const gchar *value);
 
 G_END_DECLS
 
Index: utils.c
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/utils.c,v
retrieving revision 1.2
diff -u -w -r1.2 utils.c
--- utils.c	20 Dec 2001 19:59:59 -0000	1.2
+++ utils.c	26 Dec 2001 18:58:21 -0000
@@ -22,6 +22,8 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#include <postgres.h>
+#include <catalog/pg_type.h>
 #include "gda-postgres.h"
 
 GdaError *
@@ -44,49 +46,88 @@
 	return error;
 }
 
-//TODO: This one just copied from MySQL provider!
-//Should be converted to PostgreSQL types!
 GdaType
-gda_postgres_type_to_gda (int postgres_type)
+gda_postgres_type_to_gda (Oid postgres_type)
 {
-/*	switch (postgres_type) {
-	case FIELD_TYPE_DATE :
-		return GDA_TYPE_DATE;
-	case FIELD_TYPE_DECIMAL :
-	case FIELD_TYPE_DOUBLE :
-		return GDA_TYPE_DOUBLE;
-	case FIELD_TYPE_FLOAT :
-		return GDA_TYPE_SINGLE;
-	case FIELD_TYPE_LONG :
-	case FIELD_TYPE_YEAR :
-		return GDA_TYPE_INTEGER;
-	case FIELD_TYPE_LONGLONG :
-	case FIELD_TYPE_INT24 :
+	switch (postgres_type) {
+	case BOOLOID :
+		return GDA_TYPE_BOOLEAN;
+	case BYTEAOID :
+	case CHAROID :
+	case TEXTOID :
+	case BPCHAROID :
+	case VARCHAROID :
+		return GDA_TYPE_STRING;
+	case INT8OID :
 		return GDA_TYPE_BIGINT;
-	case FIELD_TYPE_SHORT :
+	case INT4OID :
+	case RELTIMEOID :
+		return GDA_TYPE_INTEGER;
+	case INT2OID :
 		return GDA_TYPE_SMALLINT;
-	case FIELD_TYPE_TIME :
-		return GDA_TYPE_TIME;
-	case FIELD_TYPE_TIMESTAMP :
-	case FIELD_TYPE_DATETIME :
+	case FLOAT4OID :
+		return GDA_TYPE_SINGLE;
+	case FLOAT8OID :
+	case NUMERICOID :
+		return GDA_TYPE_DOUBLE;
+	case ABSTIMEOID :
+	case TIMESTAMPOID :
 		return GDA_TYPE_TIMESTAMP;
-	case FIELD_TYPE_TINY :
-		return GDA_TYPE_TINYINT;
-	case FIELD_TYPE_TINY_BLOB :
-	case FIELD_TYPE_MEDIUM_BLOB :
-	case FIELD_TYPE_LONG_BLOB :
-	case FIELD_TYPE_BLOB :
+	case DATEOID :
+		return GDA_TYPE_DATE;
+	case TIMEOID :
+	case TIMETZOID :
+		return GDA_TYPE_TIME;
+	case VARBITOID :
 		return GDA_TYPE_BINARY;
-	case FIELD_TYPE_VAR_STRING :
-	case FIELD_TYPE_STRING :
-		return GDA_TYPE_STRING;
-	case FIELD_TYPE_NULL :
-	case FIELD_TYPE_NEWDATE :
-	case FIELD_TYPE_ENUM :
-	case FIELD_TYPE_SET :
-		break;
 	}
-*/
+
 	return GDA_TYPE_UNKNOWN;
+}
+
+void 
+gda_postgres_set_type_value (GdaField *field, GdaType type, const gchar *value)
+{
+	switch (type) {
+	case GDA_TYPE_BOOLEAN :
+		gda_field_set_gdatype (field, type);
+		gda_field_set_boolean_value (field, atoi (value));
+		break;
+	case GDA_TYPE_STRING :
+		gda_field_set_gdatype (field, type);
+		gda_field_set_string_value (field, value);
+		break;
+	case GDA_TYPE_BIGINT :
+		gda_field_set_gdatype (field, type);
+		gda_field_set_bigint_value (field, atoll (value));
+		break;
+	case GDA_TYPE_INTEGER :
+		gda_field_set_gdatype (field, type);
+		gda_field_set_integer_value (field, atol (value));
+		break;
+	case GDA_TYPE_SMALLINT :
+		gda_field_set_gdatype (field, type);
+		gda_field_set_smallint_value (field, atoi (value));
+		break;
+	case GDA_TYPE_SINGLE :
+		gda_field_set_gdatype (field, type);
+		gda_field_set_single_value (field, atof (value));
+		break;
+	case GDA_TYPE_DOUBLE :
+		gda_field_set_gdatype (field, type);
+		gda_field_set_double_value (field, atof (value));
+		break;
+	case GDA_TYPE_TIMESTAMP : //FIXME
+		break;
+	case GDA_TYPE_DATE : //FIXME
+		break;
+	case GDA_TYPE_TIME : //FIXME
+		break;
+	case GDA_TYPE_BINARY : //FIXME
+		break;
+	default :
+		gda_field_set_string_value (field, value);
+		gda_field_set_gdatype (field, GDA_TYPE_UNKNOWN);
+	}
 }
 


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