Commits

Mike Bayer committed cdcdfc6

- has_sequence() now takes the current "schema" argument into
account [ticket:1155]

  • Participants
  • Parent commits 394ce8a

Comments (0)

Files changed (3)

       and instead uses subqueries in conjunction with a special
       Oracle optimization comment.  Allows LIMIT/OFFSET to work
       in conjunction with DISTINCT. [ticket:536]
-
+    - has_sequence() now takes the current "schema" argument into
+      account [ticket:1155]
 
 0.5beta3
 ========

File lib/sqlalchemy/databases/oracle.py

         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):
-        cursor = connection.execute("""select sequence_name from all_sequences where sequence_name=:name""", {'name':self._denormalize_name(sequence_name)})
+    def has_sequence(self, connection, sequence_name, schema=None):
+        if not schema:
+            schema = self.get_default_schema_name(connection)
+        cursor = connection.execute("""select sequence_name from all_sequences where sequence_name=:name and sequence_owner=:schema_name""", {'name':self._denormalize_name(sequence_name), 'schema_name':self._denormalize_name(schema)})
         return cursor.fetchone() is not None
 
     def _normalize_name(self, name):
         return colspec
 
     def visit_sequence(self, sequence):
-        if not self.checkfirst  or not self.dialect.has_sequence(self.connection, sequence.name):
+        if not self.checkfirst  or not self.dialect.has_sequence(self.connection, sequence.name, sequence.schema):
             self.append("CREATE SEQUENCE %s" % self.preparer.format_sequence(sequence))
             self.execute()
 
 class OracleSchemaDropper(compiler.SchemaDropper):
     def visit_sequence(self, sequence):
-        if not self.checkfirst or self.dialect.has_sequence(self.connection, sequence.name):
+        if not self.checkfirst or self.dialect.has_sequence(self.connection, sequence.name, sequence.schema):
             self.append("DROP SEQUENCE %s" % self.preparer.format_sequence(sequence))
             self.execute()
 

File lib/sqlalchemy/engine/base.py

 
         raise NotImplementedError()
 
-    def has_sequence(self, connection, sequence_name):
+    def has_sequence(self, connection, sequence_name, schema=None):
         """Check the existence of a particular sequence in the database.
 
         Given a [sqlalchemy.engine#Connection] object and a string
     """
     @util.decorator
     def decorated(fn, self, connection):
+        connection = connection.connect()
         try:
             return connection.info[key]
         except KeyError: