# HG changeset patch # User Adrien Di Mascio # Date 1303897062 -7200 # Node ID ccd44caeb9365d65c2a3af1fe65823d9af0f5ed6 # Parent 68b9e21efa632752a8e3020f6fe22a445521d60e [rql] support CAST() Function diff -r 68b9e21efa63 -r ccd44caeb936 server/sources/rql2sql.py --- a/server/sources/rql2sql.py Wed Apr 27 09:41:55 2011 +0200 +++ b/server/sources/rql2sql.py Wed Apr 27 11:37:42 2011 +0200 @@ -1407,6 +1407,8 @@ if constant.type is None: return 'NULL' value = constant.value + if constant.type == 'etype': + return value if constant.type == 'Int' and isinstance(constant.parent, SortTerm): return value if constant.type in ('Date', 'Datetime'): diff -r 68b9e21efa63 -r ccd44caeb936 server/test/unittest_rql2sql.py --- a/server/test/unittest_rql2sql.py Wed Apr 27 09:41:55 2011 +0200 +++ b/server/test/unittest_rql2sql.py Wed Apr 27 11:37:42 2011 +0200 @@ -1331,6 +1331,11 @@ '''SELECT SUBSTR(_P.cw_nom, 1, 1) FROM cw_Personne AS _P''') + def test_cast(self): + self._check("Any CAST(String, P) WHERE P is Personne", + '''SELECT CAST(_P.cw_eid AS text) +FROM cw_Personne AS _P''') + def test_parser_parse(self): for t in self._parse(PARSER): yield t @@ -1726,6 +1731,10 @@ for t in self._parse(WITH_LIMIT):# + ADVANCED_WITH_LIMIT_OR_ORDERBY): yield t + def test_cast(self): + self._check("Any CAST(String, P) WHERE P is Personne", + '''SELECT CAST(_P.cw_eid AS nvarchar(max)) +FROM cw_Personne AS _P''') class SqliteSQLGeneratorTC(PostgresSQLGeneratorTC): @@ -1879,6 +1888,11 @@ '''SELECT EXTRACT(MONTH from _P.cw_creation_date) FROM cw_Personne AS _P''') + def test_cast(self): + self._check("Any CAST(String, P) WHERE P is Personne", + '''SELECT CAST(_P.cw_eid AS mediumtext) +FROM cw_Personne AS _P''') + def test_from_clause_needed(self): queries = [("Any 1 WHERE EXISTS(T is CWGroup, T name 'managers')", '''SELECT 1