]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
mysql table introspection uses 'describe' to work with 3/4/5
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 13 Jan 2006 01:23:55 +0000 (01:23 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 13 Jan 2006 01:23:55 +0000 (01:23 +0000)
no foreign key introspection available, sorry !

lib/sqlalchemy/databases/mysql.py
test/engines.py

index f1d4630c83c50df66c7a49973f4281a9c339b323..fda41a3fc4ef47b4bf4917baf566e2e956a6e973 100644 (file)
@@ -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
index 0ed537bca38a70b702e4e38648c3b854a804552a..b649b5a70c245268726a137f13dbe195bd042421 100644 (file)
@@ -59,7 +59,8 @@ class EngineTest(PersistTest):
         try:
             # create a join from the two tables, this insures that
             # theres a foreign key set up
-#            addresses.c.remote_user_id.append_item(ForeignKey('engine_users.user_id'))
+            if testbase.db.engine.__module__.endswith('mysql'):
+                addresses.c.remote_user_id.append_item(ForeignKey('engine_users.user_id'))
             j = join(users, addresses)
             print str(j.onclause)
             self.assert_((users.c.user_id==addresses.c.remote_user_id).compare(j.onclause))