server/test/unittest_rql2sql.py
changeset 8893 eebf286b405e
parent 8695 358d8bed9626
child 9230 a68b2fe8a800
equal deleted inserted replaced
8889:be91151107f6 8893:eebf286b405e
   104 FROM cw_Personne AS _P'''),
   104 FROM cw_Personne AS _P'''),
   105 
   105 
   106     ("Personne P WHERE P test TRUE",
   106     ("Personne P WHERE P test TRUE",
   107      '''SELECT _P.cw_eid
   107      '''SELECT _P.cw_eid
   108 FROM cw_Personne AS _P
   108 FROM cw_Personne AS _P
   109 WHERE _P.cw_test=TRUE'''),
   109 WHERE _P.cw_test=True'''),
   110 
   110 
   111     ("Personne P WHERE P test false",
   111     ("Personne P WHERE P test false",
   112      '''SELECT _P.cw_eid
   112      '''SELECT _P.cw_eid
   113 FROM cw_Personne AS _P
   113 FROM cw_Personne AS _P
   114 WHERE _P.cw_test=FALSE'''),
   114 WHERE _P.cw_test=False'''),
   115 
   115 
   116     ("Personne P WHERE P eid -1",
   116     ("Personne P WHERE P eid -1",
   117      '''SELECT -1'''),
   117      '''SELECT -1'''),
   118 
   118 
   119     ("Personne P WHERE S is Societe, P travaille S, S nom 'Logilab';",
   119     ("Personne P WHERE S is Societe, P travaille S, S nom 'Logilab';",
   530 
   530 
   531 
   531 
   532     ("Any X WHERE X eid 0, X test TRUE",
   532     ("Any X WHERE X eid 0, X test TRUE",
   533      '''SELECT _X.cw_eid
   533      '''SELECT _X.cw_eid
   534 FROM cw_Personne AS _X
   534 FROM cw_Personne AS _X
   535 WHERE _X.cw_eid=0 AND _X.cw_test=TRUE'''),
   535 WHERE _X.cw_eid=0 AND _X.cw_test=True'''),
   536 
   536 
   537     ('Any 1 WHERE X in_group G, X is CWUser',
   537     ('Any 1 WHERE X in_group G, X is CWUser',
   538      '''SELECT 1
   538      '''SELECT 1
   539 FROM in_group_relation AS rel_in_group0'''),
   539 FROM in_group_relation AS rel_in_group0'''),
   540 
   540 
  1754 
  1754 
  1755 
  1755 
  1756 class SqlServer2005SQLGeneratorTC(PostgresSQLGeneratorTC):
  1756 class SqlServer2005SQLGeneratorTC(PostgresSQLGeneratorTC):
  1757     backend = 'sqlserver2005'
  1757     backend = 'sqlserver2005'
  1758     def _norm_sql(self, sql):
  1758     def _norm_sql(self, sql):
  1759         return sql.strip().replace(' SUBSTR', ' SUBSTRING').replace(' || ', ' + ').replace(' ILIKE ', ' LIKE ').replace('TRUE', '1').replace('FALSE', '0')
  1759         return sql.strip().replace(' SUBSTR', ' SUBSTRING').replace(' || ', ' + ').replace(' ILIKE ', ' LIKE ')
  1760 
  1760 
  1761     def test_has_text(self):
  1761     def test_has_text(self):
  1762         for t in self._parse(HAS_TEXT_LG_INDEXER):
  1762         for t in self._parse(HAS_TEXT_LG_INDEXER):
  1763             yield t
  1763             yield t
  1764 
  1764 
  1939 
  1939 
  1940 class SqliteSQLGeneratorTC(PostgresSQLGeneratorTC):
  1940 class SqliteSQLGeneratorTC(PostgresSQLGeneratorTC):
  1941     backend = 'sqlite'
  1941     backend = 'sqlite'
  1942 
  1942 
  1943     def _norm_sql(self, sql):
  1943     def _norm_sql(self, sql):
  1944         return sql.strip().replace(' ILIKE ', ' LIKE ').replace('TRUE', '1').replace('FALSE', '0')
  1944         return sql.strip().replace(' ILIKE ', ' LIKE ')
  1945 
  1945 
  1946     def test_date_extraction(self):
  1946     def test_date_extraction(self):
  1947         self._check("Any MONTH(D) WHERE P is Personne, P creation_date D",
  1947         self._check("Any MONTH(D) WHERE P is Personne, P creation_date D",
  1948                     '''SELECT MONTH(_P.cw_creation_date)
  1948                     '''SELECT MONTH(_P.cw_creation_date)
  1949 FROM cw_Personne AS _P''')
  1949 FROM cw_Personne AS _P''')
  2106 
  2106 
  2107 class MySQLGenerator(PostgresSQLGeneratorTC):
  2107 class MySQLGenerator(PostgresSQLGeneratorTC):
  2108     backend = 'mysql'
  2108     backend = 'mysql'
  2109 
  2109 
  2110     def _norm_sql(self, sql):
  2110     def _norm_sql(self, sql):
  2111         sql = sql.strip().replace(' ILIKE ', ' LIKE ').replace('TRUE', '1').replace('FALSE', '0')
  2111         sql = sql.strip().replace(' ILIKE ', ' LIKE ')
  2112         newsql = []
  2112         newsql = []
  2113         latest = None
  2113         latest = None
  2114         for line in sql.splitlines(False):
  2114         for line in sql.splitlines(False):
  2115             firstword = line.split(None, 1)[0]
  2115             firstword = line.split(None, 1)[0]
  2116             if firstword == 'WHERE' and latest == 'SELECT':
  2116             if firstword == 'WHERE' and latest == 'SELECT':