[tracker/wip/garnacho/sparql1.1: 17/23] libtracker-data: Add support for NOW() builtin function
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/garnacho/sparql1.1: 17/23] libtracker-data: Add support for NOW() builtin function
- Date: Thu, 20 Aug 2015 08:54:06 +0000 (UTC)
commit 3634e54d333c153a7e32f6c73c1ef58e7f35fd07
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Jul 29 01:07:03 2015 +0200
libtracker-data: Add support for NOW() builtin function
This function is defined in Sparql 1.1 query language recommendation,
http://www.w3.org/TR/sparql11-query/#func-now
src/libtracker-data/tracker-sparql-expression.vala | 6 ++++++
src/libtracker-data/tracker-sparql-scanner.vala | 13 ++++++++++++-
2 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-expression.vala
b/src/libtracker-data/tracker-sparql-expression.vala
index ea5c22c..2da4b1f 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -1346,6 +1346,12 @@ class Tracker.Sparql.Expression : Object {
expect (SparqlTokenType.CLOSE_PARENS);
sql.append ("SparqlRand()");
return PropertyType.DOUBLE;
+ case SparqlTokenType.NOW:
+ next ();
+ expect (SparqlTokenType.OPEN_PARENS);
+ expect (SparqlTokenType.CLOSE_PARENS);
+ sql.append ("strftime('%s', 'now')");
+ return PropertyType.DATETIME;
case SparqlTokenType.GROUP_CONCAT:
next ();
sql.append ("GROUP_CONCAT(");
diff --git a/src/libtracker-data/tracker-sparql-scanner.vala b/src/libtracker-data/tracker-sparql-scanner.vala
index fdd0898..0e73fba 100644
--- a/src/libtracker-data/tracker-sparql-scanner.vala
+++ b/src/libtracker-data/tracker-sparql-scanner.vala
@@ -121,7 +121,16 @@ public class Tracker.SparqlScanner : Object {
break;
case 'N':
case 'n':
- if (matches (begin, "NOT")) return SparqlTokenType.NOT;
+ switch (begin[2]) {
+ case 'T':
+ case 't':
+ if (matches (begin, "NOT")) return SparqlTokenType.NOT;
+ break;
+ case 'W':
+ case 'w':
+ if (matches (begin, "NOW")) return SparqlTokenType.NOW;
+ break;
+ }
break;
case 'S':
case 's':
@@ -1018,6 +1027,7 @@ public enum Tracker.SparqlTokenType {
MINUS,
NAMED,
NOT,
+ NOW,
NULL, /* Non-standard in SPARQL spec */
OFFSET,
OP_AND,
@@ -1131,6 +1141,7 @@ public enum Tracker.SparqlTokenType {
case MINUS: return "`-'";
case NAMED: return "`NAMED'";
case NOT: return "`NOT'";
+ case NOW: return "`NOW'";
case OFFSET: return "`OFFSET'";
case OP_AND: return "`&&'";
case OP_EQ: return "`='";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]