]> 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:21 +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 837a498fbb8a85f2b9fc2fca6718ddbd251f57a3..6df38e57ef63a7faff9a326b5f4e15a6184c7840 100644 (file)
@@ -813,7 +813,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 36eacf8643fdad86b8da2055d0f29cef32479d5d..a771c5d80aad5346c6f131a6183db9ece931f21c 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()