Support for ANSI CHARACTER LARGE OBJECT[(p)] and CHAR LARGE OBJECT[(p)]. (#671)

Add tests for both and `CLOB[(p)]`.
This commit is contained in:
AugustoFKL 2022-10-15 08:55:08 -03:00 committed by GitHub
parent a59874136d
commit b42632fa0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 1 deletions

View file

@ -39,7 +39,15 @@ pub enum DataType {
Nvarchar(Option<u64>), Nvarchar(Option<u64>),
/// Uuid type /// Uuid type
Uuid, Uuid,
/// Large character object with optional length e.g. CLOB, CLOB(1000), [standard], [Oracle] /// Large character object with optional length e.g. CHARACTER LARGE OBJECT, CHARACTER LARGE OBJECT(1000), [standard]
///
/// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#character-large-object-type
CharacterLargeObject(Option<u64>),
/// Large character object with optional length e.g. CHAR LARGE OBJECT, CHAR LARGE OBJECT(1000), [standard]
///
/// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#character-large-object-type
CharLargeObject(Option<u64>),
/// Large character object with optional length e.g. CLOB, CLOB(1000), [standard]
/// ///
/// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#character-large-object-type /// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#character-large-object-type
/// [Oracle]: https://docs.oracle.com/javadb/10.10.1.2/ref/rrefclob.html /// [Oracle]: https://docs.oracle.com/javadb/10.10.1.2/ref/rrefclob.html
@ -145,6 +153,12 @@ impl fmt::Display for DataType {
format_type_with_optional_length(f, "NVARCHAR", size, false) format_type_with_optional_length(f, "NVARCHAR", size, false)
} }
DataType::Uuid => write!(f, "UUID"), DataType::Uuid => write!(f, "UUID"),
DataType::CharacterLargeObject(size) => {
format_type_with_optional_length(f, "CHARACTER LARGE OBJECT", size, false)
}
DataType::CharLargeObject(size) => {
format_type_with_optional_length(f, "CHAR LARGE OBJECT", size, false)
}
DataType::Clob(size) => format_type_with_optional_length(f, "CLOB", size, false), DataType::Clob(size) => format_type_with_optional_length(f, "CLOB", size, false),
DataType::Binary(size) => format_type_with_optional_length(f, "BINARY", size, false), DataType::Binary(size) => format_type_with_optional_length(f, "BINARY", size, false),
DataType::Varbinary(size) => { DataType::Varbinary(size) => {

View file

@ -3546,6 +3546,10 @@ impl<'a> Parser<'a> {
Ok(DataType::CharacterVarying( Ok(DataType::CharacterVarying(
self.parse_optional_character_length()?, self.parse_optional_character_length()?,
)) ))
} else if self.parse_keywords(&[Keyword::LARGE, Keyword::OBJECT]) {
Ok(DataType::CharacterLargeObject(
self.parse_optional_precision()?,
))
} else { } else {
Ok(DataType::Character(self.parse_optional_character_length()?)) Ok(DataType::Character(self.parse_optional_character_length()?))
} }
@ -3555,6 +3559,8 @@ impl<'a> Parser<'a> {
Ok(DataType::CharVarying( Ok(DataType::CharVarying(
self.parse_optional_character_length()?, self.parse_optional_character_length()?,
)) ))
} else if self.parse_keywords(&[Keyword::LARGE, Keyword::OBJECT]) {
Ok(DataType::CharLargeObject(self.parse_optional_precision()?))
} else { } else {
Ok(DataType::Char(self.parse_optional_character_length()?)) Ok(DataType::Char(self.parse_optional_character_length()?))
} }
@ -5624,6 +5630,39 @@ mod tests {
); );
} }
#[test]
fn test_ansii_character_large_object_types() {
// Character large object types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#character-large-object-length>
let dialect = TestedDialects {
dialects: vec![Box::new(GenericDialect {}), Box::new(AnsiDialect {})],
};
test_parse_data_type!(
dialect,
"CHARACTER LARGE OBJECT",
DataType::CharacterLargeObject(None)
);
test_parse_data_type!(
dialect,
"CHARACTER LARGE OBJECT(20)",
DataType::CharacterLargeObject(Some(20))
);
test_parse_data_type!(
dialect,
"CHAR LARGE OBJECT",
DataType::CharLargeObject(None)
);
test_parse_data_type!(
dialect,
"CHAR LARGE OBJECT(20)",
DataType::CharLargeObject(Some(20))
);
test_parse_data_type!(dialect, "CLOB", DataType::Clob(None));
test_parse_data_type!(dialect, "CLOB(20)", DataType::Clob(Some(20)));
}
#[test] #[test]
fn test_ansii_exact_numeric_types() { fn test_ansii_exact_numeric_types() {
// Exact numeric types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#exact-numeric-type> // Exact numeric types: <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#exact-numeric-type>