server/test/unittest_rql2sql.py
changeset 3998 94cc7cad3d2d
parent 3890 d7a270f50f54
parent 3987 f85ef29f6214
child 4191 01638461d4b0
equal deleted inserted replaced
3895:92ead039d3d0 3998:94cc7cad3d2d
  1042 FROM cw_CWUser AS _S
  1042 FROM cw_CWUser AS _S
  1043 WHERE _S.cw_eid=0 AND _S.cw_in_state IS NOT NULL
  1043 WHERE _S.cw_eid=0 AND _S.cw_in_state IS NOT NULL
  1044 UNION ALL
  1044 UNION ALL
  1045 SELECT _S.cw_in_state
  1045 SELECT _S.cw_in_state
  1046 FROM cw_Note AS _S
  1046 FROM cw_Note AS _S
  1047 WHERE _S.cw_eid=0 AND _S.cw_in_state IS NOT NULL''')
  1047 WHERE _S.cw_eid=0 AND _S.cw_in_state IS NOT NULL'''),
       
  1048 
       
  1049     ('Any X WHERE NOT Y for_user X, X eid 123',
       
  1050      '''SELECT 123
       
  1051 WHERE NOT EXISTS(SELECT 1 FROM cw_CWProperty AS _Y WHERE _Y.cw_for_user=123)
       
  1052 '''),
  1048 
  1053 
  1049     ]
  1054     ]
  1050 
  1055 
  1051 INTERSECT = [
  1056 INTERSECT = [
  1052     ('Any SN WHERE NOT X in_state S, S name SN',
  1057     ('Any SN WHERE NOT X in_state S, S name SN',
  1551         dbms_helper.fti_restriction_sql = indexer.restriction_sql
  1556         dbms_helper.fti_restriction_sql = indexer.restriction_sql
  1552         dbms_helper.fti_need_distinct_query = indexer.need_distinct
  1557         dbms_helper.fti_need_distinct_query = indexer.need_distinct
  1553         self.o = SQLGenerator(schema, dbms_helper)
  1558         self.o = SQLGenerator(schema, dbms_helper)
  1554 
  1559 
  1555     def _norm_sql(self, sql):
  1560     def _norm_sql(self, sql):
  1556         return sql.strip().replace(' ILIKE ', ' LIKE ').replace('TRUE', '1').replace('FALSE', '0')
  1561         sql = sql.strip().replace(' ILIKE ', ' LIKE ').replace('TRUE', '1').replace('FALSE', '0')
       
  1562         newsql = []
       
  1563         latest = None
       
  1564         for line in sql.splitlines(False):
       
  1565             firstword = line.split(None, 1)[0]
       
  1566             if firstword == 'WHERE' and latest == 'SELECT':
       
  1567                 newsql.append('FROM (SELECT 1) AS _T')
       
  1568             newsql.append(line)
       
  1569             latest = firstword
       
  1570         return '\n'.join(newsql)
  1557 
  1571 
  1558     def test_from_clause_needed(self):
  1572     def test_from_clause_needed(self):
  1559         queries = [("Any 1 WHERE EXISTS(T is CWGroup, T name 'managers')",
  1573         queries = [("Any 1 WHERE EXISTS(T is CWGroup, T name 'managers')",
  1560                     '''SELECT 1
  1574                     '''SELECT 1
  1561 FROM (SELECT 1) AS _T
  1575 FROM (SELECT 1) AS _T