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