[rql2sql] correctly handle modulo operator (closes #2192457)
rql has % as a modulo operator. The string we output gets passed to a
substitution function so the % needs to be escaped.
--- a/server/sources/rql2sql.py Fri Feb 17 14:41:28 2012 +0100
+++ b/server/sources/rql2sql.py Mon Feb 20 11:32:06 2012 +0100
@@ -1454,6 +1454,8 @@
lhs, rhs = mexpr.get_parts()
# check for string concatenation
operator = mexpr.operator
+ if operator == '%':
+ operator = '%%'
try:
if mexpr.operator == '+' and mexpr.get_type(self._state.solution, self._args) == 'String':
return '(%s)' % self.dbhelper.sql_concat_string(lhs.accept(self),
--- a/server/test/unittest_rql2sql.py Fri Feb 17 14:41:28 2012 +0100
+++ b/server/test/unittest_rql2sql.py Mon Feb 20 11:32:06 2012 +0100
@@ -1744,6 +1744,9 @@
GROUP BY CAST(EXTRACT(YEAR from _X.cw_modification_date) AS INTEGER),CAST(EXTRACT(MONTH from _X.cw_modification_date) AS INTEGER)
ORDER BY 1'''),
+ def test_modulo(self):
+ self._check('Any 5 % 2', '''SELECT (5 % 2)''')
+
class SqlServer2005SQLGeneratorTC(PostgresSQLGeneratorTC):
backend = 'sqlserver2005'