diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-01-13 01:23:55 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-01-13 01:23:55 +0000 |
commit | 1117b0bf814fa35048e5f420778189d7e8ad8f41 (patch) | |
tree | 8d97017b5155c6d55f9ec4c0422b70bfbceaa81b /lib/sqlalchemy/databases/mysql.py | |
parent | f9f80215918346582ba262ff1e2e63e4ea17a8f7 (diff) | |
download | sqlalchemy-1117b0bf814fa35048e5f420778189d7e8ad8f41.tar.gz |
mysql table introspection uses 'describe' to work with 3/4/5
no foreign key introspection available, sorry !
Diffstat (limited to 'lib/sqlalchemy/databases/mysql.py')
-rw-r--r-- | lib/sqlalchemy/databases/mysql.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index f1d4630c8..fda41a3fc 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -146,7 +146,29 @@ class MySQLEngine(ansisql.ANSISQLEngine): return self.module def reflecttable(self, table): - ischema.reflecttable(self, table, ischema_names, use_mysql=True) + # to use information_schema: + #ischema.reflecttable(self, table, ischema_names, use_mysql=True) + + c = self.execute("describe " + table.name, {}) + while True: + row = c.fetchone() + if row is None: + break + #print "row! " + repr(row) + (name, type, nullable, primary_key, default) = (row[0], row[1], row[2] == 'YES', row[3] == 'PRI', row[4]) + + match = re.match(r'(\w+)(\(.*?\))?', type) + coltype = match.group(1) + args = match.group(2) + + #print "coltype: " + repr(coltype) + " args: " + repr(args) + coltype = ischema_names.get(coltype, MSString) + if args is not None: + args = re.findall(r'(\d+)', args) + #print "args! " +repr(args) + coltype = coltype(*[int(a) for a in args]) + table.append_item(schema.Column(name, coltype, primary_key=primary_key, nullable=nullable, default=default)) + class MySQLTableImpl(sql.TableImpl): """attached to a schema.Table to provide it with a Selectable interface |