Skip to content

Commit 99697d2

Browse files
authored
add on update for my sql (apache#522)
1 parent ca15a4e commit 99697d2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/parser.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,12 @@ impl<'a> Parser<'a> {
22542254
Ok(Some(ColumnOption::DialectSpecific(vec![
22552255
Token::make_keyword("AUTOINCREMENT"),
22562256
])))
2257+
} else if self.parse_keywords(&[Keyword::ON, Keyword::UPDATE])
2258+
&& dialect_of!(self is MySqlDialect)
2259+
{
2260+
Ok(Some(ColumnOption::DialectSpecific(vec![
2261+
Token::make_keyword("ON UPDATE"),
2262+
])))
22572263
} else {
22582264
Ok(None)
22592265
}

tests/sqlparser_mysql.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,31 @@ fn parse_kill() {
834834
);
835835
}
836836

837+
#[test]
838+
fn parse_table_colum_option_on_update() {
839+
let sql1 = "CREATE TABLE foo (`modification_time` DATETIME ON UPDATE)";
840+
match mysql().verified_stmt(sql1) {
841+
Statement::CreateTable { name, columns, .. } => {
842+
assert_eq!(name.to_string(), "foo");
843+
assert_eq!(
844+
vec![ColumnDef {
845+
name: Ident::with_quote('`', "modification_time"),
846+
data_type: DataType::Datetime,
847+
collation: None,
848+
options: vec![ColumnOptionDef {
849+
name: None,
850+
option: ColumnOption::DialectSpecific(vec![Token::make_keyword(
851+
"ON UPDATE"
852+
)]),
853+
},],
854+
}],
855+
columns
856+
);
857+
}
858+
_ => unreachable!(),
859+
}
860+
}
861+
837862
fn mysql() -> TestedDialects {
838863
TestedDialects {
839864
dialects: vec![Box::new(MySqlDialect {})],

0 commit comments

Comments
 (0)