]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Using column names that would require quotes
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 27 Mar 2011 23:44:40 +0000 (19:44 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 27 Mar 2011 23:44:40 +0000 (19:44 -0400)
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]

CHANGES
lib/sqlalchemy/dialects/oracle/cx_oracle.py
test/dialect/test_oracle.py

diff --git a/CHANGES b/CHANGES
index d7822261a3a57717114f12a2ba213ad914690fdb..53ef46ef53e3e289f67243f9b85f98d4c38fe670 100644 (file)
--- 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,
index 4fc018282bebb1daccf84c9e132fc029517ec913..e0da995f6a8ed68c008763c1430c166a4f1dcaf1 100644 (file)
@@ -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()
                                 )
index 492714e6c1df9d7eb6092b0e29270636840e801b..29bb58b505e518aa83421d2462c1cb6365047f7b 100644 (file)
@@ -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'’é')
+
+