server/test/unittest_rql2sql.py
branchstable
changeset 3987 f85ef29f6214
parent 3852 03121ca1f85e
child 3998 94cc7cad3d2d
child 4212 ab6573088b4a
--- a/server/test/unittest_rql2sql.py	Thu Dec 03 11:39:31 2009 +0100
+++ b/server/test/unittest_rql2sql.py	Thu Dec 03 12:44:30 2009 +0100
@@ -1043,7 +1043,12 @@
 UNION ALL
 SELECT _S.cw_in_state
 FROM cw_Note AS _S
-WHERE _S.cw_eid=0 AND _S.cw_in_state IS NOT NULL''')
+WHERE _S.cw_eid=0 AND _S.cw_in_state IS NOT NULL'''),
+
+    ('Any X WHERE NOT Y for_user X, X eid 123',
+     '''SELECT 123
+WHERE NOT EXISTS(SELECT 1 FROM cw_CWProperty AS _Y WHERE _Y.cw_for_user=123)
+'''),
 
     ]
 
@@ -1552,7 +1557,16 @@
         self.o = SQLGenerator(schema, dbms_helper)
 
     def _norm_sql(self, sql):
-        return sql.strip().replace(' ILIKE ', ' LIKE ').replace('TRUE', '1').replace('FALSE', '0')
+        sql = sql.strip().replace(' ILIKE ', ' LIKE ').replace('TRUE', '1').replace('FALSE', '0')
+        newsql = []
+        latest = None
+        for line in sql.splitlines(False):
+            firstword = line.split(None, 1)[0]
+            if firstword == 'WHERE' and latest == 'SELECT':
+                newsql.append('FROM (SELECT 1) AS _T')
+            newsql.append(line)
+            latest = firstword
+        return '\n'.join(newsql)
 
     def test_from_clause_needed(self):
         queries = [("Any 1 WHERE EXISTS(T is CWGroup, T name 'managers')",