[libgda] gda_connection_get_meta_store_data() can now export table's indexes information



commit 635b040b302238c290972f316e400300ab37adaf
Author: Vivien Malerba <malerba gnome-db org>
Date:   Fri Feb 5 21:26:25 2010 +0100

    gda_connection_get_meta_store_data() can now export table's indexes information

 doc/C/store-meta-type.xml      |   68 ++++++++++++++++++++++++++++++++++++++--
 doc/C/tmpl/gda-connection.sgml |    5 ++-
 libgda/gda-connection.c        |   25 ++++++++++++++
 libgda/gda-connection.h        |   15 ++++++++-
 4 files changed, 107 insertions(+), 6 deletions(-)
---
diff --git a/doc/C/store-meta-type.xml b/doc/C/store-meta-type.xml
index 6c56ff1..0235a4f 100644
--- a/doc/C/store-meta-type.xml
+++ b/doc/C/store-meta-type.xml
@@ -99,7 +99,7 @@
     </para>
     <para>Optional filter:
       <itemizedlist>
-	<listitem><para>"name" (G_TYPE_STRING): the full name of the table</para></listitem>
+	<listitem><para>"name" (G_TYPE_STRING): the name of the table</para></listitem>
       </itemizedlist>
     </para>
     <para>Columns of the returned data model:
@@ -150,7 +150,7 @@
     </para>
     <para>Optional filter:
       <itemizedlist>
-	<listitem><para>"name" (G_TYPE_STRING): the full name of the view</para></listitem>
+	<listitem><para>"name" (G_TYPE_STRING): the name of the view</para></listitem>
       </itemizedlist>
     </para>
     <para>Columns of the returned data model:
@@ -201,7 +201,7 @@
     </para>
     <para>Mandatory filter:
       <itemizedlist>
-	<listitem><para>"name" (G_TYPE_STRING): the full name of the table or view</para></listitem>
+	<listitem><para>"name" (G_TYPE_STRING): the name of the table or view</para></listitem>
       </itemizedlist>
     </para>
     <para>Optional filter:
@@ -265,4 +265,66 @@
       </table>
     </para>
   </sect2>
+
+  <sect2 id="GdaConnectionMetaTypeGDA_CONNECTION_META_INDEXES">
+    <title>GDA_CONNECTION_META_INDEXES</title>
+    <para>Lists a table's associated indexes
+    </para>
+    <para>Mandatory filter:
+      <itemizedlist>
+	<listitem><para>"name" (G_TYPE_STRING): the name of the table</para></listitem>
+      </itemizedlist>
+    </para>
+    <para>Optional filter:
+      <itemizedlist>
+	<listitem><para>"index_name" (G_TYPE_STRING): the name of an index</para></listitem>
+      </itemizedlist>
+    </para>
+    <para>Columns of the returned data model:
+      <table frame="all">
+        <tgroup cols="3" colsep="1" rowsep="1" align="justify">
+          <thead>
+            <row>
+              <entry>Column #</entry>
+              <entry>Type</entry>
+              <entry>Description</entry>
+            </row>
+          </thead>
+	  <tbody>
+            <row>
+              <entry>0</entry> 
+              <entry>G_TYPE_STRING</entry>
+              <entry>Table's name</entry>
+            </row>
+            <row>
+              <entry>1</entry> 
+              <entry>G_TYPE_STRING</entry>
+              <entry>Namespace in which the table is</entry>
+            </row>
+            <row>
+              <entry>2</entry> 
+              <entry>G_TYPE_STRING</entry>
+              <entry>Index's name</entry>
+            </row>
+            <row>
+              <entry>3</entry> 
+              <entry>G_TYPE_STRING</entry>
+              <entry>Column's name involved in the index</entry>
+            </row>
+            <row>
+              <entry>4</entry> 
+              <entry>G_TYPE_INT</entry>
+              <entry>Sequence order</entry>
+            </row>
+            <row>
+              <entry>5</entry> 
+              <entry>G_TYPE_STRING</entry>
+              <entry>Index's type</entry>
+            </row>
+	  </tbody>
+	</tgroup>
+      </table>
+    </para>
+  </sect2>
+
 </sect1>
diff --git a/doc/C/tmpl/gda-connection.sgml b/doc/C/tmpl/gda-connection.sgml
index 3515eaa..2b80f40 100644
--- a/doc/C/tmpl/gda-connection.sgml
+++ b/doc/C/tmpl/gda-connection.sgml
@@ -647,11 +647,12 @@ A connection to a database
 
 </para>
 
- GDA_CONNECTION_META_NAMESPACES: lists the <link linkend="GdaConnectionMetaTypeGDA_CONNECTION_META_NAMESPACES">namespaces</link> (or schemas for PostgreSQL)
+ GDA_CONNECTION_META_NAMESPACES: 
 @GDA_CONNECTION_META_TYPES: 
- GDA_CONNECTION_META_TABLES: lists the <link linkend="GdaConnectionMetaTypeGDA_CONNECTION_META_TABLES">tables</link>
+ GDA_CONNECTION_META_TABLES: 
 @GDA_CONNECTION_META_VIEWS: 
 @GDA_CONNECTION_META_FIELDS: 
