backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 08 Mar 2010 18:07:20 +0100
changeset 502 f35e05bc3df6
parent 501 d166d9ece0b7 (current diff)
parent 499 583427b3646c (diff)
child 503 7abe7da80684
backport stable
--- a/__init__.py	Mon Mar 08 18:07:02 2010 +0100
+++ b/__init__.py	Mon Mar 08 18:07:20 2010 +0100
@@ -128,6 +128,7 @@
         for subquery in select.with_:
             for select in subquery.query.children:
                 self._simplify(select)
+        rewritten = False
         for var in select.defined_vars.values():
             stinfo = var.stinfo
             if stinfo['constnode'] and not stinfo['blocsimplification']:
@@ -176,9 +177,10 @@
                         rhs = copy_uid_node(select, rhs, vconsts)
                         vref.parent.replace(vref, rhs)
                 del select.defined_vars[var.name]
+                rewritten = True
                 if vconsts:
                     select.stinfo['rewritten'][var.name] = vconsts
-        if select.stinfo['rewritten'] and select.solutions:
+        if rewritten and select.solutions:
             select.clean_solutions()
 
     def compare(self, rqlstring1, rqlstring2):
--- a/analyze.py	Mon Mar 08 18:07:02 2010 +0100
+++ b/analyze.py	Mon Mar 08 18:07:20 2010 +0100
@@ -368,12 +368,15 @@
     def visit(self, node, uid_func_mapping=None, kwargs=None, debug=False):
         # FIXME: not thread safe
         self.debug = debug
-        if uid_func_mapping:
+        if uid_func_mapping is not None:
             assert len(uid_func_mapping) <= 1
             self.uid_func_mapping = uid_func_mapping
             self.uid_func = uid_func_mapping.values()[0]
         self.kwargs = kwargs
         self._visit(node)
+        if uid_func_mapping is not None:
+            self.uid_func_mapping = None
+            self.uid_func = None
 
     def visit_union(self, node):
         for select in node.children:
--- a/nodes.py	Mon Mar 08 18:07:02 2010 +0100
+++ b/nodes.py	Mon Mar 08 18:07:20 2010 +0100
@@ -945,7 +945,7 @@
 
 class ColumnAlias(Referenceable):
     __slots__ = ('colnum', 'query',
-                 '_q_sql', '_q_sqltable') # XXX ginco specific
+                 '_q_sql', '_q_sqltable') # XXX cubicweb specific
     def __init__(self, alias, colnum, query=None):
         super(ColumnAlias, self).__init__(alias)
         self.colnum = int(colnum)
--- a/test/unittest_compare.py	Mon Mar 08 18:07:02 2010 +0100
+++ b/test/unittest_compare.py	Mon Mar 08 18:07:20 2010 +0100
@@ -19,10 +19,10 @@
 
 class RQLCompareClassTest(TestCase):
     """ Compare RQL strings """
-    
+
     def setUp(self):
         self.h = RQLHelper(DummySchema(), None)
-        
+
     def _compareEquivalent(self,r1,r2):
         """fails if the RQL strings r1 and r2 are equivalent"""
         self.skip('broken')
@@ -37,7 +37,7 @@
     # equivalent queries ##################################################
 
     def test_same_request_simple(self):
-        r = "Any X where X is Note ;"
+        r = "Any X WHERE X is Note ;"
         self._compareEquivalent(r, r)
 
     def test_same_request_diff_names(self):
@@ -46,42 +46,42 @@
         self._compareEquivalent(r1, r2)
 
     def test_same_request_diff_names_simple(self):
-        r1 = "Any X where X is Note ;"
-        r2 = "Any Y where Y is Note ;"
+        r1 = "Any X WHERE X is Note ;"
+        r2 = "Any Y WHERE Y is Note ;"
         self._compareEquivalent(r1, r2)
 
     def test_same_request_any(self):
-        r1 = "Any X where X is Note ;"
+        r1 = "Any X WHERE X is Note ;"
         r2 = "Note X ;"
         self._compareEquivalent(r1, r2)
 
     def test_same_request_any_diff_names(self):
-        r1 = "Any X where X is Note ;"
+        r1 = "Any X WHERE X is Note ;"
         r2 = "Note Y ;"
         self._compareEquivalent(r1, r2)
 
     def test_same_request_complex(self):
-        r = "Any N, N2 where N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
+        r = "Any N, N2 WHERE N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
         self._compareEquivalent(r, r)
 
     def test_same_request_comma_and(self):
