Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sqlx-mysql/src/any.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::protocol::text::ColumnType;
use crate::protocol::text::{ColumnFlags, ColumnType};
use crate::{
MySql, MySqlColumn, MySqlConnectOptions, MySqlConnection, MySqlQueryResult, MySqlRow,
MySqlTransactionManager, MySqlTypeInfo,
Expand Down Expand Up @@ -169,7 +169,11 @@ impl<'a> TryFrom<&'a MySqlTypeInfo> for AnyTypeInfo {
| ColumnType::MediumBlob
| ColumnType::LongBlob => AnyTypeInfoKind::Blob,
ColumnType::String | ColumnType::VarString | ColumnType::VarChar => {
AnyTypeInfoKind::Text
if type_info.flags.contains(ColumnFlags::BINARY) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Using the BINARY flag is actually misleading, because it's also set for text collations with the binary property, e.g. utf8mb4_bin. This was the root cause of #3387 which resulted in a lot of complaints and headache.

There's some more context in https://github.com/launchbadge/sqlx/blob/main/sqlx-mysql/src/collation.rs#L1-L37 but the gist of it is that the main discriminator is the collation ID: binary (63) is a binary blob, everything else we just assume is a string (ignoring the character set, because it's actually always transcoded to the connection character set).

To avoid duplicating this logic, this could just forward to str::is_compatible() and [u8]::is_compatible().

I think it's also important to add a test for this, both to verify the fix and to guard against future regressions.

AnyTypeInfoKind::Blob
} else {
AnyTypeInfoKind::Text
}
}
_ => {
return Err(sqlx_core::Error::AnyDriverError(
Expand Down
Loading