From: Ants Aasma Date: Tue, 26 Jun 2007 16:38:16 +0000 (+0000) Subject: merge from trunk #624 fix, modulo operator escaping X-Git-Tag: rel_0_4_6~175 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5330306430bb8facee39d68f9dde916b1730e3a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git merge from trunk #624 fix, modulo operator escaping --- diff --git a/CHANGES b/CHANGES index ffef7a4745..c7c8be6a85 100644 --- a/CHANGES +++ b/CHANGES @@ -112,6 +112,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], @@ -120,6 +121,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 diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 66bb306b56..cc304842ac 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -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): diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 15cdc23e2a..3fa66df749 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -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) diff --git a/test/sql/query.py b/test/sql/query.py index 701752d7a3..f27c7624c2 100644 --- a/test/sql/query.py +++ b/test/sql/query.py @@ -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()