]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed long-standing bug in Oracle dialect where bound parameter
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 11 Oct 2014 22:25:21 +0000 (18:25 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 11 Oct 2014 22:25:54 +0000 (18:25 -0400)
names that started with numbers would not be quoted, as Oracle
doesn't like numerics in bound parameter names.
fixes #2138

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/dialects/oracle/base.py
test/dialect/test_oracle.py

index e2b893d07fc08b051c4169c78cb5cdd10fb9ad68..fdc83c7670f74e76c63b16bea5edbb6490d2b990 100644 (file)
 .. changelog::
     :version: 0.9.8
 
+    .. change::
+        :tags: bug, oracle
+        :versions: 1.0.0
+        :tickets: 2138
+
+        Fixed long-standing bug in Oracle dialect where bound parameter
+        names that started with numbers would not be quoted, as Oracle
+        doesn't like numerics in bound parameter names.
+
     .. change::
         :tags: bug, sql
         :versions: 1.0.0
index 4d45f8506ecf16fd66255d513a2fb6b1f056c2fd..643021a36fc2ddb485151d427b85bd47a50e727c 100644 (file)
@@ -781,7 +781,8 @@ class OracleDDLCompiler(compiler.DDLCompiler):
 class OracleIdentifierPreparer(compiler.IdentifierPreparer):
 
     reserved_words = set([x.lower() for x in RESERVED_WORDS])
-    illegal_initial_characters = set(range(0, 10)).union(["_", "$"])
+    illegal_initial_characters = set(
+        (str(dig) for dig in range(0, 10))).union(["_", "$"])
 
     def _bindparam_requires_quotes(self, value):
         """Return True if the given identifier requires quoting."""
index 4e5a4bbd240758bd7537e7a8b581a031eb6f146a..7b853a10f8bdddf15e0ba47306a4d4ff8a43b7ac 100644 (file)
@@ -104,6 +104,28 @@ class QuotedBindRoundTripTest(fixtures.TestBase):
             (2, 2, 2)
         )
 
+    def test_numeric_bind_round_trip(self):
+        eq_(
+            testing.db.scalar(
+                select([
+                    literal_column("2", type_=Integer()) +
+                    bindparam("2_1", value=2)])
+            ),
+            4
+        )
+
+    @testing.provide_metadata
+    def test_numeric_bind_in_crud(self):
+        t = Table(
+            "asfd", self.metadata,
+            Column("100K", Integer)
+        )
+        t.create()
+
+        testing.db.execute(t.insert(), {"100K": 10})
+        eq_(
+            testing.db.scalar(t.select()), 10
+        )
 
 class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
     __dialect__ = "oracle" #oracle.dialect()