Skip to content

Zero-pad fixed-length binary fields #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Zero-pad fixed-length binary fields #2

wants to merge 1 commit into from

Conversation

oseemann
Copy link
Owner

@oseemann oseemann commented May 13, 2023

MySQL is zero-padding fixed-length binary fields [1], but is not storing trailing zeros to the binlog. Consequently, when reading values of fixed-length binary fields, the value must be padded with zeros up to the specified length.

The test_fixed_length_binary test case exemplifies the issue. varbinary columns are not padded and not affected.

This commit extends the information_schema query in __get_table_information to fetch information about the length limitation of the field and stores this information in the fixed_binary_length attribute of Column instances.

Upon decoding of binary fields (which share the same binlog field type value of 254 as strings), the value is zero padded at the end, when it does not meet the specified length as retrieved from the information schema.

[1] https://dev.mysql.com/doc/refman/5.7/en/binary-varbinary.html

MySQL is zero-padding fixed-length binary fields [1], but is not storing
trailing zeros to the binlog. Consequently, when reading values of
fixed-length binary fields, the value must be padded with zeros up to
the specified length.

The `test_fixed_length_binary` test case exemplifies the issue.
`varbinary` columns are not padded and not affected.

This commit extends the `information_schema` query in
`__get_table_information` to fetch information about the length
limitation of the field and stores this information in the
`fixed_binary_length` attribute of `Column` instances.

Upon decoding of binary fields (which share the same binlog field type
value of `254` as strings), the value is zero padded at the end, when it
does not meet the specified length as retrieved from the information
schema.

Fixes julien-duponchelle#400.

[1] https://dev.mysql.com/doc/refman/5.7/en/binary-varbinary.html
@oseemann oseemann closed this May 25, 2023
@oseemann oseemann deleted the issue-400 branch June 3, 2023 20:44
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