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);

Issue fork drupal-3118014

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pjotr.savitski created an issue. See original summary.

pjotr.savitski’s picture

Issue summary: View changes
xjm’s picture

Version: 8.8.3 » 8.8.x-dev
sanjayk’s picture

@pjotr.savitski

I have check the same issue and made a patch please apply this patch. If you still any issue please let me know.

sanjayk’s picture

Status: Active » Needs review
daffie’s picture

Status: Needs review » Closed (won't fix)

On MySQL there is no such thing as a medium blob field. MySQL has a "blob" field and a "longblob" field. In Drupal they have respectively the sizes are named "normal" and "big". The "mysql_type" is the direct name MySQL field name, which is here "blob" and that is why it works. Adding the size type "medium" is to me not something that makes the MySQL database driver better. Therefor, for me it is a "won't fix".

gapple’s picture

Version: 8.8.x-dev » 9.1.x-dev
Category: Bug report » Feature request
Priority: Major » Normal
Status: Closed (won't fix) » Needs work

MySQL has Blob sizes corresponding to the available Text field sizes: TINYBLOB (255 bytes), BLOB (65KiB), MEDIUMBLOB (16MiB), and LONGBLOB (4 GiB)

https://dev.mysql.com/doc/refman/5.7/en/blob.html
https://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html#data-t...

The additional field type mappings would also have be applied to the pgsql and sqlite drivers (though both only use a single blob type regardless of size).

gapple’s picture

Title: Error when creating medium blob field for MySQL » Additional blob field sizes in schema definitions
Status: Needs work » Needs review
StatusFileSize
new1.65 KB

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

sanjayk’s picture

Just run test cases for 9.2

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new189 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

amateescu’s picture

Category: Feature request » Bug report

I just closed 2 issues in the IP address fields module which show that this is a real problem that needs to be fixed in core:

- #3467884: Unable to execute related tests via sqlite successfully
- #3268730: Error when the project is over postresql

gapple’s picture

Status: Needs work » Needs review

Made a MR with changes from patch file.

smustgrave’s picture

Status: Needs review » Needs work

Appears to have pipeline issues.

gapple’s picture

Status: Needs work » Needs review

Quick fix to add new words to cspell dictionary

arunsahijpal’s picture

Status: Needs review » Reviewed & tested by the community

The pipeline is all green now and the MR seems to be working fine
Hence moving it to RTBC.

heddn’s picture

+1 on RTBC. I don't think additional test coverage is needed. LGTM.

smustgrave’s picture

daffie’s picture

Category: Bug report » Feature request
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

I think we should add testing for this change. Lets add testing for:
- as a field of a new table
- add a field to an existing table
- change an existing field to use the new field type

For each way to create a field add a check that the field is of the correct type and do that for each new blob type.

Please add a change record

Changed the issue to a feature request.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.