Additional blob field sizes in schema definitions

Created on 5 March 2020, almost 5 years ago
Updated 30 January 2023, almost 2 years ago

Trying to create medium blob field for MySQL results in a database error. Current case an examples are from running the code during update function call. Though it will most probably produce the same results when defining schema.

Changing size to values of big or normal seemed to be working just fine.

Code producing an error:

  $data_spec = [
    'description' => 'Serialized data',
    'type' => 'blob',
    'serialize' => TRUE,
    'not null' => FALSE,
    'size' => 'medium',
  ];

  $schema = \Drupal::service('database')->schema();

  $schema->addField('some_table', 'data', $data_spec);

The error produced is:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL DEFAULT NULL COMMENT 'Serialized data'' at line 1: ALTER TABLE {some_table} ADD `data`  NULL DEFAULT NULL COMMENT 'Serialized data';

It does seem that required data type is not detected correctly in in case size is set to medium.

Running similar code with MySQL specific hint works as expected:

  $data_spec = [
    'description' => 'Serialized data',
    'type' => 'blob',
    'mysql_type' => 'blob',
    'serialize' => TRUE,
    'not null' => FALSE,
    'size' => 'medium',
  ];

  $schema = \Drupal::service('database')->schema();

  $schema->addField('some_table', 'data', $data_spec);
Feature request
Status

Needs work

Version

10.1

Component
Database 

Last updated about 20 hours ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇪🇪Estonia pjotr.savitski

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

Merge Requests

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