]> saetta.ns0.it Git - libgdaex/commitdiff
Added function GdaEx::data_model_columns_to_hashtable.
authorAndrea Zagli <azagli@libero.it>
Tue, 30 Aug 2011 07:16:20 +0000 (09:16 +0200)
committerAndrea Zagli <azagli@libero.it>
Tue, 30 Aug 2011 07:16:20 +0000 (09:16 +0200)
src/gdaex.c
src/gdaex.h

index 7f1bce6be2d68d00fb7c5a788fc7bae61448229e..eda33073fb1cc4cd26796848fee5738bd06c23d6 100644 (file)
@@ -2128,6 +2128,42 @@ struct tm
        return ret;
 }
 
+/**
+ * gdaex_data_model_columns_to_hashtable:
+ * @dm: a #GdaDataModel object.
+ *
+ * Returns: a #GHashTable with keys as the columns names from @dm,
+ * and values as columns numbers.
+ */
+GHashTable
+*gdaex_data_model_columns_to_hashtable (GdaDataModel *dm)
+{
+       GHashTable *ret;
+
+       guint cols;
+       guint col;
+
+       g_return_val_if_fail (GDA_IS_DATA_MODEL (dm), NULL);
+
+       ret = NULL;
+
+       cols = gda_data_model_get_n_columns (dm);
+
+       if (cols > 0)
+               {
+                       ret = g_hash_table_new (g_str_hash, g_str_equal);
+
+                       for (col = 0; col < cols; col++)
+                               {
+                                       g_hash_table_insert (ret,
+                                                            g_strdup (gda_data_model_get_column_name (dm, col)),
+                                                            g_strdup_printf ("%d", col));
+                               }
+               }
+
+       return ret;
+}
+
 /**
  * gdaex_begin:
  * @gdaex: a #GdaEx object.
index 909faf606305067d02de5d14410d3821ba845df3..8b8cff5853bbd567c2c3472acab2c1366b9c94b6 100644 (file)
@@ -173,6 +173,8 @@ GDateTime *gdaex_data_model_iter_get_value_gdatetime_at (GdaDataModelIter *iter,
 struct tm *gdaex_data_model_iter_get_value_tm_at (GdaDataModelIter *iter,
                                            gint col);
 
+GHashTable *gdaex_data_model_columns_to_hashtable (GdaDataModel *dm);
+
 gboolean gdaex_begin (GdaEx *gdaex);
 
 gint gdaex_execute (GdaEx *gdaex, const gchar *sql);