Author: phd
Date: 2006-03-21 02:10:09 -0700 (Tue, 21 Mar 2006)
New Revision: 1670
Modified:
home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py
Log:
Merged patches from the revisions 1667:1669 from the trunk: a patch by David Faure <df...@kl...> to use DESCRIBE instead of SHOW TABLES.
Modified: home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py 2006-03-21 09:09:14 UTC (rev 1669)
+++ home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py 2006-03-21 09:10:09 UTC (rev 1670)
@@ -116,10 +116,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' %
|