close
Skip to content

Implement FROM_BASE64() and TO_BASE64() MySQL functions#326

Merged
adamziel merged 1 commit intotrunkfrom
add-base64-functions
Mar 11, 2026
Merged

Implement FROM_BASE64() and TO_BASE64() MySQL functions#326
adamziel merged 1 commit intotrunkfrom
add-base64-functions

Conversation

@adamziel
Copy link
Collaborator

Summary

This adds support for MySQL's FROM_BASE64() and TO_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() and base64_decode(). Because they're registered through WP_SQLite_PDO_User_Defined_Functions::register_for(), they work with both the legacy and AST-based drivers automatically.

FROM_BASE64() returns NULL for NULL or invalid base64 input. TO_BASE64() returns NULL for NULL input.

Test plan

  • Run composer run test -- --filter 'testFromBase64|testToBase64'
  • Verify basic encoding/decoding, NULL handling, empty string handling, and round-trip correctness

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.
@adamziel adamziel requested a review from JanJakes March 10, 2026 09:39
@adamziel adamziel merged commit c92910c into trunk Mar 11, 2026
16 checks passed
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)
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.

1 participant