-        r1 = "Any N, N2 where N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
-        r2 = "Any N, N2 where N is Note AND N2 is Note AND N a_faire_par P1 AND P1 nom 'jphc' AND N2 a_faire_par P2 AND P2 nom 'ocy' ;"
+        r1 = "Any N, N2 WHERE N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
+        r2 = "Any N, N2 WHERE N is Note AND N2 is Note AND N a_faire_par P1 AND P1 nom 'jphc' AND N2 a_faire_par P2 AND P2 nom 'ocy' ;"
         self._compareEquivalent(r1, r2)
 
     def test_same_request_diff_names_complex(self):
-        r1 = "Any N, N2 where N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
-        r2 = "Any Y, X  where X is Note, Y is Note,  X a_faire_par A1, A1 nom 'ocy',  Y a_faire_par A2,  A2 nom 'jphc' ;"
+        r1 = "Any N, N2 WHERE N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
+        r2 = "Any Y, X  WHERE X is Note, Y is Note,  X a_faire_par A1, A1 nom 'ocy',  Y a_faire_par A2,  A2 nom 'jphc' ;"
         self._compareEquivalent(r1, r2)
 
     def test_same_request_diff_order(self):
-        r1 = "Any N, N2 where N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
-        r2 = "Any N, N2 where N2 is Note, N is Note, N a_faire_par P1, N2 a_faire_par P2, P2 nom 'ocy', P1 nom 'jphc' ;"
+        r1 = "Any N, N2 WHERE N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
+        r2 = "Any N, N2 WHERE N2 is Note, N is Note, N a_faire_par P1, N2 a_faire_par P2, P2 nom 'ocy', P1 nom 'jphc' ;"
         self._compareEquivalent(r1, r2)
 
     def test_same_request_diff_order_diff_names(self):
-        r1 = "Any N, N2 where N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
-        r2 = "Any Y, X  where X is Note, X a_faire_par P1, P1 nom 'ocy', Y is Note,    Y a_faire_par P2,  P2 nom 'jphc' ;"
+        r1 = "Any N, N2 WHERE N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
+        r2 = "Any Y, X  WHERE X is Note, X a_faire_par P1, P1 nom 'ocy', Y is Note,    Y a_faire_par P2,  P2 nom 'jphc' ;"
         self._compareEquivalent(r1, r2)
 
     def test_same_request_with_comparison(self):
@@ -117,8 +117,8 @@
     # non equivalent queries ##################################################
 
     def test_diff_request(self):
-        r1 = "Any N,  N2 where N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
-        r2 = "Any X where X is Note ;"
+        r1 = "Any N, N2 WHERE N is Note, N2 is Note, N a_faire_par P1, P1 nom 'jphc', N2 a_faire_par P2, P2 nom 'ocy' ;"
+        r2 = "Any X WHERE X is Note ;"
         self._compareNotEquivalent(r1,r2)
 
     def test_diff_request_and_or(self):
@@ -132,28 +132,28 @@
         self._compareNotEquivalent(r1, r2)
 
     def test_diff_request_non_selected_var(self):
-        r1 = "Any X, D where X is Note, X creation_date D ;"
-        r2 = "Any X where X is Note, X creation_date D ;"
+        r1 = "Any X, D WHERE X is Note, X creation_date D ;"
+        r2 = "Any X WHERE X is Note, X creation_date D ;"
         self._compareNotEquivalent(r1, r2)
 
     def test_diff_request_aggregat(self):
-        r1 = "Any X, D where X is Note, X creation_date D ;"
-        r2 = "Any X, MAX(D) where X is Note, X creation_date D ;"
+        r1 = "Any X, D WHERE X is Note, X creation_date D ;"
+        r2 = "Any X, MAX(D) WHERE X is Note, X creation_date D ;"
         self._compareNotEquivalent(r1, r2)
 
     def test_diff_request_group(self):
-        r1 = "Any X where X is Note GROUPBY X ;"
-        r2 = "Any X where X is Note;"
+        r1 = "Any X GROUPBY X WHERE X is Note;"
+        r2 = "Any X WHERE X is Note;"
         self._compareNotEquivalent(r1, r2)
 
     def test_diff_request_sort(self):
-        r1 = "Any X where X is Note ORDERBY X ;"
-        r2 = "Any X where X is Note;"
+        r1 = "Any X ORDERBY X WHERE X is Note;"
+        r2 = "Any X WHERE X is Note;"
         self._compareNotEquivalent(r1, r2)
 
     def test_diff_request_not(self):
-        r1 = "Any X where not X is Note ;"
-        r2 = "Any X where X is Note;"
+        r1 = "Any X WHERE NOT X is Note ;"
+        r2 = "Any X WHERE X is Note;"
         self._compareNotEquivalent(r1, r2)
 
     def test_diff_request_not_in_or(self):