Column default values cannot contain braces on MSSQL

Created on 8 July 2015, about 9 years ago
Updated 25 August 2023, about 1 year ago

If you try to define a Field with a default value that contains a brace (for example a string literal 'a:{}') prefixTables() in Connection.php
will strip them out (or even prefix them!).

This is because the statement used to create and alter fields uses the DEFAULT literal (because there is no way PDO will let you bind parameters to an ALTER TABLE or CREATE TABLE statement):

    // $spec['default'] can be NULL, so we explicitly check for the key here.
    if (array_key_exists('default', $spec)) {
      $sql .= ' DEFAULT ' . $this->escapeDefaultValue($spec['default']);
    }

This is already fixed in the MSSQL server driver for 7.x, but this bug affects both 7.x and 8.x of drupal core.

Just reporting this if someone wants to fix it on the core database drivers. What I did on the MSSQL driver was to embed the table prefixing logic into the query generation, and then skip prefixTables().

Probably prefixTables() could be replaced by regex logic to overcome the issue.

πŸ› Bug report
Status

Closed: outdated

Version

9.5

Component
DatabaseΒ  β†’

Last updated less than a minute ago

  • Maintained by
  • πŸ‡³πŸ‡±Netherlands @daffie
Created by

πŸ‡ͺπŸ‡ΈSpain david_garcia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024