[libgda] Generate a header file to help providers' implementing meta data retreival



commit 28d214aead5ab8156a2c00a49966fb73a21e0b9d
Author: Vivien Malerba <malerba gnome-db org>
Date:   Thu Jun 25 22:36:06 2009 +0200

    Generate a header file to help providers' implementing meta data retreival
    
    The tools/information-schema-types program generates the
    libgda/providers-support/gda-meta-column-types.h file from the libgda/information_schema.xml
    specifications files which defines the data types expected when implementing meta data
    retreival in the providers.

 libgda/information_schema.xml                    |    6 +
 libgda/providers-support/Makefile.am             |    3 +-
 libgda/providers-support/gda-meta-column-types.h |  501 ++++++++++++++++++++++
 providers/postgres/gda-postgres-meta.c           |   46 +--
 tools/.gitignore                                 |    1 +
 tools/Makefile.am                                |    9 +-
 tools/information-schema-types.c                 |  155 +++++++
 7 files changed, 694 insertions(+), 27 deletions(-)
---
diff --git a/libgda/information_schema.xml b/libgda/information_schema.xml
index ff71657..913d385 100644
--- a/libgda/information_schema.xml
+++ b/libgda/information_schema.xml
@@ -3,6 +3,12 @@
     Information schema for Libgda's dictionary DB.
     This is the base schema and can be extended by applications by adding new
     DBMS objects, but: the '_' prefix is reserved for Libgda's internals...
+
+    NOTE: when modified, please re-run:
+       tools/information-schema-doc
+       tools/information-schema-types
+
+    and copy the generated files to doc/C and libgda/providers-support
 -->
 
 
diff --git a/libgda/providers-support/Makefile.am b/libgda/providers-support/Makefile.am
index c3402e9..7e3d768 100644
--- a/libgda/providers-support/Makefile.am
+++ b/libgda/providers-support/Makefile.am
@@ -8,7 +8,8 @@ AM_CPPFLAGS = \
 
 psupport_headers = \
 	gda-data-select-priv.h \
-	gda-pstmt.h
+	gda-pstmt.h \
+	gda-meta-column-types.h
 
 libgda_psupport_la_SOURCES = \
 	$(psupport_headers) \
