[gnome-db] Another patch for the postgres provider
- From: Gonzalo Paniagua Javier <gonzalo gnome-db org>
- To: Gnome-db list <gnome-db-list gnome org>
- Subject: [gnome-db] Another patch for the postgres provider
- Date: Mon, 7 Jan 2002 01:47:29 +0100
Here goes another patch.
This one makes the provider get the data types from the system
catalog instead of doing it 'by hand'.
Also fixes the little mistake in libgda/Changelog
Bye!
Index: libgda/ChangeLog
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/libgda/ChangeLog,v
retrieving revision 1.59
diff -u -r1.59 ChangeLog
--- libgda/ChangeLog 5 Jan 2002 22:44:30 -0000 1.59
+++ libgda/ChangeLog 7 Jan 2002 00:41:24 -0000
@@ -6,12 +6,11 @@
2002-01-03 Gonzalo Paniagua Javier <gonzalo gnome-db org>
- * gda-row.[ch]:
- * gda-value.[ch]: added support for GdaGeometricPoint type
+ * Changelog: fix little mistake.
- * 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().
+ * gda-row.[ch]:
+ * gda-value.[ch]:
+ Added support for GeometricPoint data type.
2002-01-02 Gonzalo Paniagua Javier <gonzalo gnome-db org>
@@ -20,6 +19,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: providers/postgres/ChangeLog
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/ChangeLog,v
retrieving revision 1.5
diff -u -r1.5 ChangeLog
--- providers/postgres/ChangeLog 4 Jan 2002 02:15:25 -0000 1.5
+++ providers/postgres/ChangeLog 7 Jan 2002 00:34:52 -0000
@@ -1,3 +1,12 @@
+2002-01-07 Gonzalo Paniagua Javier <gonzalo gnome-db org>
+
+ * *.[ch]: changed copyright to the GNOME Foundation.
+
+ * gda-postgres-provider.[ch]: moved #define's to header file. Now use
+ GdaPostgresConnectionPrivate to store the connection and the data
+ associated data types.
+ (add_string_row()): now it is called from g_list_foreach().
+
2002-01-03 Gonzalo Paniagua Javier <gonzalo gnome-db org>
* utils.c:
Index: providers/postgres/gda-postgres-provider.c
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/gda-postgres-provider.c,v
retrieving revision 1.4
diff -u -r1.4 gda-postgres-provider.c
--- providers/postgres/gda-postgres-provider.c 3 Jan 2002 17:01:35 -0000 1.4
+++ providers/postgres/gda-postgres-provider.c 7 Jan 2002 00:39:47 -0000
@@ -1,5 +1,5 @@
/* GNOME DB Postgres Provider
- * Copyright (C) 1998-2001 The Free Software Foundation
+ * Copyright (C) 1998-2002 The GNOME Foundation
*
* AUTHORS:
* Vivien Malerba <malerba gnome-db org>
@@ -22,11 +22,7 @@
*/
#include "gda-postgres.h"
-#include <libgda/gda-server-recordset-model.h>
-
-#define PARENT_TYPE GDA_TYPE_SERVER_PROVIDER
-
-#define OBJECT_DATA_POSTGRES_HANDLE "GDA_Postgres_PostgresHandle"
+#include "gda-postgres-provider.h"
static void gda_postgres_provider_class_init (GdaPostgresProviderClass *klass);
static void gda_postgres_provider_init (GdaPostgresProvider *provider,
@@ -72,6 +68,16 @@
GNOME_Database_Connection_Schema schema,
GdaParameterList *params);
+typedef struct {
+ Oid oid;
+ gchar *name;
+} GdaPostgresTypeDataPrivate;
+
+typedef struct {
+ PGconn *pconn;
+ GList *type_list; // list of GdaPostgresTypeDataPrivate
+} GdaPostgresConnectionPrivate;
+
static GObjectClass *parent_class = NULL;
/*
@@ -136,6 +142,41 @@
return type;
}
+static GList *
+get_connection_type_list (PGconn *pconn)
+{
+ PGresult *pg_res;
+ GList *list;
+ GdaPostgresTypeDataPrivate *priv_td;
+ gint llen;
+ gint i;
+
+ pg_res = PQexec (pconn, "SELECT oid, typname FROM pg_type "
+ "WHERE typrelid = 0 AND typname !~ '^_' "
+ " AND typname not in ('SET', 'cid', "
+ "'int2vector', 'oidvector', 'regproc', "
+ "'smgr', 'tid', 'unknown', 'xid') "
+ "ORDER BY typname");
+
+ if (pg_res == NULL || PQresultStatus (pg_res) != PGRES_TUPLES_OK) {
+ if (pg_res) PQclear (pg_res);
+ return NULL;
+ }
+
+ list = NULL;
+ llen = PQntuples (pg_res);
+ for (i = 0; i < llen; i++) {
+ priv_td = g_new (GdaPostgresTypeDataPrivate, 1);
+ priv_td->oid = atoi (PQgetvalue (pg_res, i, 0));
+ priv_td->name = g_strdup (PQgetvalue (pg_res, i, 1));
+ list = g_list_append (list, priv_td);
+ }
+
+ PQclear (pg_res);
+
+ return list;
+}
+
/* open_connection handler for the GdaPostgresProvider class */
static gboolean
gda_postgres_provider_open_connection (GdaServerProvider *provider,
@@ -154,6 +195,8 @@
const gchar *pq_hostaddr;
const gchar *pq_requiressl;
gchar *conn_string;
+ GdaPostgresConnectionPrivate *priv_data;
+ GList *type_list;
PGconn *pconn;
PGresult *pg_res;
GdaError *error;
@@ -213,26 +256,49 @@
pg_res = PQexec (pconn, "SET DATESTYLE TO 'ISO'");
PQclear (pg_res);
- g_object_set_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE, pconn);
+ type_list = get_connection_type_list (pconn);
+ if (type_list == NULL) {
+ gda_server_connection_add_error (
+ cnc, gda_postgres_make_error (pconn));
+ PQfinish(pconn);
+ return FALSE;
+ }
+
+ priv_data = g_new (GdaPostgresConnectionPrivate, 1);
+ priv_data->pconn = pconn;
+ priv_data->type_list = type_list;
+ g_object_set_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE, priv_data);
return TRUE;
}
+void
+free_type_list (gpointer data, gpointer user_data)
+{
+ GdaPostgresTypeDataPrivate *priv_td;
+
+ priv_td = data;
+ g_free (priv_td->name);
+ g_free (priv_td);
+}
+
/* close_connection handler for the GdaPostgresProvider class */
static gboolean
gda_postgres_provider_close_connection (GdaServerProvider *provider, GdaServerConnection *cnc)
{
- PGconn *pconn;
+ GdaPostgresConnectionPrivate *priv_data;
GdaPostgresProvider *pg_prv = (GdaPostgresProvider *) provider;
g_return_val_if_fail (GDA_IS_POSTGRES_PROVIDER (pg_prv), FALSE);
g_return_val_if_fail (GDA_IS_SERVER_CONNECTION (cnc), FALSE);
- pconn = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE);
- if (!pconn)
+ priv_data = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE);
+ if (!priv_data)
return FALSE;
- PQfinish (pconn);
+ PQfinish (priv_data->pconn);
+ g_list_foreach (priv_data->type_list, free_type_list, NULL);
+ g_list_free (priv_data->type_list);
g_object_set_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE, NULL);
return TRUE;
@@ -241,15 +307,17 @@
static GList *
process_sql_commands (GList *reclist, GdaServerConnection *cnc, const gchar *sql)
{
+ GdaPostgresConnectionPrivate *priv_data;
PGconn *pconn;
gchar **arr;
- pconn = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE);
- if (!pconn) {
+ priv_data = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE);
+ if (!priv_data) {
gda_server_connection_add_error_string (cnc, _("Invalid PostgreSQL handle"));
return NULL;
}
+ pconn = priv_data->pconn;
/* parse SQL string, which can contain several commands, separated by ';' */
arr = g_strsplit (sql, ";", 0);
if (arr) {
@@ -355,16 +423,18 @@
GdaServerConnection *cnc,
const gchar *command)
{
+ GdaPostgresConnectionPrivate *priv_data;
PGconn *pconn;
PGresult *pg_res;
gboolean result;
- pconn = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE);
- if (!pconn) {
+ priv_data = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE);
+ if (!priv_data) {
gda_server_connection_add_error_string (cnc, _("Invalid PostgreSQL handle"));
return FALSE;
}
+ pconn = priv_data->pconn;
result = FALSE;
pg_res = PQexec(pconn, command);
if (pg_res != NULL){
@@ -438,14 +508,19 @@
}
static void
-add_string_row (GdaServerRecordsetModel *recset, const gchar *str)
+add_string_row (gpointer data, gpointer user_data)
{
GdaValue *value;
GList list;
+ GdaServerRecordsetModel *recset;
+ GdaPostgresTypeDataPrivate *priv_td;
+
+ priv_td = data;
+ recset = user_data;
g_return_if_fail (GDA_IS_SERVER_RECORDSET_MODEL (recset));
- value = gda_value_new_string (str);
+ value = gda_value_new_string (priv_td->name);
list.data = value;
list.next = NULL;
list.prev = NULL;
@@ -459,6 +534,7 @@
get_postgres_types (GdaServerConnection *cnc, GdaParameterList *params)
{
GdaServerRecordsetModel *recset;
+ GdaPostgresConnectionPrivate *priv_data;
g_return_val_if_fail (GDA_IS_SERVER_CONNECTION (cnc), NULL);
@@ -470,27 +546,9 @@
gda_server_recordset_model_set_field_gdatype (recset, 0, GDA_TYPE_STRING);
/* fill the recordset */
- //TODO: Get it from system tables.
- add_string_row (recset, "abstime");
- add_string_row (recset, "boolean");
- add_string_row (recset, "bpchar");
- add_string_row (recset, "bytea");
- add_string_row (recset, "char");
- add_string_row (recset, "date");
- add_string_row (recset, "datetz");
- add_string_row (recset, "float4");
- add_string_row (recset, "float8");
- add_string_row (recset, "int2");
- add_string_row (recset, "int4");
- add_string_row (recset, "int8");
- add_string_row (recset, "numeric");
- add_string_row (recset, "reltime");
- add_string_row (recset, "time");
- add_string_row (recset, "timetz");
- add_string_row (recset, "timestamp");
- add_string_row (recset, "text");
- add_string_row (recset, "varbit");
- add_string_row (recset, "varchar");
+ priv_data = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_POSTGRES_HANDLE);
+
+ g_list_foreach (priv_data->type_list, add_string_row, recset);
return GDA_SERVER_RECORDSET (recset);
}
Index: providers/postgres/gda-postgres-provider.h
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/gda-postgres-provider.h,v
retrieving revision 1.1
diff -u -r1.1 gda-postgres-provider.h
--- providers/postgres/gda-postgres-provider.h 19 Dec 2001 12:54:59 -0000 1.1
+++ providers/postgres/gda-postgres-provider.h 7 Jan 2002 00:25:58 -0000
@@ -1,5 +1,5 @@
/* GNOME DB Postgres Provider
- * Copyright (C) 1998-2001 The Free Software Foundation
+ * Copyright (C) 1998-2002 The GNOME Foundation
*
* AUTHORS:
* Vivien Malerba <malerba gnome-db org>
@@ -25,8 +25,7 @@
# define __gda_postgres_provider_h__
#include <libgda/gda-server-provider.h>
-
-G_BEGIN_DECLS
+#include <libgda/gda-server-recordset-model.h>
#define GDA_TYPE_POSTGRES_PROVIDER (gda_postgres_provider_get_type())
#define GDA_POSTGRES_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_POSTGRES_PROVIDER, GdaPostgresProvider))
@@ -34,6 +33,10 @@
#define GDA_IS_POSTGRES_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GDA_TYPE_POSTGRES_PROVIDER))
#define GDA_IS_POSTGRES_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDA_TYPE_POSTGRES_PROVIDER))
+#define PARENT_TYPE GDA_TYPE_SERVER_PROVIDER
+#define OBJECT_DATA_POSTGRES_HANDLE "GDA_Postgres_PostgresHandle"
+
+
typedef struct _GdaPostgresProvider GdaPostgresProvider;
typedef struct _GdaPostgresProviderClass GdaPostgresProviderClass;
@@ -44,6 +47,8 @@
struct _GdaPostgresProviderClass {
GdaServerProviderClass parent_class;
};
+
+G_BEGIN_DECLS
GType gda_postgres_provider_get_type (void);
Index: providers/postgres/gda-postgres-recordset.c
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/gda-postgres-recordset.c,v
retrieving revision 1.3
diff -u -r1.3 gda-postgres-recordset.c
--- providers/postgres/gda-postgres-recordset.c 29 Dec 2001 21:01:59 -0000 1.3
+++ providers/postgres/gda-postgres-recordset.c 6 Jan 2002 22:40:14 -0000
@@ -1,5 +1,5 @@
/* GDA DB Postgres provider
- * Copyright (C) 1998-2001 The Free Software Foundation
+ * Copyright (C) 1998-2001 The GNOME Foundation
*
* AUTHORS:
* Michael Lausch <michael lausch at>
Index: providers/postgres/gda-postgres-recordset.h
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/gda-postgres-recordset.h,v
retrieving revision 1.1
diff -u -r1.1 gda-postgres-recordset.h
--- providers/postgres/gda-postgres-recordset.h 19 Dec 2001 12:54:59 -0000 1.1
+++ providers/postgres/gda-postgres-recordset.h 6 Jan 2002 22:41:02 -0000
@@ -1,5 +1,5 @@
/* GDA DB Postgres provider
- * Copyright (C) 1998-2001 The Free Software Foundation
+ * Copyright (C) 1998-2002 The GNOME Foundation
*
* AUTHORS:
* Michael Lausch <michael lausch at>
Index: providers/postgres/gda-postgres.h
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/gda-postgres.h,v
retrieving revision 1.3
diff -u -r1.3 gda-postgres.h
--- providers/postgres/gda-postgres.h 29 Dec 2001 21:01:59 -0000 1.3
+++ providers/postgres/gda-postgres.h 6 Jan 2002 22:40:38 -0000
@@ -1,5 +1,5 @@
/* GNOME DB Postgres Provider
- * Copyright (C) 1998-2001 The Free Software Foundation
+ * Copyright (C) 1998-2002 The GNOME Foundation
*
* AUTHORS:
* Vivien Malerba <malerba gnome-db org>
Index: providers/postgres/main.c
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/main.c,v
retrieving revision 1.1
diff -u -r1.1 main.c
--- providers/postgres/main.c 19 Dec 2001 12:54:59 -0000 1.1
+++ providers/postgres/main.c 6 Jan 2002 22:41:06 -0000
@@ -1,5 +1,5 @@
/* GNOME DB Postgres Provider
- * Copyright (C) 1998-2001 The Free Software Foundation
+ * Copyright (C) 1998-2002 The GNOME Foundation
*
* AUTHORS:
* Vivien Malerba <malerba gnome-db org>
Index: providers/postgres/utils.c
===================================================================
RCS file: /home/gpanjav/gnome-db-2/cvs/libgda/providers/postgres/utils.c,v
retrieving revision 1.5
diff -u -r1.5 utils.c
--- providers/postgres/utils.c 4 Jan 2002 02:15:25 -0000 1.5
+++ providers/postgres/utils.c 6 Jan 2002 22:41:11 -0000
@@ -1,5 +1,5 @@
/* GNOME DB Postgres Provider
- * Copyright (C) 1998-2001 The Free Software Foundation
+ * Copyright (C) 1998-2002 The GNOME Foundation
*
* AUTHORS:
* Vivien Malerba <malerba gnome-db org>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]