[tracker/subqueries] Fix nested subqueries
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/subqueries] Fix nested subqueries
- Date: Sun, 6 Dec 2009 20:49:53 +0000 (UTC)
commit 47088edf3d2ef171db388962885d2aa37d2badd6
Author: Jürg Billeter <j bitron ch>
Date: Fri Dec 4 19:36:09 2009 +0100
Fix nested subqueries
src/libtracker-data/tracker-sparql-query.vala | 47 +++++++++++++++----------
1 files changed, 28 insertions(+), 19 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index cb73a55..5422ca8 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -268,7 +268,7 @@ public class Tracker.SparqlQuery : Object {
List<Variable> pattern_variables;
HashTable<Variable,VariableBindingList> pattern_var_map;
- HashTable<string,Variable> outer_var_map;
+ List<unowned HashTable<string,Variable>> outer_var_maps;
// All SPARQL variables within a subgraph pattern (used by UNION)
HashTable<Variable,int> subgraph_var_set;
@@ -668,6 +668,11 @@ public class Tracker.SparqlQuery : Object {
} else {
translate_expression_as_string (sql);
}
+ if (accept (SparqlTokenType.AS)) {
+ expect (SparqlTokenType.VAR);
+ string variable_name = get_last_string ().substring (1);
+ sql.append_printf (" AS %s", get_variable (variable_name).sql_expression);
+ }
}
}
@@ -1797,7 +1802,8 @@ public class Tracker.SparqlQuery : Object {
if (current () == SparqlTokenType.SELECT) {
// FIXME ensure that inner variables are only exported if selected
- outer_var_map = var_map;
+ outer_var_maps.append (var_map);
+ var outer_var_map = var_map;
var outer_predicate_variable_map = predicate_variable_map;
var outer_used_sql_identifiers = used_sql_identifiers;
begin_query ();
@@ -2527,23 +2533,26 @@ public class Tracker.SparqlQuery : Object {
VariableBindingList? get_variable_binding_list (Variable variable) {
var binding_list = pattern_var_map.lookup (variable);
- if (binding_list == null && outer_var_map != null) {
- // in scalar subquery: check variables of outer query
- var outer_var = outer_var_map.lookup (variable.name);
- if (outer_var != null) {
- // capture outer variable
- var binding = new VariableBinding ();
- binding.data_type = outer_var.binding.data_type;
- binding.variable = get_variable (variable.name);
- binding.type = outer_var.binding.type;
- binding.sql_expression = outer_var.sql_expression;
- binding_list = new VariableBindingList ();
- pattern_variables.append (binding.variable);
- pattern_var_map.insert (binding.variable, binding_list);
+ if (binding_list == null && outer_var_maps != null) {
+ // in scalar subquery: check variables of outer queries
+ foreach (unowned HashTable<string,Variable> outer_var_map in outer_var_maps) {
+ var outer_var = outer_var_map.lookup (variable.name);
+ if (outer_var != null) {
+ // capture outer variable
+ var binding = new VariableBinding ();
+ binding.data_type = outer_var.binding.data_type;
+ binding.variable = get_variable (variable.name);
+ binding.type = outer_var.binding.type;
+ binding.sql_expression = outer_var.sql_expression;
+ binding_list = new VariableBindingList ();
+ pattern_variables.append (binding.variable);
+ pattern_var_map.insert (binding.variable, binding_list);
- subgraph_var_set.insert (binding.variable, VariableState.BOUND);
- binding_list.list.append (binding);
- binding.variable.binding = binding;
+ subgraph_var_set.insert (binding.variable, VariableState.BOUND);
+ binding_list.list.append (binding);
+ binding.variable.binding = binding;
+ break;
+ }
}
}
return binding_list;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]