Implement FROM_BASE64() and TO_BASE64() MySQL functions#326
Merged
Conversation
These functions allow encoding and decoding base64 data in SQL queries, matching the behavior of their MySQL counterparts. They are registered as SQLite user-defined functions backed by PHP's base64_encode() and base64_decode(), so both the legacy and AST-based drivers can use them. FROM_BASE64() returns NULL for NULL or invalid base64 input. TO_BASE64() returns NULL for NULL input.
2 tasks
adamziel
added a commit
to adamziel/streaming-site-migration
that referenced
this pull request
Mar 13, 2026
## Summary
- Registers `FROM_BASE64()` and `TO_BASE64()` as SQLite user-defined
functions when creating a SQLite target connection for db-apply
- `MySQLDumpProducer` encodes all non-numeric values as
`FROM_BASE64('...')` in SQL dumps — without these function definitions,
SQLite imports fail because SQLite has no built-in base64 support
- Both functions handle NULL inputs correctly
- We'll be able to remove those functions once
WordPress/sqlite-database-integration#326 gets
released
## Test plan
- [ ] Verify existing e2e test `import-38-db-apply-sqlite-target` still
passes
- [ ] Verify unit tests pass (`composer test:fast` — confirmed locally,
432 tests green)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds support for MySQL's
FROM_BASE64()andTO_BASE64()functions, allowing SQL queries to encode and decode base64 data.Both functions are implemented as SQLite user-defined functions backed by PHP's
base64_encode()andbase64_decode(). Because they're registered throughWP_SQLite_PDO_User_Defined_Functions::register_for(), they work with both the legacy and AST-based drivers automatically.FROM_BASE64()returnsNULLforNULLor invalid base64 input.TO_BASE64()returnsNULLforNULLinput.Test plan
composer run test -- --filter 'testFromBase64|testToBase64'