diff -r 3b79a0fc91db -r c5aec27c1bf7 server/test/unittest_rql2sql.py --- a/server/test/unittest_rql2sql.py Mon Mar 08 09:51:29 2010 +0100 +++ b/server/test/unittest_rql2sql.py Mon Mar 08 17:57:29 2010 +0100 @@ -13,7 +13,6 @@ from logilab.common.testlib import TestCase, unittest_main, mock_object from rql import BadRQLQuery -from indexer import get_indexer #from cubicweb.server.sources.native import remove_unused_solutions from cubicweb.server.sources.rql2sql import SQLGenerator, remove_unused_solutions @@ -1072,7 +1071,7 @@ WHERE rel_is0.eid_to=2'''), ] -from logilab.common.adbh import ADV_FUNC_HELPER_DIRECTORY +from logilab.db import get_db_helper class CWRQLTC(RQLGeneratorTC): schema = schema @@ -1106,12 +1105,7 @@ #capture = True def setUp(self): RQLGeneratorTC.setUp(self) - indexer = get_indexer('postgres', 'utf8') - dbms_helper = ADV_FUNC_HELPER_DIRECTORY['postgres'] - dbms_helper.fti_uid_attr = indexer.uid_attr - dbms_helper.fti_table = indexer.table - dbms_helper.fti_restriction_sql = indexer.restriction_sql - dbms_helper.fti_need_distinct_query = indexer.need_distinct + dbms_helper = get_db_helper('postgres') self.o = SQLGenerator(schema, dbms_helper) def _norm_sql(self, sql): @@ -1212,6 +1206,13 @@ FROM cw_CWUser AS _X WHERE _X.cw_login IS NULL''') + + def test_date_extraction(self): + self._check("Any MONTH(D) WHERE P is Personne, P creation_date D", + '''SELECT CAST(EXTRACT(MONTH from _P.cw_creation_date) AS INTEGER) +FROM cw_Personne AS _P''') + + def test_parser_parse(self): for t in self._parse(PARSER): yield t @@ -1409,17 +1410,17 @@ def setUp(self): RQLGeneratorTC.setUp(self) - indexer = get_indexer('sqlite', 'utf8') - dbms_helper = ADV_FUNC_HELPER_DIRECTORY['sqlite'] - dbms_helper.fti_uid_attr = indexer.uid_attr - dbms_helper.fti_table = indexer.table - dbms_helper.fti_restriction_sql = indexer.restriction_sql - dbms_helper.fti_need_distinct_query = indexer.need_distinct + dbms_helper = get_db_helper('sqlite') self.o = SQLGenerator(schema, dbms_helper) def _norm_sql(self, sql): return sql.strip().replace(' ILIKE ', ' LIKE ').replace('\nINTERSECT ALL\n', '\nINTERSECT\n') + def test_date_extraction(self): + self._check("Any MONTH(D) WHERE P is Personne, P creation_date D", + '''SELECT MONTH(_P.cw_creation_date) +FROM cw_Personne AS _P''') + def test_union(self): for t in self._parse(( ('(Any N ORDERBY 1 WHERE X name N, X is State)' @@ -1517,12 +1518,7 @@ def setUp(self): RQLGeneratorTC.setUp(self) - indexer = get_indexer('mysql', 'utf8') - dbms_helper = ADV_FUNC_HELPER_DIRECTORY['mysql'] - dbms_helper.fti_uid_attr = indexer.uid_attr - dbms_helper.fti_table = indexer.table - dbms_helper.fti_restriction_sql = indexer.restriction_sql - dbms_helper.fti_need_distinct_query = indexer.need_distinct + dbms_helper = get_db_helper('mysql') self.o = SQLGenerator(schema, dbms_helper) def _norm_sql(self, sql): @@ -1537,6 +1533,11 @@ latest = firstword return '\n'.join(newsql) + def test_date_extraction(self): + self._check("Any MONTH(D) WHERE P is Personne, P creation_date D", + '''SELECT EXTRACT(MONTH from _P.cw_creation_date) +FROM cw_Personne AS _P''') + def test_from_clause_needed(self): queries = [("Any 1 WHERE EXISTS(T is CWGroup, T name 'managers')", '''SELECT 1