Skip to content

Support odd-length 0x hexadecimal literals - #573

Merged
JanJakes merged 1 commit into
trunkfrom
fix-odd-hex-literals
Oct 27, 2026
Merged

JanJakes merged 1 commit into
trunkfrom
fix-odd-hex-literals

Conversation

@JanJakes

@JanJakes JanJakes commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

The AST driver converts 0x711 to x'711', which SQLite rejects. This breaks otherwise valid queries and SQL imports.

Pad odd-length 0x literals with a leading zero before translating them to SQLite blob literals, matching MySQL's documented behavior. Existing leading zeros are preserved, and odd-length quoted X'…' literals remain invalid.

Regression tests cover reads, HEX(), inserts and updates into text and blob columns, single-digit values, leading zeros, mixed-case digits, long literals, and invalid quoted literals.

Fixes #543.

Summary by CodeRabbit

  • Bug Fixes
    • Odd-length numeric hexadecimal literals are now handled correctly in queries and when writing to text, varchar, or blob columns. A leading zero completes the final byte; for example, 0x711 is interpreted as 0x0711. Even-length numeric literals continue to behave as before.
    • Odd-length quoted hexadecimal literals remain rejected rather than being treated as valid numeric literals.

@coderabbitai

coderabbitai Bot commented Oct 27, 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: 1f88d5b4-e871-4c4b-b2ea-fc96c33cd5d2
Commits

Reviewing files that changed from the base of the PR and between 1313683 and cd4384b.

Files selected for processing: 1
  • 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; 0 remain after this review.

Walkthrough

The translator now pads odd-length numeric 0x literals with a leading zero before emitting SQLite hex-string literals. Tests cover conversion, decoded values, writes to text and blob columns, and rejection of odd-length quoted hexadecimal literals.

Changes: Hexadecimal literal handling

Layer / File(s) Summary
Pad odd-length numeric literals
packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php, packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Tests.php, packages/mysql-on-sqlite/tests/WP_MySQL_On_SQLite_Translation_Tests.php
translate_token() pads odd-length numeric hexadecimal payloads before emitting SQLite hex-string literals. Tests cover odd- and even-length forms, decoded bytes, writes to text and blob columns, and rejection of odd-length quoted forms.

Priority: Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: chubes4

Merge Risk: Minimal · up to cd438

Odd-length numeric hex literals are padded without changing quoted literals. No merge-blocking risk is identified.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: fixing odd-length hexadecimal literal handling.
Linked Issues check Passed Issue #543 requires that odd-length unquoted 0x literals be left-padded to whole bytes before SQLite translation, so 0x711 becomes x'0711'. Odd-length quoted X'…' literals must stay invalid. The whole…
Out of Scope Changes check Passed The reported changes are limited to hexadecimal-literal translation in class-wp-mysql-on-sqlite.php and regression tests in WP_MySQL_On_SQLite_Tests.php and WP_MySQL_On_SQLite_Translation_Tests.php. T…
Full details: Linked Issues check

Explanation

Issue #543 requires that odd-length unquoted 0x literals be left-padded to whole bytes before SQLite translation, so 0x711 becomes x'0711'. Odd-length quoted X'…' literals must stay invalid. The whole-PR summary states that translate_token() in packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php prepends a zero to odd-length HEX_NUMBER payloads and leaves even-length payloads unchanged (+7/-1). The test summaries cover 0x711 → x'0711' and 0x00711 → x'000711' in WP_MySQL_On_SQLite_Translation_Tests.php, read and write tests for text and blob columns in WP_MySQL_On_SQLite_Tests.php, and rejection of odd-length quoted literals through testOddLengthQuotedHexadecimalLiteralsAreRejected. The prior review read the source directly and found the same behavior. In this review, the source diff tool could not read the changed blobs, and the file read was truncated before the HEX_NUMBER section. The source-level conclusion therefore rests on the summaries and the prior review, not on a fresh line-level read. The change since the previous reviewed head (1313683) was not separately verified.

