Author: phd
Date: 2006-03-21 02:09:14 -0700 (Tue, 21 Mar 2006)
New Revision: 1669
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/mysql/mysqlconnection.py
Log:
Merged a patch by David Faure <df...@kl...>
to use DESCRIBE instead of SHOW TABLES.
Modified: SQLObject/branches/0.7-bugfix/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/mysql/mysqlconnection.py 2006-03-21 09:08:36 UTC (rev 1668)
+++ SQLObject/branches/0.7-bugfix/sqlobject/mysql/mysqlconnection.py 2006-03-21 09:09:14 UTC (rev 1669)
@@ -105,10 +105,16 @@
return 'INT NOT NULL'
def tableExists(self, tableName):
- for (table,) in self.queryAll('SHOW TABLES'):
- if table.lower() == tableName.lower():
- return True
- return False
+ try:
+ # Use DESCRIBE instead of SHOW TABLES because SHOW TABLES
+ # assumes there is a default database selected
+ # which is not always True (for an embedded application, e.g.)
+ self.query('DESCRIBE %s' % (tableName))
+ return True
+ except MySQLdb.ProgrammingError, e:
+ if e.args[0] == 1146: # ER_NO_SUCH_TABLE
+ return False
+ raise
def addColumn(self, tableName, column):
self.query('ALTER TABLE %s ADD COLUMN %s' %
|