]> saetta.ns0.it Git - libgdaex/commitdiff
Added functions GdaEx::get_field_value_tm_at and GdaEx::get_value_tm_at.
authorAndrea Zagli <azagli@libero.it>
Fri, 4 Sep 2009 17:51:38 +0000 (19:51 +0200)
committerAndrea Zagli <azagli@libero.it>
Fri, 4 Sep 2009 17:51:38 +0000 (19:51 +0200)
docs/reference/libgdaex-decl-list.txt
docs/reference/libgdaex-decl.txt
docs/reference/libgdaex-undocumented.txt
docs/reference/libgdaex-unused.txt
src/gdaex.c
src/libgdaex.h

index b8046e8c3fd3ae0d3b2af48702ba32166c9bbf92..06d40e39574a88e99d61f2fa0474fcec922220bd 100644 (file)
@@ -22,6 +22,7 @@ gdaex_data_model_get_field_value_double_at
 gdaex_data_model_get_field_value_boolean_at
 gdaex_data_model_get_field_value_gdatimestamp_at
 gdaex_data_model_get_field_value_gdate_at
+gdaex_data_model_get_field_value_tm_at
 gdaex_data_model_get_value_stringify_at
 gdaex_data_model_get_value_integer_at
 gdaex_data_model_get_value_float_at
@@ -29,6 +30,7 @@ gdaex_data_model_get_value_double_at
 gdaex_data_model_get_value_boolean_at
 gdaex_data_model_get_value_gdatimestamp_at
 gdaex_data_model_get_value_gdate_at
+gdaex_data_model_get_value_tm_at
 gdaex_begin
 gdaex_execute
 gdaex_commit
index b6c29028c5e700f298709cf361cd65493fb4e7a0..e6f2a09e4e6416c80b8591c3860a746924a5b1d1 100644 (file)
@@ -113,6 +113,11 @@ GdaDataModel *data_model,gint row,const gchar *field_name
 GdaDataModel *data_model,gint row,const gchar *field_name
 </FUNCTION>
 <FUNCTION>
+<NAME>gdaex_data_model_get_field_value_tm_at</NAME>
+<RETURNS>struct tm *</RETURNS>
+GdaDataModel *data_model,gint row,const gchar *field_name
+</FUNCTION>
+<FUNCTION>
 <NAME>gdaex_data_model_get_value_stringify_at</NAME>
 <RETURNS>gchar *</RETURNS>
 GdaDataModel *data_model,gint row,gint col
@@ -148,6 +153,11 @@ GdaDataModel *data_model,gint row,gint col
 GdaDataModel *data_model,gint row,gint col
 </FUNCTION>
 <FUNCTION>
+<NAME>gdaex_data_model_get_value_tm_at</NAME>
+<RETURNS>struct tm *</RETURNS>
+GdaDataModel *data_model,gint row,gint col
+</FUNCTION>
+<FUNCTION>
 <NAME>gdaex_begin</NAME>
 <RETURNS>gboolean </RETURNS>
 GdaEx *gdaex
index 11dd57a861d23237dcc47670daf864d2fbdc1bce..6f2c8c3bde6bfb7717b89ac3b74b0050284358f5 100644 (file)
@@ -1,7 +1,7 @@
-36% symbol docs coverage.
+33% symbol docs coverage.
 10 symbols documented.
 1 symbols incomplete.
-18 not documented.
+20 not documented.
 
 
 gdaex_data_model_get_field_value_boolean_at (row, field_name)
@@ -11,6 +11,7 @@ gdaex_data_model_get_field_value_gdate_at
 gdaex_data_model_get_field_value_gdatimestamp_at
 gdaex_data_model_get_field_value_integer_at
 gdaex_data_model_get_field_value_stringify_at
+gdaex_data_model_get_field_value_tm_at
 gdaex_data_model_get_value_boolean_at
 gdaex_data_model_get_value_double_at
 gdaex_data_model_get_value_float_at
@@ -18,6 +19,7 @@ gdaex_data_model_get_value_gdate_at
 gdaex_data_model_get_value_gdatimestamp_at
 gdaex_data_model_get_value_integer_at
 gdaex_data_model_get_value_stringify_at
+gdaex_data_model_get_value_tm_at
 gdaex_get_chr_quoting
 gdaex_get_gdaconnection
 gdaex_get_provider
index 3ba391828037a4befc2cfae78599ae7a3ab35ee6..1b27fde7bed2f181e3ecc98216763dcdbf845fef 100644 (file)
@@ -15,6 +15,7 @@ gdaex_data_model_get_field_value_gdate_at
 gdaex_data_model_get_field_value_gdatimestamp_at
 gdaex_data_model_get_field_value_integer_at
 gdaex_data_model_get_field_value_stringify_at
+gdaex_data_model_get_field_value_tm_at
 gdaex_data_model_get_value_boolean_at
 gdaex_data_model_get_value_double_at
 gdaex_data_model_get_value_float_at
@@ -22,6 +23,7 @@ gdaex_data_model_get_value_gdate_at
 gdaex_data_model_get_value_gdatimestamp_at
 gdaex_data_model_get_value_integer_at
 gdaex_data_model_get_value_stringify_at
+gdaex_data_model_get_value_tm_at
 gdaex_execute
 gdaex_free
 gdaex_get_chr_quoting
index f15687318f115977f39e7e7599457d166efe278e..4ec85b6c0da3e6e043242702cd6fe16bddaa3bf8 100644 (file)
@@ -269,7 +269,7 @@ GdaDataModel
  * @row:
  * @field_name:
  *
