Skip to content

Fix '0' column default preservation during non-strict INSERT - #569

Open
noruzzamans wants to merge 1 commit into
WordPress:trunkfrom
noruzzamans:fix/552-non-strict-insert-zero-default
Open

noruzzamans wants to merge 1 commit into
WordPress:trunkfrom
noruzzamans:fix/552-non-strict-insert-zero-default

Conversation

@noruzzamans

@noruzzamans noruzzamans commented Oct 24, 2026 •

Copy link
Copy Markdown

Fixes #552.

Description

In MySQL non-strict mode, omitted columns during INSERT are filtered out from the synthetic wrapper subquery if they have a default value defined, allowing SQLite to populate their schema default.

Previously, translate_insert_or_replace_body() evaluated $column['COLUMN_DEFAULT'] with a loose truthiness check ($has_default = $column['COLUMN_DEFAULT']). In PHP, string '0' evaluates to false, treating the column as having no default value and incorrectly populating it with an implicit default empty string ('').

This PR:

  • Updates the check to null !== $column['COLUMN_DEFAULT'], consistent with other default checks in the driver.
  • Adds regression test assertions in testNonStrictSqlModeNotNullWithDefault covering DEFAULT '0' and DEFAULT 0.

Testing instructions

Run unit tests in packages/mysql-on-sqlite:

cd packages/mysql-on-sqlite
composer run test -- --filter testNonStrictSqlModeNotNullWithDefault

Summary by CodeRabbit

  • Bug Fixes
    • Corrected handling of columns with a default value of 0 when inserting rows without explicitly providing those columns. Such columns now receive their configured defaults instead of being treated as if no default were set.
    • Added coverage for numeric and text columns with zero defaults to help ensure omitted values are populated correctly.

In non-strict mode, omitted columns are filtered from synthetic subqueries when they have a default value. A loose truthiness check previously caused string '0' to be evaluated as false, substituting an implicit default empty string instead of preserving the column default.

Use strict null check consistent with the rest of the codebase, and add regression assertions in testNonStrictSqlModeNotNullWithDefault.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 190de306-4ec2-40d0-b98a-7d5647088f46
Commits

Reviewing files that changed from the base of the PR and between db55ab1 and 285bebf.

Files selected for processing: 2
  • packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php
  • packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

The omitted-column filter now treats any non-null COLUMN_DEFAULT as a default, including string and integer zero. The test inserts a row without those columns and checks that both values are '0'.

Changes: Non-strict INSERT defaults

Layer / File(s) Summary
Recognize zero defaults
packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php, packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php
The omitted-column filter checks whether COLUMN_DEFAULT is non-null. The test covers omitted string and integer columns with zero defaults.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Possibly related PRs

Suggested reviewers: janjakes

Merge Risk: Minimal · up to 285be

The zero-default fix is correctly scoped and no merge-blocking risk remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: preserving '0' column defaults during non-strict INSERT operations.
Linked Issues check Passed Issue #552 requires non-strict INSERT handling to preserve a defined default of string '0'. The PR changes translate_insert_or_replace_body() to treat COLUMN_DEFAULT as defined when it is not `n…
Out of Scope Changes check Passed The reviewed changes contain one driver condition update and regression test coverage in the related test method. Both changes directly support issue #552. No unrelated product behavior or files appea…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 …
Full details: Linked Issues check

Explanation

Issue #552 requires non-strict INSERT handling to preserve a defined default of string '0'. The PR changes translate_insert_or_replace_body() to treat COLUMN_DEFAULT as defined when it is not null. The PR adds regression assertions for DEFAULT '0' and DEFAULT 0 in testNonStrictSqlModeNotNullWithDefault. These changes address the linked issue. The supplied evidence does not report test execution, but it shows the required automated regression coverage.

Full details: Out of Scope Changes check

Explanation

The reviewed changes contain one driver condition update and regression test coverage in the related test method. Both changes directly support issue #552. No unrelated product behavior or files appear in the supplied change summary.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 too large.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 PHPStan (2.3.0)

PHPStan reported 1 non-file analysis error(s); analysis is incomplete

🔧 PHPMD (3.0.0)
packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php

PHPMD could not process this file (exit code 255): 0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0%
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2097152 bytes) in phar:///usr/bin/phpmd/vendor/pdepend/pdepend/src/Util/Cache/Driver/FileCacheDriver.php on line 183

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@noruzzamans
noruzzamans marked this pull request as ready for review October 24, 2026 11:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant