refactor(mysql): remove binary type IDs

This commit is contained in:
Ryan Leckey 2021-02-23 01:55:09 -08:00
parent 22960f1610
commit 0756ef0e59
No known key found for this signature in database
GPG Key ID: F8AA68C235AB08C9
3 changed files with 13 additions and 21 deletions

View File

@ -176,33 +176,24 @@ impl MySqlTypeId {
///
pub const NULL: Self = Self(6, 0);
/// A fixed-length string that is always right-padded with spaces
/// to the specified length when stored.
///
pub const CHAR: Self = Self(254, 0);
/// A fixed-length binary string that is always right-padded with zeroes
/// to the specified length when stored.
/// A fixed-length string that is always right-padded with spaces or
/// zeroes (for binary collations) to the specified length when stored.
///
/// The type identifier for `BINARY` is the same as `CHAR`. At the type
/// level, they are identical. At the column, the presence of a binary (`_bin`)
/// collation determines if the type stores binary data.
///
pub const BINARY: Self = Self(254, 0);
#[doc(alias = "BINARY")]
pub const CHAR: Self = Self(254, 0);
/// A variable-length string.
pub const VARCHAR: Self = Self(253, 0);
/// A variable-length binary string.
///
/// The type identifier for `VARBINARY` is the same as `VARCHAR`. At the type
/// level, they are identical. At the column, the presence of a binary (`_bin`)
/// collation determines if the type stores binary data.
///
pub const VARBINARY: Self = Self(253, 0);
/// A variable-length string that is assumed to be stored by reference.
pub const TEXT: Self = Self(252, 0);
#[doc(alias = "VARBINARY")]
pub const VARCHAR: Self = Self(253, 0);
/// A variable-length string that is assumed to be stored by reference.
///
@ -210,5 +201,6 @@ impl MySqlTypeId {
/// level, they are identical. At the column, the presence of a binary (`_bin`)
/// collation determines if the type stores binary data.
///
pub const BLOB: Self = Self(252, 0);
#[doc(alias = "BLOB")]
pub const TEXT: Self = Self(252, 0);
}

View File

@ -67,9 +67,9 @@ impl MySqlTypeInfo {
// note: VARBINARY, BINARY, and BLOB have the same type IDs as
// VARCHAR, CHAR, and TEXT; the only difference is the
// presence of a binary collation
MySqlTypeId::VARBINARY if self.has_binary_collation() => "VARBINARY",
MySqlTypeId::BINARY if self.has_binary_collation() => "BINARY",
MySqlTypeId::BLOB if self.has_binary_collation() => "BLOB",
MySqlTypeId::VARCHAR if self.has_binary_collation() => "VARBINARY",
MySqlTypeId::CHAR if self.has_binary_collation() => "BINARY",
MySqlTypeId::TEXT if self.has_binary_collation() => "BLOB",
MySqlTypeId::VARCHAR => "VARCHAR",
MySqlTypeId::CHAR => "CHAR",

View File

@ -7,11 +7,11 @@ use crate::{MySql, MySqlOutput, MySqlRawValue, MySqlTypeId};
impl Type<MySql> for &'_ [u8] {
fn type_id() -> MySqlTypeId {
MySqlTypeId::BLOB
MySqlTypeId::TEXT
}
fn compatible(ty: &MySqlTypeInfo) -> bool {
matches!(ty.id(), MySqlTypeId::BLOB | MySqlTypeId::BINARY | MySqlTypeId::VARBINARY)
matches!(ty.id(), MySqlTypeId::TEXT | MySqlTypeId::CHAR | MySqlTypeId::VARCHAR)
}
}