- * Returns: the field_name's #GValue as #gchar (stringify)
+ * Returns: the @field_name's #GValue as #gchar (stringify)
  */
 gchar
 *gdaex_data_model_get_field_value_stringify_at (GdaDataModel *data_model,
@@ -304,7 +304,7 @@ gchar
  * @row:
  * @field_name:
  *
- * Returns: the field_name's #GValue as #gint
+ * Returns: the @field_name's #GValue as #gint
  */
 gint
 gdaex_data_model_get_field_value_integer_at (GdaDataModel *data_model,
@@ -334,7 +334,7 @@ gdaex_data_model_get_field_value_integer_at (GdaDataModel *data_model,
  * @row:
  * @field_name:
  *
- * Returns: the field_name's #GValue as #gfloat
+ * Returns: the @field_name's #GValue as #gfloat
  */
 gfloat
 gdaex_data_model_get_field_value_float_at (GdaDataModel *data_model,
@@ -364,7 +364,7 @@ gdaex_data_model_get_field_value_float_at (GdaDataModel *data_model,
  * @row:
  * @field_name:
  *
- * Returns: the field_name's #GValue as #gdouble
+ * Returns: the @field_name's #GValue as #gdouble
  */
 gdouble
 gdaex_data_model_get_field_value_double_at (GdaDataModel *data_model,
@@ -394,7 +394,7 @@ gdaex_data_model_get_field_value_double_at (GdaDataModel *data_model,
  * @row:
  * @field_name:
  *
- * return the field_name's #GValue as #gboolean
+ * return the @field_name's #GValue as #gboolean
  */
 gboolean
 gdaex_data_model_get_field_value_boolean_at (GdaDataModel *data_model,
@@ -424,7 +424,7 @@ gdaex_data_model_get_field_value_boolean_at (GdaDataModel *data_model,
  * @row:
  * @field_name:
  *
- * Returns: the field_name's #GValue as #GdaTimestamp.
+ * Returns: the @field_name's #GValue as #GdaTimestamp.
  */
 GdaTimestamp
 *gdaex_data_model_get_field_value_gdatimestamp_at (GdaDataModel *data_model,
@@ -459,7 +459,7 @@ GdaTimestamp
  * @row:
  * @field_name:
  *
- * Returns: the field_name's #GValue as #GDate.
+ * Returns: the @field_name's #GValue as #GDate.
  */
 GDate
 *gdaex_data_model_get_field_value_gdate_at (GdaDataModel *data_model,
@@ -488,6 +488,42 @@ GDate
        return value;
 }
 
+
+/**
+ * gdaex_data_model_get_field_value_tm_at:
+ * @data_model: a #GdaDataModel object.
+ * @row:
+ * @field_name:
+ *
+ * Returns: the @field_name's value as a struct tm.
+ */
+struct tm
+*gdaex_data_model_get_field_value_tm_at (GdaDataModel *data_model,
+                                           gint row,
+                                           const gchar *field_name)
+{
+       struct tm *value;
+       gint col;
+
+       col = gda_data_model_get_column_index (data_model, field_name);
+
+       if (col >= 0)
+               {
+                       value = gdaex_data_model_get_value_tm_at (data_model, row, col);
+                       if (value == NULL)
+                               {
+                                       g_warning ("Error retrieving «%s»'s value.", field_name);
+                               }
+               }
+       else
+               {
+                       g_warning ("No column found with name «%s»\n", field_name);
+                       value = NULL;
+               }
+
+       return value;
+}
+
 /**
  * gdaex_data_model_get_value_stringify_at:
  * @data_model: a #GdaDataModel object.
@@ -702,10 +738,11 @@ gdaex_data_model_get_value_boolean_at (GdaDataModel *data_model, gint row, gint
 GdaTimestamp
 *gdaex_data_model_get_value_gdatimestamp_at (GdaDataModel *data_model, gint row, gint col)
 {
-       const GdaTimestamp *gdatimestamp = NULL;
+       GdaTimestamp *gdatimestamp;
        const GValue *v;
        GError *error;
 
+       gdatimestamp = NULL;
        error = NULL;
 
        v = gda_data_model_get_value_at (data_model, col, row, &error);
@@ -716,7 +753,47 @@ GdaTimestamp
                }
        else if (!gda_value_is_null (v))
                {
-                       gdatimestamp = gda_value_get_timestamp (v);
+                       if (gda_value_isa (v, GDA_TYPE_TIMESTAMP))
+                               {
+                                       gdatimestamp = (GdaTimestamp *)gda_value_get_timestamp (v);
+                               }
+                       else if (gda_value_isa (v, G_TYPE_DATE))
+                               {
+                                       GDate *date;
+
+                                       date = gdaex_data_model_get_value_gdate_at (data_model, row, col);
+
+                                       if (date != NULL)
+                                               {
+                                                       gdatimestamp = g_malloc0 (sizeof (GdaTimestamp));
+                                                       if (g_date_valid (date))
+                                                               {
+                                                                       gdatimestamp->year = g_date_get_year (date);
+                                                                       gdatimestamp->month = g_date_get_month (date);
+                                                                       gdatimestamp->day = g_date_get_day (date);
+                                                               }
+                                                       else
+                                                               {
+                                                                       gdatimestamp->year = date->year;
+                                                                       gdatimestamp->month = date->month;
+                                                                       gdatimestamp->day = date->day;
+                                                               }
+                                               }
+                               }
+                       else if (gda_value_isa (v, GDA_TYPE_TIME))
+                               {
+                                       const GdaTime *time;
+
+                                       time = gda_value_get_time (v);
+
+                                       if (time != NULL)
+                                               {
+                                                       gdatimestamp = g_malloc0 (sizeof (GdaTimestamp));
+                                                       gdatimestamp->hour = time->hour;
+                                                       gdatimestamp->minute = time->minute;
+                                                       gdatimestamp->second = time->second;
+                                               }
+                               }                               
                }
 
        return (GdaTimestamp *)gda_timestamp_copy ((gpointer)gdatimestamp);
@@ -733,11 +810,12 @@ GdaTimestamp
 GDate
 *gdaex_data_model_get_value_gdate_at (GdaDataModel *data_model, gint row, gint col)
 {
-       GDate *ret = NULL;
+       GDate *ret;
        const GdaTimestamp *gdatimestamp;
        const GValue *v;
        GError *error;
 
+       ret = NULL;
        error = NULL;
 
        v = gda_data_model_get_value_at (data_model, col, row, &error);
@@ -748,14 +826,59 @@ GDate
                }
        else if (!gda_value_is_null (v))
                {
-                       gdatimestamp = gda_value_get_timestamp (v);
-                       if (g_date_valid_dmy ((GDateDay)gdatimestamp->day,
-                                             (GDateMonth)gdatimestamp->month,
-                                             (GDateYear)gdatimestamp->year))
+                       if (gda_value_isa (v, GDA_TYPE_TIMESTAMP))
+                               {
+                                       gdatimestamp = gdaex_data_model_get_value_gdatimestamp_at (data_model, row, col);
+                               }
+                       else if (gda_value_isa (v, G_TYPE_DATE))
+                               {
+                                       ret = (GDate *)g_value_get_boxed (v);
+                               }
+               }
+
+       return ret;
+}
+
+/**
+ * gdaex_data_model_get_value_tm_at:
+ * @data_model: a #GdaDataModel object.
+ * @row: row number.
+ * @col: col number.
+ *
+ * Returns: the field's value as a struct tm.
+ */
+struct tm
+*gdaex_data_model_get_value_tm_at (GdaDataModel *data_model, gint row, gint col)
+{
+       struct tm *ret;
+       const GValue *v;
+       GError *error;
+
+       ret = NULL;
+       error = NULL;
+
+       v = gda_data_model_get_value_at (data_model, col, row, &error);
+       if (v == NULL || error != NULL)
+               {
+                       g_warning ("Error on retrieving field's value: %s\n",
+                                  error->message);
+               }
+       else if (!gda_value_is_null (v))
+               {
+                       GdaTimestamp *gdatimestamp;
+
+                       gdatimestamp = gdaex_data_model_get_value_gdatimestamp_at (data_model, row, col);
+
+                       if (gdatimestamp != NULL)
                                {
-                                       ret = g_date_new_dmy ((GDateDay)gdatimestamp->day,
-                                                             (GDateMonth)gdatimestamp->month,
-                                                             (GDateYear)gdatimestamp->year);
+                                       ret = g_malloc0 (sizeof (struct tm));
+
+                                       ret->tm_year = gdatimestamp->year - 1900;
+                                       ret->tm_mon = gdatimestamp->month - 1;
+                                       ret->tm_mday = gdatimestamp->day;
+                                       ret->tm_hour = gdatimestamp->hour;
+                                       ret->tm_min = gdatimestamp->minute;
+                                       ret->tm_sec = gdatimestamp->second;
                                }
                }
 
index addc069e03a57941d1dbc640621a131beafff8f3..793ec637a59818dadd797a6d3cb8a04602c8f993 100644 (file)
@@ -21,6 +21,7 @@
  *  
  */
 
+#include <time.h>
 #include <glib.h>
 #include <glib-object.h>
 #include <libgda/libgda.h>
@@ -85,6 +86,9 @@ GdaTimestamp *gdaex_data_model_get_field_value_gdatimestamp_at (GdaDataModel *da
 GDate *gdaex_data_model_get_field_value_gdate_at (GdaDataModel *data_model,
                                                  gint row,
                                                  const gchar *field_name);
+struct tm *gdaex_data_model_get_field_value_tm_at (GdaDataModel *data_model,
+                                                 gint row,
+                                                 const gchar *field_name);
 
 gchar *gdaex_data_model_get_value_stringify_at (GdaDataModel *data_model,
                                                gint row,
@@ -107,6 +111,9 @@ GdaTimestamp *gdaex_data_model_get_value_gdatimestamp_at (GdaDataModel *data_mod
 GDate *gdaex_data_model_get_value_gdate_at (GdaDataModel *data_model,
                                            gint row,
                                            gint col);
+struct tm *gdaex_data_model_get_value_tm_at (GdaDataModel *data_model,
+                                           gint row,
+                                           gint col);
 
 gboolean gdaex_begin (GdaEx *gdaex);