from sqlalchemy.ansisql import *
generic_engine = ansisql.engine()
+
+gen_schemata = schema.Table("schemata", generic_engine,
+ Column("catalog_name", String),
+ Column("schema_name", String),
+ Column("schema_owner", String),
+ schema="information_schema")
+
+gen_tables = schema.Table("tables", generic_engine,
+ Column("table_catalog", String),
+ Column("table_schema", String),
+ Column("table_name", String),
+ Column("table_type", String),
+ schema="information_schema")
+
gen_columns = schema.Table("columns", generic_engine,
Column("table_schema", String),
Column("table_name", String),
Column("constraint_name", String),
schema="information_schema")
+class ISchema(object):
+ def __init__(self, engine):
+ self.engine = engine
+ self.cache = {}
+ def __getattr__(self, name):
+ if name not in self.cache:
+ # This is a bit of a hack.
+ # It would probably be better to have a dict
+ # with just the information_schema tables at
+ # the module level, so as to avoid returning
+ # unrelated objects that happen to be named
+ # 'gen_*'
+ try:
+ gen_tbl = globals()['gen_'+name]
+ except KeyError:
+ raise AttributeError('information_schema table %s not found' % name)
+ self.cache[name] = gen_tbl.toengine(self.engine)
+ return self.cache[name]
+
def reflecttable(engine, table, ischema_names, use_mysql=False):
columns = gen_columns.toengine(engine)
self.echo_uow = echo_uow
self.context = util.ThreadLocal(raiseerror=False)
self.tables = {}
+ self._ischema = None
self._figure_paramstyle()
if logger is None:
self.logger = sys.stdout
else:
self.logger = logger
+ def _get_ischema(self):
+ # We use a property for ischema so that the accessor
+ # creation only happens as needed, since otherwise we
+ # have a circularity problem with the generic
+ # ansisql.engine()
+ if self._ischema is None:
+ import sqlalchemy.databases.information_schema as ischema
+ self._ischema = ischema.ISchema(self)
+ return self._ischema
+ ischema = property(_get_ischema, doc="""returns an ISchema object for this engine, which allows access to information_schema tables (if supported)""")
+
def hash_key(self):
return "%s(%s)" % (self.__class__.__name__, repr(self.connect_args()))