Skip to content

INSERT in non-strict mode stores '' instead of the column default '0' #552

Open

Description

@JanJakes

Reproduction

CREATE TABLE t (id INT NOT NULL, label VARCHAR(10) NOT NULL DEFAULT '0');

SET sql_mode = '';
INSERT INTO t (id) VALUES (1);

SELECT label FROM t;
-- ''   (MySQL: '0')

Reproduced on trunk (3.1.0) with PHP 8.5 and SQLite 3.54.1. In strict mode, the same INSERT stores '0' correctly. WordPress runs in non-strict mode, so plugin tables with a DEFAULT '0' string column can silently get empty values.

Cause

In non-strict mode, the INSERT emulation leaves out omitted columns that have a default, so that SQLite fills them in, and gives the remaining omitted columns their type's implicit default, such as ''. It checks for a default with a truthiness check:

$has_default = $column['COLUMN_DEFAULT'];

PHP treats the string '0' as false, so a '0' default counts as no default. Checking null !== $column['COLUMN_DEFAULT'] would fix it.

Related

Date/time columns with a stored '0' default take the same path and get a zero value. For numeric zero defaults stored by driver 3.1.0 and older (#541, #542), that's the right value by accident. For YEAR string zeros (#545), MySQL expects 2000. A fix changes what both get.

Activity

  1. changed the title [-]Non-strict INSERT stores '' instead of a '0' column default[/-] [+]`INSERT` in non-strict mode stores `''` instead of the column default `'0'`[/+] 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