You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
INSERT in non-strict mode stores '' instead of the column default '0' #552
CREATETABLEt (id INTNOT 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.
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
Activity
[-]Non-strict INSERT stores '' instead of a '0' column default[/-][+]`INSERT` in non-strict mode stores `''` instead of the column default `'0'`[/+]