From 960176790a229eaa21cff08360ccab195a821ca8 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 5 Aug 2011 14:43:11 +0200 Subject: [PATCH] Inserted backticks for foreign keys in MySQL Somehow MySQL does not like symbol names starting with a number, while within backticks they're allowed. As a side note, documentation does not mention this pitfall once. Like always. --- .../lib/system/database/editor/MySQLDatabaseEditor.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php b/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php index c9678debde..53fac0494f 100644 --- a/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php +++ b/wcfsetup/install/files/lib/system/database/editor/MySQLDatabaseEditor.class.php @@ -138,7 +138,7 @@ class MySQLDatabaseEditor extends DatabaseEditor { $sql = "ALTER TABLE ".$tableName." ADD"; // add index name - if (!empty($indexName)) $sql .= " CONSTRAINT ".$indexName; + if (!empty($indexName)) $sql .= " CONSTRAINT `".$indexName."`"; // add columns $sql .= " FOREIGN KEY (".str_replace(',', ',', preg_replace('/\s+/', '', $indexData['columns'])).")"; @@ -169,7 +169,7 @@ class MySQLDatabaseEditor extends DatabaseEditor { * @see wcf\system\database\editor\DatabaseEditor::dropForeignKey() */ public function dropForeignKey($tableName, $indexName) { - $sql = "ALTER TABLE ".$tableName." DROP FOREIGN KEY ".$indexName; + $sql = "ALTER TABLE ".$tableName." DROP FOREIGN KEY `".$indexName."`"; $statement = $this->dbObj->prepareStatement($sql); $statement->execute(); } -- 2.20.1