[tracker/wip/garnacho/sparql1.1: 67/69] libtracker-data: Resolve variables looking up the binding if we're in same context



commit e825bf2275f16319032ba39aed4b10d0a75c518f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Oct 18 22:04:21 2015 +0200

    libtracker-data: Resolve variables looking up the binding if we're in same context
    
    This is necessary for BIND support, as the variables looked up to add the
    BIND alias likely belong to the same scope that we're currently building.
    This results in SQL like (very simplified, and shortened):
    
      SELECT "nie:url" AS "1_u", "1_u" AS "2_u" ...
    
    The second "1_u" can't be looked up yet in this scope (only on the WHERE
    clause, or a wrapping SELECT), so ends up as the string itself. With this
    change, this kind of queries will result in (shortened again):
    
      SELECT "nie:url" AS "1_u", "nie:url" AS "2_u" ...
    
    Which is legal, and results in the expected values assigned to the BIND
    alias.

 src/libtracker-data/tracker-sparql-expression.vala |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-expression.vala 
b/src/libtracker-data/tracker-sparql-expression.vala
index c6062b8..ef2954c 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -1142,7 +1142,15 @@ class Tracker.Sparql.Expression : Object {
                        next ();
                        string variable_name = get_last_string ().substring (1);
                        var variable = context.get_variable (variable_name);
-                       sql.append (variable.sql_expression);
+
+                       if (context == variable.origin_context) {
+                               if (variable.binding == null)
+                                       throw get_error ("use of undefined variable `%s'".printf 
(variable.name));
+
+                               sql.append (variable.binding.sql_expression);
+                       } else {
+                               sql.append (variable.sql_expression);
+                       }
 
                        if (variable.binding == null) {
                                return PropertyType.UNKNOWN;


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