]> saetta.ns0.it Git - libgdaex/commitdiff
Added functions DataModelIter::get_value_at and DataModelIter::get_field_value_at.
authorAndrea Zagli <azagli@libero.it>
Sun, 27 Sep 2020 08:12:18 +0000 (10:12 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 27 Sep 2020 08:12:18 +0000 (10:12 +0200)
src/gdaex.c
src/gdaex.h

index f7b2523719fa51912c8ef094b655e76f99721dc7..f042c2c3baf1fd6361ea7665c6e868675fc4ae34 100644 (file)
@@ -1678,6 +1678,32 @@ struct tm
        return ret;
 }
 
+GValue
+*gdaex_data_model_iter_get_field_value_at (GdaDataModelIter *iter,
+                                           const gchar *field_name)
+{
+       GdaDataModel *data_model;
+       gint col;
+
+       GValue *ret;
+
+       g_object_get (G_OBJECT (iter), "data-model", &data_model, NULL);
+
+       col = gda_data_model_get_column_index (data_model, field_name);
+
+       if (col >= 0)
+               {
+                       ret = gdaex_data_model_iter_get_value_at (iter, col);
+               }
+       else
+               {
+                       g_warning (_("No column found with name «%s»."), field_name);
+                       ret = gda_value_new_null ();
+               }
+
+       return ret;
+}
+
 /**
  * gdaex_data_model_iter_get_field_value_stringify_at:
  * @iter: a #GdaDataModelIter object.
@@ -1983,6 +2009,34 @@ struct tm
        return value;
 }
 
+GValue
+*gdaex_data_model_iter_get_value_at (GdaDataModelIter *iter, gint col)
+{
+       const GValue *v;
+       GValue *ret;
+
+       v = gda_data_model_iter_get_value_at (iter, col);
+       if (v == NULL)
+               {
+                       GdaDataModel *data_model;
+
+                       g_object_get (G_OBJECT (iter), "data-model", &data_model, NULL);
+
+                       g_warning (_("Error on retrieving field's value: «%s»."),
+                                  gda_data_model_get_column_name (data_model, col));
+
+                       ret = gda_value_new_null ();
+               }
+       else
+               {
+                       ret = g_new0 (GValue, 1);
+                       ret = g_value_init (ret, G_VALUE_TYPE (v));
+                       g_value_copy (v, ret);
+               }
+
+       return ret;
+}
+
 /**
  * gdaex_data_model_iter_get_value_stringify_at:
  * @iter: a #GdaDataModelIter object.
index 2030c1ea5b85da113ead3dec7726b157a3852f29..828a1144ff7e1fd7f270ff822a5d229c49080e42 100644 (file)
@@ -164,6 +164,8 @@ struct tm *gdaex_data_model_get_value_tm_at (GdaDataModel *data_model,
                                              gint row,
                                              gint col);
 
+GValue *gdaex_data_model_iter_get_field_value_at (GdaDataModelIter *iter,
+                                                  const gchar *field_name);
 gchar *gdaex_data_model_iter_get_field_value_stringify_at (GdaDataModelIter *iter,
                                                            const gchar *field_name);
 gchar *gdaex_data_model_iter_get_field_value_stringify_escaped_at (GdaDataModelIter *iter,
@@ -185,6 +187,8 @@ GDateTime *gdaex_data_model_iter_get_field_value_gdatetime_at (GdaDataModelIter
 struct tm *gdaex_data_model_iter_get_field_value_tm_at (GdaDataModelIter *iter,
                                                         const gchar *field_name);
 
+GValue *gdaex_data_model_iter_get_value_at (GdaDataModelIter *iter,
+                                            gint col);
 gchar *gdaex_data_model_iter_get_value_stringify_at (GdaDataModelIter *iter,
                                                      gint col);
 gchar *gdaex_data_model_iter_get_value_stringify_escaped_at (GdaDataModelIter *iter,