[tracker/sparql-in] libtracker-data: Support for SPARQL 1.1's IN operator
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/sparql-in] libtracker-data: Support for SPARQL 1.1's IN operator
- Date: Fri, 30 Jul 2010 09:17:17 +0000 (UTC)
commit 6c83d3270c817f54137db1dd7cf169aedd62feca
Author: Philip Van Hoof <philip codeminded be>
Date: Fri Jul 30 11:14:50 2010 +0200
libtracker-data: Support for SPARQL 1.1's IN operator
src/libtracker-data/tracker-sparql-expression.vala | 15 +++++++++++++++
src/libtracker-data/tracker-sparql-scanner.vala | 15 +++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-expression.vala b/src/libtracker-data/tracker-sparql-expression.vala
index 4325fcd..d8e6f30 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -1088,6 +1088,19 @@ class Tracker.Sparql.Expression : Object {
return PropertyType.BOOLEAN;
}
+ PropertyType translate_in (StringBuilder sql) throws SparqlError {
+ expect (SparqlTokenType.OPEN_PARENS);
+ sql.append ("IN (");
+ translate_expression_as_string (sql);
+ while (accept (SparqlTokenType.COMMA)) {
+ sql.append (", ");
+ translate_expression_as_string (sql);
+ }
+ expect (SparqlTokenType.CLOSE_PARENS);
+ sql.append (")");
+ return PropertyType.BOOLEAN;
+ }
+
PropertyType translate_relational_expression (StringBuilder sql) throws SparqlError {
long begin = sql.len;
// TODO: improve performance (linked list)
@@ -1105,6 +1118,8 @@ class Tracker.Sparql.Expression : Object {
return process_relational_expression (sql, begin, n_bindings, optype, " <= ");
} else if (accept (SparqlTokenType.OP_GT)) {
return process_relational_expression (sql, begin, n_bindings, optype, " > ");
+ } else if (accept (SparqlTokenType.OP_IN)) {
+ return translate_in (sql);
}
return optype;
}
diff --git a/src/libtracker-data/tracker-sparql-scanner.vala b/src/libtracker-data/tracker-sparql-scanner.vala
index d803045..152bd04 100644
--- a/src/libtracker-data/tracker-sparql-scanner.vala
+++ b/src/libtracker-data/tracker-sparql-scanner.vala
@@ -59,6 +59,10 @@ public class Tracker.SparqlScanner : Object {
case 'b':
if (matches (begin, "BY")) return SparqlTokenType.BY;
break;
+ case 'i':
+ case 'I':
+ if (matches (begin, "IN")) return SparqlTokenType.OP_IN;
+ break;
}
break;
case 3:
@@ -590,6 +594,15 @@ public class Tracker.SparqlScanner : Object {
}
}
break;
+ case 'i':
+ case 'I':
+ type = SparqlTokenType.OP_IN;
+ current++;
+ if (current < end && (current[0] == 'n' || current[0] == 'N')) {
+ type = SparqlTokenType.OP_IN;
+ current++;
+ }
+ break;
case '>':
type = SparqlTokenType.OP_GT;
current++;
@@ -863,6 +876,7 @@ public enum Tracker.SparqlTokenType {
OP_NE,
OP_NEG,
OP_OR,
+ OP_IN,
OPEN_BRACE,
OPEN_BRACKET,
OPEN_PARENS,
@@ -953,6 +967,7 @@ public enum Tracker.SparqlTokenType {
case OP_NE: return "`!='";
case OP_NEG: return "`!'";
case OP_OR: return "`||'";
+ case OP_IN: return "`IN'";
case OPEN_BRACE: return "`{'";
case OPEN_BRACKET: return "`['";
case OPEN_PARENS: return "`('";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]