From 245424a42794a8fa741b6fe86b78f2dda0a51e93 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 21 Sep 2014 16:50:12 +0200 Subject: [PATCH] Added support for 'DROP FOREIGN KEY' --- .../lib/system/database/util/SQLParser.class.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wcfsetup/install/files/lib/system/database/util/SQLParser.class.php b/wcfsetup/install/files/lib/system/database/util/SQLParser.class.php index 439ef7b2a9..433f364eb2 100644 --- a/wcfsetup/install/files/lib/system/database/util/SQLParser.class.php +++ b/wcfsetup/install/files/lib/system/database/util/SQLParser.class.php @@ -157,6 +157,10 @@ class SQLParser { else if (preg_match('~^ALTER\s+TABLE\s+(\w+)\s+DROP\s+(?:INDEX|KEY)\s+(\w+)~is', $query, $match)) { $this->executeDropIndexStatement($match[1], $match[2]); } + // drop foreign key + else if (preg_match('~^ALTER\s+TABLE\s+(\w+)\s+DROP\s+FOREIGN KEY\s+(\w+)~is', $query, $match)) { + $this->executeDropForeignKeyStatement($match[1], self::getGenericIndexName($match[1], $match[2], 'fk')); + } // drop column else if (preg_match('~^ALTER\s+TABLE\s+(\w+)\s+DROP\s+(?:COLUMN\s+)?(\w+)~is', $query, $match)) { $this->executeDropColumnStatement($match[1], $match[2]); @@ -278,6 +282,16 @@ class SQLParser { WCF::getDB()->getEditor()->dropIndex($tableName, $indexName); } + /** + * Executes a 'DROP FOREIGN KEY' statement. + * + * @param string $tableName + * @param string $indexName + */ + protected function executeDropForeignKeyStatement($tableName, $indexName) { + WCF::getDB()->getEditor()->dropForeignKey($tableName, $indexName); + } + /** * Executes a 'DROP TABLE' statement. * -- 2.20.1