]> 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:39:39 +0000 (19:39 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 27 Mar 2011 23:39:39 +0000 (19:39 -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]  (Also
in 0.6.7)

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

diff --git a/CHANGES b/CHANGES
index 4654016e4ed8a96592c2dad19de4cc6e7db94405..15c07087017d3f13281a80d53836384f2f2a17ff 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -41,6 +41,15 @@ CHANGES
     collection of Sequence objects, list
     of schema names.  [ticket:2104]
 
+- 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]  (Also
+    in 0.6.7)
+
 0.7.0b3
 =======
 - general
index b00adcd6328b3a441e36036e37be300f26c4ae1b..a917aac021178a415ffb487bd014400184286246 100644 (file)
@@ -294,10 +294,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 994f500e14108a4092a12ce3a96e2d18de8016e5..26e46349ea7b02052c6271f121c08a9b279a7e31 100644 (file)
@@ -1323,3 +1323,39 @@ class ExecuteTest(fixtures.TestBase):
         )
 
 
+class UnicodeSchemaTest(fixtures.TestBase):
+    __only_on__ = 'oracle'
+
+    @testing.provide_metadata
+    def test_quoted_column_non_unicode(self):
+        metadata = self.metadata
+        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):
+        metadata = self.metadata
+        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'’é')
+
+