[libgda] Make GdaTimestamp introspectable
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Make GdaTimestamp introspectable
- Date: Tue, 23 May 2017 19:25:22 +0000 (UTC)
commit eca2bf8950a37dbee852ac61b3c53775bae22b9e
Author: Daniel Espinosa <esodan gmail com>
Date: Tue May 23 14:24:20 2017 -0500
Make GdaTimestamp introspectable
Fix Bug:
https://bugzilla.gnome.org/show_bug.cgi?id=765776
libgda-ui/data-entries/gdaui-entry-common-time.c | 56 ++++---
libgda/gda-statement.c | 5 +-
libgda/gda-util.c | 21 +--
libgda/gda-value.c | 193 ++++++++++++++++++---
libgda/gda-value.h | 49 +++---
libgda/handlers/gda-handler-time.c | 101 ++++++------
libgda/sqlite/gda-sqlite-provider.c | 25 ++--
libgda/sqlite/gda-sqlite-recordset.c | 16 +-
libgda/sqlite/virtual/gda-vconnection-hub.c | 8 +-
libgda/sqlite/virtual/gda-vprovider-data-model.c | 3 +-
providers/ldap/gda-ldap-util.c | 70 +++++---
providers/postgres/gda-postgres-provider.c | 7 +-
providers/postgres/gda-postgres-recordset.c | 15 +-
providers/sqlcipher/Makefile.am | 2 +
tests/data-models/check_vcnc.c | 14 ++-
tests/providers/prov-test-common.c | 25 ++-
tests/test-input-parsers.c | 92 ++++++-----
tests/test-sql-renderer.c | 30 ++--
tools/browser/ldap-browser/entry-properties.c | 22 ++--
19 files changed, 475 insertions(+), 279 deletions(-)
---
diff --git a/libgda-ui/data-entries/gdaui-entry-common-time.c
b/libgda-ui/data-entries/gdaui-entry-common-time.c
index 26b6eac..2916822 100644
--- a/libgda-ui/data-entries/gdaui-entry-common-time.c
+++ b/libgda-ui/data-entries/gdaui-entry-common-time.c
@@ -2,6 +2,7 @@
* Copyright (C) 2009 - 2015 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -400,12 +401,12 @@ icon_press_cb (GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event,
}
}
else if (type == GDA_TYPE_TIMESTAMP) {
- const GdaTimestamp *ts;
- ts = gda_value_get_timestamp (value);
+ GdaTimestamp *ts;
+ ts = (GdaTimestamp*) gda_value_get_timestamp (value);
if (ts) {
- year = ts->year;
- month = ts->month - 1;
- day = ts->day;
+ year = gda_timestamp_get_year (ts);
+ month = gda_timestamp_get_month (ts) - 1;
+ day = gda_timestamp_get_day (ts);
unset = FALSE;
}
}
@@ -484,10 +485,10 @@ date_day_selected (GtkCalendar *calendar, GdauiEntryCommonTime *mgtim)
if (value && (G_VALUE_TYPE (value) != GDA_TYPE_NULL)) {
/* copy the 'fraction' and 'timezone' parts, we have not modified */
- const GdaTimestamp *ets = gda_value_get_timestamp (value);
- mtm.tm_hour = ets->hour;
- mtm.tm_min = ets->minute;
- mtm.tm_sec = ets->second;
+ GdaTimestamp *ets = (GdaTimestamp*) gda_value_get_timestamp (value);
+ mtm.tm_hour = gda_timestamp_get_hour (ets);
+ mtm.tm_min = gda_timestamp_get_minute (ets);
+ mtm.tm_sec = gda_timestamp_get_second (ets);
}
gda_value_free (value);
}
@@ -689,18 +690,18 @@ real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
mgtim->priv->value_fraction = 0;
}
else {
- const GdaTimestamp *gts;
- GdaTimestamp copy;
- gts = gda_value_get_timestamp (value);
- mgtim->priv->value_tz = fit_tz (gts->timezone);
- mgtim->priv->value_fraction = gts->fraction;
+ GdaTimestamp *gts;
+ GdaTimestamp *copy;
+ gts = (GdaTimestamp*) gda_value_get_timestamp (value);
+ mgtim->priv->value_tz = fit_tz (gda_timestamp_get_timezone (gts));
+ mgtim->priv->value_fraction = gda_timestamp_get_fraction (gts);
- copy = *gts;
- gda_timestamp_change_timezone (©, mgtim->priv->displayed_tz);
+ copy = gda_timestamp_copy (gts);
+ gda_timestamp_change_timezone (copy, mgtim->priv->displayed_tz);
GValue *copy_value;
copy_value = g_new0 (GValue, 1);
- gda_value_set_timestamp (copy_value, ©);
+ gda_value_set_timestamp (copy_value, copy);
gchar *str;
str = gda_data_handler_get_str_from_value (dh, copy_value);
@@ -708,6 +709,7 @@ real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), str);
g_free (str);
+ gda_timestamp_free (copy);
}
}
else
@@ -767,10 +769,10 @@ real_get_value (GdauiEntryWrapper *mgwrap)
if (value && (G_VALUE_TYPE (value) != GDA_TYPE_NULL)) {
/* copy the 'fraction' part, we have not modified */
- GdaTimestamp *gdatime = g_new (GdaTimestamp, 1);
- *gdatime = *(gda_value_get_timestamp (value));
- gdatime->fraction = mgtim->priv->value_fraction;
- gdatime->timezone = mgtim->priv->displayed_tz;
+ GdaTimestamp *gdatime;
+ gdatime = (GdaTimestamp*) gda_value_get_timestamp (value);
+ gda_timestamp_set_fraction (gdatime, mgtim->priv->value_fraction);
+ gda_timestamp_set_timezone (gdatime, mgtim->priv->displayed_tz);
gda_timestamp_change_timezone (gdatime, mgtim->priv->value_tz);
gda_value_set_timestamp (value, gdatime);
g_free (gdatime);
@@ -879,9 +881,9 @@ entry_insert_func (G_GNUC_UNUSED GdauiFormattedEntry *fentry, gunichar insert_ch
date = (GDate*) g_value_get_boxed (value);
}
else if (type == GDA_TYPE_TIMESTAMP) {
- const GdaTimestamp *ts;
- ts = gda_value_get_timestamp (value);
- date = g_date_new_dmy (ts->day, ts->month, ts->year);
+ GdaTimestamp *ts;
+ ts = (GdaTimestamp*) gda_value_get_timestamp (value);
+ date = g_date_new_dmy (gda_timestamp_get_day (ts), gda_timestamp_get_month (ts),
gda_timestamp_get_year (ts));
}
if (date) {
@@ -908,9 +910,9 @@ entry_insert_func (G_GNUC_UNUSED GdauiFormattedEntry *fentry, gunichar insert_ch
else if (type == GDA_TYPE_TIMESTAMP) {
GdaTimestamp *ts;
ts = (GdaTimestamp*) gda_timestamp_copy ((gpointer)
gda_value_get_timestamp (value));
- ts->day = g_date_get_day (ndate);
- ts->month = g_date_get_month (ndate);
- ts->year = g_date_get_year (ndate);
+ gda_timestamp_set_day (ts, g_date_get_day (ndate));
+ gda_timestamp_set_month (ts, g_date_get_month (ndate));
+ gda_timestamp_set_year (ts, g_date_get_year (ndate));
g_date_free (date);
g_date_free (ndate);
gda_value_set_timestamp (value, ts);
diff --git a/libgda/gda-statement.c b/libgda/gda-statement.c
index bc59b08..efa3cb0 100644
--- a/libgda/gda-statement.c
+++ b/libgda/gda-statement.c
@@ -4,6 +4,7 @@
* Copyright (C) 2008 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2010 Jonh Wendell <jwendell gnome org>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -819,10 +820,10 @@ default_render_value (const GValue *value, GdaSqlRenderingContext *context, GErr
else if (G_VALUE_TYPE (value) == GDA_TYPE_TIMESTAMP) {
GdaTimestamp *nts;
nts = (GdaTimestamp*) gda_value_get_timestamp (value);
- if (nts && (nts->timezone != GDA_TIMEZONE_INVALID)) {
+ if (nts && (gda_timestamp_get_timezone (nts) != GDA_TIMEZONE_INVALID)) {
nts = gda_timestamp_copy (nts);
gda_timestamp_change_timezone (nts, 0);
- nts->timezone = GDA_TIMEZONE_INVALID;
+ gda_timestamp_set_timezone (nts, GDA_TIMEZONE_INVALID);
GValue v = {0};
g_value_init (&v, GDA_TYPE_TIMESTAMP);
gda_value_set_timestamp (&v, nts);
diff --git a/libgda/gda-util.c b/libgda/gda-util.c
index 5b57773..d3cb3a3 100644
--- a/libgda/gda-util.c
+++ b/libgda/gda-util.c
@@ -4,7 +4,7 @@
* Copyright (C) 2003 - 2004 Laurent Sansonetti <lrz gnome org>
* Copyright (C) 2003 Paisa Seeluangsawat <paisa users sf net>
* Copyright (C) 2004 Caolan McNamara <caolanm redhat com>
- * Copyright (C) 2004 J�rg Billeter <j bitron ch>
+ * Copyright (C) 2004 Jürg Billeter <j bitron ch>
* Copyright (C) 2004 - 2013 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2005 - 2015 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2007 - 2009 Armin Burgmeier <armin openismus com>
@@ -3408,7 +3408,6 @@ gda_parse_formatted_timestamp (GdaTimestamp *timestamp, const gchar *value,
GDate gdate;
GdaTime timegda;
- memset (timestamp, 0, sizeof (GdaTimestamp));
memset (&timegda, 0, sizeof (GdaTime));
timegda.timezone = GDA_TIMEZONE_INVALID;
@@ -3420,9 +3419,9 @@ gda_parse_formatted_timestamp (GdaTimestamp *timestamp, const gchar *value,
retval = FALSE;
goto out;
}
- timestamp->year = g_date_get_year (&gdate);
- timestamp->month = g_date_get_month (&gdate);
- timestamp->day = g_date_get_day (&gdate);
+ gda_timestamp_set_year (timestamp, g_date_get_year (&gdate));
+ gda_timestamp_set_month (timestamp, g_date_get_month (&gdate));
+ gda_timestamp_set_day (timestamp, g_date_get_day (&gdate));
/* separator */
if (!*endptr)
@@ -3441,11 +3440,11 @@ gda_parse_formatted_timestamp (GdaTimestamp *timestamp, const gchar *value,
*endptr)
retval = FALSE;
out:
- timestamp->hour = timegda.hour;
- timestamp->minute = timegda.minute;
- timestamp->second = timegda.second;
- timestamp->fraction = timegda.fraction;
- timestamp->timezone = timegda.timezone;
+ gda_timestamp_set_hour (timestamp, timegda.hour);
+ gda_timestamp_set_minute (timestamp, timegda.minute);
+ gda_timestamp_set_second (timestamp, timegda.second);
+ gda_timestamp_set_fraction (timestamp, timegda.fraction);
+ gda_timestamp_set_timezone (timestamp, timegda.timezone);
- return retval;
+ return retval;
}
diff --git a/libgda/gda-value.c b/libgda/gda-value.c
index 5091243..cde34a1 100644
--- a/libgda/gda-value.c
+++ b/libgda/gda-value.c
@@ -19,7 +19,7 @@
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2010 Jonh Wendell <jwendell gnome org>
- * Copyright (C) 2011 - 2012 Daniel Espinosa <despinosa src gnome org>
+ * Copyright (C) 2011 - 2017 Daniel Espinosa <esodan gmail com>
* Copyright (C) 2013 Miguel Angel Cabrera Moya <madmac2501 gmail com>
*
* This library is free software; you can redistribute it and/or
@@ -216,11 +216,12 @@ set_from_string (GValue *value, const gchar *as_string)
}
}
else if (type == GDA_TYPE_TIMESTAMP) {
- GdaTimestamp timestamp;
- if (gda_parse_iso8601_timestamp (×tamp, as_string)) {
- gda_value_set_timestamp (value, ×tamp);
+ GdaTimestamp* timestamp = gda_timestamp_new ();
+ if (gda_parse_iso8601_timestamp (timestamp, as_string)) {
+ gda_value_set_timestamp (value, timestamp);
retval = TRUE;
}
+ gda_timestamp_free (timestamp);
}
else if (type == GDA_TYPE_NULL) {
gda_value_set_null (value);
@@ -1511,6 +1512,31 @@ gda_time_change_timezone (GdaTime *time, glong ntz)
time->timezone = ntz;
}
+
+/**
+ * GdaTimestamp:
+ * @year: year representation of the time stamp
+ * @month: month representation of the time stamp, as a number between 1 and 12
+ * @day: day representation of the time stamp, as a number between 1 and 31
+ * @hour: hour representation of the time stamp, as a number between 0 and 23
+ * @minute: minute representation of the time stamp, as a number between 0 and 59
+ * @second: second representation of the time stamp, as a number between 0 and 59
+ * @fraction: fractionnal part of the seconds, in millionth' of second
+ * @timezone: number of seconds added to the GMT timezone
+ *
+ * Represents an instant (a time stamp)
+ */
+struct _GdaTimestamp {
+ gshort year;
+ gushort month;
+ gushort day;
+ gushort hour;
+ gushort minute;
+ gushort second;
+ gulong fraction;
+ glong timezone;
+};
+
/*
* Register the GdaTimestamp type in the GType system
*/
@@ -1518,13 +1544,14 @@ gda_time_change_timezone (GdaTime *time, glong ntz)
static void
string_to_timestamp (const GValue *src, GValue *dest)
{
- GdaTimestamp timestamp;
+ GdaTimestamp* timestamp = gda_timestamp_new ();
g_return_if_fail (G_VALUE_HOLDS_STRING (src) &&
GDA_VALUE_HOLDS_TIMESTAMP (dest));
- gda_parse_iso8601_timestamp (×tamp, g_value_get_string (src));
- gda_value_set_timestamp (dest, ×tamp);
+ gda_parse_iso8601_timestamp (timestamp, g_value_get_string (src));
+ gda_value_set_timestamp (dest, timestamp);
+ gda_timestamp_free (timestamp);
}
static void
@@ -1540,17 +1567,17 @@ timestamp_to_string (const GValue *src, GValue *dest)
GString *string;
string = g_string_new ("");
g_string_append_printf (string, "%04u-%02u-%02u %02u:%02u:%02u",
- timestamp->year,
- timestamp->month,
- timestamp->day,
- timestamp->hour,
- timestamp->minute,
- timestamp->second);
- if (timestamp->fraction > 0)
- g_string_append_printf (string, ".%lu", timestamp->fraction);
- if (timestamp->timezone != GDA_TIMEZONE_INVALID)
+ gda_timestamp_get_year (timestamp),
+ gda_timestamp_get_month (timestamp),
+ gda_timestamp_get_day (timestamp),
+ gda_timestamp_get_hour (timestamp),
+ gda_timestamp_get_minute (timestamp),
+ gda_timestamp_get_second (timestamp));
+ if (gda_timestamp_get_fraction (timestamp) > 0)
+ g_string_append_printf (string, ".%lu", gda_timestamp_get_fraction (timestamp));
+ if (gda_timestamp_get_timezone (timestamp) != GDA_TIMEZONE_INVALID)
g_string_append_printf (string, "%+02d",
- (int) timestamp->timezone/3600);
+ (int) gda_timestamp_get_timezone (timestamp)/3600);
g_value_take_string (dest, string->str);
g_string_free (string, FALSE);
}
@@ -1575,6 +1602,17 @@ gda_timestamp_get_type (void)
return type;
}
+
+/**
+ * gda_timestamp_new:
+ *
+ * Returns: (transfer full):
+ */
+GdaTimestamp*
+gda_timestamp_new (void)
+{
+ return g_new0 (GdaTimestamp, 1);
+}
/**
* gda_timestamp_copy:
*
@@ -1588,7 +1626,7 @@ gda_timestamp_copy (gpointer boxed)
g_return_val_if_fail(src, NULL);
- copy = g_new0 (GdaTimestamp, 1);
+ copy = gda_timestamp_new ();
copy->year = src->year;
copy->month = src->month;
copy->day = src->day;
@@ -1701,6 +1739,104 @@ gda_timestamp_change_timezone (GdaTimestamp *ts, glong ntz)
ts->timezone = ntz;
}
+
+gshort
+gda_timestamp_get_year (GdaTimestamp* timestamp)
+{
+ g_return_val_if_fail (timestamp != NULL, 0);
+ return timestamp->year;
+}
+void
+gda_timestamp_set_year (GdaTimestamp* timestamp, gshort year)
+{
+ g_return_if_fail (timestamp != NULL);
+ timestamp->year = year;
+}
+gushort
+gda_timestamp_get_month (GdaTimestamp* timestamp)
+{
+ g_return_val_if_fail (timestamp != NULL, 0);
+ return timestamp->month;
+}
+void
+gda_timestamp_set_month (GdaTimestamp* timestamp, gushort month)
+{
+ g_return_if_fail (timestamp != NULL);
+ timestamp->month = month;
+}
+gushort
+gda_timestamp_get_day (GdaTimestamp* timestamp)
+{
+ g_return_val_if_fail (timestamp != NULL, 0);
+ return timestamp->day;
+}
+void
+gda_timestamp_set_day (GdaTimestamp* timestamp, gushort day)
+{
+ g_return_if_fail (timestamp != NULL);
+ timestamp->day = day;
+}
+gushort
+gda_timestamp_get_hour (GdaTimestamp* timestamp)
+{
+ g_return_val_if_fail (timestamp != NULL, 0);
+ return timestamp->hour;
+}
+void
+gda_timestamp_set_hour (GdaTimestamp* timestamp, gushort hour)
+{
+ g_return_if_fail (timestamp != NULL);
+ timestamp->hour = hour;
+}
+gushort
+gda_timestamp_get_minute (GdaTimestamp* timestamp)
+{
+ g_return_val_if_fail (timestamp != NULL, 0);
+ return timestamp->minute;
+}
+void
+gda_timestamp_set_minute (GdaTimestamp* timestamp, gushort minute)
+{
+ g_return_if_fail (timestamp != NULL);
+ timestamp->minute = minute;
+}
+gushort
+gda_timestamp_get_second (GdaTimestamp* timestamp)
+{
+ g_return_val_if_fail (timestamp != NULL, 0);
+ return timestamp->second;
+}
+void
+gda_timestamp_set_second (GdaTimestamp* timestamp, gushort second)
+{
+ g_return_if_fail (timestamp != NULL);
+ timestamp->second = second;
+}
+gulong
+gda_timestamp_get_fraction (GdaTimestamp* timestamp)
+{
+ g_return_val_if_fail (timestamp != NULL, 0);
+ return timestamp->fraction;
+}
+void
+gda_timestamp_set_fraction (GdaTimestamp* timestamp, glong fraction)
+{
+ g_return_if_fail (timestamp != NULL);
+ timestamp->fraction = fraction;
+}
+glong
+gda_timestamp_get_timezone (GdaTimestamp* timestamp)
+{
+ g_return_val_if_fail (timestamp != NULL, 0);
+ return timestamp->timezone;
+}
+void
+gda_timestamp_set_timezone (GdaTimestamp* timestamp, glong timezone)
+{
+ g_return_if_fail (timestamp != NULL);
+ timestamp->timezone = timezone;
+}
+
/**
* gda_value_new: (skip)
* @type: the new value type.
@@ -1905,18 +2041,19 @@ gda_value_new_timestamp_from_timet (time_t val)
#endif
if (ltm) {
- GdaTimestamp tstamp;
- tstamp.year = ltm->tm_year + 1900;
- tstamp.month = ltm->tm_mon + 1;
- tstamp.day = ltm->tm_mday;
- tstamp.hour = ltm->tm_hour;
- tstamp.minute = ltm->tm_min;
- tstamp.second = ltm->tm_sec;
- tstamp.fraction = 0;
- tstamp.timezone = tz;
+ GdaTimestamp* tstamp = gda_timestamp_new ();
+ gda_timestamp_set_year (tstamp, ltm->tm_year + 1900);
+ gda_timestamp_set_month (tstamp, ltm->tm_mon + 1);
+ gda_timestamp_set_day (tstamp, ltm->tm_mday);
+ gda_timestamp_set_hour (tstamp, ltm->tm_hour);
+ gda_timestamp_set_minute (tstamp, ltm->tm_min);
+ gda_timestamp_set_second (tstamp, ltm->tm_sec);
+ gda_timestamp_set_fraction (tstamp, 0);
+ gda_timestamp_set_timezone (tstamp, tz);
value = g_new0 (GValue, 1);
- gda_value_set_timestamp (value, (const GdaTimestamp *) &tstamp);
+ gda_value_set_timestamp (value, (const GdaTimestamp *) tstamp);
+ gda_timestamp_free (tstamp);
}
return value;
diff --git a/libgda/gda-value.h b/libgda/gda-value.h
index 09583c0..c30ae23 100644
--- a/libgda/gda-value.h
+++ b/libgda/gda-value.h
@@ -9,7 +9,7 @@
* Copyright (C) 2004 Paisa Seeluangsawat <paisa users sf net>
* Copyright (C) 2008 Przemysław Grzegorczyk <pgrzegorczyk gmail com>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
- * Copyright (C) 2011 - 2013 Daniel Espinosa <esodan gmail com>
+ * Copyright (C) 2011 - 2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -109,30 +109,6 @@ typedef struct {
} GdaTime;
/**
- * GdaTimestamp:
- * @year: year representation of the time stamp
- * @month: month representation of the time stamp, as a number between 1 and 12
- * @day: day representation of the time stamp, as a number between 1 and 31
- * @hour: hour representation of the time stamp, as a number between 0 and 23
- * @minute: minute representation of the time stamp, as a number between 0 and 59
- * @second: second representation of the time stamp, as a number between 0 and 59
- * @fraction: fractionnal part of the seconds, in millionth' of second
- * @timezone: number of seconds added to the GMT timezone
- *
- * Represents an instant (a time stamp)
- */
-typedef struct {
- gshort year;
- gushort month;
- gushort day;
- gushort hour;
- gushort minute;
- gushort second;
- gulong fraction;
- glong timezone;
-} GdaTimestamp;
-
-/**
* GdaBinary: (ref-func gda_binary_new) (unref-func gda_binary_free) (get-value-func gda_value_get_binary)
(set-value-func gda_value_set_binary)
*/
typedef struct _GdaBinary GdaBinary;
@@ -251,8 +227,6 @@ gushort gda_value_get_ushort (const GValue *value);
void gda_value_set_ushort (GValue *value, const gushort val);
const GdaTime *gda_value_get_time (const GValue *value);
void gda_value_set_time (GValue *value, const GdaTime *val);
-const GdaTimestamp *gda_value_get_timestamp (const GValue *value);
-void gda_value_set_timestamp (GValue *value, const GdaTimestamp *val);
@@ -285,11 +259,32 @@ void gda_time_free (gpointer boxed);
gboolean gda_time_valid (const GdaTime *time);
void gda_time_change_timezone (GdaTime *time, glong ntz);
+
+typedef struct _GdaTimestamp GdaTimestamp;
GType gda_timestamp_get_type (void) G_GNUC_CONST;
+GdaTimestamp *gda_timestamp_new (void);
+gshort gda_timestamp_get_year (GdaTimestamp* timestamp);
+void gda_timestamp_set_year (GdaTimestamp* timestamp, gshort year);
+gushort gda_timestamp_get_month (GdaTimestamp* timestamp);
+void gda_timestamp_set_month (GdaTimestamp* timestamp, gushort month);
+gushort gda_timestamp_get_day (GdaTimestamp* timestamp);
+void gda_timestamp_set_day (GdaTimestamp* timestamp, gushort day);
+gushort gda_timestamp_get_hour (GdaTimestamp* timestamp);
+void gda_timestamp_set_hour (GdaTimestamp* timestamp, gushort hour);
+gushort gda_timestamp_get_minute (GdaTimestamp* timestamp);
+void gda_timestamp_set_minute (GdaTimestamp* timestamp, gushort minute);
+gushort gda_timestamp_get_second (GdaTimestamp* timestamp);
+void gda_timestamp_set_second (GdaTimestamp* timestamp, gushort second);
+gulong gda_timestamp_get_fraction (GdaTimestamp* timestamp);
+void gda_timestamp_set_fraction (GdaTimestamp* timestamp, glong fraction);
+glong gda_timestamp_get_timezone (GdaTimestamp* timestamp);
+void gda_timestamp_set_timezone (GdaTimestamp* timestamp, glong timezone);
gpointer gda_timestamp_copy (gpointer boxed);
void gda_timestamp_free (gpointer boxed);
gboolean gda_timestamp_valid (const GdaTimestamp *timestamp);
void gda_timestamp_change_timezone (GdaTimestamp *ts, glong ntz);
+const GdaTimestamp *gda_value_get_timestamp (const GValue *value);
+void gda_value_set_timestamp (GValue *value, const GdaTimestamp *val);
GType gda_geometricpoint_get_type (void) G_GNUC_CONST;
diff --git a/libgda/handlers/gda-handler-time.c b/libgda/handlers/gda-handler-time.c
index 5c4385a..6d66f97 100644
--- a/libgda/handlers/gda-handler-time.c
+++ b/libgda/handlers/gda-handler-time.c
@@ -4,7 +4,7 @@
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2010 Jonh Wendell <jwendell gnome org>
- * Copyright (C) 2011 Daniel Espinosa <despinosa src gnome org>
+ * Copyright (C) 2011-2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -469,11 +469,11 @@ gda_handler_time_get_no_locale_str_from_value (GdaHandlerTime *dh, const GValue
retval = g_string_free (string, FALSE);
}
else if (type == GDA_TYPE_TIMESTAMP) {
- const GdaTimestamp *gdats;
+ GdaTimestamp *gdats;
GDate *vdate;
gdats = gda_value_get_timestamp ((GValue *) value);
- vdate = g_date_new_dmy (gdats->day, gdats->month, gdats->year);
+ vdate = g_date_new_dmy (gda_timestamp_get_day (gdats), gda_timestamp_get_month (gdats),
gda_timestamp_get_year (gdats));
str = render_date_locale (vdate, dh->priv->sql_locale);
g_date_free (vdate);
@@ -481,15 +481,15 @@ gda_handler_time_get_no_locale_str_from_value (GdaHandlerTime *dh, const GValue
GString *string;
string = g_string_new ("");
g_string_append_printf (string, "%02u:%02u:%02u",
- gdats->hour,
- gdats->minute,
- gdats->second);
- if (gdats->fraction != 0)
- g_string_append_printf (string, ".%lu", gdats->fraction);
+ gda_timestamp_get_hour (gdats),
+ gda_timestamp_get_minute (gdats),
+ gda_timestamp_get_second (gdats));
+ if (gda_timestamp_get_fraction (gdats) != 0)
+ g_string_append_printf (string, ".%lu", gda_timestamp_get_fraction (gdats));
- if (gdats->timezone != GDA_TIMEZONE_INVALID)
+ if (gda_timestamp_get_timezone (gdats) != GDA_TIMEZONE_INVALID)
g_string_append_printf (string, "%+02d",
- (int) gdats->timezone / 3600);
+ (int) gda_timestamp_get_timezone (gdats) / 3600);
retval = g_strdup_printf ("%s %s", str, string->str);
g_free (str);
@@ -704,11 +704,11 @@ gda_handler_time_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
retval = g_string_free (string, FALSE);
}
else if (type == GDA_TYPE_TIMESTAMP) {
- const GdaTimestamp *gdats;
+ GdaTimestamp *gdats;
GDate *vdate;
gdats = gda_value_get_timestamp ((GValue *) value);
- vdate = g_date_new_dmy (gdats->day, gdats->month, gdats->year);
+ vdate = g_date_new_dmy (gda_timestamp_get_day(gdats), gda_timestamp_get_month (gdats),
gda_timestamp_get_year (gdats));
str = render_date_locale (vdate, hdl->priv->sql_locale);
g_date_free (vdate);
@@ -716,15 +716,15 @@ gda_handler_time_get_sql_from_value (GdaDataHandler *iface, const GValue *value)
GString *string;
string = g_string_new ("");
g_string_append_printf (string, "%02u:%02u:%02u",
- gdats->hour,
- gdats->minute,
- gdats->second);
- if (gdats->fraction != 0)
- g_string_append_printf (string, ".%lu", gdats->fraction);
+ gda_timestamp_get_hour (gdats),
+ gda_timestamp_get_minute (gdats),
+ gda_timestamp_get_second (gdats));
+ if (gda_timestamp_get_fraction (gdats) != 0)
+ g_string_append_printf (string, ".%lu", gda_timestamp_get_fraction (gdats));
- if (gdats->timezone != GDA_TIMEZONE_INVALID)
+ if (gda_timestamp_get_timezone (gdats) != GDA_TIMEZONE_INVALID)
g_string_append_printf (string, "%+02d",
- (int) gdats->timezone / 3600);
+ (int) gda_timestamp_get_timezone (gdats) / 3600);
retval = g_strdup_printf ("'%s %s'", str, string->str);
g_free (str);
@@ -808,11 +808,11 @@ gda_handler_time_get_str_from_value (GdaDataHandler *iface, const GValue *value)
g_free (str);
}
else if (type == GDA_TYPE_TIMESTAMP) {
- const GdaTimestamp *gdats;
+ GdaTimestamp *gdats;
GDate *vdate;
gdats = gda_value_get_timestamp ((GValue *) value);
- vdate = g_date_new_dmy (gdats->day, gdats->month, gdats->year);
+ vdate = g_date_new_dmy (gda_timestamp_get_day (gdats), gda_timestamp_get_month (gdats),
gda_timestamp_get_year (gdats));
str = render_date_locale (vdate, hdl->priv->str_locale);
g_date_free (vdate);
@@ -820,15 +820,15 @@ gda_handler_time_get_str_from_value (GdaDataHandler *iface, const GValue *value)
GString *string;
string = g_string_new ("");
g_string_append_printf (string, "%02u:%02u:%02u",
- gdats->hour,
- gdats->minute,
- gdats->second);
- if (gdats->fraction != 0)
- g_string_append_printf (string, ".%lu", gdats->fraction);
+ gda_timestamp_get_hour (gdats),
+ gda_timestamp_get_minute (gdats),
+ gda_timestamp_get_second (gdats));
+ if (gda_timestamp_get_fraction (gdats) != 0)
+ g_string_append_printf (string, ".%lu", gda_timestamp_get_fraction (gdats));
- if (gdats->timezone != GDA_TIMEZONE_INVALID)
+ if (gda_timestamp_get_timezone (gdats) != GDA_TIMEZONE_INVALID)
g_string_append_printf (string, "%+02d",
- (int) gdats->timezone / 3600);
+ (int) gda_timestamp_get_timezone (gdats) / 3600);
retval = g_strdup_printf ("%s %s", str, string->str);
g_free (str);
@@ -1021,11 +1021,12 @@ gda_handler_time_get_value_from_locale (GdaDataHandler *iface, const gchar *sql,
}
}
else if (type == GDA_TYPE_TIMESTAMP) {
- GdaTimestamp timestamp;
- if (make_timestamp (hdl, ×tamp, sql, locale)) {
+ GdaTimestamp* timestamp = gda_timestamp_new ();
+ if (make_timestamp (hdl, timestamp, sql, locale)) {
value = g_value_init (g_new0 (GValue, 1), GDA_TYPE_TIMESTAMP);
- gda_value_set_timestamp (value, ×tamp);
+ gda_value_set_timestamp (value, timestamp);
}
+ gda_timestamp_free (timestamp);
}
else if (type == G_TYPE_DATE_TIME) {
GDateTime *ts;
@@ -1096,9 +1097,9 @@ make_timestamp (GdaHandlerTime *hdl, GdaTimestamp *timestamp, const gchar *value
vtime.timezone = GDA_TIMEZONE_INVALID;
retval = make_date (hdl, &vdate, value, locale, &end_ptr);
- timestamp->day = vdate.day;
- timestamp->month = vdate.month;
- timestamp->year = vdate.year;
+ gda_timestamp_set_day (timestamp, vdate.day);
+ gda_timestamp_set_month (timestamp, vdate.month);
+ gda_timestamp_set_year (timestamp, vdate.year);
if (retval) {
if (*end_ptr != ' ')
@@ -1107,11 +1108,11 @@ make_timestamp (GdaHandlerTime *hdl, GdaTimestamp *timestamp, const gchar *value
retval = make_time (hdl, &vtime, end_ptr + 1);
}
- timestamp->hour = vtime.hour;
- timestamp->minute = vtime.minute;
- timestamp->second = vtime.second;
- timestamp->fraction = vtime.fraction;
- timestamp->timezone = vtime.timezone;
+ gda_timestamp_set_hour (timestamp, vtime.hour);
+ gda_timestamp_set_minute (timestamp, vtime.minute);
+ gda_timestamp_set_second (timestamp, vtime.second);
+ gda_timestamp_set_fraction (timestamp, vtime.fraction);
+ gda_timestamp_set_timezone (timestamp, vtime.timezone);
/*g_print ("Value #%s# => %d\n", value, retval);*/
@@ -1316,18 +1317,18 @@ gda_handler_time_get_sane_init_value (G_GNUC_UNUSED GdaDataHandler *iface, GType
gda_value_set_time (value, >ime);
}
else if (type == GDA_TYPE_TIMESTAMP) {
- GdaTimestamp gts;
-
- gts.year = stm->tm_year + 1900;
- gts.month = stm->tm_mon + 1;
- gts.day = stm->tm_mday;
- gts.hour = stm->tm_hour;
- gts.minute = stm->tm_min;
- gts.second = stm->tm_sec;
- gts.fraction = 0;
- gts.timezone = GDA_TIMEZONE_INVALID;
+ GdaTimestamp* gts = gda_timestamp_new ();
+
+ gda_timestamp_set_year (gts, stm->tm_year + 1900);
+ gda_timestamp_set_month(gts, stm->tm_mon + 1);
+ gda_timestamp_set_day (gts, stm->tm_mday);
+ gda_timestamp_set_hour (gts, stm->tm_hour);
+ gda_timestamp_set_minute (gts, stm->tm_min);
+ gda_timestamp_set_second (gts, stm->tm_sec);
+ gda_timestamp_set_fraction (gts, 0);
+ gda_timestamp_set_timezone (gts, GDA_TIMEZONE_INVALID);
value = g_value_init (g_new0 (GValue, 1), GDA_TYPE_TIMESTAMP);
- gda_value_set_timestamp (value, >s);
+ gda_value_set_timestamp (value, gts);
}
else if (type == G_TYPE_DATE_TIME) {
GDateTime *ts;
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index a909cb8..7cbae76 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -1,15 +1,15 @@
/*
- * Copyright (C) 2001 - 2002 Carlos Perell� Mar�n <carlos gnome-db org>
+ * Copyright (C) 2001 - 2002 Carlos Perelló Marín <carlos gnome-db org>
* Copyright (C) 2001 - 2003 Rodrigo Moya <rodrigo gnome-db org>
* Copyright (C) 2002 - 2003 Gonzalo Paniagua Javier <gonzalo src gnome org>
* Copyright (C) 2004 Benjamin Otte <in7y118 public uni-hamburg de>
* Copyright (C) 2004 J.H.M. Dassen (Ray) <jdassen debian org>
* Copyright (C) 2004 Julio M. Merino Vidal <jmmv menta net>
- * Copyright (C) 2004 J�rg Billeter <j bitron ch>
+ * Copyright (C) 2004 Jürg Billeter <j bitron ch>
* Copyright (C) 2004 Nikolai Weibull <ruby-gnome2-devel-en-list pcppopper org>
* Copyright (C) 2005 Denis Fortin <denis fortin free fr>
* Copyright (C) 2005 - 2015 Vivien Malerba <malerba gnome-db org>
- * Copyright (C) 2005 �lvaro Pe�a <alvaropg telefonica net>
+ * Copyright (C) 2005 Álvaro Peña <alvaropg telefonica net>
* Copyright (C) 2008 - 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2008 - 2014 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2009 Armin Burgmeier <armin openismus com>
@@ -17,6 +17,7 @@
* Copyright (C) 2011 Daniel Espinosa <despinosa src gnome org>
* Copyright (C) 2011 Marek Černocký <marek manet cz>
* Copyright (C) 2012 Marco Ciampa <ciampix libero it>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -3287,7 +3288,7 @@ gda_sqlite_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
timestamp = (GdaTimestamp *) gda_value_get_timestamp (value);
string = g_string_new ("");
- if (timestamp->timezone != GDA_TIMEZONE_INVALID) {
+ if (gda_timestamp_get_timezone (timestamp) != GDA_TIMEZONE_INVALID) {
/* SQLite cant' store timezone information, so if timezone information is
* provided, we do our best and convert it to GMT */
timestamp = gda_timestamp_copy (timestamp);
@@ -3296,14 +3297,14 @@ gda_sqlite_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
}
g_string_append_printf (string, "%04u-%02u-%02u %02u:%02u:%02u",
- timestamp->year,
- timestamp->month,
- timestamp->day,
- timestamp->hour,
- timestamp->minute,
- timestamp->second);
- if (timestamp->fraction > 0)
- g_string_append_printf (string, ".%lu", timestamp->fraction);
+ gda_timestamp_get_year (timestamp),
+ gda_timestamp_get_month (timestamp),
+ gda_timestamp_get_day (timestamp),
+ gda_timestamp_get_hour (timestamp),
+ gda_timestamp_get_minute (timestamp),
+ gda_timestamp_get_second (timestamp));
+ if (gda_timestamp_get_fraction (timestamp) > 0)
+ g_string_append_printf (string, ".%lu", gda_timestamp_get_fraction
(timestamp));
if (tofree)
gda_timestamp_free (timestamp);
diff --git a/libgda/sqlite/gda-sqlite-recordset.c b/libgda/sqlite/gda-sqlite-recordset.c
index 677ecaf..b09d378 100644
--- a/libgda/sqlite/gda-sqlite-recordset.c
+++ b/libgda/sqlite/gda-sqlite-recordset.c
@@ -1,15 +1,16 @@
/*
- * Copyright (C) 2001 - 2002 Carlos Perell� Mar�n <carlos gnome-db org>
+ * Copyright (C) 2001 - 2002 Carlos Perelló Marín <carlos gnome-db org>
* Copyright (C) 2002 - 2003 Gonzalo Paniagua Javier <gonzalo src gnome org>
* Copyright (C) 2002 - 2005 Rodrigo Moya <rodrigo gnome-db org>
* Copyright (C) 2005 Denis Fortin <denis fortin free fr>
* Copyright (C) 2005 - 2014 Vivien Malerba <malerba gnome-db org>
- * Copyright (C) 2005 �lvaro Pe�a <alvaropg telefonica net>
+ * Copyright (C) 2005 Álvaro Peña <alvaropg telefonica net>
* Copyright (C) 2006 - 2008 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2007 Armin Burgmeier <arminb src gnome org>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Marco Ciampa <ciampix libero it>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -556,8 +557,8 @@ fetch_next_sqlite_row (GdaSqliteRecordset *model, gboolean do_store, GError **er
}
}
else if (type == GDA_TYPE_TIMESTAMP) {
- GdaTimestamp timestamp;
- if (!gda_parse_iso8601_timestamp (×tamp,
+ GdaTimestamp* timestamp = gda_timestamp_new ();
+ if (!gda_parse_iso8601_timestamp (timestamp,
(gchar *) SQLITE3_CALL
(sqlite3_column_text) (ps->sqlite_stmt,
real_col))) {
GError *lerror = NULL;
@@ -568,10 +569,11 @@ fetch_next_sqlite_row (GdaSqliteRecordset *model, gboolean do_store, GError **er
gda_row_invalidate_value_e (prow, value, lerror);
}
else {
- if (timestamp.timezone == GDA_TIMEZONE_INVALID)
- timestamp.timezone = 0; /* set to GMT */
- gda_value_set_timestamp (value, ×tamp);
+ if (gda_timestamp_get_timezone (timestamp) ==
GDA_TIMEZONE_INVALID)
+ gda_timestamp_set_timezone (timestamp, 0); /* set to
GMT */
+ gda_value_set_timestamp (value, timestamp);
}
+ gda_timestamp_free (timestamp);
}
else if (type == G_TYPE_CHAR) {
gint64 i;
diff --git a/libgda/sqlite/virtual/gda-vconnection-hub.c b/libgda/sqlite/virtual/gda-vconnection-hub.c
index 7f26280..7dd182d 100644
--- a/libgda/sqlite/virtual/gda-vconnection-hub.c
+++ b/libgda/sqlite/virtual/gda-vconnection-hub.c
@@ -3,6 +3,7 @@
* Copyright (C) 2008 - 2011 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -698,8 +699,8 @@ create_value_from_sqlite3_gvalue (GType type, GValue *svalue, GError **error)
if (G_VALUE_TYPE (svalue) != G_TYPE_STRING)
allok = FALSE;
else {
- GdaTimestamp timestamp;
- if (!gda_parse_iso8601_timestamp (×tamp, g_value_get_string (svalue))) {
+ GdaTimestamp* timestamp = gda_timestamp_new ();
+ if (!gda_parse_iso8601_timestamp (timestamp, g_value_get_string (svalue))) {
g_set_error (error, GDA_SERVER_PROVIDER_ERROR,
GDA_SERVER_PROVIDER_DATA_ERROR,
_("Invalid timestamp '%s' (format should be YYYY-MM-DD
HH:MM:SS[.ms])"),
@@ -707,7 +708,8 @@ create_value_from_sqlite3_gvalue (GType type, GValue *svalue, GError **error)
allok = FALSE;
}
else
- gda_value_set_timestamp (value, ×tamp);
+ gda_value_set_timestamp (value, timestamp);
+ gda_timestamp_free (timestamp);
}
}
else
diff --git a/libgda/sqlite/virtual/gda-vprovider-data-model.c
b/libgda/sqlite/virtual/gda-vprovider-data-model.c
index fee377a..f105e4e 100644
--- a/libgda/sqlite/virtual/gda-vprovider-data-model.c
+++ b/libgda/sqlite/virtual/gda-vprovider-data-model.c
@@ -2,6 +2,7 @@
* Copyright (C) 2007 - 2016 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1096,7 +1097,7 @@ create_value_from_sqlite3_value_notype (sqlite3_value *svalue)
bin = gda_binary_new ();
glong length = SQLITE3_CALL (sqlite3_value_bytes) (svalue);
if (length > 0) {
- gpointer data = g_new (guchar, length);
+ //gpointer data = g_new (guchar, length);
gda_binary_set_data (bin, SQLITE3_CALL (sqlite3_value_blob) (svalue), length);
}
gda_value_take_binary (value, bin);
diff --git a/providers/ldap/gda-ldap-util.c b/providers/ldap/gda-ldap-util.c
index 75087fa..76d07f8 100644
--- a/providers/ldap/gda-ldap-util.c
+++ b/providers/ldap/gda-ldap-util.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011 - 2016 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -995,16 +996,17 @@ gda_ldap_attr_value_to_g_value (LdapConnectionData *cdata, GType type, BerValue
return NULL;
if (type == GDA_TYPE_TIMESTAMP) {
- GdaTimestamp ts;
- ts.year = ptm->tm_year + 1900;
- ts.month = ptm->tm_mon + 1;
- ts.day = ptm->tm_mday;
- ts.hour = ptm->tm_hour;
- ts.minute = ptm->tm_min;
- ts.second = ptm->tm_sec;
- ts.timezone = GDA_TIMEZONE_INVALID;
+ GdaTimestamp *ts = gda_timestamp_new ();
+ gda_timestamp_set_year (ts, ptm->tm_year + 1900);
+ gda_timestamp_set_month (ts, ptm->tm_mon + 1);
+ gda_timestamp_set_day (ts, ptm->tm_mday);
+ gda_timestamp_set_hour (ts, ptm->tm_hour);
+ gda_timestamp_set_minute (ts, ptm->tm_min);
+ gda_timestamp_set_second (ts, ptm->tm_sec);
+ gda_timestamp_set_timezone (ts, GDA_TIMEZONE_INVALID);
value = gda_value_new (type);
- gda_value_set_timestamp (value, &ts);
+ gda_value_set_timestamp (value, ts);
+ gda_timestamp_free (ts);
}
else {
GDate *date;
@@ -1044,28 +1046,48 @@ gda_ldap_attr_g_value_to_value (LdapConnectionData *cdata, const GValue *cvalue)
bv->bv_len = strlen (cstr);
}
else if (G_VALUE_TYPE (cvalue) == GDA_TYPE_TIMESTAMP) {
- const GdaTimestamp *ts;
+ GdaTimestamp *ts;
gchar *str;
- ts = gda_value_get_timestamp (cvalue);
- if (ts->fraction == 0) {
- if (ts->timezone == GDA_TIMEZONE_INVALID)
- str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d", ts->year, ts->month,
- ts->day, ts->hour, ts->minute, ts->second);
+ ts = (GdaTimestamp*) gda_value_get_timestamp (cvalue);
+ if (gda_timestamp_get_fraction (ts) == 0) {
+ if (gda_timestamp_get_timezone (ts) == GDA_TIMEZONE_INVALID)
+ str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d",
+
gda_timestamp_get_year (ts),
+
gda_timestamp_get_month (ts),
+
gda_timestamp_get_day (ts),
+
gda_timestamp_get_hour (ts),
+
gda_timestamp_get_minute (ts),
+
gda_timestamp_get_second (ts));
else {
- str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d", ts->year, ts->month,
- ts->day, ts->hour, ts->minute, ts->second);
+ str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d",
+
gda_timestamp_get_year (ts),
+
gda_timestamp_get_month (ts),
+
gda_timestamp_get_day (ts),
+
gda_timestamp_get_hour (ts),
+
gda_timestamp_get_minute (ts),
+
gda_timestamp_get_second (ts));
TO_IMPLEMENT;
}
}
else {
- if (ts->timezone == GDA_TIMEZONE_INVALID)
- str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d,%lu", ts->year,
ts->month,
- ts->day, ts->hour, ts->minute, ts->second,
- ts->fraction);
+ if (gda_timestamp_get_timezone (ts) == GDA_TIMEZONE_INVALID)
+ str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d,%lu",
+
gda_timestamp_get_year (ts),
+
gda_timestamp_get_month (ts),
+
gda_timestamp_get_day (ts),
+
gda_timestamp_get_hour (ts),
+
gda_timestamp_get_minute (ts),
+
gda_timestamp_get_second (ts),
+
gda_timestamp_get_fraction (ts));
else {
- str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d,%lu", ts->year,
ts->month,
- ts->day, ts->hour, ts->minute, ts->second,
- ts->fraction);
+ str = g_strdup_printf ("%04d-%02d-%02dT%02d:%02d:%02d,%lu",
+
gda_timestamp_get_year (ts),
+
gda_timestamp_get_month (ts),
+
gda_timestamp_get_day (ts),
+
gda_timestamp_get_hour (ts),
+
gda_timestamp_get_minute (ts),
+
gda_timestamp_get_second (ts),
+
gda_timestamp_get_fraction (ts));
TO_IMPLEMENT;
}
}
diff --git a/providers/postgres/gda-postgres-provider.c b/providers/postgres/gda-postgres-provider.c
index 154f86b..cae07be 100644
--- a/providers/postgres/gda-postgres-provider.c
+++ b/providers/postgres/gda-postgres-provider.c
@@ -6,13 +6,14 @@
* Copyright (C) 2003 Akira TAGOH <tagoh gnome-db org>
* Copyright (C) 2004 - 2005 Alan Knowles <alank src gnome org>
* Copyright (C) 2004 Denis Loginov <dloginov crl nmsu edu>
- * Copyright (C) 2004 Jos� Mar�a Casanova Crespo <jmcasanova igalia com>
+ * Copyright (C) 2004 José María Casanova Crespo <jmcasanova igalia com>
* Copyright (C) 2004 Julio M. Merino Vidal <jmmv menta net>
* Copyright (C) 2005 - 2009 Bas Driessen <bas driessen xobas com>
- * Copyright (C) 2005 �lvaro Pe�a <alvaropg telefonica net>
+ * Copyright (C) 2005 Álvaro Peña <alvaropg telefonica net>
* Copyright (C) 2006 - 2015 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2007 Armin Burgmeier <armin openismus com>
* Copyright (C) 2010 David King <davidk openismus com>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -2228,7 +2229,7 @@ gda_postgres_provider_statement_execute (GdaServerProvider *provider, GdaConnect
GdaTimestamp *timestamp;
timestamp = (GdaTimestamp *) gda_value_get_timestamp (value);
- if (timestamp->timezone != GDA_TIMEZONE_INVALID) {
+ if (gda_timestamp_get_timezone (timestamp) != GDA_TIMEZONE_INVALID) {
/* PostgreSQL does not store timezone information, so if timezone information
is
* provided, we do our best and convert it to GMT */
timestamp = gda_timestamp_copy (timestamp);
diff --git a/providers/postgres/gda-postgres-recordset.c b/providers/postgres/gda-postgres-recordset.c
index 43687ca..777b41b 100644
--- a/providers/postgres/gda-postgres-recordset.c
+++ b/providers/postgres/gda-postgres-recordset.c
@@ -9,11 +9,11 @@
* Copyright (C) 2004 Szalai Ferenc <szferi einstein ki iif hu>
* Copyright (C) 2004 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2005 Alex <alex igalia com>
- * Copyright (C) 2005 �lvaro Pe�a <alvaropg telefonica net>
+ * Copyright (C) 2005 Álvaro Peña <alvaropg telefonica net>
* Copyright (C) 2006 - 2011 Murray Cumming <murrayc murrayc com>
* Copyright (C) 2007 Armin Burgmeier <armin openismus com>
* Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2011 Daniel Espinosa <despinosa src gnome org>
+ * Copyright (C) 2011-2017 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -674,12 +674,12 @@ set_value (GdaConnection *cnc, GdaRow *row, GValue *value, GType type, const gch
PostgresConnectionData *cdata;
cdata = (PostgresConnectionData*) gda_connection_internal_get_provider_data_error (cnc,
error);
if (cdata) {
- GdaTimestamp timestamp;
- if (gda_parse_formatted_timestamp (×tamp, thevalue, cdata->date_first,
cdata->date_second,
+ GdaTimestamp* timestamp = gda_timestamp_new ();
+ if (gda_parse_formatted_timestamp (timestamp, thevalue, cdata->date_first,
cdata->date_second,
cdata->date_third, cdata->date_sep)) {
- if (timestamp.timezone == GDA_TIMEZONE_INVALID)
- timestamp.timezone = 0; /* set to GMT */
- gda_value_set_timestamp (value, ×tamp);
+ if (gda_timestamp_get_timezone (timestamp) == GDA_TIMEZONE_INVALID)
+ gda_timestamp_set_timezone (timestamp, 0); /* set to GMT */
+ gda_value_set_timestamp (value, timestamp);
}
else {
gda_row_invalidate_value (row, value);
@@ -687,6 +687,7 @@ set_value (GdaConnection *cnc, GdaRow *row, GValue *value, GType type, const gch
GDA_SERVER_PROVIDER_DATA_ERROR,
_("Invalid timestamp value '%s'"), thevalue);
}
+ gda_timestamp_free (timestamp);
}
else
g_set_error (error, GDA_SERVER_PROVIDER_ERROR,
diff --git a/providers/sqlcipher/Makefile.am b/providers/sqlcipher/Makefile.am
index ad1b988..04071e0 100644
--- a/providers/sqlcipher/Makefile.am
+++ b/providers/sqlcipher/Makefile.am
@@ -15,6 +15,8 @@ AM_CPPFLAGS = \
$(sqliteinc) \
-DSQLITE_HAS_CODEC -DSQLITE_API= -DSQLITE_PRIVATE= -DSQLITE_ENABLE_COLUMN_METADATA
-DSQLITE_THREADSAFE=1
+#sqlcipher.patch:
+# cp $(srcdir)/sqlcipher-3.3.patch $(srcdir)/sqlcipher.patch
sqlite_sources = sqlite3.c sqlite3.h
sqlite3.c: $(srcdir)/sqlcipher.patch $(top_srcdir)/libgda/sqlite/sqlite-src/sqlite3.c
diff --git a/tests/data-models/check_vcnc.c b/tests/data-models/check_vcnc.c
index 7c42ab0..1518b83 100644
--- a/tests/data-models/check_vcnc.c
+++ b/tests/data-models/check_vcnc.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -581,7 +582,15 @@ check_date (GdaConnection *virtual)
{
g_print ("*** insert dates into 'misc' table...\n");
GdaSet *set;
- GdaTimestamp ts = {2011, 01, 31, 12, 34, 56, 0, 0};
+ GdaTimestamp *ts = gda_timestamp_new ();
+ gda_timestamp_set_year (ts, 2011);
+ gda_timestamp_set_month (ts, 01);
+ gda_timestamp_set_day (ts, 31);
+ gda_timestamp_set_hour (ts, 12);
+ gda_timestamp_set_minute (ts, 34);
+ gda_timestamp_set_second (ts, 56);
+ gda_timestamp_set_fraction (ts, 0);
+ gda_timestamp_set_timezone (ts, 0);
GdaTime atime = {13, 45, 59, 0, 0};
GDate *adate;
GdaDataModel *model;
@@ -589,7 +598,7 @@ check_date (GdaConnection *virtual)
adate = g_date_new_dmy (23, G_DATE_FEBRUARY, 2010);
set = gda_set_new_inline (3,
- "ts", GDA_TYPE_TIMESTAMP, &ts,
+ "ts", GDA_TYPE_TIMESTAMP, ts,
"adate", G_TYPE_DATE, adate,
"atime", GDA_TYPE_TIME, &atime);
g_date_free (adate);
@@ -641,4 +650,5 @@ check_date (GdaConnection *virtual)
}
g_object_unref (set);
+ gda_timestamp_free (ts);
}
diff --git a/tests/providers/prov-test-common.c b/tests/providers/prov-test-common.c
index 06dd5f3..e3a2411 100644
--- a/tests/providers/prov-test-common.c
+++ b/tests/providers/prov-test-common.c
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2007 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2012 Daniel Espinosa <despinosa src gnome org>
+ * Copyright (C) 2012-2017 Daniel Espinosa <esodan gmail com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -719,17 +719,24 @@ timestamp_equal (const GValue *cv1, const GValue *cv2)
{
g_assert (G_VALUE_TYPE (cv1) == GDA_TYPE_TIMESTAMP);
g_assert (G_VALUE_TYPE (cv2) == GDA_TYPE_TIMESTAMP);
- const GdaTimestamp *ts1, *ts2;
- ts1 = gda_value_get_timestamp (cv1);
- ts2 = gda_value_get_timestamp (cv2);
- if (ts1->timezone == ts2->timezone)
+ GdaTimestamp *ts1, *ts2;
+ ts1 = (GdaTimestamp*) gda_value_get_timestamp (cv1);
+ ts2 = (GdaTimestamp*) gda_value_get_timestamp (cv2);
+ if (gda_timestamp_get_timezone (ts1) == gda_timestamp_get_timezone (ts2))
return gda_value_differ (cv1, cv2) ? FALSE : TRUE;
GdaTimestamp *ts;
- ts = gda_timestamp_copy ((GdaTimestamp*) ts1);
- gda_timestamp_change_timezone (ts, ts2->timezone);
- gboolean res;
- res = memcmp (ts2, ts, sizeof (GdaTimestamp)) ? FALSE : TRUE;
+ ts = gda_timestamp_copy (ts1);
+ gda_timestamp_change_timezone (ts, gda_timestamp_get_timezone (ts2));
+ gboolean res = TRUE;
+ if (gda_timestamp_get_year (ts1) != gda_timestamp_get_year (ts2)) res = FALSE;
+ if (gda_timestamp_get_month (ts1) != gda_timestamp_get_month (ts2)) res = FALSE;
+ if (gda_timestamp_get_day (ts1) != gda_timestamp_get_day (ts2)) res = FALSE;
+ if (gda_timestamp_get_hour (ts1) != gda_timestamp_get_hour (ts2)) res = FALSE;
+ if (gda_timestamp_get_minute (ts1) != gda_timestamp_get_minute (ts2)) res = FALSE;
+ if (gda_timestamp_get_second (ts1) != gda_timestamp_get_second (ts2)) res = FALSE;
+ if (gda_timestamp_get_fraction (ts1) != gda_timestamp_get_fraction (ts2)) res = FALSE;
+ if (gda_timestamp_get_timezone (ts1) != gda_timestamp_get_timezone (ts2)) res = FALSE;
gda_timestamp_free (ts);
return res;
}
diff --git a/tests/test-input-parsers.c b/tests/test-input-parsers.c
index 77c9351..ef30b6a 100644
--- a/tests/test-input-parsers.c
+++ b/tests/test-input-parsers.c
@@ -2,6 +2,7 @@
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2010 - 2013 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -198,36 +199,38 @@ test_parse_iso8601_timestamp (void)
gchar *str;
str = g_strdup_printf ("%s %s", td.in_string, tt.in_string);
- GdaTimestamp timestamp;
+ GdaTimestamp* timestamp = gda_timestamp_new ();
gboolean exp_result = td.exp_retval && tt.exp_retval;
/*g_print ("[%s]\n", str);*/
- if (gda_parse_iso8601_timestamp (×tamp, str) != exp_result) {
+ if (gda_parse_iso8601_timestamp (timestamp, str) != exp_result) {
g_print ("Wrong result for gda_parse_iso8601_timestamp (\"%s\"): got %s\n",
td.in_string, exp_result ? "FALSE" : "TRUE");
return FALSE;
}
if ((td.exp_retval &&
- ((timestamp.year != td.exp_year) ||
- (timestamp.month != td.exp_month) ||
- (timestamp.day != td.exp_day))) &&
- (((timestamp.hour != tt.exp_time.hour) ||
- (timestamp.minute != tt.exp_time.minute) ||
- (timestamp.second != tt.exp_time.second) ||
- (timestamp.fraction != tt.exp_time.fraction) ||
- (timestamp.timezone != tt.exp_time.timezone)))) {
+ ((gda_timestamp_get_year (timestamp) != td.exp_year) ||
+ (gda_timestamp_get_month (timestamp) != td.exp_month) ||
+ (gda_timestamp_get_day (timestamp) != td.exp_day))) &&
+ (((gda_timestamp_get_hour (timestamp) != tt.exp_time.hour) ||
+ (gda_timestamp_get_minute (timestamp) != tt.exp_time.minute) ||
+ (gda_timestamp_get_second (timestamp) != tt.exp_time.second) ||
+ (gda_timestamp_get_fraction (timestamp) != tt.exp_time.fraction) ||
+ (gda_timestamp_get_timezone (timestamp) != tt.exp_time.timezone)))) {
g_print ("Wrong result for gda_parse_iso8601_timestamp (\"%s\"):\n"
" exp: DD=%d MM=%d YYYY=%d HH=%d MM=%d SS=%d FF=%ld TZ=%ld\n"
" got: DD=%d MM=%d YYYY=%d HH=%d MM=%d SS=%d FF=%ld TZ=%ld\n",
str, td.exp_day, td.exp_month, td.exp_year,
tt.exp_time.hour, tt.exp_time.minute, tt.exp_time.second,
tt.exp_time.fraction, tt.exp_time.timezone,
- timestamp.year, timestamp.month, timestamp.day, timestamp.hour,
timestamp.minute,
- timestamp.second, timestamp.fraction, timestamp.timezone);
+ gda_timestamp_get_year (timestamp), gda_timestamp_get_month
(timestamp),
+ gda_timestamp_get_day (timestamp), gda_timestamp_get_hour
(timestamp), gda_timestamp_get_minute (timestamp),
+ gda_timestamp_get_second (timestamp), gda_timestamp_get_fraction
(timestamp), gda_timestamp_get_timezone (timestamp));
g_free (str);
return FALSE;
}
g_free (str);
+ gda_timestamp_free (timestamp);
}
}
g_print ("All %d iso8601 timestamp parsing tests passed\n", idate * itime);
@@ -432,35 +435,37 @@ test_timestamp_handler (void)
g_free (str);
continue;
}
- const GdaTimestamp *ptimestamp;
- GdaTimestamp timestamp;
- ptimestamp = gda_value_get_timestamp (value);
- timestamp = *ptimestamp;
+ GdaTimestamp *ptimestamp;
+ GdaTimestamp *timestamp;
+ ptimestamp = (GdaTimestamp*) gda_value_get_timestamp (value);
+ timestamp = gda_timestamp_copy (ptimestamp);
gda_value_free (value);
-
+
if ((td.exp_retval &&
- ((timestamp.year != td.exp_year) ||
- (timestamp.month != td.exp_month) ||
- (timestamp.day != td.exp_day))) &&
+ ((gda_timestamp_get_year (timestamp) != td.exp_year) ||
+ (gda_timestamp_get_month (timestamp) != td.exp_month) ||
+ (gda_timestamp_get_day (timestamp) != td.exp_day))) &&
((tt.exp_retval) &&
- ((timestamp.hour != tt.exp_time.hour) ||
- (timestamp.minute != tt.exp_time.minute) ||
- (timestamp.second != tt.exp_time.second) ||
- (timestamp.fraction != tt.exp_time.fraction) ||
- (timestamp.timezone != tt.exp_time.timezone)))) {
+ ((gda_timestamp_get_hour (timestamp) != tt.exp_time.hour) ||
+ (gda_timestamp_get_minute (timestamp) != tt.exp_time.minute) ||
+ (gda_timestamp_get_second (timestamp) != tt.exp_time.second) ||
+ (gda_timestamp_get_fraction (timestamp) != tt.exp_time.fraction) ||
+ (gda_timestamp_get_timezone (timestamp) != tt.exp_time.timezone)))) {
g_print ("Wrong result for gda_data_handler_get_value_from_str (\"%s\",
GDA_TYPE_TIMESTAMP):\n"
" exp: DD=%d MM=%d YYYY=%d HH=%d MM=%d SS=%d FF=%ld TZ=%ld\\n"
" got: DD=%d MM=%d YYYY=%d HH=%d MM=%d SS=%d FF=%ld TZ=%ld\\n",
str, td.exp_day, td.exp_month, td.exp_year,
tt.exp_time.hour, tt.exp_time.minute, tt.exp_time.second,
tt.exp_time.fraction, tt.exp_time.timezone,
- timestamp.year, timestamp.month, timestamp.day, timestamp.hour,
timestamp.minute,
- timestamp.second, timestamp.fraction, timestamp.timezone);
+ gda_timestamp_get_year (timestamp), gda_timestamp_get_month
(timestamp), gda_timestamp_get_day (timestamp),
+ gda_timestamp_get_hour (timestamp), gda_timestamp_get_minute
(timestamp),
+ gda_timestamp_get_second (timestamp), gda_timestamp_get_fraction
(timestamp), gda_timestamp_get_timezone (timestamp));
g_object_unref (dh);
g_free (str);
return FALSE;
}
g_free (str);
+ gda_timestamp_free (timestamp);
}
}
@@ -488,33 +493,36 @@ test_timestamp_handler (void)
g_free (str);
continue;
}
- const GdaTimestamp *ptimestamp;
- GdaTimestamp timestamp;
- ptimestamp = gda_value_get_timestamp (value);
- timestamp = *ptimestamp;
+ GdaTimestamp *ptimestamp;
+ GdaTimestamp *timestamp;
+ ptimestamp = (GdaTimestamp*) gda_value_get_timestamp (value);
+ timestamp = gda_timestamp_copy (ptimestamp);
gda_value_free (value);
-
- if ((timestamp.year != td.exp_year) ||
- (timestamp.month != td.exp_month) ||
- (timestamp.day != td.exp_day) ||
- (timestamp.hour != tt.exp_time.hour) ||
- (timestamp.minute != tt.exp_time.minute) ||
- (timestamp.second != tt.exp_time.second) ||
- (timestamp.fraction != tt.exp_time.fraction) ||
- (timestamp.timezone != tt.exp_time.timezone)) {
+
+ if ((gda_timestamp_get_year (timestamp) != td.exp_year) ||
+ (gda_timestamp_get_month (timestamp) != td.exp_month) ||
+ (gda_timestamp_get_day (timestamp) != td.exp_day) ||
+ (gda_timestamp_get_hour (timestamp) != tt.exp_time.hour) ||
+ (gda_timestamp_get_minute (timestamp) != tt.exp_time.minute) ||
+ (gda_timestamp_get_second (timestamp) != tt.exp_time.second) ||
+ (gda_timestamp_get_fraction (timestamp) != tt.exp_time.fraction) ||
+ (gda_timestamp_get_timezone (timestamp) != tt.exp_time.timezone)) {
g_print ("Wrong result for gda_data_handler_get_value_from_str (\"%s\",
GDA_TYPE_TIMESTAMP):\n"
" exp: DD=%d MM=%d YYYY=%d HH=%d MM=%d SS=%d FF=%ld TZ=%ld\\n"
" got: DD=%d MM=%d YYYY=%d HH=%d MM=%d SS=%d FF=%ld TZ=%ld\\n",
str, td.exp_day, td.exp_month, td.exp_year,
tt.exp_time.hour, tt.exp_time.minute, tt.exp_time.second,
tt.exp_time.fraction, tt.exp_time.timezone,
- timestamp.year, timestamp.month, timestamp.day, timestamp.hour,
timestamp.minute,
- timestamp.second, timestamp.fraction, timestamp.timezone);
+ gda_timestamp_get_year (timestamp), gda_timestamp_get_month
(timestamp),
+ gda_timestamp_get_day (timestamp), gda_timestamp_get_hour
(timestamp),
+ gda_timestamp_get_minute (timestamp), gda_timestamp_get_second
(timestamp),
+ gda_timestamp_get_fraction (timestamp), gda_timestamp_get_timezone
(timestamp));
g_object_unref (dh);
g_free (str);
return FALSE;
}
g_free (str);
+ gda_timestamp_free (timestamp);
}
}
diff --git a/tests/test-sql-renderer.c b/tests/test-sql-renderer.c
index a0d401e..c039532 100644
--- a/tests/test-sql-renderer.c
+++ b/tests/test-sql-renderer.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 - 2014 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -40,15 +41,18 @@ string_equal_to_template (const gchar *str, const gchar *tmpl)
return TRUE;
}
-GdaTimestamp ts = {
- .year = 2013,
- .month = 8,
- .day = 28,
- .hour = 17,
- .minute = 10,
- .second = 23,
- .timezone = 3600 * 2
-};
+GdaTimestamp* create_timestamp (void) {
+ GdaTimestamp *ts = gda_timestamp_new ();
+ gda_timestamp_set_year (ts, 2013);
+ gda_timestamp_set_month (ts, 8);
+ gda_timestamp_set_day (ts, 28);
+ gda_timestamp_set_hour (ts, 17);
+ gda_timestamp_set_minute (ts, 10);
+ gda_timestamp_set_second (ts, 23);
+ gda_timestamp_set_timezone (ts, 3600*2);
+ return ts;
+}
+
GdaTime gt = {
.hour = 16,
.minute = 9,
@@ -87,8 +91,8 @@ do_a_test (GdaServerProvider *prov, GdaSqlParser *parser)
nfailed ++;
goto endtest;
}
-
- if (! gda_set_set_holder_value (params, &error, "ts", &ts)) {
+ GdaTimestamp *ts = create_timestamp ();
+ if (! gda_set_set_holder_value (params, &error, "ts", ts)) {
g_print ("Failed to bind 'ts' parameter: %s\n", error && error->message ? error->message :
"No detail");
g_clear_error (&error);
g_object_unref (stmt);
@@ -185,8 +189,7 @@ do_a_test (GdaServerProvider *prov, GdaSqlParser *parser)
nfailed ++;
goto endtest;
}
-
- if (! gda_set_set_holder_value (params, &error, "ts", &ts)) {
+ if (! gda_set_set_holder_value (params, &error, "ts", ts)) {
g_print ("Failed to bind 'ts' parameter: %s\n", error && error->message ? error->message :
"No detail");
g_clear_error (&error);
g_object_unref (stmt);
@@ -194,6 +197,7 @@ do_a_test (GdaServerProvider *prov, GdaSqlParser *parser)
nfailed ++;
goto endtest;
}
+ gda_timestamp_free (ts);
if (! gda_set_set_holder_value (params, &error, "time", >)) {
g_print ("Failed to bind 'time' parameter: %s\n", error && error->message ? error->message :
"No detail");
diff --git a/tools/browser/ldap-browser/entry-properties.c b/tools/browser/ldap-browser/entry-properties.c
index 6cbb156..cb9eed3 100644
--- a/tools/browser/ldap-browser/entry-properties.c
+++ b/tools/browser/ldap-browser/entry-properties.c
@@ -597,7 +597,7 @@ ad_1601_timestamp_to_string (const gchar *value, const gchar *attname)
GdaDataHandler *dh;
struct tm *stm;
GValue tvalue;
- GdaTimestamp ts;
+ GdaTimestamp *ts;
time_t nsec = (time_t) i64;
gchar *str;
#ifdef HAVE_LOCALTIME_R
@@ -616,20 +616,20 @@ ad_1601_timestamp_to_string (const gchar *value, const gchar *attname)
if (!stm)
return NULL;
- memset (&ts, 0, sizeof (GdaTimestamp));
- ts.year = stm->tm_year + 1900;
- ts.month = stm->tm_mon + 1;
- ts.day = stm->tm_mday;
- ts.hour = stm->tm_hour;
- ts.minute = stm->tm_min;
- ts.second = stm->tm_sec;
- ts.timezone = GDA_TIMEZONE_INVALID;
+ ts = gda_timestamp_new ();
+ gda_timestamp_set_year (ts, stm->tm_year + 1900);
+ gda_timestamp_set_month(ts, stm->tm_mon + 1);
+ gda_timestamp_set_day (ts, stm->tm_mday);
+ gda_timestamp_set_hour (ts, stm->tm_hour);
+ gda_timestamp_set_minute (ts, stm->tm_min);
+ gda_timestamp_set_second (ts, stm->tm_sec);
+ gda_timestamp_set_timezone (ts, GDA_TIMEZONE_INVALID);
memset (&tvalue, 0, sizeof (GValue));
- gda_value_set_timestamp (&tvalue, &ts);
+ gda_value_set_timestamp (&tvalue, ts);
dh = gda_data_handler_get_default (GDA_TYPE_TIMESTAMP);
str = gda_data_handler_get_str_from_value (dh, &tvalue);
g_value_reset (&tvalue);
-
+ gda_timestamp_free (ts);
return str;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]