Skip to content

fix(mysql): treat BINARY columns as Blob in Any type mapping#4225

Open
barry3406 wants to merge 1 commit intolaunchbadge:mainfrom
barry3406:fix/mysql-binary-any-type
Open

fix(mysql): treat BINARY columns as Blob in Any type mapping#4225
barry3406 wants to merge 1 commit intolaunchbadge:mainfrom
barry3406:fix/mysql-binary-any-type

Conversation

@barry3406
Copy link
Copy Markdown
Contributor

@barry3406 barry3406 commented Apr 9, 2026

Does your PR solve an issue?

Fixes #4132

Is this a breaking change?

Yes, this is a breaking behavior change.

Previously, MySQL BINARY(size) columns were mapped through the Any driver to AnyTypeInfoKind::Text, which caused a UTF-8 decoding panic (Utf8Error { valid_up_to: 4, error_len: Some(1) }) when reading raw binary data through AnyRow. After this change, those columns are mapped to AnyTypeInfoKind::Blob and can be decoded as Vec<u8> / &[u8] instead.

Code that previously relied on the (broken) Text mapping and was somehow decoding these columns as strings would need to switch to a binary type, so per Hyrum's Law this should land in the next major release (0.{x + 1}.0).


MySQL BINARY(size) columns report ColumnType::String with the BINARY flag set. The Any driver's type conversion checked the column type but not the flags, so BINARY columns got mapped to AnyTypeInfoKind::Text. Reading raw binary data through AnyRow then blew up with a UTF-8 decoding error.

Before:

SELECT * FROM test  -- where `id` is BINARY(16)
-- panics: Utf8Error { valid_up_to: 4, error_len: Some(1) }

After:

-- works: BINARY columns correctly mapped to Blob

The fix checks ColumnFlags::BINARY for String/VarString/VarChar column types and maps to Blob when set.

MySQL BINARY(size) columns report ColumnType::String with the BINARY
flag set. The Any driver type conversion only checked the column type
without looking at flags, so BINARY columns got mapped to
AnyTypeInfoKind::Text instead of Blob. This caused UTF-8 decoding
errors when reading raw binary data through AnyRow.

Check ColumnFlags::BINARY for String/VarString/VarChar column types
and map to Blob when set.

Fixes launchbadge#4132
Copy link
Copy Markdown
Collaborator

@abonander abonander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barry3406 you somehow bypassed the PR template which asks you if there are any breaking changes, and if so, to characterize them. This is a breaking behavior change, so can you please add that to your PR description?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected treat MySQL BINARY(size) type as String in AnyRow

2 participants