diff -u b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php --- b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -312,7 +312,7 @@ $return[] = 'substr(' . $field[0] . ', 1, ' . $field[1] . ')'; } else { - $return[] = $this->connection->quote($field); + $return[] = '"' . $field . '"'; } } return implode(', ', $return); @@ -329,10 +329,10 @@ $return = array(); foreach ($fields as $field) { if (is_array($field)) { - $return[] = $this->connection->quote($field[0]); + $return[] = '"' . $field[0] . '"'; } else { - $return[] = $this->connection->quote($field); + $return[] = '"' . $field . '"'; } } return implode(', ', $return); @@ -423,7 +423,7 @@ return FALSE; } - $this->connection->query('ALTER TABLE {' . $table . '} DROP COLUMN ' . $this->connection->quote($field)); + $this->connection->query('ALTER TABLE {' . $table . '} DROP COLUMN "' . $field . '"'); return TRUE; } @@ -439,7 +439,7 @@ $default = is_string($default) ? $this->connection->quote($default) : $default; } - $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN ' . $this->connection->quote($field) . ' SET DEFAULT ' . $default); + $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN "' . $field . '" SET DEFAULT ' . $default); } public function fieldSetNoDefault($table, $field) { @@ -453,7 +453,7 @@ public function indexExists($table, $name) { // Details http://www.postgresql.org/docs/8.3/interactive/view-pg-indexes.html $index_name = '{' . $table . '}_' . $name . '_idx'; - return (bool) $this->connection->query('SELECT 1 FROM pg_indexes WHERE indexname = ' . $this->connection->quote($index_name))->fetchField(); + return (bool) $this->connection->query("SELECT 1 FROM pg_indexes WHERE indexname = '$index_name'")->fetchField(); } /** @@ -466,7 +466,7 @@ */ protected function constraintExists($table, $name) { $constraint_name = '{' . $table . '}_' . $name; - return (bool) $this->connection->query('SELECT 1 FROM pg_constraint WHERE conname = ' . $this->connection->quote($constraint_name))->fetchField(); + return (bool) $this->connection->query("SELECT 1 FROM pg_constraint WHERE conname = '$constraint_name'")->fetchField(); } public function addPrimaryKey($table, $fields) { @@ -497,7 +497,7 @@ throw new SchemaObjectExistsException(t("Cannot add unique key @name to table @table: unique key already exists.", array('@table' => $table, '@name' => $name))); } - $this->connection->query('ALTER TABLE {' . $table . '} ADD CONSTRAINT ' . $this->connection->quote($this->prefixNonTable($table, $name, 'key')). ' UNIQUE (' . implode(',', $fields) . ')'); + $this->connection->query('ALTER TABLE {' . $table . '} ADD CONSTRAINT "' . $this->prefixNonTable($table, $name, 'key') . '" UNIQUE (' . implode(',', $fields) . ')'); } public function dropUniqueKey($table, $name) { @@ -505,7 +505,7 @@ return FALSE; } - $this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT ' . $this->connection->quote($this->prefixNonTable($table, $name, 'key'))); + $this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT "' . $this->prefixNonTable($table, $name, 'key') . '"'); return TRUE; } @@ -560,7 +560,7 @@ $field_info = $this->queryFieldInformation($table, $field); foreach ($field_info as $check) { - $this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT ' . $this->connection->quote($check)); + $this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT "' . $check . '"'); } // Remove old default. @@ -571,7 +571,7 @@ // the typecast does not work for conversions to bytea. // @see http://www.postgresql.org/docs/current/static/datatype-binary.html if ($spec['pgsql_type'] != 'bytea') { - $this->connection->query('ALTER TABLE {' . $table . '} ALTER ' . $this->connection->quote($field) . ' TYPE ' . $typecast . ' USING ' . $this->connection->quote($field) . '::' . $typecast); + $this->connection->query('ALTER TABLE {' . $table . '} ALTER "' . $field . '" TYPE ' . $typecast . ' USING "' . $field . '"::' . $typecast); } else { // Do not attempt to convert a field that is bytea already. @@ -580,7 +580,7 @@ // Convert to a bytea type by using the SQL replace() function to // convert any single backslashes in the field content to double // backslashes ('\' to '\\'). - $this->connection->query('ALTER TABLE {' . $table . '} ALTER ' . $this->connection->quote($field) . ' TYPE ' . $typecast . ' USING decode(replace("' . $field . '"' . ", '\\', '\\\\'), 'escape');"); + $this->connection->query('ALTER TABLE {' . $table . '} ALTER "' . $field . '" TYPE ' . $typecast . ' USING decode(replace("' . $field . '"' . ", '\\', '\\\\'), 'escape');"); } } @@ -591,7 +591,7 @@ else { $nullaction = 'DROP NOT NULL'; } - $this->connection->query('ALTER TABLE {' . $table . '} ALTER ' . $this->connection->quote($field) . ' ' . $nullaction); + $this->connection->query('ALTER TABLE {' . $table . '} ALTER "' . $field . '" ' . $nullaction); } if (in_array($spec['pgsql_type'], array('serial', 'bigserial'))) { @@ -602,18 +602,18 @@ $this->connection->query("CREATE SEQUENCE " . $seq); // Set sequence to maximal field value to not conflict with existing // entries. - $this->connection->query('SELECT setval(' . $this->connection->quote($seq) . ', MAX(' . $this->connection->quote($field) . ')) FROM {' . $table . '}'); - $this->connection->query('ALTER TABLE {' . $table . '} ALTER ' . $this->connection->quote($field) . ' SET DEFAULT nextval(' . $this->connection->quote($seq) . ')'); + $this->connection->query("SELECT setval('" . $seq . "', MAX(\"" . $field . '")) FROM {' . $table . "}"); + $this->connection->query('ALTER TABLE {' . $table . '} ALTER ' . $field . ' SET DEFAULT nextval(' . $this->connection->quote($seq) . ')'); } // Rename the column if necessary. if ($field != $field_new) { - $this->connection->query('ALTER TABLE {' . $table . '} RENAME ' . $this->connection->quote($field) . ' TO ' . $this->connection->quote($field_new)); + $this->connection->query('ALTER TABLE {' . $table . '} RENAME "' . $field . '" TO "' . $field_new . '"'); } // Add unsigned check if necessary. if (!empty($spec['unsigned'])) { - $this->connection->query('ALTER TABLE {' . $table . '} ADD CHECK (' . $this->connection->quote($field_new) . ' >= 0)'); + $this->connection->query('ALTER TABLE {' . $table . '} ADD CHECK ("' . $field_new . '" >= 0)'); } // Add default if necessary. @@ -623,7 +623,7 @@ // Change description if necessary. if (!empty($spec['description'])) { - $this->connection->query('COMMENT ON COLUMN {' . $table . '}.' . $this->connection->quote($field_new) . ' IS ' . $this->prepareComment($spec['description'])); + $this->connection->query('COMMENT ON COLUMN {' . $table . '}."' . $field_new . '" IS ' . $this->prepareComment($spec['description'])); } if (isset($new_keys)) { @@ -632,7 +632,7 @@ } protected function _createIndexSql($table, $name, $fields) { - $query = 'CREATE INDEX ' . $this->connection->quote($this->prefixNonTable($table, $name, 'idx')) . ' ON {' . $table . '} ('; + $query = 'CREATE INDEX "' . $this->prefixNonTable($table, $name, 'idx') . '" ON {' . $table . '} ('; $query .= $this->_createKeySql($fields) . ')'; return $query; } diff -u b/core/modules/system/lib/Drupal/system/Tests/Database/SchemaTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/SchemaTest.php --- b/core/modules/system/lib/Drupal/system/Tests/Database/SchemaTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Database/SchemaTest.php @@ -47,6 +47,13 @@ 'not null' => TRUE, 'description' => 'Schema column description.', ), + 'test_field_string' => array( + 'type' => 'varchar', + 'length' => 20, + 'not null' => TRUE, + 'default' => "'\"funky default'\"", + 'description' => 'Schema column description for string.', + ), ), ); db_create_table('test_table', $table_specification);