Skip to content
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

Remove collation compatibility check. #2652

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 6 additions & 10 deletions sqlx-mysql/src/protocol/text/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ pub(crate) struct ColumnDefinition {
table: Bytes,
alias: Bytes,
name: Bytes,
pub(crate) char_set: u16,
#[allow(unused)]
pub(crate) collation: u16,
pub(crate) max_size: u32,
pub(crate) r#type: ColumnType,
pub(crate) flags: ColumnFlags,
Expand Down Expand Up @@ -142,7 +143,7 @@ impl Decode<'_, Capabilities> for ColumnDefinition {
let alias = buf.get_bytes_lenenc();
let name = buf.get_bytes_lenenc();
let _next_len = buf.get_uint_lenenc(); // always 0x0c
let char_set = buf.get_u16_le();
let collation = buf.get_u16_le();
let max_size = buf.get_u32_le();
let type_id = buf.get_u8();
let flags = buf.get_u16_le();
Expand All @@ -155,7 +156,7 @@ impl Decode<'_, Capabilities> for ColumnDefinition {
table,
alias,
name,
char_set,
collation,
max_size,
r#type: ColumnType::try_from_u16(type_id)?,
flags: ColumnFlags::from_bits_truncate(flags),
Expand All @@ -165,13 +166,8 @@ impl Decode<'_, Capabilities> for ColumnDefinition {
}

impl ColumnType {
pub(crate) fn name(
self,
char_set: u16,
flags: ColumnFlags,
max_size: Option<u32>,
) -> &'static str {
let is_binary = char_set == 63;
pub(crate) fn name(self, flags: ColumnFlags, max_size: Option<u32>) -> &'static str {
let is_binary = flags.contains(ColumnFlags::BINARY);
let is_unsigned = flags.contains(ColumnFlags::UNSIGNED);
let is_enum = flags.contains(ColumnFlags::ENUM);

Expand Down
9 changes: 2 additions & 7 deletions sqlx-mysql/src/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::protocol::text::{ColumnDefinition, ColumnFlags, ColumnType};
pub struct MySqlTypeInfo {
pub(crate) r#type: ColumnType,
pub(crate) flags: ColumnFlags,
pub(crate) char_set: u16,

// [max_size] for integer types, this is (M) in BIT(M) or TINYINT(M)
#[cfg_attr(feature = "offline", serde(default))]
Expand All @@ -22,7 +21,6 @@ impl MySqlTypeInfo {
Self {
r#type: ty,
flags: ColumnFlags::BINARY,
char_set: 63,
max_size: None,
}
}
Expand All @@ -32,7 +30,6 @@ impl MySqlTypeInfo {
Self {
r#type: ColumnType::Enum,
flags: ColumnFlags::BINARY,
char_set: 63,
max_size: None,
}
}
Expand All @@ -55,7 +52,6 @@ impl MySqlTypeInfo {
Self {
r#type: column.r#type,
flags: column.flags,
char_set: column.char_set,
max_size: Some(column.max_size),
}
}
Expand All @@ -73,7 +69,7 @@ impl TypeInfo for MySqlTypeInfo {
}

fn name(&self) -> &str {
self.r#type.name(self.char_set, self.flags, self.max_size)
self.r#type.name(self.flags, self.max_size)
}
}

Expand Down Expand Up @@ -102,9 +98,8 @@ impl PartialEq<MySqlTypeInfo> for MySqlTypeInfo {
| ColumnType::String
| ColumnType::VarString
| ColumnType::Enum => {
return self.char_set == other.char_set;
return self.flags == other.flags;
}

_ => {}
}

Expand Down
1 change: 0 additions & 1 deletion sqlx-mysql/src/types/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ impl Type<MySql> for bool {
// MySQL has no actual `BOOLEAN` type, the type is an alias of `TINYINT(1)`
MySqlTypeInfo {
flags: ColumnFlags::BINARY | ColumnFlags::UNSIGNED,
char_set: 63,
max_size: Some(1),
r#type: ColumnType::Tiny,
}
Expand Down
20 changes: 2 additions & 18 deletions sqlx-mysql/src/types/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@ use crate::types::Type;
use crate::{MySql, MySqlTypeInfo, MySqlValueRef};
use std::borrow::Cow;

const COLLATE_UTF8_GENERAL_CI: u16 = 33;
const COLLATE_UTF8_UNICODE_CI: u16 = 192;
const COLLATE_UTF8MB4_UNICODE_CI: u16 = 224;
const COLLATE_UTF8MB4_BIN: u16 = 46;
const COLLATE_UTF8MB4_GENERAL_CI: u16 = 45;
const COLLATE_UTF8MB4_0900_AI_CI: u16 = 255;

impl Type<MySql> for str {
fn type_info() -> MySqlTypeInfo {
MySqlTypeInfo {
r#type: ColumnType::VarString, // VARCHAR
char_set: COLLATE_UTF8MB4_UNICODE_CI, // utf8mb4_unicode_ci
r#type: ColumnType::VarString, // VARCHAR
flags: ColumnFlags::empty(),
max_size: None,
}
Expand All @@ -36,15 +28,7 @@ impl Type<MySql> for str {
| ColumnType::String
| ColumnType::VarString
| ColumnType::Enum
) && matches!(
ty.char_set,
COLLATE_UTF8MB4_UNICODE_CI
| COLLATE_UTF8_UNICODE_CI
| COLLATE_UTF8_GENERAL_CI
| COLLATE_UTF8MB4_BIN
| COLLATE_UTF8MB4_GENERAL_CI
| COLLATE_UTF8MB4_0900_AI_CI
)
) && !ty.flags.contains(ColumnFlags::BINARY)
}
}

Expand Down
1 change: 0 additions & 1 deletion sqlx-mysql/src/types/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ fn uint_type_info(ty: ColumnType) -> MySqlTypeInfo {
MySqlTypeInfo {
r#type: ty,
flags: ColumnFlags::BINARY | ColumnFlags::UNSIGNED,
char_set: 63,
max_size: None,
}
}
Expand Down