[tracker/wip/garnacho/sparql1.1: 64/69] 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: 64/69] libtracker-data: Add support for NOW() builtin function
- Date: Mon, 19 Oct 2015 12:37:35 +0000 (UTC)
commit 1ab3cbcff824ee0a1f2a54f28f5e578666b3eec9
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 247a066..c6062b8 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -1349,6 +1349,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.SECONDS:
next ();
expect (SparqlTokenType.OPEN_PARENS);
diff --git a/src/libtracker-data/tracker-sparql-scanner.vala b/src/libtracker-data/tracker-sparql-scanner.vala
index 2fbbcf6..f23ba0a 100644
--- a/src/libtracker-data/tracker-sparql-scanner.vala
+++ b/src/libtracker-data/tracker-sparql-scanner.vala
@@ -129,7 +129,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':
@@ -1071,6 +1080,7 @@ public enum Tracker.SparqlTokenType {
MONTH,
NAMED,
NOT,
+ NOW,
NULL, /* Non-standard in SPARQL spec */
OFFSET,
OP_AND,
@@ -1194,6 +1204,7 @@ public enum Tracker.SparqlTokenType {
case MONTH: return "`MONTH'";
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]