From 9d6f11d5d524afeacd9cb702612d8667c15a6e3c Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 4 Jun 2013 19:34:51 -0400 Subject: [PATCH] new way of detecting if table exists. --- framework/yii/db/mysql/Schema.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/framework/yii/db/mysql/Schema.php b/framework/yii/db/mysql/Schema.php index e7b34e0..b42ef15 100644 --- a/framework/yii/db/mysql/Schema.php +++ b/framework/yii/db/mysql/Schema.php @@ -178,15 +178,21 @@ class Schema extends \yii\db\Schema * Collects the metadata of table columns. * @param TableSchema $table the table metadata * @return boolean whether the table exists in the database + * @throws \Exception if DB query fails */ protected function findColumns($table) { - $rows = $this->db->createCommand("SHOW TABLES LIKE " . $this->quoteValue($table->name))->queryAll(); - if (count($rows) === 0) { - return false; - } $sql = 'SHOW FULL COLUMNS FROM ' . $this->quoteSimpleTableName($table->name); - $columns = $this->db->createCommand($sql)->queryAll(); + try { + $columns = $this->db->createCommand($sql)->queryAll(); + } catch (\Exception $e) { + $previous = $e->getPrevious(); + if ($previous instanceof \PDOException && $previous->getCode() == '42S02') { + // table does not exist + return false; + } + throw $e; + } foreach ($columns as $info) { $column = $this->loadColumnSchema($info); $table->columns[$column->name] = $column;