]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug in Oracle dialect where reflection of tables and other
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 5 Oct 2015 13:49:34 +0000 (09:49 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 5 Oct 2015 13:49:34 +0000 (09:49 -0400)
symbols with names quoted to force all-lower-case would not be
identified properly in reflection queries.  The :class:`.quoted_name`
construct is now applied to incoming symbol names that detect as
forced into all-lower-case within the "name normalize" process.
fixes #3548

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

index ef125eecff43d4c232792a11c9de23767d8f6dc7..a3b3e0092ca00457accc02dcf4a514665ef1e762 100644 (file)
 .. changelog::
     :version: 1.0.9
 
+    .. change::
+        :tags: bug, oracle
+        :versions: 1.1.0b1
+        :tickets: 3548
+
+        Fixed bug in Oracle dialect where reflection of tables and other
+        symbols with names quoted to force all-lower-case would not be
+        identified properly in reflection queries.  The :class:`.quoted_name`
+        construct is now applied to incoming symbol names that detect as
+        forced into all-lower-case within the "name normalize" process.
+
     .. change::
         :tags: feature, orm
         :versions: 1.1.0b1
index c605bd510c3c5ca9492585de449296ce62f831b7..2449b5a81ec38b4f9fd388a42f02e2263fa1f061 100644 (file)
@@ -287,6 +287,7 @@ from sqlalchemy import util, sql
 from sqlalchemy.engine import default, reflection
 from sqlalchemy.sql import compiler, visitors, expression
 from sqlalchemy.sql import operators as sql_operators
+from sqlalchemy.sql.elements import quoted_name
 from sqlalchemy import types as sqltypes, schema as sa_schema
 from sqlalchemy.types import VARCHAR, NVARCHAR, CHAR, \
     BLOB, CLOB, TIMESTAMP, FLOAT
@@ -1032,6 +1033,8 @@ class OracleDialect(default.DefaultDialect):
         if name.upper() == name and not \
                 self.identifier_preparer._requires_quotes(name.lower()):
             return name.lower()
+        elif name.lower() == name:
+            return quoted_name(name, quote=True)
         else:
             return name
 
index e080568cf3d000f7c47526b9ad1ecbb37f3815e2..dd4a888ffc84afdb9f4745a7a92d697cd644353c 100644 (file)
@@ -5,6 +5,7 @@ from sqlalchemy.testing import eq_
 from sqlalchemy import *
 from sqlalchemy import types as sqltypes, exc, schema
 from sqlalchemy.sql import table, column
+from sqlalchemy.sql.elements import quoted_name
 from sqlalchemy.testing import fixtures, AssertsExecutionResults, AssertsCompiledSQL
 from sqlalchemy import testing
 from sqlalchemy.util import u, b
@@ -1859,6 +1860,31 @@ class TableReflectionTest(fixtures.TestBase):
         tbl = Table('test_compress', m2, autoload=True)
         assert tbl.dialect_options['oracle']['compress'] == "OLTP"
 
+    @testing.provide_metadata
+    def test_reflect_lowercase_forced_tables(self):
+        metadata = self.metadata
+
+        Table(
+            quoted_name('t1', quote=True), metadata,
+            Column('id', Integer, primary_key=True),
+        )
+        Table(
+            quoted_name('t2', quote=True), metadata,
+            Column('id', Integer, primary_key=True),
+            Column('t1id', ForeignKey('t1.id'))
+        )
+        metadata.create_all()
+
+        m2 = MetaData(testing.db)
+        t2_ref = Table(quoted_name('t2', quote=True), m2, autoload=True)
+        t1_ref = m2.tables['t1']
+        assert t2_ref.c.t1id.references(t1_ref.c.id)
+
+        m3 = MetaData(testing.db)
+        m3.reflect(only=lambda name, m: name.lower() in ('t1', 't2'))
+        assert m3.tables['t2'].c.t1id.references(m3.tables['t1'].c.id)
+
+
 
 class RoundTripIndexTest(fixtures.TestBase):
     __only_on__ = 'oracle'