From: Alexander Ebert Date: Fri, 5 Aug 2011 12:43:11 +0000 (+0200) Subject: Inserted backticks for foreign keys in MySQL X-Git-Tag: 2.0.0_Beta_1~1910 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=960176790a229eaa21cff08360ccab195a821ca8;p=GitHub%2FWoltLab%2FWCF.git 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. --- 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(); }