Full details: Out of Scope Changes check

Explanation

The reported changes are limited to hexadecimal-literal translation in class-wp-mysql-on-sqlite.php and regression tests in WP_MySQL_On_SQLite_Tests.php and WP_MySQL_On_SQLite_Translation_Tests.php. The production change is the padding of odd-length 0x payloads, which implements #543. The test changes verify that padding, its write-path behavior, and the quoted-literal rejection that #543 requires. The test method signature change to testHexadecimalLiterals(string $literal, string $hex) and the new data providers support those same cases. The summaries identify no unrelated production behavior or unrelated test area. The source diff could not be read directly in this review, so this conclusion relies on the summaries and the prior review.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • 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.

Add a leading zero to odd-length 0x literals before translating them to SQLite blob literals. Preserve leading zeros and keep rejecting odd-length quoted hexadecimal literals.

Cover SELECT, HEX(), INSERT, UPDATE, and literal edge cases.

Fixes #543
@JanJakes
JanJakes force-pushed the fix-odd-hex-literals branch from 1313683 to cd4384b Compare October 27, 2026 13:01
@JanJakes
JanJakes merged commit 57eb90d into trunk Oct 27, 2026
18 checks passed
@JanJakes
JanJakes deleted the fix-odd-hex-literals branch October 27, 2026 13:16
@youknowriad

Copy link
Copy Markdown

Hello folks, when can we expect this one in a release.

@JanJakes JanJakes changed the title Fix odd-length hexadecimal literals Support odd-length 0x hexadecimal literals Oct 28, 2026
@JanJakes JanJakes mentioned this pull request Oct 28, 2026
JanJakes added a commit that referenced this pull request Oct 28, 2026
## Release `3.1.2`

Version bump and changelog update for release `3.1.2`.

**Changelog draft:**
* Allow configuring the SQLite busy timeout with `SQLITE_BUSY_TIMEOUT`
([#558](#558))
* Keep the user transaction active after a failed statement
([#536](#536))
* Support odd-length `0x` hexadecimal literals
([#573](#573))
* Fix rebuilds of legacy text and binary columns
([#565](#565))
* Use `'0'` column defaults in non-strict `INSERT` statements
([#569](#569))
* Roll back failed `OPTIMIZE TABLE` and `REPAIR TABLE` rebuilds
([#567](#567))
* Remove the Rust parser extension
([#566](#566))
* Preserve `AUTO_INCREMENT` counters when rebuilding tables
([#561](#561))
* Fix `ALTER TABLE ... ADD (...)` for columns, indexes, and constraints
([#557](#557))
* Fix `ON UPDATE CURRENT_TIMESTAMP` for explicit values and unchanged
rows
([#560](#560))
* Normalize zero defaults in date and time columns
([#542](#542))
* Add support for `ALTER COLUMN` with `SET DEFAULT` and `DROP DEFAULT`
([#555](#555))

**Full changelog:**
v3.1.1...release/v3.1.2

## Next steps

1. **Review** the changes in this pull request.
2. **Push** any additional edits to this branch (`release/v3.1.2`).
3. **Merge** this pull request to complete the release.

Merging will automatically build the plugin ZIP, create a [GitHub
release](https://github.com/WordPress/sqlite-database-integration/releases),
and deploy to
[WordPress.org](https://wordpress.org/plugins/sqlite-database-integration/).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Release**
  * Updated the SQLite database integration to version 3.1.2.

* **New Features**
* Added support for more `ALTER TABLE` operations and configurable
SQLite busy timeouts.

* **Bug Fixes**
* Improved transaction handling after failed statements and addressed
SQL compatibility, table rebuild, and default-value handling issues.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@JanJakes

Copy link
Copy Markdown
Member Author

@youknowriad I just released v3.1.2.

@youknowriad

Copy link
Copy Markdown

Awesome thanks :)

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.

AST driver rejects odd-length 0x hex literals that MySQL accepts (e.g. 0x711)

2 participants