[tracker/subqueries-for-master: 12/14] SPARQL: Add support for compositional subqueries
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/subqueries-for-master: 12/14] SPARQL: Add support for compositional subqueries
- Date: Wed, 9 Dec 2009 14:42:14 +0000 (UTC)
commit aceffb7a828e1d7c8b8f91bfb5cdef170ca88d7a
Author: Jürg Billeter <j bitron ch>
Date: Wed Dec 2 18:03:16 2009 +0200
SPARQL: Add support for compositional subqueries
src/libtracker-data/tracker-sparql-query.vala | 40 ++++++++++++++++++------
1 files changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 48db214..2f1a3db 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -610,10 +610,9 @@ public class Tracker.SparqlQuery : Object {
}
}
- void translate_select_expression (StringBuilder sql) throws SparqlError {
+ void translate_select_expression (StringBuilder sql, bool subquery) throws SparqlError {
long begin = sql.len;
var type = PropertyType.UNKNOWN;
-
if (accept (SparqlTokenType.COUNT)) {
sql.append ("COUNT(");
translate_expression (sql);
@@ -649,7 +648,9 @@ public class Tracker.SparqlQuery : Object {
type = translate_expression (sql);
}
- convert_expression_to_string (sql, type, begin);
+ if (!subquery) {
+ convert_expression_to_string (sql, type, begin);
+ }
if (accept (SparqlTokenType.AS)) {
string variable_name;
@@ -676,11 +677,20 @@ public class Tracker.SparqlQuery : Object {
DBResultSet? execute_select () throws Error {
// SELECT query
- var pattern_sql = new StringBuilder ();
begin_query ();
// build SQL
var sql = new StringBuilder ();
+ translate_select (sql);
+
+ expect (SparqlTokenType.EOF);
+
+ return exec_sql (sql.str);
+ }
+
+ void translate_select (StringBuilder sql, bool subquery = false) throws Error {
+ var pattern_sql = new StringBuilder ();
+
sql.append ("SELECT ");
expect (SparqlTokenType.SELECT);
@@ -715,7 +725,12 @@ public class Tracker.SparqlQuery : Object {
} else {
first = false;
}
- append_expression_as_string (sql, variable.sql_expression, variable.binding.data_type);
+ if (subquery) {
+ // don't convert to string in subqueries
+ sql.append (variable.sql_expression);
+ } else {
+ append_expression_as_string (sql, variable.sql_expression, variable.binding.data_type);
+ }
}
} else {
while (true) {
@@ -725,7 +740,7 @@ public class Tracker.SparqlQuery : Object {
first = false;
}
- translate_select_expression (sql);
+ translate_select_expression (sql, subquery);
switch (current ()) {
case SparqlTokenType.FROM:
@@ -823,10 +838,6 @@ public class Tracker.SparqlQuery : Object {
binding.data_type = PropertyType.INTEGER;
bindings.append (binding);
}
-
- expect (SparqlTokenType.EOF);
-
- return exec_sql (sql.str);
}
void translate_expression_as_order_condition (StringBuilder sql) throws SparqlError {
@@ -2241,6 +2252,15 @@ public class Tracker.SparqlQuery : Object {
void translate_group_graph_pattern (StringBuilder sql) throws Error {
expect (SparqlTokenType.OPEN_BRACE);
+ if (current () == SparqlTokenType.SELECT) {
+ // FIXME ensure that inner variables are only exported if selected
+
+ translate_select (sql, true);
+
+ expect (SparqlTokenType.CLOSE_BRACE);
+ return;
+ }
+
SourceLocation[] filters = { };
bool in_triples_block = false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]