Skip to content

Commit

Permalink
fix: check constraint support and expr in mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed Jan 22, 2024
1 parent f416e21 commit 835d45f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ast",
"sql-ast"
],
"author": "taozhi8833998 <taozhi8833998@163.com>",
"author": "taozhi8833998 <taozhi8833998@gmail.com>",
"files": [
"ast/",
"build",
Expand Down
2 changes: 1 addition & 1 deletion pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ create_constraint_foreign
}

check_constraint_definition
= kc:constraint_name? __ u:'CHECK'i __ LPAREN __ c:expr __ RPAREN __ ne:(KW_NOT? __ 'ENFORCED'i)? {
= kc:constraint_name? __ u:'CHECK'i __ LPAREN __ c:or_and_expr __ RPAREN __ ne:(KW_NOT? __ 'ENFORCED'i)? {
const enforced = []
if (ne) enforced.push(ne[0], ne[2])
return {
Expand Down
2 changes: 1 addition & 1 deletion pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ create_constraint_foreign
}

check_constraint_definition
= kc:constraint_name? __ u:'CHECK'i __ LPAREN __ c:expr __ RPAREN __ ne:(KW_NOT? __ 'ENFORCED'i)? {
= kc:constraint_name? __ u:'CHECK'i __ LPAREN __ c:or_and_expr __ RPAREN __ ne:(KW_NOT? __ 'ENFORCED'i)? {
const enforced = []
if (ne) enforced.push(ne[0], ne[2])
return {
Expand Down
9 changes: 9 additions & 0 deletions test/mysql-mariadb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,15 @@ describe('mysql', () => {
`CREATE USER 'jeffrey'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'new_password' DEFAULT ROLE 'administrator', 'developer' REQUIRE SSL AND X509 WITH MAX_QUERIES_PER_HOUR 100 PASSWORD EXPIRE INTERVAL 180 DAY FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2 ACCOUNT LOCK COMMENT 'test comment' ATTRIBUTE '{"fname": "James", "lname": "Scott", "phone": "123-456-7890"}'`
]
},
{
title: 'check constraint',
sql: [
'CREATE TABLE `table` (\n' +
'`name` VARCHAR(255) CHECK(`name` LIKE \'ABC%\' AND LENGTH(`name`) >= 5)\n' +
');',
"CREATE TABLE `table` (`name` VARCHAR(255) CHECK (`name` LIKE 'ABC%' AND LENGTH(`name`) >= 5))"
]
}
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
Expand Down

0 comments on commit 835d45f

Please sign in to comment.