Re: [gnome-db] Patch for new data type (Point) and support for it in postgres.



On Fri, Jan 04, 2002 at 12:35:06AM +0100, Rodrigo Moya wrote:
> hmm, you should call it GdaGeometricPoint everywhere, that is, in the
> IDL, in the GDA type names and macros, in the _set_geometric_point_*
> functions, etc. Please send a new patch with these corrections, and I'll
> apply it.

	Ok. Here it is!

> > 		doc/C/tmpl/gda-report-client.sgml
> > 		doc/C/tmpl/gda-report-datasource.sgml
> > 		doc/C/tmpl/gda-report-document.sgml
> > 		doc/C/tmpl/gda-server-recordset-model.sgml
> > 		doc/C/tmpl/gda-util.sgml
> > 
> those are generated files, by gtk-doc, so they may have changed in your
> system, but don't mind about them.

	As they are generated files may be they should be removed from
	the CVS. Should they?

Index: idl/ChangeLog
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/idl/ChangeLog,v
retrieving revision 1.19
diff -u -r1.19 ChangeLog
--- idl/ChangeLog	30 Dec 2001 12:48:41 -0000	1.19
+++ idl/ChangeLog	4 Jan 2002 00:54:42 -0000
@@ -1,3 +1,7 @@
+2002-01-03  Gonzalo Paniagua Javier <gonzalo gnome-db org>
+
+	* GNOME_Database.idl: added GeometricPoint as new data type.
+
 2001-12-29  Rodrigo Moya <rodrigo gnome-db org>
 
 	* GNOME_Database.idl: added more schemas (VIEWS, PROCEDURES, TYPES)
Index: idl/GNOME_Database.idl
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/idl/GNOME_Database.idl,v
retrieving revision 1.13
diff -u -r1.13 GNOME_Database.idl
--- idl/GNOME_Database.idl	30 Dec 2001 12:48:41 -0000	1.13
+++ idl/GNOME_Database.idl	4 Jan 2002 00:51:18 -0000
@@ -33,10 +33,11 @@
 			TYPE_SMALLINT,
 			TYPE_TINYINT,
 			TYPE_STRING,
+			TYPE_GEOMETRIC_POINT,
 			TYPE_UNKNOWN
 		};
 
