]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added basic schema reflection coverage to main tests
authorJason Kirtland <jek@discorporate.us>
Tue, 17 Jul 2007 13:21:46 +0000 (13:21 +0000)
committerJason Kirtland <jek@discorporate.us>
Tue, 17 Jul 2007 13:21:46 +0000 (13:21 +0000)
- Fix stupid mysql typo (#662)
- Merged mysql osx/multibyte has_table from 0.4 (r2943)

lib/sqlalchemy/databases/mysql.py
test/engine/reflection.py

index 5806bee2ecc4e6561fc27ed4df26379606047534..d656964b16a100d0e784a5003f9ce7578435730b 100644 (file)
@@ -1044,11 +1044,21 @@ class MySQLDialect(ansisql.ANSIDialect):
         return self._default_schema_name
 
     def has_table(self, connection, table_name, schema=None):
+        # SHOW TABLE STATUS LIKE and SHOW TABLES LIKE do not function properly
+        # on macosx (and maybe win?) with multibyte table names.
+        #
+        # TODO: if this is not a problem on win, make the strategy swappable
+        # based on platform.  DESCRIBE is much slower.
         if schema is not None:
-            st = 'SHOW TABLE STATUS FROM `%s` LIKE %%s' % schema
+            st = "DESCRIBE `%s`.`%s`" % (schema, table_name)
         else:
-            st = 'SHOW TABLE STATUS LIKE %s'
-        return connection.execute(st, table_name).rowcount != 0
+            st = "DESCRIBE `%s`" % table_name
+        try:
+            return connection.execute(st).rowcount > 0
+        except exceptions.SQLError, e:
+            if e.orig.args[0] == 1146:
+                return False
+            raise
 
     def get_version_info(self, connectable):
         if hasattr(connectable, 'connect'):
@@ -1160,7 +1170,7 @@ class MySQLDialect(ansisql.ANSIDialect):
 
     def _escape_table_name(self, table):
         if table.schema is not None:
-            return '`%s`.`%s`' % (table.schema. table.name)
+            return '`%s`.`%s`' % (table.schema, table.name)
         else:
             return '`%s`' % table.name
 
index fc0ff400fb8956c2a76b1dd5a492247a3b970354..a7d18b7b6065fed2473d8e4b073a60bacb88db03 100644 (file)
@@ -557,6 +557,24 @@ class SchemaTest(PersistTest):
         print buf
         assert buf.index("CREATE TABLE someschema.table1") > -1
         assert buf.index("CREATE TABLE someschema.table2") > -1
+
+    @testbase.unsupported('sqlite')
+    def testcreate(self):
+        schema = testbase.db.url.database
+        metadata = MetaData(testbase.db)
+        table1 = Table('table1', metadata, 
+            Column('col1', Integer, primary_key=True),
+            schema=schema)
+        table2 = Table('table2', metadata, 
+            Column('col1', Integer, primary_key=True),
+            Column('col2', Integer, ForeignKey('%s.table1.col1' % schema)),
+            schema=schema)
+        metadata.create_all()
+        metadata.create_all(checkfirst=True)
+        metadata.clear()
+        table1 = Table('table1', metadata, autoload=True, schema=schema)
+        table2 = Table('table2', metadata, autoload=True, schema=schema)
+        metadata.drop_all()
     
         
 if __name__ == "__main__":