Skip to content

ALTER TABLE fails when legacy BLOB columns contain TEXT values #546

Open

Description

@JanJakes

Problem

Rebuilding a table created by the legacy driver can fail when a BLOB column contains a value stored as SQLite TEXT. This affects ALTER TABLE, OPTIMIZE TABLE, and REPAIR TABLE.

The legacy driver accepts an ordinary string for a BLOB column and stores it with SQLite's TEXT storage class. The AST driver can open and read that table, but rebuilding it creates a STRICT table and copies the values without converting their storage classes.

Reproduction

Using the legacy driver from v2.2.23, run:

CREATE TABLE blob_demo (id INT PRIMARY KEY, payload BLOB);
INSERT INTO blob_demo VALUES (1, 'abc');

Reopen the same database with the AST driver, then run:

ALTER TABLE blob_demo ADD COLUMN note TEXT;

The statement fails:

SQLSTATE[23000]: Integrity constraint violation: 19 cannot store TEXT value in BLOB column _wp_sqlite_tmp_blob_demo_<suffix>.payload

A native SQLite query confirms that the original value is stored as TEXT:

SELECT payload, typeof(payload) FROM blob_demo;
-- abc | text

On separate copies of the original database, OPTIMIZE TABLE blob_demo and REPAIR TABLE blob_demo return the same failure in their result rows.

Verified on trunk at e88a817e89a80c4fab2b46f86606367822695b45, with PHP 8.3.35 and SQLite 3.54.1.

Expected behavior

Rebuilding a legacy table should preserve its valid data. The shared copy operation needs to handle legacy storage classes while preserving the bytes of binary values.

The relevant path is recreate_table_from_information_schema().

This can also affect sites already running the AST driver, because earlier upgrades retained the original SQLite tables.

Related

Activity

  1. changed the title [-]ALTER TABLE fails when legacy BLOB columns contain TEXT values[/-] [+]`ALTER TABLE` fails when legacy `BLOB` columns contain `TEXT` values[/+] on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions