[libgda] Fix usages of GdaTime and GdaTimestmap



commit 2677f068c1c23a0a376514bfc7f8cef4c7074a5e
Author: Guillaume Poirier-Morency <guillaumepoiriermorency gmail com>
Date:   Mon Oct 23 11:45:47 2017 -0400

    Fix usages of GdaTime and GdaTimestmap

 libgda/gda-value.c                    |   28 +++++++++++++++++++++++++
 libgda/gda-value.h                    |    1 +
 providers/mysql/gda-mysql-provider.c  |   26 +++++++++++-----------
 providers/mysql/gda-mysql-recordset.c |   36 +++++++++++++++-----------------
 4 files changed, 59 insertions(+), 32 deletions(-)
---
diff --git a/libgda/gda-value.c b/libgda/gda-value.c
index d6f2b83..31c5357 100644
--- a/libgda/gda-value.c
+++ b/libgda/gda-value.c
@@ -1878,6 +1878,34 @@ gda_timestamp_new (void)
 {
        return g_new0 (GdaTimestamp, 1);
 }
+
+/**
+ * gda_timestamp_new_from_values:
+ * @year: year
+ * @month: month
+ * @hour: hours
+ * @minute: minutes
+ * @second: seconds
+ * @fraction: fraction of seconds
+ * @timezone: timezone used
+ *
+ * Returns: (transfer full): a new value storing a timestamp
+ */
+GdaTimestamp*
+gda_timestamp_new_from_values (gushort year, gushort month, gushort day, gushort hour, gushort minute, 
gushort second, gulong fraction, glong timezone)
+{
+       GdaTimestamp* timestamp = g_new0 (GdaTimestamp, 1);
+       timestamp->year = year;
+       timestamp->month = month;
+       timestamp->day = day;
+       timestamp->hour = hour;
+       timestamp->minute = minute;
+       timestamp->second = second;
+       timestamp->fraction = fraction;
+       timestamp->timezone = timezone;
+       return timestamp;
+}
+
 /**
  * gda_timestamp_copy:
  *
diff --git a/libgda/gda-value.h b/libgda/gda-value.h
index 6658b17..746f140 100644
--- a/libgda/gda-value.h
+++ b/libgda/gda-value.h
@@ -266,6 +266,7 @@ GType                             gda_default_get_type (void) G_GNUC_CONST;
 typedef struct _GdaTimestamp GdaTimestamp;
 GType                             gda_timestamp_get_type (void) G_GNUC_CONST;
 GdaTimestamp                     *gda_timestamp_new (void);
+GdaTimestamp                     *gda_timestamp_new_from_values (gushort year, gushort month, gushort day, 
gushort hour, gushort minute, gushort second, gulong fraction, glong timezone);
 gshort                            gda_timestamp_get_year (const GdaTimestamp* timestamp);
 void                              gda_timestamp_set_year (GdaTimestamp* timestamp, gshort year);
 gushort                           gda_timestamp_get_month (const GdaTimestamp* timestamp);
diff --git a/providers/mysql/gda-mysql-provider.c b/providers/mysql/gda-mysql-provider.c
index eec5671..acab132 100644
--- a/providers/mysql/gda-mysql-provider.c
+++ b/providers/mysql/gda-mysql-provider.c
@@ -2397,7 +2397,7 @@ gda_mysql_provider_statement_execute (GdaServerProvider               *provider,
                        }
                        else {
                                gboolean tofree = FALSE;
-                               if (ts->timezone != GDA_TIMEZONE_INVALID) {
+                               if (gda_timestamp_get_timezone (ts) != GDA_TIMEZONE_INVALID) {
                                        /* MySQL does not store timezone information, so if timezone 
information is
                                         * provided, we do our best and convert it to GMT */
                                        ts = gda_timestamp_copy (ts);
@@ -2408,13 +2408,13 @@ gda_mysql_provider_statement_execute (GdaServerProvider               *provider,
                                MYSQL_TIME *mtime;
                                mtime = g_new0 (MYSQL_TIME, 1);
                                mem_to_free = g_slist_prepend (mem_to_free, mtime);
-                               mtime->year = ts->year;
-                               mtime->month = ts->month;
-                               mtime->day = ts->day;
-                               mtime->hour = ts->hour;
-                               mtime->minute = ts->minute;
-                               mtime->second = ts->second;
-                               mtime->second_part = ts->fraction;
+                               mtime->year = gda_timestamp_get_year (ts);
+                               mtime->month = gda_timestamp_get_month (ts);
+                               mtime->day = gda_timestamp_get_day (ts);
+                               mtime->hour = gda_timestamp_get_hour (ts);
+                               mtime->minute = gda_timestamp_get_minute (ts);
+                               mtime->second = gda_timestamp_get_second (ts);
+                               mtime->second_part = gda_timestamp_get_fraction (ts);
                                if (tofree)
                                        gda_timestamp_free (ts);
 
@@ -2433,7 +2433,7 @@ gda_mysql_provider_statement_execute (GdaServerProvider               *provider,
                        }
                        else {
                                gboolean tofree = FALSE;
-                               if (ts->timezone != GDA_TIMEZONE_INVALID) {
+                               if (gda_time_get_timezone (ts) != GDA_TIMEZONE_INVALID) {
                                        /* MySQL does not store timezone information, so if timezone 
information is
                                         * provided, we do our best and convert it to GMT */
                                        ts = gda_time_copy (ts);
@@ -2444,10 +2444,10 @@ gda_mysql_provider_statement_execute (GdaServerProvider               *provider,
                                MYSQL_TIME *mtime;
                                mtime = g_new0 (MYSQL_TIME, 1);
                                mem_to_free = g_slist_prepend (mem_to_free, mtime);
-                               mtime->hour = ts->hour;
-                               mtime->minute = ts->minute;
-                               mtime->second = ts->second;
-                               mtime->second_part = ts->fraction;
+                               mtime->hour = gda_time_get_hour (ts);
+                               mtime->minute = gda_time_get_minute (ts);
+                               mtime->second = gda_time_get_second (ts);
+                               mtime->second_part = gda_time_get_fraction (ts);
                                if (tofree)
                                        gda_time_free (ts);
 
diff --git a/providers/mysql/gda-mysql-recordset.c b/providers/mysql/gda-mysql-recordset.c
index 2e1aae4..8e659bc 100644
--- a/providers/mysql/gda-mysql-recordset.c
+++ b/providers/mysql/gda-mysql-recordset.c
@@ -859,14 +859,13 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, G_GNUC_UNUSED gint rownum, G
                        memmove (&bvalue, mysql_bind_result[i].buffer, sizeof (bvalue));
 
                        if (type == GDA_TYPE_TIME) {
-                               GdaTime time = {
-                                       .hour = bvalue.hour,
-                                       .minute = bvalue.minute,
-                                       .second = bvalue.second,
-                                       .fraction = bvalue.second_part,
-                                       .timezone = 0 /* GMT */
-                               };
-                               gda_value_set_time (value, &time);
+                               GdaTime *time = gda_time_new_from_values (bvalue.hour,
+                                                                             bvalue.minute,
+                                                                             bvalue.second,
+                                                                             bvalue.second_part,
+                                                                             0); /* GMT */
+                               gda_value_set_time (value, time);
+                gda_time_free (time);
                        }
                        else if (type == G_TYPE_DATE) {
                                GDate *date = g_date_new_dmy
@@ -876,17 +875,16 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, G_GNUC_UNUSED gint rownum, G
                                g_value_take_boxed (value, date);
                        }
                        else if (type == GDA_TYPE_TIMESTAMP) {
-                               GdaTimestamp timestamp = {
-                                       .year = bvalue.year,
-                                       .month = bvalue.month,
-                                       .day = bvalue.day,
-                                       .hour = bvalue.hour,
-                                       .minute = bvalue.minute,
-                                       .second = bvalue.second,
-                                       .fraction = bvalue.second_part,
-                                       .timezone = 0 /* GMT */
-                               };
-                               gda_value_set_timestamp (value, &timestamp);
+                               GdaTimestamp *timestamp = gda_timestamp_new_from_values (bvalue.year,
+                                                                                            bvalue.month,
+                                                                                            bvalue.day,
+                                                                                            bvalue.hour,
+                                                                                            bvalue.minute,
+                                                                                            bvalue.second,
+                                                                                            
bvalue.second_part,
+                                                                                            0); /* GMT */
+                               gda_value_set_timestamp (value, timestamp);
+                gda_timestamp_free (timestamp);
                        }
                        else {
                                gda_row_invalidate_value (row, value);


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