Commits

Pierre Carbonnelle committed 75fef4e

Fix variable extraction in unsafe in-line queries

Comments (0)

Files changed (2)

pyDatalog/examples/test.py

     assert unsafe(3, 1) == [()] #this query is safe
     assert unsafe(3, Y) == [(1,)] #this query is safe
     assert unsafe(X, 1) == True # X is undefined
-    assert (unsafe(X,1) >= X) == None
+    assert (unsafe(X,1) >= X) == True
     assert (unsafe(2,Y) >= Y) == 1
-    assert (unsafe(X,Y) >= Y) == None
+    assert (unsafe(X,Y) >= Y) == True
     
     unsafe2(X) <= lower(3,2)
     assert unsafe2(3) == []

pyDatalog/pyParser.py

                 raise util.DatalogError("Syntax error: Incorrect use of aggregation.", None, None)
             if isinstance(arg, Variable):
                 arg.todo = self
-                del arg._data[:] # reset the variable. For use in in-line queries
+                arg._data = [] # reset the variable. For use in in-line queries
             self.terms.append(Expression._pyD_for(arg))
                             
         for term in self.terms:
         literal.todo, self.todo = None, None
         if not Thread_storage.ProgramMode and self._data: 
             if self._data is True:
+                for arg in literal.terms:
+                    if isinstance(arg, Variable):
+                        arg._data = True
+                        arg.todo = None
                 return True
             transposed = list(zip(*(self._data))) # transpose result
             result = []