+ GDA_CONNECTION_META_INDEXES: 
 
 <!-- ##### FUNCTION gda_connection_get_meta_store_data ##### -->
 <para>
diff --git a/libgda/gda-connection.c b/libgda/gda-connection.c
index 6bae026..d6ed18c 100644
--- a/libgda/gda-connection.c
+++ b/libgda/gda-connection.c
@@ -4241,6 +4241,10 @@ prepare_meta_statements_hash (void)
 	name_col_array[0] = "name";
 	name_col_array[1] = "field_name";
 
+	gchar **name_index_array = g_new (gchar *, 2);
+	name_index_array[0] = "name";
+	name_index_array[1] = "index_name";
+
 	h = g_hash_table_new (meta_key_hash, meta_key_equal);
 	
 	/* GDA_CONNECTION_META_NAMESPACES */
@@ -4340,6 +4344,27 @@ prepare_meta_statements_hash (void)
 		g_error ("Could not parse internal statement: %s\n", sql);
 	g_hash_table_insert (h, key, stmt);
 
+	/* GDA_CONNECTION_META_INDEXES */
+	key = g_new0 (MetaKey, 1);
+	key->meta_type = GDA_CONNECTION_META_INDEXES;
+	key->nb_filters = 1;
+	key->filters = name_array;
+	sql = "SELECT i.table_name, i.table_schema, i.index_name, d.column_name, d.ordinal_position, i.index_type FROM _table_indexes as i INNER JOIN _index_column_usage as d ON (d.table_catalog = i.table_catalog AND d.table_schema = i.table_schema AND d.table_name = i.table_name) INNER JOIN _tables t ON (t.table_catalog = i.table_catalog AND t.table_schema = i.table_schema AND t.table_name = i.table_name) WHERE t.table_short_name=##name::string";
+	stmt = gda_sql_parser_parse_string (parser, sql, NULL, NULL);
+	if (!stmt)
+		g_error ("Could not parse internal statement: %s\n", sql);
+	g_hash_table_insert (h, key, stmt);
+
+	key = g_new0 (MetaKey, 1);
+	key->meta_type = GDA_CONNECTION_META_INDEXES;
+	key->nb_filters = 2;
+	key->filters = name_index_array;
+	sql = "SELECT i.table_name, i.table_schema, i.index_name, d.column_name, d.ordinal_position, i.index_type FROM _table_indexes as i INNER JOIN _index_column_usage as d ON (d.table_catalog = i.table_catalog AND d.table_schema = i.table_schema AND d.table_name = i.table_name) INNER JOIN _tables t ON (t.table_catalog = i.table_catalog AND t.table_schema = i.table_schema AND t.table_name = i.table_name) WHERE t.table_short_name=##name::string AND i.index_name=##index_name::string";
+	stmt = gda_sql_parser_parse_string (parser, sql, NULL, NULL);
+	if (!stmt)
+		g_error ("Could not parse internal statement: %s\n", sql);
+	g_hash_table_insert (h, key, stmt);
+
 	return h;
 }
 
diff --git a/libgda/gda-connection.h b/libgda/gda-connection.h
index 6aa531a..1a74338 100644
--- a/libgda/gda-connection.h
+++ b/libgda/gda-connection.h
@@ -157,12 +157,25 @@ typedef enum {
 	GDA_CONNECTION_SCHEMA_TABLE_CONTENTS
 } GdaConnectionSchema;
 
+/**
+ * GdaConnectionMetaType:
+ * @GDA_CONNECTION_META_NAMESPACES: lists the <link linkend="GdaConnectionMetaTypeGDA_CONNECTION_META_NAMESPACES">namespaces</link> (or schemas for PostgreSQL)
+ * @GDA_CONNECTION_META_TYPES: lists the <link linkend="GdaConnectionMetaTypeGDA_CONNECTION_META_TYPES">database types</link>
+ * @GDA_CONNECTION_META_TABLES: lists the <link linkend="GdaConnectionMetaTypeGDA_CONNECTION_META_TABLES">tables</link>
+ * @GDA_CONNECTION_META_VIEWS: lists the <link linkend="GdaConnectionMetaTypeGDA_CONNECTION_META_VIEWS">views</link>
+ * @GDA_CONNECTION_META_FIELDS: lists the <link linkend="GdaConnectionMetaTypeGDA_CONNECTION_META_FIELDS">table's or view's fields</link>
+ * @GDA_CONNECTION_META_INDEXES: lists the <link linkend="GdaConnectionMetaTypeGDA_CONNECTION_META_INDEXES">table's indexes</link>
+ *
+ * Used with gda_connection_get_meta_store_data() to describe what meta data to extract from
+ * a connection's associated #GdaMetaStore.
+ */
 typedef enum {
 	GDA_CONNECTION_META_NAMESPACES,
 	GDA_CONNECTION_META_TYPES,
 	GDA_CONNECTION_META_TABLES,
 	GDA_CONNECTION_META_VIEWS,
-	GDA_CONNECTION_META_FIELDS
+	GDA_CONNECTION_META_FIELDS,
+	GDA_CONNECTION_META_INDEXES
 } GdaConnectionMetaType;
 
 



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