-		struct Date{
+		struct Date {
 			short year;
 			unsigned short month;
 			unsigned short day;
@@ -54,6 +55,10 @@
 			unsigned short minute;
 			unsigned short second;
 			unsigned long  fraction;
+		};
+		struct GeometricPoint {
+			double x;
+			double y;
 		};
 
 		/*
Index: libgda/ChangeLog
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/libgda/ChangeLog,v
retrieving revision 1.57
diff -u -r1.57 ChangeLog
--- libgda/ChangeLog	3 Jan 2002 17:01:09 -0000	1.57
+++ libgda/ChangeLog	4 Jan 2002 00:54:28 -0000
@@ -1,8 +1,10 @@
 2002-01-03  Gonzalo Paniagua Javier <gonzalo gnome-db org>
 
-	* gda-server-connection.c (gda_server_connection_free_error_list): 
-	Test if the error list is NULL to avoid failing assertion in
-	gda_error_list_free().
+	* Changelog: fix little mistake.
+
+	* gda-row.[ch]:
+	* gda-value.[ch]:
+	Added support for GeometricPoint data type.	
 
 2002-01-02  Gonzalo Paniagua Javier <gonzalo gnome-db org>
 
@@ -11,6 +13,7 @@
 
 	* Makefile.am: s/IDLFILES/IDL_FILES, so that ORBit-generated files
 	are regenerated when the IDL files change
+
 	* gda-server-connection.c (gda_server_connection_free_error_list): 
 	Test if the error list is NULL to avoid failing assertion in
 	gda_error_list_free().
Index: libgda/gda-row.c
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/libgda/gda-row.c,v
retrieving revision 1.8
diff -u -r1.8 gda-row.c
--- libgda/gda-row.c	30 Dec 2001 16:29:44 -0000	1.8
+++ libgda/gda-row.c	4 Jan 2002 00:45:53 -0000
@@ -632,6 +632,31 @@
 }
 
 
+/**
+ * gda_field_get_geometric_point_value
+ */
+GdaGeometricPoint *
+gda_field_get_geometric_point_value (GdaField *field)
+{
+	g_return_val_if_fail (field != NULL, NULL);
+	return gda_value_get_geometric_point (&field->value);
+}
+
+/**
+ * gda_field_set_geometric_point_value
+ */
+void
+gda_field_set_geometric_point_value (GdaField *field, GdaGeometricPoint *value)
+{
+	g_return_if_fail (field != NULL);
+	g_return_if_fail (value != NULL);
+
+	field->attributes.gdaType = GDA_TYPE_GEOMETRIC_POINT;
+	field->actualSize = sizeof (GdaGeometricPoint);
+
+	gda_value_set_geometric_point (&field->value, value);
+}
+
 
 /**
  * gda_field_stringify
Index: libgda/gda-row.h
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/libgda/gda-row.h,v
retrieving revision 1.5
diff -u -r1.5 gda-row.h
--- libgda/gda-row.h	30 Dec 2001 16:29:44 -0000	1.5
+++ libgda/gda-row.h	4 Jan 2002 00:46:47 -0000
@@ -49,6 +49,7 @@
 #define GDA_TYPE_SMALLINT GNOME_Database_TYPE_SMALLINT
 #define GDA_TYPE_STRING GNOME_Database_TYPE_STRING
 #define GDA_TYPE_TINYINT GNOME_Database_TYPE_TINYINT
+#define GDA_TYPE_GEOMETRIC_POINT GNOME_Database_TYPE_GEOMETRIC_POINT
 #define GDA_TYPE_UNKNOWN GNOME_Database_TYPE_UNKNOWN
 
 GdaRow             *gda_row_new (gint count);
@@ -106,6 +107,9 @@
 void                gda_field_set_timestamp_value (GdaField *field, time_t value);
 gchar               gda_field_get_tinyint_value (GdaField *field);
 void                gda_field_set_tinyint_value (GdaField *field, gchar value);
+GdaGeometricPoint  *gda_field_get_geometric_point_value (GdaField *field);
+void                gda_field_set_geometric_point_value (GdaField *field, GdaGeometricPoint *value);
+
 gchar              *gda_field_stringify (GdaField *field);
 
 G_END_DECLS
Index: libgda/gda-value.c
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/libgda/gda-value.c,v
retrieving revision 1.9
diff -u -r1.9 gda-value.c
--- libgda/gda-value.c	24 Dec 2001 00:32:21 -0000	1.9
+++ libgda/gda-value.c	4 Jan 2002 00:48:56 -0000
@@ -146,6 +146,13 @@
 	return bonobo_arg_new_from (GDA_VALUE_TYPE_TINYINT, (gconstpointer) &val);
 }
 
+GdaValue *
+gda_value_new_geometric_point (GdaGeometricPoint *val)
+{
+	return bonobo_arg_new_from (GDA_VALUE_TYPE_GEOMETRIC_POINT, 
+					(gconstpointer) val);
+}
+
 /**
  * gda_value_free
  */
@@ -557,6 +564,36 @@
 }
 
 /**
+ * gda_value_get_geometric_point
+ */
+GdaGeometricPoint *
+gda_value_get_geometric_point (GdaValue *value)
+{
+	g_return_val_if_fail (value != NULL, NULL);
+
+	return (GdaGeometricPoint *) value->_value;
+}
+
+/**
+ * gda_value_set_geometric_point
+ */
+void
+gda_value_set_geometric_point (GdaValue *value, GdaGeometricPoint *val)
+{
+	g_return_if_fail (value != NULL);
+	g_return_if_fail (val != NULL);
+
+	if (!gda_value_isa (value, GDA_VALUE_TYPE_GEOMETRIC_POINT)) {
+		clear_value (value);
+		value->_type = ORBit_RootObject_duplicate (GDA_VALUE_TYPE_GEOMETRIC_POINT);
+	}
+	else if (value->_value)
+		CORBA_free (value->_value);
+
+	value->_value = ORBit_copy_value (val, TC_GNOME_Database_GeometricPoint);
+}
+
+/**
  * gda_value_stringify
  */
 gchar *
@@ -590,6 +627,12 @@
 	}
 	else if (gda_value_isa (value, GDA_VALUE_TYPE_TIMESTAMP)) {
 		/* FIXME: implement, and add all missing ones */
+	}
+	else if (gda_value_isa (value, GDA_VALUE_TYPE_GEOMETRIC_POINT)) {
+		GdaGeometricPoint *point;
+
+		point = gda_value_get_geometric_point (value);
+		retval = g_strdup_printf ("(%f,%f)", point->x, point->y);
 	}
 	else if (gda_value_isa (value, GDA_VALUE_TYPE_NULL))
 		retval = g_strdup ("NULL");
Index: libgda/gda-value.h
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/libgda/gda-value.h,v
retrieving revision 1.4
diff -u -r1.4 gda-value.h
--- libgda/gda-value.h	7 Nov 2001 19:00:42 -0000	1.4
+++ libgda/gda-value.h	4 Jan 2002 00:50:15 -0000
@@ -31,6 +31,7 @@
 
 typedef CORBA_any      GdaValue;
 typedef CORBA_TypeCode GdaValueType;
+typedef GNOME_Database_GeometricPoint GdaGeometricPoint;
 
 #define GDA_VALUE_TYPE_NULL      TC_null
 #define GDA_VALUE_TYPE_BIGINT    TC_CORBA_long_long
