raise NotImplementedError()
def visit_metadata(self, metadata):
- collection = [t for t in metadata.table_iterator(reverse=False, tables=self.tables) if (not self.checkfirst or not self.dialect.has_table(self.connection, t.name))]
+ collection = [t for t in metadata.table_iterator(reverse=False, tables=self.tables) if (not self.checkfirst or not self.dialect.has_table(self.connection, t.name, schema=t.schema))]
for table in collection:
table.accept_schema_visitor(self, traverse=False)
if self.supports_alter():
self.dialect = self.engine.dialect
def visit_metadata(self, metadata):
- collection = [t for t in metadata.table_iterator(reverse=True, tables=self.tables) if (not self.checkfirst or self.dialect.has_table(self.connection, t.name))]
+ collection = [t for t in metadata.table_iterator(reverse=True, tables=self.tables) if (not self.checkfirst or self.dialect.has_table(self.connection, t.name, schema=t.schema))]
if self.supports_alter():
for alterable in self.find_alterables(collection):
self.drop_foreignkey(alterable)
def preparer(self):
return FBIdentifierPreparer(self)
- def has_table(self, connection, table_name):
+ def has_table(self, connection, table_name, schema=None):
tblqry = """
SELECT count(*)
FROM RDB$RELATIONS R
c.name = c.name.upper()
return t
- def has_table(self, connection, tablename):
+ def has_table(self, connection, tablename, schema=None):
import sqlalchemy.databases.information_schema as ischema
- current_schema = self.get_default_schema_name()
+ current_schema = schema or self.get_default_schema_name()
columns = self.uppercase_table(ischema.columns)
s = sql.select([columns],
current_schema
def dbapi(self):
return self.module
- def has_table(self, connection, table_name):
+ def has_table(self, connection, table_name, schema=None):
cursor = connection.execute("show table status like '" + table_name + "'")
return bool( not not cursor.rowcount )
return OracleDefaultRunner(engine, proxy)
- def has_table(self, connection, table_name):
+ def has_table(self, connection, table_name, schema=None):
cursor = connection.execute("""select table_name from all_tables where table_name=:name""", {'name':table_name.upper()})
return bool( cursor.fetchone() is not None )
def dbapi(self):
return sqlite
- def has_table(self, connection, table_name):
+ def has_table(self, connection, table_name, schema=None):
cursor = connection.execute("PRAGMA table_info(" + table_name + ")", {})
row = cursor.fetchone()
def reflecttable(self, connection, table):
"""given an Connection and a Table object, reflects its columns and properties from the database."""
raise NotImplementedError()
- def has_table(self, connection, table_name):
+ def has_table(self, connection, table_name, schema=None):
raise NotImplementedError()
def has_sequence(self, connection, sequence_name):
raise NotImplementedError()
finally:
if connection is None:
conn.close()
- def has_table(self, table_name):
- return self.run_callable(lambda c: self.dialect.has_table(c, table_name))
+ def has_table(self, table_name, schema=None):
+ return self.run_callable(lambda c: self.dialect.has_table(c, table_name, schema=schema))
def raw_connection(self):
"""returns a DBAPI connection."""
def do(conn):
e = conn.engine
- return e.dialect.has_table(conn, self.name)
+ return e.dialect.has_table(conn, self.name, schema=self.schema)
return connectable.run_callable(do)
def create(self, connectable=None, checkfirst=False):
print buf
assert buf.index("CREATE TABLE someschema.table1") > -1
assert buf.index("CREATE TABLE someschema.table2") > -1
-
-
+
+ @testbase.supported('postgres')
+ def testpg(self):
+ """note: this test requires that the 'test_schema' schema be separate and accessible by the test user"""
+ meta1 = BoundMetaData(testbase.db)
+ users = Table('users', meta1,
+ Column('user_id', Integer, primary_key = True),
+ Column('user_name', String(30), nullable = False),
+ schema="test_schema"
+ )
+
+ addresses = Table('email_addresses', meta1,
+ Column('address_id', Integer, primary_key = True),
+ Column('remote_user_id', Integer, ForeignKey(users.c.user_id)),
+ Column('email_address', String(20)),
+ schema="test_schema"
+ )
+ meta1.create_all()
+ try:
+ meta2 = BoundMetaData(testbase.db)
+ users = Table('users', meta2, autoload = True, schema="test_schema")
+ addresses = Table('email_addresses', meta2, autoload = True, schema="test_schema")
+
+ print users
+ print addresses
+ j = join(users, addresses)
+ print str(j.onclause)
+ self.assert_((users.c.user_id==addresses.c.remote_user_id).compare(j.onclause))
+ finally:
+ meta1.drop_all()
if __name__ == "__main__":
testbase.main()