]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
merge from trunk #624 fix, modulo operator escaping
authorAnts Aasma <ants.aasma@gmail.com>
Tue, 26 Jun 2007 16:38:16 +0000 (16:38 +0000)
committerAnts Aasma <ants.aasma@gmail.com>
Tue, 26 Jun 2007 16:38:16 +0000 (16:38 +0000)
CHANGES
lib/sqlalchemy/databases/mysql.py
lib/sqlalchemy/databases/postgres.py
test/sql/query.py

diff --git a/CHANGES b/CHANGES
index ffef7a474575b0e07520282e9cf8f6aae726e7e5..c7c8be6a858ac773cdac9ff32f39659cb422640e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
       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],
       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 66bb306b56f7ffb518df7e35dc4d43c4bfe0a044..cc304842ac41352c07e7072132e5d143a2d23a33 100644 (file)
@@ -1208,6 +1208,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 15cdc23e2a954d0b9a5acd5eb2b77d4938b75b1e..3fa66df74996aaa18a01ea7ecc40a79fb5db0db3 100644 (file)
@@ -445,6 +445,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 701752d7a3529ef00f404ad648eb536655bd9aa6..f27c7624c20e3ce5f28d9842819137e6148343c7 100644 (file)
@@ -598,6 +598,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()