commit 541947e80b684e6438d956dcf8ee6e5b178eff5c Author: Matthew Radcliffe Date: Mon Oct 7 23:37:15 2013 -0400 Issue #2001350 by mfradcliffe: Add a helper function to add primary keys because it was merely imploding an array, which sometimes has arrays inside of it. Didn't implement FILLFACTOR due to complexity. diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php index 8b4f913..5f33415 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -130,7 +130,7 @@ protected function createTableSql($name, $table) { $sql_keys = array(); if (isset($table['primary key']) && is_array($table['primary key'])) { - $sql_keys[] = 'PRIMARY KEY (' . implode(', ', $table['primary key']) . ')'; + $sql_keys[] = 'PRIMARY KEY (' . $this->_createPrimaryKeySql($table['primary key']) . ')'; } if (isset($table['unique keys']) && is_array($table['unique keys'])) { foreach ($table['unique keys'] as $key_name => $key) { @@ -318,6 +318,21 @@ protected function _createKeySql($fields) { return implode(', ', $return); } + protected function _createPrimaryKeySql($fields) { + $return = array(); + foreach ($fields as $field) { + if (is_array($field)) { + // Postgresql does not support key length. It does support fillfactor, + // but that requires a db lookup for each column. + $return[] = '"' . $field[0] . '"'; + } + else { + $return[] = '"' . $field . '"'; + } + } + return implode(', ', $return); + } + function renameTable($table, $new_name) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot rename @table to @table_new: table @table doesn't exist.", array('@table' => $table, '@table_new' => $new_name))); @@ -457,7 +472,7 @@ public function addPrimaryKey($table, $fields) { throw new SchemaObjectExistsException(t("Cannot add primary key to table @table: primary key already exists.", array('@table' => $table))); } - $this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . implode(',', $fields) . ')'); + $this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->_createPrimaryKeySql($fields) . ')'); } public function dropPrimaryKey($table) {