diff --git a/libgda/providers-support/gda-meta-column-types.h b/libgda/providers-support/gda-meta-column-types.h
new file mode 100644
index 0000000..4b2eb10
--- /dev/null
+++ b/libgda/providers-support/gda-meta-column-types.h
@@ -0,0 +1,501 @@
+/*
+ * File generated by the tools/information-schema-types program from the
+ * libgda/information_schema.xml file,
+ * This file contains declaration of the expected data types when
+ * extracting meta data, it should be updated when the libgda/information_schema.xml file changes
+ * DO NOT MODIFY
+ */
+
+
+
+
+/*
+ * TABLE: _attributes
+ *
+ * Table to store (key,value) pairs (keys starting with '_' are reserved)
+ */
+GType _col_types_attributes[] = {
+  G_TYPE_STRING  /* column: att_name */
+, G_TYPE_STRING  /* column: att_value */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _information_schema_catalog_name
+ *
+ * Name of the current database (current catalog), has only one row
+ */
+GType _col_types_information_schema_catalog_name[] = {
+  G_TYPE_STRING  /* column: catalog_name */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _schemata
+ *
+ * List of schemas
+ */
+GType _col_types_schemata[] = {
+  G_TYPE_STRING  /* column: catalog_name */
+, G_TYPE_STRING  /* column: schema_name */
+, G_TYPE_STRING  /* column: schema_owner */
+, G_TYPE_BOOLEAN  /* column: schema_internal */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _builtin_data_types
+ *
+ * List of built-in data types such as varchar, int, ...
+ */
+GType _col_types_builtin_data_types[] = {
+  G_TYPE_STRING  /* column: short_type_name */
+, G_TYPE_STRING  /* column: full_type_name */
+, G_TYPE_STRING  /* column: gtype */
+, G_TYPE_STRING  /* column: comments */
+, G_TYPE_STRING  /* column: synonyms */
+, G_TYPE_BOOLEAN  /* column: internal */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _udt
+ *
+ * User defined data types
+ */
+GType _col_types_udt[] = {
+  G_TYPE_STRING  /* column: udt_catalog */
+, G_TYPE_STRING  /* column: udt_schema */
+, G_TYPE_STRING  /* column: udt_name */
+, G_TYPE_STRING  /* column: udt_gtype */
+, G_TYPE_STRING  /* column: udt_comments */
+, G_TYPE_STRING  /* column: udt_short_name */
+, G_TYPE_STRING  /* column: udt_full_name */
+, G_TYPE_BOOLEAN  /* column: udt_internal */
+, G_TYPE_STRING  /* column: udt_owner */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _udt_columns
+ *
+ * List of components for a user defined data type for composed data types (such as a complex number data type which has real and imaginary parts)
+ */
+GType _col_types_udt_columns[] = {
+  G_TYPE_STRING  /* column: udt_catalog */
+, G_TYPE_STRING  /* column: udt_schema */
+, G_TYPE_STRING  /* column: udt_name */
+, G_TYPE_STRING  /* column: udt_column */
+, G_TYPE_INT  /* column: ordinal_position */
+, G_TYPE_STRING  /* column: data_type */
+, G_TYPE_STRING  /* column: array_spec */
+, G_TYPE_INT  /* column: character_maximum_length */
+, G_TYPE_INT  /* column: character_octet_length */
+, G_TYPE_INT  /* column: numeric_precision */
+, G_TYPE_INT  /* column: numeric_scale */
+, G_TYPE_INT  /* column: datetime_precision */
+, G_TYPE_STRING  /* column: character_set_catalog */
+, G_TYPE_STRING  /* column: character_set_schema */
+, G_TYPE_STRING  /* column: character_set_name */
+, G_TYPE_STRING  /* column: collation_catalog */
+, G_TYPE_STRING  /* column: collation_schema */
+, G_TYPE_STRING  /* column: collation_name */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _enums
+ *
+ * List of possible enumeration labels for enumerations
+ */
+GType _col_types_enums[] = {
+  G_TYPE_STRING  /* column: udt_catalog */
+, G_TYPE_STRING  /* column: udt_schema */
+, G_TYPE_STRING  /* column: udt_name */
+, G_TYPE_STRING  /* column: label */
+, G_TYPE_INT  /* column: ordinal_position */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _element_types
+ *
+ * Array specific attributes for array data types
+ */
+GType _col_types_element_types[] = {
+  G_TYPE_STRING  /* column: specific_name */
+, G_TYPE_STRING  /* column: object_catalog */
+, G_TYPE_STRING  /* column: object_schema */
+, G_TYPE_STRING  /* column: object_name */
+, G_TYPE_STRING  /* column: object_type */
+, G_TYPE_STRING  /* column: data_type */
+, G_TYPE_STRING  /* column: array_spec */
+, G_TYPE_INT  /* column: min_cardinality */
+, G_TYPE_INT  /* column: max_cardinality */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _domains
+ *
+ * List of domains
+ */
+GType _col_types_domains[] = {
+  G_TYPE_STRING  /* column: domain_catalog */
+, G_TYPE_STRING  /* column: domain_schema */
+, G_TYPE_STRING  /* column: domain_name */
+, G_TYPE_STRING  /* column: data_type */
+, G_TYPE_STRING  /* column: array_spec */
+, G_TYPE_STRING  /* column: domain_gtype */
+, G_TYPE_INT  /* column: character_maximum_length */
+, G_TYPE_INT  /* column: character_octet_length */
+, G_TYPE_STRING  /* column: collation_catalog */
+, G_TYPE_STRING  /* column: collation_schema */
+, G_TYPE_STRING  /* column: collation_name */
+, G_TYPE_STRING  /* column: character_set_catalog */
+, G_TYPE_STRING  /* column: character_set_schema */
+, G_TYPE_STRING  /* column: character_set_name */
+, G_TYPE_INT  /* column: numeric_precision */
+, G_TYPE_INT  /* column: numeric_scale */
+, G_TYPE_STRING  /* column: domain_default */
+, G_TYPE_STRING  /* column: domain_comments */
+, G_TYPE_STRING  /* column: domain_short_name */
+, G_TYPE_STRING  /* column: domain_full_name */
+, G_TYPE_BOOLEAN  /* column: domain_internal */
+, G_TYPE_STRING  /* column: domain_owner */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _tables
+ *
+ * List of tables (tables, views or other objects which can contain data)
+ */
+GType _col_types_tables[] = {
+  G_TYPE_STRING  /* column: table_catalog */
+, G_TYPE_STRING  /* column: table_schema */
+, G_TYPE_STRING  /* column: table_name */
+, G_TYPE_STRING  /* column: table_type */
+, G_TYPE_BOOLEAN  /* column: is_insertable_into */
+, G_TYPE_STRING  /* column: table_comments */
+, G_TYPE_STRING  /* column: table_short_name */
+, G_TYPE_STRING  /* column: table_full_name */
+, G_TYPE_STRING  /* column: table_owner */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _views
+ *
+ * List of views and their specific information
+ */
+GType _col_types_views[] = {
+  G_TYPE_STRING  /* column: table_catalog */
+, G_TYPE_STRING  /* column: table_schema */
+, G_TYPE_STRING  /* column: table_name */
+, G_TYPE_STRING  /* column: view_definition */
+, G_TYPE_STRING  /* column: check_option */
+, G_TYPE_BOOLEAN  /* column: is_updatable */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _collations
+ *
+ * List of collations methods
+ */
+GType _col_types_collations[] = {
+  G_TYPE_STRING  /* column: collation_catalog */
+, G_TYPE_STRING  /* column: collation_schema */
+, G_TYPE_STRING  /* column: collation_name */
+, G_TYPE_STRING  /* column: collation_comments */
+, G_TYPE_STRING  /* column: collation_short_name */
+, G_TYPE_STRING  /* column: collation_full_name */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _character_sets
+ *
+ * List of character sets
+ */
+GType _col_types_character_sets[] = {
+  G_TYPE_STRING  /* column: character_set_catalog */
+, G_TYPE_STRING  /* column: character_set_schema */
+, G_TYPE_STRING  /* column: character_set_name */
+, G_TYPE_STRING  /* column: default_collate_catalog */
+, G_TYPE_STRING  /* column: default_collate_schema */
+, G_TYPE_STRING  /* column: default_collate_name */
+, G_TYPE_STRING  /* column: character_set_comments */
+, G_TYPE_STRING  /* column: character_set_short_name */
+, G_TYPE_STRING  /* column: character_set_full_name */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _routines
+ *
+ * List of functions and stored procedures (note: the primary jey for that table is composed of (specific_catalog, specific_schema, specific_name))
+ */
+GType _col_types_routines[] = {
+  G_TYPE_STRING  /* column: specific_catalog */
+, G_TYPE_STRING  /* column: specific_schema */
+, G_TYPE_STRING  /* column: specific_name */
+, G_TYPE_STRING  /* column: routine_catalog */
+, G_TYPE_STRING  /* column: routine_schema */
+, G_TYPE_STRING  /* column: routine_name */
+, G_TYPE_STRING  /* column: routine_type */
+, G_TYPE_STRING  /* column: return_type */
+, G_TYPE_BOOLEAN  /* column: returns_set */
+, G_TYPE_INT  /* column: nb_args */
+, G_TYPE_STRING  /* column: routine_body */
+, G_TYPE_STRING  /* column: routine_definition */
+, G_TYPE_STRING  /* column: external_name */
+, G_TYPE_STRING  /* column: external_language */
+, G_TYPE_STRING  /* column: parameter_style */
+, G_TYPE_BOOLEAN  /* column: is_deterministic */
+, G_TYPE_STRING  /* column: sql_data_access */
+, G_TYPE_BOOLEAN  /* column: is_null_call */
+, G_TYPE_STRING  /* column: routine_comments */
+, G_TYPE_STRING  /* column: routine_short_name */
+, G_TYPE_STRING  /* column: routine_full_name */
+, G_TYPE_STRING  /* column: routine_owner */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _triggers
+ *
+ * List of triggers
+ */
+GType _col_types_triggers[] = {
+  G_TYPE_STRING  /* column: trigger_catalog */
+, G_TYPE_STRING  /* column: trigger_schema */
+, G_TYPE_STRING  /* column: trigger_name */
+, G_TYPE_STRING  /* column: event_manipulation */
+, G_TYPE_STRING  /* column: event_object_catalog */
+, G_TYPE_STRING  /* column: event_object_schema */
+, G_TYPE_STRING  /* column: event_object_table */
+, G_TYPE_STRING  /* column: action_statement */
+, G_TYPE_STRING  /* column: action_orientation */
+, G_TYPE_STRING  /* column: condition_timing */
+, G_TYPE_STRING  /* column: trigger_comments */
+, G_TYPE_STRING  /* column: trigger_short_name */
+, G_TYPE_STRING  /* column: trigger_full_name */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _columns
+ *
+ * List of columns composing tables
+ */
+GType _col_types_columns[] = {
+  G_TYPE_STRING  /* column: table_catalog */
+, G_TYPE_STRING  /* column: table_schema */
+, G_TYPE_STRING  /* column: table_name */
+, G_TYPE_STRING  /* column: column_name */
+, G_TYPE_INT  /* column: ordinal_position */
+, G_TYPE_STRING  /* column: column_default */
+, G_TYPE_BOOLEAN  /* column: is_nullable */
+, G_TYPE_STRING  /* column: data_type */
+, G_TYPE_STRING  /* column: array_spec */
+, G_TYPE_STRING  /* column: gtype */
+, G_TYPE_INT  /* column: character_maximum_length */
+, G_TYPE_INT  /* column: character_octet_length */
+, G_TYPE_INT  /* column: numeric_precision */
+, G_TYPE_INT  /* column: numeric_scale */
+, G_TYPE_INT  /* column: datetime_precision */
+, G_TYPE_STRING  /* column: character_set_catalog */
+, G_TYPE_STRING  /* column: character_set_schema */
+, G_TYPE_STRING  /* column: character_set_name */
+, G_TYPE_STRING  /* column: collation_catalog */
+, G_TYPE_STRING  /* column: collation_schema */
+, G_TYPE_STRING  /* column: collation_name */
+, G_TYPE_STRING  /* column: extra */
+, G_TYPE_BOOLEAN  /* column: is_updatable */
+, G_TYPE_STRING  /* column: column_comments */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _table_constraints
+ *
+ * List of constraints applied to tables (Check, primary or foreign key, or unique constraints)
+ */
+GType _col_types_table_constraints[] = {
+  G_TYPE_STRING  /* column: constraint_catalog */
+, G_TYPE_STRING  /* column: constraint_schema */
+, G_TYPE_STRING  /* column: constraint_name */
+, G_TYPE_STRING  /* column: table_catalog */
+, G_TYPE_STRING  /* column: table_schema */
+, G_TYPE_STRING  /* column: table_name */
+, G_TYPE_STRING  /* column: constraint_type */
+, G_TYPE_STRING  /* column: check_clause */
+, G_TYPE_BOOLEAN  /* column: is_deferrable */
+, G_TYPE_BOOLEAN  /* column: initially_deferred */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _referential_constraints
+ *
+ * List of foreign key constraints, along with some specific attributes
+ */
+GType _col_types_referential_constraints[] = {
+  G_TYPE_STRING  /* column: table_catalog */
+, G_TYPE_STRING  /* column: table_schema */
+, G_TYPE_STRING  /* column: table_name */
+, G_TYPE_STRING  /* column: constraint_name */
+, G_TYPE_STRING  /* column: ref_table_catalog */
+, G_TYPE_STRING  /* column: ref_table_schema */
+, G_TYPE_STRING  /* column: ref_table_name */
+, G_TYPE_STRING  /* column: ref_constraint_name */
+, G_TYPE_STRING  /* column: match_option */
+, G_TYPE_STRING  /* column: update_rule */
+, G_TYPE_STRING  /* column: delete_rule */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _key_column_usage
+ *
+ * List of primary key constraints and the name of the tables' columns involved
+ */
+GType _col_types_key_column_usage[] = {
+  G_TYPE_STRING  /* column: table_catalog */
+, G_TYPE_STRING  /* column: table_schema */
+, G_TYPE_STRING  /* column: table_name */
+, G_TYPE_STRING  /* column: constraint_name */
+, G_TYPE_STRING  /* column: column_name */
+, G_TYPE_INT  /* column: ordinal_position */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _check_column_usage
+ *
+ * List of check constraints and the name of the tables' columns involved
+ */
+GType _col_types_check_column_usage[] = {
+  G_TYPE_STRING  /* column: table_catalog */
+, G_TYPE_STRING  /* column: table_schema */
+, G_TYPE_STRING  /* column: table_name */
+, G_TYPE_STRING  /* column: constraint_name */
+, G_TYPE_STRING  /* column: column_name */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _view_column_usage
+ *
+ * List of the tables' columns involved in a view
+ */
+GType _col_types_view_column_usage[] = {
+  G_TYPE_STRING  /* column: view_catalog */
+, G_TYPE_STRING  /* column: view_schema */
+, G_TYPE_STRING  /* column: view_name */
+, G_TYPE_STRING  /* column: table_catalog */
+, G_TYPE_STRING  /* column: table_schema */
+, G_TYPE_STRING  /* column: table_name */
+, G_TYPE_STRING  /* column: column_name */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _domain_constraints
+ *
+ * List of constraints applicable to domains
+ */
+GType _col_types_domain_constraints[] = {
+  G_TYPE_STRING  /* column: constraint_catalog */
+, G_TYPE_STRING  /* column: constraint_schema */
+, G_TYPE_STRING  /* column: constraint_name */
+, G_TYPE_STRING  /* column: domain_catalog */
+, G_TYPE_STRING  /* column: domain_schema */
+, G_TYPE_STRING  /* column: domain_name */
+, G_TYPE_STRING  /* column: check_clause */
+, G_TYPE_BOOLEAN  /* column: is_deferrable */
+, G_TYPE_BOOLEAN  /* column: initially_deferred */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _parameters
+ *
+ * List of routines' (functions and stored procedures) parameters (may not contain data for some routines which accept any type of parameter)
+ */
+GType _col_types_parameters[] = {
+  G_TYPE_STRING  /* column: specific_catalog */
+, G_TYPE_STRING  /* column: specific_schema */
+, G_TYPE_STRING  /* column: specific_name */
+, G_TYPE_INT  /* column: ordinal_position */
+, G_TYPE_STRING  /* column: parameter_mode */
+, G_TYPE_STRING  /* column: parameter_name */
+, G_TYPE_STRING  /* column: data_type */
+, G_TYPE_STRING  /* column: array_spec */
+, G_TYPE_NONE /* end of array marker */
+};
+
+
+
+/*
+ * TABLE: _routine_columns
+ *
+ * List of routines' (functions and stored procedures) returned values' parts (columns) for routines returning composed values
+ */
+GType _col_types_routine_columns[] = {
+  G_TYPE_STRING  /* column: specific_catalog */
+, G_TYPE_STRING  /* column: specific_schema */
+, G_TYPE_STRING  /* column: specific_name */
+, G_TYPE_STRING  /* column: column_name */
+, G_TYPE_INT  /* column: ordinal_position */
+, G_TYPE_STRING  /* column: data_type */
+, G_TYPE_STRING  /* column: array_spec */
+, G_TYPE_NONE /* end of array marker */
+};
+
diff --git a/providers/postgres/gda-postgres-meta.c b/providers/postgres/gda-postgres-meta.c
index b5cd804..d72771a 100644
--- a/providers/postgres/gda-postgres-meta.c
+++ b/providers/postgres/gda-postgres-meta.c
@@ -32,6 +32,7 @@
 #include <libgda/gda-connection-private.h>
 #include <libgda/gda-data-model-array.h>
 #include <libgda/gda-set.h>
+#include <libgda/providers-support/gda-meta-column-types.h>
 
 /*
  * predefined statements' IDs
@@ -389,13 +390,12 @@ _gda_postgres_meta__udt_cols (GdaServerProvider *prov, GdaConnection *cnc,
 {
 	GdaDataModel *model;
 	gboolean retval;
-	GType col_types[] = {
-		G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, 
-		G_TYPE_INT, G_TYPE_NONE
-	};
 
-	model = gda_connection_statement_execute_select_full (cnc, internal_stmt[I_STMT_UDT_COLUMNS_ALL], NULL, 
-							      GDA_STATEMENT_MODEL_RANDOM_ACCESS, col_types, error);
+	model = gda_connection_statement_execute_select_full (cnc,
+							      internal_stmt[I_STMT_UDT_COLUMNS_ALL],
+							      NULL, 
+							      GDA_STATEMENT_MODEL_RANDOM_ACCESS,
+							      _col_types_udt_columns, error);
 
 	if (!model)
 		return FALSE;
@@ -412,10 +412,6 @@ _gda_postgres_meta_udt_cols (GdaServerProvider *prov, GdaConnection *cnc,
 {
 	GdaDataModel *model;
 	gboolean retval = TRUE;
-	GType col_types[] = {
-		G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, 
-		G_TYPE_INT, G_TYPE_NONE
-	};
 
 	if (!gda_holder_set_value (gda_set_get_holder (i_set, "cat"), udt_catalog, error))
 		return FALSE;
@@ -423,8 +419,11 @@ _gda_postgres_meta_udt_cols (GdaServerProvider *prov, GdaConnection *cnc,
 		return FALSE;
 	if (! gda_holder_set_value (gda_set_get_holder (i_set, "name"), udt_name, error))
 		return FALSE;
-	model = gda_connection_statement_execute_select_full (cnc, internal_stmt[I_STMT_UDT_COLUMNS_ALL], i_set, 
-							      GDA_STATEMENT_MODEL_RANDOM_ACCESS, col_types, error);
+	model = gda_connection_statement_execute_select_full (cnc,
+							      internal_stmt[I_STMT_UDT_COLUMNS_ALL],
+							      i_set, 
+							      GDA_STATEMENT_MODEL_RANDOM_ACCESS,
+							      _col_types_udt_columns, error);
 	if (!model)
 		return FALSE;
 	retval = gda_meta_store_modify_with_context (store, context, model, error);
@@ -802,18 +801,16 @@ gboolean _gda_postgres_meta__columns (GdaServerProvider *prov, GdaConnection *cn
 	gboolean retval = TRUE;
 	gint i, nrows;
 	PostgresConnectionData *cdata;
-	GType col_types[] = {
-		G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, 
-		G_TYPE_INT, G_TYPE_NONE
-	};
 
 	cdata = (PostgresConnectionData*) gda_connection_internal_get_provider_data (cnc);
 	if (!cdata)
 		return FALSE;
 
 	/* use a prepared statement for the "base" model */
-	model = gda_connection_statement_execute_select_full (cnc, internal_stmt[I_STMT_COLUMNS_ALL], i_set, 
-							      GDA_STATEMENT_MODEL_RANDOM_ACCESS, col_types, error);
+	model = gda_connection_statement_execute_select_full (cnc,
+							      internal_stmt[I_STMT_COLUMNS_ALL], i_set, 
+							      GDA_STATEMENT_MODEL_RANDOM_ACCESS,
+							      _col_types_columns, error);
 	if (!model)
 		return FALSE;
 
@@ -894,10 +891,6 @@ _gda_postgres_meta_columns (GdaServerProvider *prov, GdaConnection *cnc,
 	gboolean retval = TRUE;
 	gint i, nrows;
 	PostgresConnectionData *cdata;
-	GType col_types[] = {
-		G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, 
-		G_TYPE_INT, G_TYPE_NONE
-	};
 
 	/* check correct postgres server version */
 	cdata = (PostgresConnectionData*) gda_connection_internal_get_provider_data (cnc);
@@ -916,8 +909,11 @@ _gda_postgres_meta_columns (GdaServerProvider *prov, GdaConnection *cnc,
 		return FALSE;
 	if (! gda_holder_set_value (gda_set_get_holder (i_set, "name"), table_name, error))
 		return FALSE;
-	model = gda_connection_statement_execute_select_full (cnc, internal_stmt[I_STMT_COLUMNS_OF_TABLE], i_set, 
-							      GDA_STATEMENT_MODEL_RANDOM_ACCESS, col_types, error);
+	model = gda_connection_statement_execute_select_full (cnc,
+							      internal_stmt[I_STMT_COLUMNS_OF_TABLE],
+							      i_set, 
+							      GDA_STATEMENT_MODEL_RANDOM_ACCESS,
+							      _col_types_columns, error);
 	if (!model)
 		return FALSE;
 
@@ -1457,7 +1453,7 @@ _gda_postgres_meta_routine_col (GdaServerProvider *prov, GdaConnection *cnc,
 				const GValue *rout_catalog, const GValue *rout_schema, 
 				const GValue *rout_name)
 {
-GdaDataModel *model, *proxy;
+	GdaDataModel *model, *proxy;
 	gint ordinal_pos, i, nrows;
 	const GValue *spname = NULL;
 	gboolean retval;
diff --git a/tools/.gitignore b/tools/.gitignore
index 3b718da..d1e24a3 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -2,4 +2,5 @@ gda-sql-4*
 gda-list-config-4*
 gda-list-server-op-4*
 information-schema-doc
+information-schema-types
 gda-sql-4.*.1
diff --git a/tools/Makefile.am b/tools/Makefile.am
index a248098..6e1c5e7 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -9,7 +9,7 @@ bin_PROGRAMS = \
 	gda-sql-4.0 \
 	gda-list-server-op-4.0
 
-noinst_PROGRAMS = information-schema-doc
+noinst_PROGRAMS = information-schema-doc information-schema-types
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir) \
@@ -82,6 +82,13 @@ information_schema_doc_LDADD = \
         $(top_builddir)/libgda/libgda-4.0.la \
         $(LIBGDA_LIBS)
 
+information_schema_types_SOURCES = \
+        information-schema-types.c
+
+information_schema_types_LDADD = \
+        $(top_builddir)/libgda/libgda-4.0.la \
+        $(LIBGDA_LIBS)
+
 webdatadir = $(datadir)/libgda-4.0/web
 webdata_DATA = \
 	cnc.js \
diff --git a/tools/information-schema-types.c b/tools/information-schema-types.c
new file mode 100644
index 0000000..311241c
--- /dev/null
+++ b/tools/information-schema-types.c
@@ -0,0 +1,155 @@
+/* GDA - Information schema data types extractor
+ * Copyright (C) 2009 The GNOME Foundation.
+ *
+ * AUTHORS:
+ *      Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <glib-object.h>
+#include <libgda/binreloc/gda-binreloc.h>
+#include <libgda/gda-util.h>
+#include <string.h>
+
+#define FILE_NAME "information_schema.xml"
+#define OUT_FILE "gda-meta-column-types.h"
+
+int
+main (int argc, char** argv)
+{
+        xmlDocPtr doc;
+        xmlNodePtr node;
+        gchar *fname;
+	GString *out_str;
+
+	gda_init();
+
+        fname = g_build_filename (ROOT_DIR, "libgda", FILE_NAME, NULL);
+	if (! g_file_test (fname, G_FILE_TEST_EXISTS)) {
+		g_free (fname);
+		fname = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, FILE_NAME, NULL);
+		if (! g_file_test (fname, G_FILE_TEST_EXISTS)) {
+			g_print ("Could not find '%s'.\n", FILE_NAME);
+			exit (1);
+		}
+	}
+
+	doc = xmlParseFile (fname);
+	if (!doc) {
+		g_print ("Missing or malformed file '%s', check your installation", fname);
+		g_free (fname);
+		exit (1);
+        }
+	
+	node = xmlDocGetRootElement (doc);
+	g_free (fname);
+	if (strcmp ((gchar *) node->name, "schema")) {
+		g_print ("Root node should be <schema>, got <%s>\n", (gchar *) node->name);
+		xmlFreeDoc (doc);
+		exit (1);
+	}
+
+	out_str = g_string_new ("/*\n * File generated by the tools/information-schema-types "
+				"program from the\n"
+				" * libgda/" FILE_NAME " file,\n"
+				" * This file contains declaration of the expected data types when\n"
+				" * extracting meta data, it should be updated when the "
+				"libgda/"FILE_NAME " file changes\n"
+				" * DO NOT MODIFY\n */\n\n\n");
+	
+	for (node = node->children; node; node = node->next) {
+		if (!strcmp ((gchar *) node->name, "table")) {
+			xmlChar *prop, *descr;
+			xmlNodePtr child;
+
+			descr = xmlGetProp (node, BAD_CAST "descr");
+			prop = xmlGetProp (node, BAD_CAST "name");
+			if (prop) {
+				g_string_append (out_str, "\n\n");
+				if (descr)
+					g_string_append_printf (out_str, "/*\n * TABLE: %s\n *\n * %s\n */\n",
+								(gchar*) prop, (gchar *) descr);
+				else
+					g_string_append_printf (out_str, "/*\n * TABLE: %s\n */\n",
+								(gchar*) prop);
+				g_string_append_printf (out_str,
+							"GType _col_types%s[] = {\n", prop);
+				xmlFree (prop);
+			}
+			else {
+				g_warning ("FIXME: table not named");
+				continue;
+			}
+
+			if (descr)
+				xmlFree (descr);
+
+			gboolean firstcol = TRUE;
+			for (child = node->children; child; child = child->next) {
+				if (!strcmp ((gchar *) child->name, "column")) {
+					if (firstcol) {
+						firstcol = FALSE;
+						g_string_append (out_str, "  ");
+					}
+					else
+						g_string_append (out_str, ", ");
+
+					prop = xmlGetProp (child, BAD_CAST "type");
+					if (prop) {
+						GType type;
+						type = gda_g_type_from_string ((gchar*) prop);
+						if (type == G_TYPE_STRING)
+							g_string_append (out_str, "G_TYPE_STRING");
+						else if (type == G_TYPE_BOOLEAN)
+							g_string_append (out_str, "G_TYPE_BOOLEAN");
+						else if (type == G_TYPE_INT)
+							g_string_append (out_str, "G_TYPE_INT");
+						else
+							g_error ("Non handled type "
+								 "%s (interpreted as %s)\n", prop,
+								 g_type_name (type));
+
+						xmlFree (prop);
+					}
+					else
+						g_string_append (out_str, "G_TYPE_STRING");
+
+					prop = xmlGetProp (child, BAD_CAST "name");
+					if (prop) {
+						g_string_append_printf (out_str, "  /* column: %s */\n",
+									prop);
+						xmlFree (prop);
+					}
+					else
+						g_string_append (out_str, "\n");
+				}
+			}
+			g_string_append (out_str, ", G_TYPE_NONE /* end of array marker */\n");
+			g_string_append (out_str, "};\n\n");
+		}
+	}
+	xmlFreeDoc (doc);
+
+	if (! g_file_set_contents (OUT_FILE, out_str->str, -1, NULL)) 
+		g_print ("Could not write output file '%s'\n", OUT_FILE);
+	else
+		g_print ("Doc. written to '%s'\n", OUT_FILE);
+	g_string_free (out_str, TRUE);
+	
+	return 0;
+}



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