@@ -45,6 +46,7 @@
 #define GDA_VALUE_TYPE_TIME      TC_GNOME_Database_Time
 #define GDA_VALUE_TYPE_TIMESTAMP TC_GNOME_Database_Timestamp
 #define GDA_VALUE_TYPE_TINYINT   TC_CORBA_char
+#define GDA_VALUE_TYPE_GEOMETRIC_POINT     TC_GNOME_Database_GeometricPoint
 
 GdaValue     *gda_value_new_null (void);
 GdaValue     *gda_value_new_bigint (long long val);
@@ -59,6 +61,7 @@
 GdaValue     *gda_value_new_time (GTime val);
 GdaValue     *gda_value_new_timestamp (time_t val);
 GdaValue     *gda_value_new_tinyint (gchar val);
+GdaValue     *gda_value_new_geometric_point (GdaGeometricPoint *val);
 
 void          gda_value_free (GdaValue *value);
 
@@ -89,6 +92,8 @@
 void          gda_value_set_timestamp (GdaValue *value, time_t val);
 gchar         gda_value_get_tinyint (GdaValue *value);
 void          gda_value_set_tinyint (GdaValue *value, gchar val);
+GdaGeometricPoint     *gda_value_get_geometric_point (GdaValue *value);
+void          gda_value_set_geometric_point (GdaValue *value, GdaGeometricPoint *val);
 
 gchar        *gda_value_stringify (GdaValue *value);
 
Index: providers/postgres/ChangeLog
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/ChangeLog,v
retrieving revision 1.4
diff -u -r1.4 ChangeLog
--- providers/postgres/ChangeLog	3 Jan 2002 17:01:35 -0000	1.4
+++ providers/postgres/ChangeLog	3 Jan 2002 22:57:36 -0000
@@ -1,3 +1,10 @@
+2002-01-03  Gonzalo Paniagua Javier <gonzalo gnome-db org>
+
+	* utils.c:
+	* gda-postgres-recordset.c:
+	 Added support for GdaGeometricPoint.
+	
+	
 2002-01-02  Gonzalo Paniagua Javier <gonzalo gnome-db org>
 
 	* gda-postgres-provider.c (process_sql_commands()): don't call
Index: providers/postgres/utils.c
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/utils.c,v
retrieving revision 1.4
diff -u -r1.4 utils.c
--- providers/postgres/utils.c	3 Jan 2002 17:01:35 -0000	1.4
+++ providers/postgres/utils.c	4 Jan 2002 00:52:59 -0000
@@ -36,12 +36,12 @@
 		gda_error_set_description (error, PQerrorMessage(handle));
 		gda_error_set_number (error, -1);
 	} else {
-		gda_error_set_description (error, "NO DESCRIPTION");
+		gda_error_set_description (error, _("NO DESCRIPTION"));
 		gda_error_set_number (error, -1);
 	}
 
 	gda_error_set_source (error, "gda-postgres");
-	gda_error_set_sqlstate (error, "Not available");
+	gda_error_set_sqlstate (error, _("Not available"));
 
 	return error;
 }
@@ -80,15 +80,43 @@
 		return GDA_TYPE_TIME;
 	case VARBITOID :
 		return GDA_TYPE_BINARY;
+	case POINTOID :
+		return GDA_TYPE_GEOMETRIC_POINT;
 	}
 
 	return GDA_TYPE_UNKNOWN;
 }
 
+static GdaGeometricPoint *
+make_point (const gchar *value)
+{
+	GdaGeometricPoint *point;
+
+	g_return_val_if_fail (value != NULL, NULL);
+	
+	point = g_new (GdaGeometricPoint, 1);
+	value++;
+	point->x = atof (value);
+	value = strchr (value, ',');
+	value++;
+	point->y = atof (value);
+
+	return point;
+}
+
+static void
+delete_point (GdaGeometricPoint *point)
+{
+	g_return_if_fail (point != NULL);
+	
+	g_free (point);
+}
+
 void 
 gda_postgres_set_type_value (GdaField *field, GdaType type, const gchar *value)
 {
 	GDate *date;
+	GdaGeometricPoint *point;
 
 	switch (type) {
 	case GDA_TYPE_BOOLEAN :
@@ -132,6 +160,12 @@
 		gda_field_set_date_value (field, date);
 		g_date_free (date);
 		
+		break;
+	case GDA_TYPE_GEOMETRIC_POINT :
+		point = make_point (value);
+		gda_field_set_geometric_point_value (field, point);
+		gda_field_set_gdatype (field, type);
+		delete_point (point);
 		break;
 	case GDA_TYPE_TIMESTAMP : //FIXME
 	case GDA_TYPE_TIME : //FIXME


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