[SQL-CVS] r1668 - SQLObject/trunk/sqlobject/mysql
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: <sub...@co...> - 2006-03-21 09:08:44
|
Author: phd
Date: 2006-03-21 02:08:36 -0700 (Tue, 21 Mar 2006)
New Revision: 1668
Modified:
SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
Log:
A patch by David Faure <df...@kl...> to use DESCRIBE
instead of SHOW TABLES.
Modified: SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-03-20 23:15:26 UTC (rev 1667)
+++ SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-03-21 09:08:36 UTC (rev 1668)
@@ -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' %
|