[libgda] Information schema avoid GCC compilation warnings for _col_types_* definitions



commit 795ac822ead333fce3d203c129f1f22ec6ee8a22
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sun Jun 3 18:02:17 2012 +0200

    Information schema avoid GCC compilation warnings for _col_types_* definitions

 libgda/providers-support/gda-meta-column-types.h |   59 ++++++++-------
 tools/README                                     |    6 +-
 tools/information-schema-types.c                 |   86 ++++++++++++----------
 3 files changed, 84 insertions(+), 67 deletions(-)
---
diff --git a/libgda/providers-support/gda-meta-column-types.h b/libgda/providers-support/gda-meta-column-types.h
index 6e84a22..dc84b39 100644
--- a/libgda/providers-support/gda-meta-column-types.h
+++ b/libgda/providers-support/gda-meta-column-types.h
@@ -7,6 +7,12 @@
  */
 
 
+#ifdef __GNUC__
+#define MAY_BE_UNUSED __attribute__ ((unused))
+#else
+#define MAY_BE_UNUSED
+#endif
+
 
 
 /*
@@ -14,7 +20,7 @@
  *
  * Table to store (key,value) pairs (keys starting with '_' are reserved)
  */
-static GType _col_types_attributes[] = {
+MAY_BE_UNUSED static GType _col_types_attributes[] = {
   G_TYPE_STRING  /* column: att_name */
 , G_TYPE_STRING  /* column: att_value */
 , G_TYPE_NONE /* end of array marker */
@@ -27,7 +33,7 @@ static GType _col_types_attributes[] = {
  *
  * Name of the current database (current catalog), has only one row
  */
-static GType _col_types_information_schema_catalog_name[] = {
+MAY_BE_UNUSED static GType _col_types_information_schema_catalog_name[] = {
   G_TYPE_STRING  /* column: catalog_name */
 , G_TYPE_NONE /* end of array marker */
 };
@@ -39,7 +45,7 @@ static GType _col_types_information_schema_catalog_name[] = {
  *
  * List of schemas
  */
-static GType _col_types_schemata[] = {
+MAY_BE_UNUSED static GType _col_types_schemata[] = {
   G_TYPE_STRING  /* column: catalog_name */
 , G_TYPE_STRING  /* column: schema_name */
 , G_TYPE_STRING  /* column: schema_owner */
@@ -55,7 +61,7 @@ static GType _col_types_schemata[] = {
  *
  * List of built-in data types such as varchar, int, ...
  */
-static GType _col_types_builtin_data_types[] = {
+MAY_BE_UNUSED static 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 */
@@ -72,7 +78,7 @@ static GType _col_types_builtin_data_types[] = {
  *
  * User defined data types
  */
-static GType _col_types_udt[] = {
+MAY_BE_UNUSED static GType _col_types_udt[] = {
   G_TYPE_STRING  /* column: udt_catalog */
 , G_TYPE_STRING  /* column: udt_schema */
 , G_TYPE_STRING  /* column: udt_name */
@@ -92,7 +98,7 @@ static GType _col_types_udt[] = {
  *
  * 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)
  */
-static GType _col_types_udt_columns[] = {
+MAY_BE_UNUSED static GType _col_types_udt_columns[] = {
   G_TYPE_STRING  /* column: udt_catalog */
 , G_TYPE_STRING  /* column: udt_schema */
 , G_TYPE_STRING  /* column: udt_name */
@@ -121,7 +127,7 @@ static GType _col_types_udt_columns[] = {
  *
  * List of possible enumeration labels for enumerations
  */
-static GType _col_types_enums[] = {
+MAY_BE_UNUSED static GType _col_types_enums[] = {
   G_TYPE_STRING  /* column: udt_catalog */
 , G_TYPE_STRING  /* column: udt_schema */
 , G_TYPE_STRING  /* column: udt_name */
@@ -137,7 +143,7 @@ static GType _col_types_enums[] = {
  *
  * Array specific attributes for array data types
  */
-static GType _col_types_element_types[] = {
+MAY_BE_UNUSED static GType _col_types_element_types[] = {
   G_TYPE_STRING  /* column: specific_name */
 , G_TYPE_STRING  /* column: object_catalog */
 , G_TYPE_STRING  /* column: object_schema */
@@ -157,7 +163,7 @@ static GType _col_types_element_types[] = {
  *
  * List of domains
  */
-static GType _col_types_domains[] = {
+MAY_BE_UNUSED static GType _col_types_domains[] = {
   G_TYPE_STRING  /* column: domain_catalog */
 , G_TYPE_STRING  /* column: domain_schema */
 , G_TYPE_STRING  /* column: domain_name */
@@ -190,7 +196,7 @@ static GType _col_types_domains[] = {
  *
  * List of tables (tables, views or other objects which can contain data)
  */
-static GType _col_types_tables[] = {
+MAY_BE_UNUSED static GType _col_types_tables[] = {
   G_TYPE_STRING  /* column: table_catalog */
 , G_TYPE_STRING  /* column: table_schema */
 , G_TYPE_STRING  /* column: table_name */
@@ -210,7 +216,7 @@ static GType _col_types_tables[] = {
  *
  * List of views and their specific information
  */
-static GType _col_types_views[] = {
+MAY_BE_UNUSED static GType _col_types_views[] = {
   G_TYPE_STRING  /* column: table_catalog */
 , G_TYPE_STRING  /* column: table_schema */
 , G_TYPE_STRING  /* column: table_name */
@@ -227,7 +233,7 @@ static GType _col_types_views[] = {
  *
  * List of collations methods
  */
-static GType _col_types_collations[] = {
+MAY_BE_UNUSED static GType _col_types_collations[] = {
   G_TYPE_STRING  /* column: collation_catalog */
 , G_TYPE_STRING  /* column: collation_schema */
 , G_TYPE_STRING  /* column: collation_name */
@@ -244,7 +250,7 @@ static GType _col_types_collations[] = {
  *
  * List of character sets
  */
-static GType _col_types_character_sets[] = {
+MAY_BE_UNUSED static 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 */
@@ -264,7 +270,7 @@ static GType _col_types_character_sets[] = {
  *
  * List of functions and stored procedures (note: the primary jey for that table is composed of (specific_catalog, specific_schema, specific_name))
  */
-static GType _col_types_routines[] = {
+MAY_BE_UNUSED static GType _col_types_routines[] = {
   G_TYPE_STRING  /* column: specific_catalog */
 , G_TYPE_STRING  /* column: specific_schema */
 , G_TYPE_STRING  /* column: specific_name */
@@ -297,7 +303,7 @@ static GType _col_types_routines[] = {
  *
  * List of triggers
  */
-static GType _col_types_triggers[] = {
+MAY_BE_UNUSED static GType _col_types_triggers[] = {
   G_TYPE_STRING  /* column: trigger_catalog */
 , G_TYPE_STRING  /* column: trigger_schema */
 , G_TYPE_STRING  /* column: trigger_name */
@@ -321,7 +327,7 @@ static GType _col_types_triggers[] = {
  *
  * List of columns composing tables
  */
-static GType _col_types_columns[] = {
+MAY_BE_UNUSED static GType _col_types_columns[] = {
   G_TYPE_STRING  /* column: table_catalog */
 , G_TYPE_STRING  /* column: table_schema */
 , G_TYPE_STRING  /* column: table_name */
@@ -356,7 +362,7 @@ static GType _col_types_columns[] = {
  *
  * List of constraints applied to tables (Check, primary or foreign key, or unique constraints)
  */
-static GType _col_types_table_constraints[] = {
+MAY_BE_UNUSED static GType _col_types_table_constraints[] = {
   G_TYPE_STRING  /* column: constraint_catalog */
 , G_TYPE_STRING  /* column: constraint_schema */
 , G_TYPE_STRING  /* column: constraint_name */
@@ -377,7 +383,7 @@ static GType _col_types_table_constraints[] = {
  *
  * List of foreign key constraints, along with some specific attributes
  */
-static GType _col_types_referential_constraints[] = {
+MAY_BE_UNUSED static GType _col_types_referential_constraints[] = {
   G_TYPE_STRING  /* column: table_catalog */
 , G_TYPE_STRING  /* column: table_schema */
 , G_TYPE_STRING  /* column: table_name */
@@ -399,7 +405,7 @@ static GType _col_types_referential_constraints[] = {
  *
  * List of primary key constraints and the name of the tables' columns involved
  */
-static GType _col_types_key_column_usage[] = {
+MAY_BE_UNUSED static GType _col_types_key_column_usage[] = {
   G_TYPE_STRING  /* column: table_catalog */
 , G_TYPE_STRING  /* column: table_schema */
 , G_TYPE_STRING  /* column: table_name */
@@ -416,7 +422,7 @@ static GType _col_types_key_column_usage[] = {
  *
  * List of check constraints and the name of the tables' columns involved
  */
-static GType _col_types_check_column_usage[] = {
+MAY_BE_UNUSED static GType _col_types_check_column_usage[] = {
   G_TYPE_STRING  /* column: table_catalog */
 , G_TYPE_STRING  /* column: table_schema */
 , G_TYPE_STRING  /* column: table_name */
@@ -432,7 +438,7 @@ static GType _col_types_check_column_usage[] = {
  *
  * List of the tables' columns involved in a view
  */
-static GType _col_types_view_column_usage[] = {
+MAY_BE_UNUSED static GType _col_types_view_column_usage[] = {
   G_TYPE_STRING  /* column: view_catalog */
 , G_TYPE_STRING  /* column: view_schema */
 , G_TYPE_STRING  /* column: view_name */
@@ -450,7 +456,7 @@ static GType _col_types_view_column_usage[] = {
  *
  * List of constraints applicable to domains
  */
-static GType _col_types_domain_constraints[] = {
+MAY_BE_UNUSED static GType _col_types_domain_constraints[] = {
   G_TYPE_STRING  /* column: constraint_catalog */
 , G_TYPE_STRING  /* column: constraint_schema */
 , G_TYPE_STRING  /* column: constraint_name */
@@ -470,7 +476,7 @@ static GType _col_types_domain_constraints[] = {
  *
  * List of routines' (functions and stored procedures) parameters (may not contain data for some routines which accept any type of parameter)
  */
-static GType _col_types_parameters[] = {
+MAY_BE_UNUSED static GType _col_types_parameters[] = {
   G_TYPE_STRING  /* column: specific_catalog */
 , G_TYPE_STRING  /* column: specific_schema */
 , G_TYPE_STRING  /* column: specific_name */
@@ -489,7 +495,7 @@ static GType _col_types_parameters[] = {
  *
  * List of routines' (functions and stored procedures) returned values' parts (columns) for routines returning composed values
  */
-static GType _col_types_routine_columns[] = {
+MAY_BE_UNUSED static GType _col_types_routine_columns[] = {
   G_TYPE_STRING  /* column: specific_catalog */
 , G_TYPE_STRING  /* column: specific_schema */
 , G_TYPE_STRING  /* column: specific_name */
@@ -507,7 +513,7 @@ static GType _col_types_routine_columns[] = {
  *
  * List of tables' indexes which do not relate to primary keys
  */
-static GType _col_types_table_indexes[] = {
+MAY_BE_UNUSED static GType _col_types_table_indexes[] = {
   G_TYPE_STRING  /* column: index_catalog */
 , G_TYPE_STRING  /* column: index_schema */
 , G_TYPE_STRING  /* column: index_name */
@@ -530,7 +536,7 @@ static GType _col_types_table_indexes[] = {
  *
  * List of the tables' columns involved in an index listed in the _table_indexes table
  */
-static GType _col_types_index_column_usage[] = {
+MAY_BE_UNUSED static GType _col_types_index_column_usage[] = {
   G_TYPE_STRING  /* column: index_catalog */
 , G_TYPE_STRING  /* column: index_schema */
 , G_TYPE_STRING  /* column: index_name */
@@ -543,3 +549,4 @@ static GType _col_types_index_column_usage[] = {
 , G_TYPE_NONE /* end of array marker */
 };
 
+#undef MAY_BE_UNUSED
diff --git a/tools/README b/tools/README
index 5b31d0b..2ab81f3 100644
--- a/tools/README
+++ b/tools/README
@@ -1,16 +1,16 @@
-gda-sql-4.0
+gda-sql-5.0
 -----------
 Console program to open connections to databases and execute SQL commands.
 
 
-gda-list-config-4.0
+gda-list-config-5.0
 -------------------
 Gives a list of installed database providers (along with all the parameters
 they each accept when opening a connection, and a list of the configured DSN
 (data source name).
 
 
-gda-list-server-op-4.0:
+gda-list-server-op-5.0:
 -----------------------
 Gives a list of named parameters expected, for each database provider and for
 each type of server operation.
diff --git a/tools/information-schema-types.c b/tools/information-schema-types.c
index 6c463e2..9e46e3d 100644
--- a/tools/information-schema-types.c
+++ b/tools/information-schema-types.c
@@ -25,7 +25,7 @@
 #include <string.h>
 
 #define FILE_NAME "information_schema.xml"
-#define OUT_FILE "gda-meta-column-types.h"
+#define OUT_TYPES_FILENAME "gda-meta-column-types.h"
 
 int
 main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char** argv)
@@ -33,7 +33,7 @@ main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char** argv)
         xmlDocPtr doc;
         xmlNodePtr node;
         gchar *fname;
-	GString *out_str;
+	GString *out_types_str;
 
 	gda_init();
 
@@ -62,34 +62,41 @@ main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char** argv)
 		exit (1);
 	}
 
-	out_str = g_string_new ("/*\n * File generated by the tools/information-schema-types "
+	out_types_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");
-	
+	g_string_append (out_types_str, "#ifdef __GNUC__\n"
+			 "#define MAY_BE_UNUSED __attribute__ ((unused))\n"
+			 "#else\n"
+			 "#define MAY_BE_UNUSED\n"
+			 "#endif\n\n");
+
 	for (node = node->children; node; node = node->next) {
 		if (!strcmp ((gchar *) node->name, "table")) {
-			xmlChar *prop, *descr;
+			xmlChar *prop, *descr, *table_name = NULL;
 			xmlNodePtr child;
-			GString *tmp_out_str;
+			GString *tmp_out_types_str;
 
-			tmp_out_str = g_string_new ("");
+			tmp_out_types_str = g_string_new ("");
 			descr = xmlGetProp (node, BAD_CAST "descr");
 			prop = xmlGetProp (node, BAD_CAST "name");
 			if (prop) {
-				g_string_append (tmp_out_str, "\n\n");
-				if (descr)
-					g_string_append_printf (tmp_out_str, "/*\n * TABLE: %s\n *\n * %s\n */\n",
+				g_string_append (tmp_out_types_str, "\n\n");
+				if (descr) {
+					g_string_append_printf (tmp_out_types_str, "/*\n * TABLE: %s\n *\n * %s\n */\n",
 								(gchar*) prop, (gchar *) descr);
-				else
-					g_string_append_printf (tmp_out_str, "/*\n * TABLE: %s\n */\n",
+				}
+				else {
+					g_string_append_printf (tmp_out_types_str, "/*\n * TABLE: %s\n */\n",
 								(gchar*) prop);
-				g_string_append_printf (tmp_out_str,
-							"static GType _col_types%s[] = {\n", prop);
-				xmlFree (prop);
+				}
+				g_string_append_printf (tmp_out_types_str,
+							"MAY_BE_UNUSED static GType _col_types%s[] = {\n", prop);
+				table_name = prop;
 			}
 			else {
 				g_warning ("FIXME: table not named");
@@ -99,34 +106,33 @@ main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char** argv)
 			if (descr)
 				xmlFree (descr);
 
-			gboolean firstcol = TRUE;
+			gint ncols = 0;
 			for (child = node->children; child; child = child->next) {
 				if (!strcmp ((gchar *) child->name, "column")) {
-					if (firstcol) {
-						firstcol = FALSE;
-						g_string_append (tmp_out_str, "  ");
-					}
+					if (ncols == 0)
+						g_string_append (tmp_out_types_str, "  ");
 					else
-						g_string_append (tmp_out_str, ", ");
+						g_string_append (tmp_out_types_str, ", ");
+					ncols++;
 
 					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 (tmp_out_str, "G_TYPE_STRING");
+							g_string_append (tmp_out_types_str, "G_TYPE_STRING");
 						else if (type == G_TYPE_BOOLEAN)
-							g_string_append (tmp_out_str, "G_TYPE_BOOLEAN");
+							g_string_append (tmp_out_types_str, "G_TYPE_BOOLEAN");
 						else if (type == G_TYPE_INT)
-							g_string_append (tmp_out_str, "G_TYPE_INT");
+							g_string_append (tmp_out_types_str, "G_TYPE_INT");
 						else if (type == GDA_TYPE_TIMESTAMP) {
 							xmlChar *tname;
 							tname = xmlGetProp (node, BAD_CAST "name");
 							g_print ("Warning: ignoring table %s because the '%s' type is "
 								 "not constant.\n", (gchar*) tname, (gchar*) prop);
 							xmlFree (tname);
-							g_string_free (tmp_out_str, TRUE);
-							tmp_out_str = NULL;
+							g_string_free (tmp_out_types_str, TRUE);
+							tmp_out_types_str = NULL;
 							break;
 						}
 						else
@@ -137,33 +143,37 @@ main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char** argv)
 						xmlFree (prop);
 					}
 					else
-						g_string_append (tmp_out_str, "G_TYPE_STRING");
+						g_string_append (tmp_out_types_str, "G_TYPE_STRING");
 
 					prop = xmlGetProp (child, BAD_CAST "name");
 					if (prop) {
-						g_string_append_printf (tmp_out_str, "  /* column: %s */\n",
+						g_string_append_printf (tmp_out_types_str, "  /* column: %s */\n",
 									prop);
 						xmlFree (prop);
 					}
 					else
-						g_string_append (tmp_out_str, "\n");
+						g_string_append (tmp_out_types_str, "\n");
 				}
 			}
-			if (tmp_out_str) {
-				g_string_append (tmp_out_str, ", G_TYPE_NONE /* end of array marker */\n");
-				g_string_append (tmp_out_str, "};\n\n");
-				g_string_append (out_str, tmp_out_str->str);
-				g_string_free (tmp_out_str, TRUE);
+			if (tmp_out_types_str) {
+				g_string_append (tmp_out_types_str, ", G_TYPE_NONE /* end of array marker */\n");
+				g_string_append (tmp_out_types_str, "};\n\n");
+
+				g_string_append (out_types_str, tmp_out_types_str->str);
+				g_string_free (tmp_out_types_str, TRUE);
 			}
+			xmlFree (table_name);
 		}
 	}
 	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);
+	g_string_append (out_types_str, "#undef MAY_BE_UNUSED\n");
+
+	if (! g_file_set_contents (OUT_TYPES_FILENAME, out_types_str->str, -1, NULL)) 
+		g_print ("Could not write output file '%s'\n", OUT_TYPES_FILENAME);
 	else
-		g_print ("Doc. written to '%s'\n", OUT_FILE);
-	g_string_free (out_str, TRUE);
+		g_print ("Doc. written to '%s'\n", OUT_TYPES_FILENAME);
+	g_string_free (out_types_str, TRUE);
 	
 	return 0;
 }



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