[rql2sql] correctly handle modulo operator (closes #2192457) stable
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 20 Feb 2012 11:32:06 +0100
branchstable
changeset 8245 d53762ae5961
parent 8243 b1243a329b5d
child 8247 65b0d2587fb5
[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.
server/sources/rql2sql.py
server/test/unittest_rql2sql.py
--- 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'