[rql2sql] fix generated sql for eid comparison. closes #1638695 stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 19 May 2011 09:40:44 +0200
branchstable
changeset 7394 d11d88bd08e8
parent 7393 7824d61f41a2
child 7395 09ffcc04bd21
[rql2sql] fix generated sql for eid comparison. closes #1638695
server/sources/rql2sql.py
server/test/unittest_querier.py
--- a/server/sources/rql2sql.py	Wed May 18 16:05:11 2011 +0200
+++ b/server/sources/rql2sql.py	Thu May 19 09:40:44 2011 +0200
@@ -1023,6 +1023,9 @@
             # attribute relation
             if rtype == 'has_text':
                 sql = self._visit_has_text_relation(relation)
+            elif rtype == 'eid':
+                sql =  '%s%s' % (relation.children[0].variable.accept(self),
+                                 relation.children[1].accept(self))
             else:
                 rhs_vars = rhs.get_nodes(VariableRef)
                 if rhs_vars:
--- a/server/test/unittest_querier.py	Wed May 18 16:05:11 2011 +0200
+++ b/server/test/unittest_querier.py	Thu May 19 09:40:44 2011 +0200
@@ -1435,6 +1435,13 @@
     def test_nonregr_final_norestr(self):
         self.assertRaises(BadRQLQuery, self.execute, 'Date X')
 
+    def test_nonregr_eid_cmp(self):
+        peid1 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0]
+        peid2 = self.execute("INSERT Personne X: X nom 'bidule'")[0][0]
+        rset = self.execute('Any X,Y WHERE X is Personne, Y is Personne, X nom XD, Y nom XD, X eid Z, Y eid > Z')
+        self.assertEqual(rset.rows, [[peid1, peid2]])
+        rset = self.execute('Any X,Y WHERE X nom XD, Y nom XD, X eid Z, Y eid > Z')
+        self.assertEqual(rset.rows, [[peid1, peid2]])
 
 if __name__ == '__main__':
     unittest_main()