From: Mike Bayer Date: Sun, 27 Mar 2011 23:44:40 +0000 (-0400) Subject: - Using column names that would require quotes X-Git-Tag: rel_0_6_7~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45cf9be645824aafddfe36c8a6112561cc876aea;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Using column names that would require quotes for the column itself or for a name-generated bind parameter, such as names with special characters, underscores, non-ascii characters, now properly translate bind parameter keys when talking to cx_oracle. [ticket:2100] --- diff --git a/CHANGES b/CHANGES index d7822261a3..53ef46ef53 100644 --- a/CHANGES +++ b/CHANGES @@ -107,6 +107,14 @@ CHANGES - The "implicit_returning" flag on create_engine() is honored if set to False. [ticket:2083] +- oracle + - Using column names that would require quotes + for the column itself or for a name-generated + bind parameter, such as names with special + characters, underscores, non-ascii characters, + now properly translate bind parameter keys when + talking to cx_oracle. [ticket:2100] + - ext - The horizontal_shard ShardedSession class accepts the common Session argument "query_cls" as a constructor argument, diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 4fc018282b..e0da995f6a 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -293,10 +293,15 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext): quoted_bind_names = \ getattr(self.compiled, '_quoted_bind_names', None) if quoted_bind_names: - if not self.dialect.supports_unicode_binds: + if not self.dialect.supports_unicode_statements: + # if DBAPI doesn't accept unicode statements, + # keys in self.parameters would have been encoded + # here. so convert names in quoted_bind_names + # to encoded as well. quoted_bind_names = \ dict( - (fromname, toname.encode(self.dialect.encoding)) + (fromname.encode(self.dialect.encoding), + toname.encode(self.dialect.encoding)) for fromname, toname in quoted_bind_names.items() ) diff --git a/test/dialect/test_oracle.py b/test/dialect/test_oracle.py index 492714e6c1..29bb58b505 100644 --- a/test/dialect/test_oracle.py +++ b/test/dialect/test_oracle.py @@ -1304,3 +1304,37 @@ class ExecuteTest(TestBase): ) +class UnicodeSchemaTest(TestBase): + __only_on__ = 'oracle' + + @testing.provide_metadata + def test_quoted_column_non_unicode(self): + table=Table("atable", metadata, + Column("_underscorecolumn", Unicode(255), primary_key=True), + ) + metadata.create_all() + + table.insert().execute( + {'_underscorecolumn': u'’é'}, + ) + result = testing.db.execute( + table.select().where(table.c._underscorecolumn==u'’é') + ).scalar() + eq_(result, u'’é') + + @testing.provide_metadata + def test_quoted_column_unicode(self): + table=Table("atable", metadata, + Column(u"méil", Unicode(255), primary_key=True), + ) + metadata.create_all() + + table.insert().execute( + {u'méil': u'’é'}, + ) + result = testing.db.execute( + table.select().where(table.c[u'méil']==u'’é') + ).scalar() + eq_(result, u'’é') + +