sqlite should enforce VARCHAR column lengths with a CHECK constraint

Created on 22 June 2021, almost 4 years ago
Updated 3 March 2025, about 1 month ago

Problem/Motivation

When running tests of entities or other code on mysql vs. sqlite one expects reasonably consistent results.

Drupal code in the mysql driver sets the STRICT_ALL_TABLES mode so that inserting an over-long string into a VARCHAR field is an error
https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict

However, the sqlite driver does not add any column constraints on with a CHECK statement on those columns so a value that would cause a database exception on mysql will work on sqlite becuase any length string is saved as the expected behavior (see https://www.sqlite.org/faq.html).

Steps to reproduce

Run a kernel test on mysql and sqlite with an entity type with a field with a 40 char limit. Insert 100 char string - notice that it works on sqlite, fails on mysql.

Proposed resolution

sqlite should enforce VARCHAR column lengths with a CHECK constraint.

Remaining tasks

patch + tests

User interface changes

n/a

API changes

n/a

Data model changes

Newly created sqlite tables will enforce VARCHAR lengths.

Release notes snippet

todo

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component

sqlite db driver

Created by

🇺🇸United States pwolanin

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