Commit 1125ad20 authored by Jürg Billeter's avatar Jürg Billeter

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.
parent e72dd546
......@@ -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>
......@@ -402,6 +403,30 @@ function_sparql_uri_is_descendant (sqlite3_context *context,
sqlite3_result_int (context, match);
}
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,
......@@ -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);
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment