mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
Remove compatibility check by collations.
This commit is contained in:
parent
ce6d75208b
commit
33aee07094
5 changed files with 7 additions and 34 deletions
|
@ -112,6 +112,7 @@ pub(crate) struct ColumnDefinition {
|
|||
table: Bytes,
|
||||
alias: Bytes,
|
||||
name: Bytes,
|
||||
#[allow(unused)]
|
||||
pub(crate) collation: u16,
|
||||
pub(crate) max_size: u32,
|
||||
pub(crate) r#type: ColumnType,
|
||||
|
@ -165,13 +166,8 @@ impl Decode<'_, Capabilities> for ColumnDefinition {
|
|||
}
|
||||
|
||||
impl ColumnType {
|
||||
pub(crate) fn name(
|
||||
self,
|
||||
collation: u16,
|
||||
flags: ColumnFlags,
|
||||
max_size: Option<u32>,
|
||||
) -> &'static str {
|
||||
let is_binary = collation == 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);
|
||||
|
||||
|
|
|
@ -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) collation: u16,
|
||||
|
||||
// [max_size] for integer types, this is (M) in BIT(M) or TINYINT(M)
|
||||
#[cfg_attr(feature = "offline", serde(default))]
|
||||
|
@ -22,7 +21,6 @@ impl MySqlTypeInfo {
|
|||
Self {
|
||||
r#type: ty,
|
||||
flags: ColumnFlags::BINARY,
|
||||
collation: 63,
|
||||
max_size: None,
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +30,6 @@ impl MySqlTypeInfo {
|
|||
Self {
|
||||
r#type: ColumnType::Enum,
|
||||
flags: ColumnFlags::BINARY,
|
||||
collation: 63,
|
||||
max_size: None,
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +52,6 @@ impl MySqlTypeInfo {
|
|||
Self {
|
||||
r#type: column.r#type,
|
||||
flags: column.flags,
|
||||
collation: column.collation,
|
||||
max_size: Some(column.max_size),
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +69,7 @@ impl TypeInfo for MySqlTypeInfo {
|
|||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
self.r#type.name(self.collation, self.flags, self.max_size)
|
||||
self.r#type.name(self.flags, self.max_size)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,9 +98,8 @@ impl PartialEq<MySqlTypeInfo> for MySqlTypeInfo {
|
|||
| ColumnType::String
|
||||
| ColumnType::VarString
|
||||
| ColumnType::Enum => {
|
||||
return self.collation == other.collation;
|
||||
return self.flags == other.flags;
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
collation: 63,
|
||||
max_size: Some(1),
|
||||
r#type: ColumnType::Tiny,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
collation: COLLATE_UTF8MB4_UNICODE_CI, // utf8mb4_unicode_ci
|
||||
r#type: ColumnType::VarString, // VARCHAR
|
||||
flags: ColumnFlags::empty(),
|
||||
max_size: None,
|
||||
}
|
||||
|
@ -36,15 +28,7 @@ impl Type<MySql> for str {
|
|||
| ColumnType::String
|
||||
| ColumnType::VarString
|
||||
| ColumnType::Enum
|
||||
) && matches!(
|
||||
ty.collation,
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ fn uint_type_info(ty: ColumnType) -> MySqlTypeInfo {
|
|||
MySqlTypeInfo {
|
||||
r#type: ty,
|
||||
flags: ColumnFlags::BINARY | ColumnFlags::UNSIGNED,
|
||||
collation: 63,
|
||||
max_size: None,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue