Skip to content

Commit

Permalink
Changed to collation which is the actual name.
Browse files Browse the repository at this point in the history
  • Loading branch information
alu committed Jul 25, 2023
1 parent 7e7dded commit 4e5d3f2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions sqlx-mysql/src/protocol/text/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub(crate) struct ColumnDefinition {
table: Bytes,
alias: Bytes,
name: Bytes,
pub(crate) char_set: u16,
pub(crate) collation: u16,
pub(crate) max_size: u32,
pub(crate) r#type: ColumnType,
pub(crate) flags: ColumnFlags,
Expand Down Expand Up @@ -142,7 +142,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 +155,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 @@ -167,11 +167,11 @@ impl Decode<'_, Capabilities> for ColumnDefinition {
impl ColumnType {
pub(crate) fn name(
self,
char_set: u16,
collation: u16,
flags: ColumnFlags,
max_size: Option<u32>,
) -> &'static str {
let is_binary = char_set == 63;
let is_binary = collation == 63;
let is_unsigned = flags.contains(ColumnFlags::UNSIGNED);
let is_enum = flags.contains(ColumnFlags::ENUM);

Expand Down
12 changes: 6 additions & 6 deletions sqlx-mysql/src/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::protocol::text::{ColumnDefinition, ColumnFlags, ColumnType};
pub struct MySqlTypeInfo {
pub(crate) r#type: ColumnType,
pub(crate) flags: ColumnFlags,
pub(crate) char_set: u16,
pub(crate) collation: 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 +22,7 @@ impl MySqlTypeInfo {
Self {
r#type: ty,
flags: ColumnFlags::BINARY,
char_set: 63,
collation: 63,
max_size: None,
}
}
Expand All @@ -32,7 +32,7 @@ impl MySqlTypeInfo {
Self {
r#type: ColumnType::Enum,
flags: ColumnFlags::BINARY,
char_set: 63,
collation: 63,
max_size: None,
}
}
Expand All @@ -55,7 +55,7 @@ impl MySqlTypeInfo {
Self {
r#type: column.r#type,
flags: column.flags,
char_set: column.char_set,
collation: column.collation,
max_size: Some(column.max_size),
}
}
Expand All @@ -73,7 +73,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.collation, self.flags, self.max_size)
}
}

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

_ => {}
Expand Down
2 changes: 1 addition & 1 deletion sqlx-mysql/src/types/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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,
collation: 63,
max_size: Some(1),
r#type: ColumnType::Tiny,
}
Expand Down
6 changes: 3 additions & 3 deletions sqlx-mysql/src/types/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ 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
collation: COLLATE_UTF8MB4_UNICODE_CI, // utf8mb4_unicode_ci
flags: ColumnFlags::empty(),
max_size: None,
}
Expand All @@ -37,7 +37,7 @@ impl Type<MySql> for str {
| ColumnType::VarString
| ColumnType::Enum
) && matches!(
ty.char_set,
ty.collation,
COLLATE_UTF8MB4_UNICODE_CI
| COLLATE_UTF8_UNICODE_CI
| COLLATE_UTF8_GENERAL_CI
Expand Down
2 changes: 1 addition & 1 deletion sqlx-mysql/src/types/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn uint_type_info(ty: ColumnType) -> MySqlTypeInfo {
MySqlTypeInfo {
r#type: ty,
flags: ColumnFlags::BINARY | ColumnFlags::UNSIGNED,
char_set: 63,
collation: 63,
max_size: None,
}
}
Expand Down

0 comments on commit 4e5d3f2

Please sign in to comment.