diff --git a/src/Storage/IntColumnHandler.php b/src/Storage/IntColumnHandler.php index 27c064e..a1038ef 100644 --- a/src/Storage/IntColumnHandler.php +++ b/src/Storage/IntColumnHandler.php @@ -94,20 +94,21 @@ abstract class IntColumnHandler implements IntColumnHandlerInterface { $schema->addField($table, $column_int, $spec); $schema->addIndex($table, $column_int, $index_fields, $full_spec); } + $column = $this->connection->escapeField($column); + $column_int = $this->connection->escapeField($column_int); // This is the heart of this function: before an UPDATE/INSERT, set the // value of the integer column to the integer value of the string column. $body[] = $this->createBody($column_int, $column); } if ($new) { $body = implode(', ', $body); - // Remove identifier quotes from the table name. See - // \Drupal\Core\Database\Connection::$identifierQuotes. - $prefixed_name = trim($this->connection->prefixTables('{' . $table . '}'), '"'); + $prefixed_name = $this->connection->prefixTables('{' . $table . '}'); foreach (['update', 'insert'] as $op) { - $trigger = $prefixed_name . '_der_' . $op; + $trigger = trim($prefixed_name, '"') . '_der_' . $op; if (strlen($trigger) > 64) { $trigger = substr($trigger, 0, 56) . substr(hash('sha256', $trigger), 0, 8); } + $trigger = $this->connection->escapeField($trigger); $this->connection->query("DROP TRIGGER IF EXISTS $trigger"); if ($body) { $this->createTrigger($trigger, $op, $prefixed_name, $body); diff --git a/src/Storage/IntColumnHandlerPostgreSQL.php b/src/Storage/IntColumnHandlerPostgreSQL.php index 4894a1d..7966774 100644 --- a/src/Storage/IntColumnHandlerPostgreSQL.php +++ b/src/Storage/IntColumnHandlerPostgreSQL.php @@ -100,6 +100,7 @@ class IntColumnHandlerPostgreSQL implements IntColumnHandlerInterface { protected function createTrigger($table, $column, $column_int) { $function_name = $this->getFunctionName($table, $column_int); $prefixed_table = $this->getPrefixedTable($table); + $column_int = $this->connection->escapeField($column_int); // It is much easier to just drop and recreate than figuring it out whether // it exists. $this->connection->query("DROP TRIGGER IF EXISTS $column_int ON $prefixed_table"); @@ -124,7 +125,7 @@ class IntColumnHandlerPostgreSQL implements IntColumnHandlerInterface { * The plpgsql function name. */ protected function getFunctionName($table, $column_int) { - return implode('_', [$this->getPrefixedTable($table), $column_int]); + return $this->connection->escapeField(implode('_', [$this->getPrefixedTable($table), $column_int])); } /** @@ -137,9 +138,7 @@ class IntColumnHandlerPostgreSQL implements IntColumnHandlerInterface { * The prefixed table name. */ protected function getPrefixedTable($table) { - // Remove identifier quotes from the table name. See - // \Drupal\Core\Database\Driver\pgsql\Connection::$identifierQuotes. - return trim($this->connection->prefixTables('{' . $table . '}'), '"'); + return $this->connection->prefixTables('{' . $table . '}'); } }