]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Adjust has_table for MySQL, workaround multibyte issue on osx
authorJason Kirtland <jek@discorporate.us>
Tue, 17 Jul 2007 06:22:58 +0000 (06:22 +0000)
committerJason Kirtland <jek@discorporate.us>
Tue, 17 Jul 2007 06:22:58 +0000 (06:22 +0000)
lib/sqlalchemy/databases/mysql.py
test/sql/unicode.py

index 233fe050acd920d14104d3ec11374984e379a764..3e03109b78eeaf90ec9ee3dd90104b19885f41ce 100644 (file)
@@ -1068,11 +1068,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'):
index f47ac97f53b29d31611f02cd3dd55f4fbf59dc58..cfd2354da95c17e3d29e591be494c8bad8b294b6 100644 (file)
@@ -19,7 +19,7 @@ class UnicodeSchemaTest(testbase.PersistTest):
             Column(u'\u6e2c\u8a66', Integer),
 
             )
-        t2 = Table(u'unitéble2', metadata,
+        t2 = Table(u'Unitéble2', metadata,
             Column(u'méil', Integer, primary_key=True, key="a"),
             Column(u'\u6e2c\u8a66', Integer, ForeignKey(u'unitable1.méil'), key="b"),
             )