[tracker/wip/carlosg/grilo-fixes: 7/9] libtracker-data: Ensure subselects propagate the SelectClause variables



commit 12abe96bdca751585d923ea2a6b6c8e162606b4d
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon May 25 13:44:15 2020 +0200

    libtracker-data: Ensure subselects propagate the SelectClause variables
    
    Those are not being propagated upwards, which makes things like:
    
    SELECT ?u { { SELECT ?a {...} } UNION { SELECT ?b {... } }
    
    broken, as we don't have the variables to UNION properly.

 src/libtracker-data/tracker-sparql.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 5e694d5b6..1c04cc616 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -2370,8 +2370,21 @@ tracker_sparql_add_select_var (TrackerSparql       *sparql,
                               const gchar         *name,
                               TrackerPropertyType  type)
 {
-       g_ptr_array_add (sparql->var_names, g_strdup (name));
-       g_array_append_val (sparql->var_types, type);
+       if (sparql->current_state.select_context == sparql->context) {
+               /* Topmost select context */
+               g_ptr_array_add (sparql->var_names, g_strdup (name));
+               g_array_append_val (sparql->var_types, type);
+       } else {
+               TrackerContext *parent;
+               TrackerVariable *var;
+
+               /* Propagate the variable upwards */
+               parent = tracker_context_get_parent (sparql->current_state.select_context);
+               if (parent) {
+                       var = _ensure_variable (sparql, name);
+                       tracker_context_add_variable_ref (parent, var);
+               }
+       }
 }
 
 static gboolean
@@ -2391,8 +2404,7 @@ handle_as (TrackerSparql        *sparql,
        _append_string_printf (sparql, "AS %s ",
                               tracker_variable_get_sql_expression (var));
 
-       if (sparql->current_state.select_context == sparql->context)
-               tracker_sparql_add_select_var (sparql, var->name, type);
+       tracker_sparql_add_select_var (sparql, var->name, type);
 
        return TRUE;
 }
@@ -2494,7 +2506,7 @@ translate_SelectClause (TrackerSparql  *sparql,
                                if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_AS)) {
                                        if (!handle_as (sparql, binding->data_type, error))
                                                return FALSE;
-                               } else if (sparql->current_state.select_context == sparql->context) {
+                               } else {
                                        tracker_sparql_add_select_var (sparql, var->name, binding->data_type);
                                }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]