]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix #624, modulo operator escaping on mysql and postgres
authorAnts Aasma <ants.aasma@gmail.com>
Tue, 26 Jun 2007 16:37:30 +0000 (16:37 +0000)
committerAnts Aasma <ants.aasma@gmail.com>
Tue, 26 Jun 2007 16:37:30 +0000 (16:37 +0000)
someone should test this with oracle, firebird and sql server also

CHANGES
lib/sqlalchemy/databases/mysql.py
lib/sqlalchemy/databases/postgres.py
test/sql/query.py

diff --git a/CHANGES b/CHANGES
index 1b5af7a51cab04835dd67e5a5ac40dca8892ec67..be73b34feaecfde82d2ef3fdefbb11d2bee0e2b9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -46,6 +46,7 @@
       up ORM decision making [ticket:593]
     - added Interval type to types.py [ticket:595]
 - mysql
+    - fixed escaping of the modulo operator [ticket:624]
     - added 'fields' to reserved words [ticket:590]
 - oracle
     - datetime fixes: got subsecond TIMESTAMP to work [ticket:604],
@@ -54,6 +55,8 @@
       LOB objects detected in a result set to be forced into OracleBinary
       so that the LOB is read() automatically, if no typemap was present
       (i.e., if a textual execute() was issued).
+- postgres
+    - fixed escaping of the modulo operator [ticket:624]
 - sqlite
     - sqlite better handles datetime/date/time objects mixed and matched
       with various Date/Time/DateTime columns
index 91d59f1e23d89b311fb9328fc5d823b97fc7003e..6e4e0a660db9bf9e4f68e033e0e530e59e948c7c 100644 (file)
@@ -1205,6 +1205,12 @@ class MySQLCompiler(ansisql.ANSICompiler):
                 text += " \n LIMIT 18446744073709551615"
             text += " OFFSET " + str(select.offset)
         return text
+        
+    def binary_operator_string(self, binary):
+        if binary.operator == '%':
+            return '%%'
+        else:
+            return ansisql.ANSICompiler.binary_operator_string(self, binary)   
 
 class MySQLSchemaGenerator(ansisql.ANSISchemaGenerator):
     def get_column_specification(self, column, override_pk=False, first_pk=False):
index 0eca18be3800acd3782a72c8ac99b275553d114c..a514b9de0267b73256be23af4d59e06ef54c1fc7 100644 (file)
@@ -532,6 +532,8 @@ class PGCompiler(ansisql.ANSICompiler):
     def binary_operator_string(self, binary):
         if isinstance(binary.type, sqltypes.String) and binary.operator == '+':
             return '||'
+        elif binary.operator == '%':
+            return '%%'
         else:
             return ansisql.ANSICompiler.binary_operator_string(self, binary)
 
index 593b392e83676dcabc5ee4c2fa071a08de0926cd..f7c38eb87d36d55a4528799a2a8e16899175a258 100644 (file)
@@ -637,6 +637,30 @@ class CompoundTest(PersistTest):
         assert u.execute().fetchall() == [('aaa', 'bbb'), ('bbb', 'ccc'), ('ccc', 'aaa')]
         assert u.alias('foo').select().execute().fetchall() == [('aaa', 'bbb'), ('bbb', 'ccc'), ('ccc', 'aaa')]
 
+class OperatorTest(PersistTest):
+    def setUpAll(self):
+        global metadata, flds
+        metadata = BoundMetaData(testbase.db)
+        flds = Table('flds', metadata, 
+            Column('idcol', Integer, Sequence('t1pkseq'), primary_key=True),
+            Column('intcol', Integer),
+            Column('strcol', String(50)),
+            )
+        metadata.create_all()
+        
+        flds.insert().execute([
+            dict(intcol=5, strcol='foo'),
+            dict(intcol=13, strcol='bar')
+        ])
+
+    def tearDownAll(self):
+        metadata.drop_all()
+        
+    def test_modulo(self):
+        self.assertEquals(
+            select([flds.c.intcol % 3], order_by=flds.c.idcol).execute().fetchall(),
+            [(2,),(1,)]
+        )
         
 if __name__ == "__main__":
     testbase.main()