Commits

Mike Bayer  committed 4166208

oracle dialect takes schema name into account when checking for existing tables
of the same name. [ticket:709]

  • Participants
  • Parent commits 2e8cbf1

Comments (0)

Files changed (3)

       before returning, meaning it returns a lower-case name
       when the identifier is detected as case insensitive.
 
+    - creating/dropping tables takes schema name into account
+      when searching for the existing table, so that tables
+      in other owner namespaces with the same name do not
+      conflict [ticket:709]
+
+
 0.4.6
 =====
 - orm

File lib/sqlalchemy/databases/oracle.py

         return OracleExecutionContext(self, *args, **kwargs)
 
     def has_table(self, connection, table_name, schema=None):
-        cursor = connection.execute("""select table_name from all_tables where table_name=:name""", {'name':self._denormalize_name(table_name)})
+        if not schema:
+            schema = self.get_default_schema_name(connection)
+        cursor = connection.execute("""select table_name from all_tables where table_name=:name and owner=:schema_name""", {'name':self._denormalize_name(table_name), 'schema_name':self._denormalize_name(schema)})
         return cursor.fetchone() is not None
 
     def has_sequence(self, connection, sequence_name):

File test/dialect/oracle.py

             "ON addresses.address_type_id = address_types_1.id WHERE addresses.user_id = :user_id_1 ORDER BY addresses.rowid, "
             "address_types.rowid")
 
-class SchemaReflectionTest(TestBase, AssertsCompiledSQL):
+class MultiSchemaTest(TestBase, AssertsCompiledSQL):
     """instructions:
 
        1. create a user 'ed' in the oracle database.
 
     __only_on__ = 'oracle'
 
+    def test_create_same_names_explicit_schema(self):
+        schema = testing.db.dialect.get_default_schema_name(testing.db.connect())
+        meta = MetaData(testing.db)
+        parent = Table('parent', meta, 
+            Column('pid', Integer, primary_key=True),
+            schema=schema
+        )
+        child = Table('child', meta, 
+            Column('cid', Integer, primary_key=True),
+            Column('pid', Integer, ForeignKey('scott.parent.pid')),
+            schema=schema
+        )
+        meta.create_all()
+        try:
+            parent.insert().execute({'pid':1})
+            child.insert().execute({'cid':1, 'pid':1})
+            self.assertEquals(child.select().execute().fetchall(), [(1, 1)])
+        finally:
+            meta.drop_all()
+
+    def test_create_same_names_implicit_schema(self):
+        meta = MetaData(testing.db)
+        parent = Table('parent', meta, 
+            Column('pid', Integer, primary_key=True),
+        )
+        child = Table('child', meta, 
+            Column('cid', Integer, primary_key=True),
+            Column('pid', Integer, ForeignKey('parent.pid')),
+        )
+        meta.create_all()
+        try:
+            parent.insert().execute({'pid':1})
+            child.insert().execute({'cid':1, 'pid':1})
+            self.assertEquals(child.select().execute().fetchall(), [(1, 1)])
+        finally:
+            meta.drop_all()
+
+
     def test_reflect_alt_owner_explicit(self):
         meta = MetaData(testing.db)
         parent = Table('parent', meta, autoload=True, schema='ed')