Match MySQL mixed-type result and comparison semantics for IF(), CASE, and IFNULL()
Maintainers usually reply within 1 day
@JanJakes is already working on this.
Since Oct 6, 2026.
Assessment
This issue has not been assessed yet.
Description
Summary
Implement MySQL-compatible mixed-type result conversion and comparison semantics for IF(), CASE, and IFNULL().
This is a pre-existing compatibility gap, separate from the IF() condition-evaluation bug in #517. Keep #518 focused on that bug. Build this follow-up on the comparison work in #508.
Reproduction and rationale
SELECT IF(1, 2, '3') = '2';
MySQL returns 1. The raw SQLite translation returns 0:
SELECT CASE WHEN 1 THEN 2 ELSE '3' END = '2';
SQLite preserves the selected branch's integer storage class. MySQL applies result-type rules across the branches. Related mixed-type conversion gaps affect CASE and IFNULL().
An unconditional text cast can fix this example but break numeric comparisons. The solution must account for both result-type rules and the surrounding comparison semantics.
Required changes
- Determine MySQL result-type and comparison rules for mixed numeric, string, and NULL values in
IF(),CASE, andIFNULL(). - Extend the translator and comparison handling from #508 to reproduce those rules consistently.
- Preserve lazy evaluation of unselected branches and fallback expressions.
- Add regression tests against MySQL reference results for string comparisons, numeric comparisons, NULLs, nested expressions, and column-derived values.
- Avoid an unconditional text cast as the general solution.
Affected areas
packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php:translate_runtime_function_call(), expression translation, and comparison handling.packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php: regression coverage forIF(),CASE, andIFNULL().
Acceptance criteria
SELECT IF(1, 2, '3') = '2'returns1, matching MySQL.- Mixed-type string and numeric comparison cases for all three constructs match MySQL reference results.
- NULL handling and lazy evaluation remain correct.
- Existing IF() condition-evaluation and comparison tests continue to pass.
Context
Requested by @JanJakes.
- Originating PR: https://github.com/WordPress/sqlite-database-integration/pull/518
- Review discussion: https://github.com/WordPress/sqlite-database-integration/pull/518#discussion_r4194619968
- Related comparison work: https://github.com/WordPress/sqlite-database-integration/pull/508
- Dominant language
- PHP
- Stars
- 362
- Forks
- 67
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 5
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from WordPress/sqlite-database-integration
-
MySQL-on-SQLite does not translate DATE arithmetic with INTERVAL HOURPossibly taken @samuelmbabhazi claimed this 17 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
WordPress/sqlite-database-integration#454 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
WordPress/sqlite-database-integration#516 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
WordPress/sqlite-database-integration#515 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
WordPress/sqlite-database-integration#513 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
WordPress/sqlite-database-integration#504 · 3 comments ·
Maintainers usually reply within 1 day
All issues in WordPress/sqlite-database-integration
Similar issues
-
Bug Enhancement Performance
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Feature Status: Needs Triage
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 1 day
-
frontend low-priority
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
mplodowski/dynamicpdf-plugin#336 ·
Maintainers usually reply within 1 day
-
Add ZammadPossibly taken @Arslan-TR claimed this today. Openrequest
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
endoflife-date/endoflife.date#11298 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
FriendsOfFlarum/best-answer#137 ·