[tracker: 3/5] libtracker-data: Use tracker_date_to_string instead of SQLite's strftime
- From: JÃrg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker: 3/5] libtracker-data: Use tracker_date_to_string instead of SQLite's strftime
- Date: Thu, 1 Dec 2011 18:12:04 +0000 (UTC)
commit 248a210a6f4a82dfb11f971a9a19d3bebd7c2f57
Author: JÃrg Billeter <j bitron ch>
Date: Thu Dec 1 15:58:02 2011 +0100
libtracker-data: Use tracker_date_to_string instead of SQLite's strftime
This fixes an off by 1 error for timestamps before 1970.
Fixes NB#293344.
src/libtracker-data/tracker-db-interface-sqlite.c | 29 ++++++++++++++++++++
src/libtracker-data/tracker-sparql-expression.vala | 4 +-
2 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 45e973b..7e8779d 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -26,6 +26,7 @@
#include <math.h>
#include <errno.h>
+#include <libtracker-common/tracker-date-time.h>
#include <libtracker-common/tracker-locale.h>
#include <libtracker-sparql/tracker-sparql.h>
@@ -403,6 +404,30 @@ function_sparql_uri_is_descendant (sqlite3_context *context,
}
static void
+function_sparql_format_time (sqlite3_context *context,
+ int argc,
+ sqlite3_value *argv[])
+{
+ gdouble seconds;
+ gchar *str;
+
+ if (argc != 1) {
+ sqlite3_result_error (context, "Invalid argument count", -1);
+ return;
+ }
+
+ if (sqlite3_value_type (argv[0]) == SQLITE_NULL) {
+ sqlite3_result_null (context);
+ return;
+ }
+
+ seconds = sqlite3_value_double (argv[0]);
+ str = tracker_date_to_string (seconds);
+
+ sqlite3_result_text (context, str, -1, g_free);
+}
+
+static void
function_sparql_cartesian_distance (sqlite3_context *context,
int argc,
sqlite3_value *argv[])
@@ -863,6 +888,10 @@ open_database (TrackerDBInterface *db_interface,
db_interface, &function_sparql_case_fold,
NULL, NULL);
+ sqlite3_create_function (db_interface->db, "SparqlFormatTime", 1, SQLITE_ANY,
+ db_interface, &function_sparql_format_time,
+ NULL, NULL);
+
sqlite3_extended_result_codes (db_interface->db, 0);
sqlite3_busy_timeout (db_interface->db, 100000);
}
diff --git a/src/libtracker-data/tracker-sparql-expression.vala b/src/libtracker-data/tracker-sparql-expression.vala
index 720cb08..668f03d 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -322,8 +322,8 @@ class Tracker.Sparql.Expression : Object {
break;
case PropertyType.DATETIME:
// ISO 8601 format
- sql.insert (begin, "strftime (\"%Y-%m-%dT%H:%M:%fZ\", ");
- sql.append (", \"unixepoch\")");
+ sql.insert (begin, "SparqlFormatTime (");
+ sql.append (")");
break;
default:
// let sqlite convert the expression to string
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]