Skip to content

Commit 20646fc

Browse files
Make [[NOT] ENFORCED] common between dialects
1 parent 05591ed commit 20646fc

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/parser/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8140,11 +8140,12 @@ impl<'a> Parser<'a> {
81408140
let expr = Box::new(self.parse_expr()?);
81418141
self.expect_token(&Token::RParen)?;
81428142

8143-
let enforced = match dialect_of!(self is GenericDialect | MySqlDialect) {
8144-
true if self.parse_keywords(&[Keyword::NOT, Keyword::ENFORCED]) => Some(false),
8145-
true if self.parse_keyword(Keyword::ENFORCED) => Some(true),
8146-
// not MySQL, or is MySQL but not specified
8147-
_ => None,
8143+
let enforced = if self.parse_keyword(Keyword::ENFORCED) {
8144+
Some(true)
8145+
} else if self.parse_keywords(&[Keyword::NOT, Keyword::ENFORCED]) {
8146+
Some(false)
8147+
} else {
8148+
None
81488149
};
81498150

81508151
Ok(Some(TableConstraint::Check {

tests/sqlparser_common.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15336,3 +15336,10 @@ fn parse_truncate_only() {
1533615336
truncate
1533715337
);
1533815338
}
15339+
15340+
#[test]
15341+
fn check_enforced() {
15342+
all_dialects().verified_stmt(
15343+
"CREATE TABLE t (a INT, b INT, c INT, CHECK (a > 0) NOT ENFORCED, CHECK (b > 0) ENFORCED, CHECK (c > 0))",
15344+
);
15345+
}

tests/sqlparser_mysql.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4025,10 +4025,3 @@ fn parse_drop_index() {
40254025
_ => unreachable!(),
40264026
}
40274027
}
4028-
4029-
#[test]
4030-
fn check_enforced() {
4031-
mysql().verified_stmt(
4032-
"CREATE TABLE t (a INT, b INT, c INT, CHECK (a > 0) NOT ENFORCED, CHECK (b > 0) ENFORCED, CHECK (c > 0))",
4033-
);
4034-
}

0 commit comments

Comments
 (0)