#625 adding mediumint support (#630)

This commit is contained in:
AugustoFKL 2022-09-28 17:26:17 -03:00 committed by GitHub
parent 46b7c03788
commit e951cd5278
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 2 deletions

View file

@ -53,6 +53,14 @@ pub enum DataType {
SmallInt(Option<u64>),
/// Unsigned small integer with optional display width e.g. SMALLINT UNSIGNED or SMALLINT(5) UNSIGNED
UnsignedSmallInt(Option<u64>),
/// MySQL medium integer ([1]) with optional display width e.g. MEDIUMINT or MEDIUMINT(5)
///
/// [1]: https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
MediumInt(Option<u64>),
/// Unsigned medium integer ([1]) with optional display width e.g. MEDIUMINT UNSIGNED or MEDIUMINT(5) UNSIGNED
///
/// [1]: https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
UnsignedMediumInt(Option<u64>),
/// Integer with optional display width e.g. INT or INT(11)
Int(Option<u64>),
/// Integer with optional display width e.g. INTEGER or INTEGER(11)
@ -141,6 +149,12 @@ impl fmt::Display for DataType {
DataType::UnsignedSmallInt(zerofill) => {
format_type_with_optional_length(f, "SMALLINT", zerofill, true)
}
DataType::MediumInt(zerofill) => {
format_type_with_optional_length(f, "MEDIUMINT", zerofill, false)
}
DataType::UnsignedMediumInt(zerofill) => {
format_type_with_optional_length(f, "MEDIUMINT", zerofill, true)
}
DataType::Int(zerofill) => format_type_with_optional_length(f, "INT", zerofill, false),
DataType::UnsignedInt(zerofill) => {
format_type_with_optional_length(f, "INT", zerofill, true)

View file

@ -325,6 +325,7 @@ define_keywords!(
MATCHED,
MATERIALIZED,
MAX,
MEDIUMINT,
MEMBER,
MERGE,
METADATA,

View file

@ -3360,6 +3360,14 @@ impl<'a> Parser<'a> {
Ok(DataType::SmallInt(optional_precision?))
}
}
Keyword::MEDIUMINT => {
let optional_precision = self.parse_optional_precision();
if self.parse_keyword(Keyword::UNSIGNED) {
Ok(DataType::UnsignedMediumInt(optional_precision?))
} else {
Ok(DataType::MediumInt(optional_precision?))
}
}
Keyword::INT => {
let optional_precision = self.parse_optional_precision();
if self.parse_keyword(Keyword::UNSIGNED) {

View file

@ -1623,6 +1623,11 @@ fn parse_cast() {
expr_from_projection(only(&select.projection))
);
one_statement_parses_to(
"SELECT CAST(id AS MEDIUMINT) FROM customer",
"SELECT CAST(id AS MEDIUMINT) FROM customer",
);
one_statement_parses_to(
"SELECT CAST(id AS BIGINT) FROM customer",
"SELECT CAST(id AS BIGINT) FROM customer",

View file

@ -552,7 +552,7 @@ fn parse_escaped_string() {
#[test]
fn parse_create_table_with_minimum_display_width() {
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3), bar_smallint SMALLINT(5), bar_int INT(11), bar_bigint BIGINT(20))";
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3), bar_smallint SMALLINT(5), bar_mediumint MEDIUMINT(6), bar_int INT(11), bar_bigint BIGINT(20))";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
assert_eq!(name.to_string(), "foo");
@ -570,6 +570,12 @@ fn parse_create_table_with_minimum_display_width() {
collation: None,
options: vec![],
},
ColumnDef {
name: Ident::new("bar_mediumint"),
data_type: DataType::MediumInt(Some(6)),
collation: None,
options: vec![],
},
ColumnDef {
name: Ident::new("bar_int"),
data_type: DataType::Int(Some(11)),
@ -592,7 +598,7 @@ fn parse_create_table_with_minimum_display_width() {
#[test]
fn parse_create_table_unsigned() {
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3) UNSIGNED, bar_smallint SMALLINT(5) UNSIGNED, bar_int INT(11) UNSIGNED, bar_bigint BIGINT(20) UNSIGNED)";
let sql = "CREATE TABLE foo (bar_tinyint TINYINT(3) UNSIGNED, bar_smallint SMALLINT(5) UNSIGNED, bar_mediumint MEDIUMINT(13) UNSIGNED, bar_int INT(11) UNSIGNED, bar_bigint BIGINT(20) UNSIGNED)";
match mysql().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
assert_eq!(name.to_string(), "foo");
@ -610,6 +616,12 @@ fn parse_create_table_unsigned() {
collation: None,
options: vec![],
},
ColumnDef {
name: Ident::new("bar_mediumint"),
data_type: DataType::UnsignedMediumInt(Some(13)),
collation: None,
options: vec![],
},
ColumnDef {
name: Ident::new("bar_int"),
data_type: DataType::UnsignedInt(Some(11)),