[tracker/tracker-0.10] libtracker-data: Add support for xsd:date
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.10] libtracker-data: Add support for xsd:date
- Date: Fri, 5 Aug 2011 10:12:53 +0000 (UTC)
commit 5fee4ace15c58fc10c249aef4d44c2920b4bf2ca
Author: JÃrg Billeter <j bitron ch>
Date: Thu May 12 10:06:55 2011 +0200
libtracker-data: Add support for xsd:date
Fixes NB#271747.
src/libtracker-data/tracker-data-update.c | 6 ++++++
src/libtracker-data/tracker-sparql-expression.vala | 15 ++++++++++++++-
src/libtracker-data/tracker-sparql-query.vala | 2 ++
3 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 2d26f99..dbf1043 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1484,6 +1484,7 @@ string_to_gvalue (const gchar *value,
GError **error)
{
gint object_id;
+ gchar *datetime;
switch (type) {
case TRACKER_PROPERTY_TYPE_STRING:
@@ -1505,6 +1506,11 @@ string_to_gvalue (const gchar *value,
g_value_set_double (gvalue, atof (value));
break;
case TRACKER_PROPERTY_TYPE_DATE:
+ g_value_init (gvalue, G_TYPE_INT64);
+ datetime = g_strdup_printf ("%sT00:00:00Z", value);
+ g_value_set_int64 (gvalue, tracker_string_to_date (datetime, NULL, error));
+ g_free (datetime);
+ break;
case TRACKER_PROPERTY_TYPE_DATETIME:
g_value_init (gvalue, TRACKER_TYPE_DATE_TIME);
tracker_date_time_set_from_string (gvalue, value, error);
diff --git a/src/libtracker-data/tracker-sparql-expression.vala b/src/libtracker-data/tracker-sparql-expression.vala
index 76f6b93..1f39719 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -71,7 +71,7 @@ class Tracker.Sparql.Expression : Object {
}
bool maybe_numeric (PropertyType type) {
- return (type == PropertyType.INTEGER || type == PropertyType.DOUBLE || type == PropertyType.DATETIME || type == PropertyType.UNKNOWN);
+ return (type == PropertyType.INTEGER || type == PropertyType.DOUBLE || type == PropertyType.DATE || type == PropertyType.DATETIME || type == PropertyType.UNKNOWN);
}
void append_collate (StringBuilder sql) {
@@ -287,6 +287,11 @@ class Tracker.Sparql.Expression : Object {
sql.insert (begin, "CASE ");
sql.append (" WHEN 1 THEN 'true' WHEN 0 THEN 'false' ELSE NULL END");
break;
+ case PropertyType.DATE:
+ // ISO 8601 format
+ sql.insert (begin, "strftime (\"%Y-%m-%d\", ");
+ sql.append (", \"unixepoch\")");
+ break;
case PropertyType.DATETIME:
// ISO 8601 format
sql.insert (begin, "strftime (\"%Y-%m-%dT%H:%M:%SZ\", ");
@@ -965,6 +970,7 @@ class Tracker.Sparql.Expression : Object {
case PropertyType.INTEGER:
case PropertyType.BOOLEAN:
case PropertyType.DOUBLE:
+ case PropertyType.DATE:
case PropertyType.DATETIME:
if (query.no_cache) {
sql.append (escape_sql_string_literal (literal));
@@ -1224,6 +1230,13 @@ class Tracker.Sparql.Expression : Object {
// trigger string => datetime conversion
query.bindings.last ().data.data_type = PropertyType.DATETIME;
}
+ } else if ((op1type == PropertyType.DATE && op2type == PropertyType.STRING)
+ || (op1type == PropertyType.STRING && op2type == PropertyType.DATE)) {
+ // TODO: improve performance (linked list)
+ if (query.bindings.length () == n_bindings + 1) {
+ // trigger string => date conversion
+ query.bindings.last ().data.data_type = PropertyType.DATE;
+ }
}
return PropertyType.BOOLEAN;
}
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 6dc01c6..0c9f453 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -494,6 +494,8 @@ public class Tracker.Sparql.Query : Object {
} else {
throw new Sparql.Error.TYPE ("`%s' is not a valid boolean".printf (binding.literal));
}
+ } else if (binding.data_type == PropertyType.DATE) {
+ stmt.bind_int (i, string_to_date (binding.literal + "T00:00:00Z", null));
} else if (binding.data_type == PropertyType.DATETIME) {
stmt.bind_int (i, string_to_date (binding.literal, null));
} else if (binding.data_type == PropertyType.INTEGER) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]