Repository navigation
Save binary strings to BIT columns as their integer value - #650
Open
youknowriad wants to merge 7 commits into
Open
youknowriad wants to merge 7 commits into
youknowriad wants to merge 7 commits into
Conversation
In MySQL, a binary string saved to a BIT column stores the integer that its bytes represent in big-endian order, so b'101', 0x05, and _binary '\x05' all store 5. These literals are blobs in SQLite, which casts a blob to an integer as text, so the driver saved them as 0 in non-strict mode, and it failed with "cannot store BLOB value in INTEGER column" in strict mode. On INSERT, REPLACE, and UPDATE, a blob saved to a BIT column is now converted to its integer value. A value of more than 64 bits fails with an error. See Automattic/studio#6406 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
PDO SQLite in PHP < 8.4 truncates integers that user-defined functions return to 32 bits, so a BIT value above 2^31 - 1 was saved wrongly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checked against MySQL 8.4: it ignores leading zero bytes of a binary string and rejects one with more than 8 other bytes with "Data too long". The test now uses binary strings, because MySQL rejects hex literals of more than 8 bytes even when the extra bytes are zeros. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
JanJakes
requested changes
Dec 4, 2026
JanJakes
left a comment
Member
There was a problem hiding this comment.
Thanks for fixing this! I left a few comments inline.
SQLite evaluates a subquery that references no column only once, so an UPDATE or ON DUPLICATE KEY UPDATE with an expression such as RAND() saved the same BIT value to all rows. The conversion subquery now references the target column. A BIT value that uses the 64th bit is now rejected. SQLite integers are signed, and a table without STRICT silently saved such a value as a REAL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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 PR saves binary strings to
BITcolumns as the integer value of their bytes, as MySQL does.b'101',0x05, and_binary '\x05'all save5. This applies toINSERT,REPLACE, andUPDATE.Why
The driver stores
BITcolumns as SQLite integers. Hex, bit-value, and_binaryliterals are blobs in SQLite, which casts a blob to an integer as if it was text. So in non-strict mode, every such value was saved as0, and in strict mode, the query failed.BIT(8)columnb'101'50cannot store BLOB value in INTEGER column50x0550cannot store BLOB value in INTEGER column5_binary '<0x01 byte>'10cannot store BLOB value in INTEGER column1_binary '\0'00cannot store BLOB value in INTEGER column0mysqldump writes
BITvalues as_binary '…'strings, and imports run in non-strict mode, so everyBITvalue of an imported dump was silently saved as0. This was reported for a site that uses Ninja Forms, whosenf3_formstable has fourbit(1)columns: Automattic/studio#6406. A test imports a row of that table as mysqldump writes it.Notes
REAL(see Fix long bit literals and validateBITwidths and defaults #636).UPDATEorON DUPLICATE KEY UPDATE, the value is evaluated for each row, as before.BITdifferences from MySQL:'1'saves1. MySQL reads them as binary strings too, and saves49.🤖 Generated with Claude Code