Skip to content

Commit abd5ca0

Browse files
committed
fix: handle literal string to function name in mysql
1 parent a1078ea commit abd5ca0

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

pegjs/mariadb.pegjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2852,6 +2852,10 @@ column_list
28522852
= head:column tail:(__ COMMA __ column)* {
28532853
return createList(head, tail);
28542854
}
2855+
ident_name_type
2856+
= n:ident_name {
2857+
return { type: 'default', value: n }
2858+
}
28552859
ident_without_kw_type
28562860
= n:ident_name {
28572861
return { type: 'default', value: n }
@@ -3857,7 +3861,7 @@ proc_primary
38573861
}
38583862

38593863
proc_func_name
3860-
= dt:ident_without_kw_type tail:(__ DOT __ ident_without_kw_type)? {
3864+
= dt:(ident_name_type / backticks_quoted_ident) tail:(__ DOT __ ((ident_name_type / backticks_quoted_ident)))? {
38613865
const result = { name: [dt] }
38623866
if (tail !== null) {
38633867
result.schema = dt

pegjs/mysql.pegjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,11 +3133,12 @@ column_list
31333133
= head:column tail:(__ COMMA __ column)* {
31343134
return createList(head, tail);
31353135
}
3136-
ident_without_kw_type
3136+
ident_name_type
31373137
= n:ident_name {
31383138
return { type: 'default', value: n }
31393139
}
3140-
/ quoted_ident_type
3140+
ident_without_kw_type
3141+
= ident_name_type / quoted_ident_type
31413142

31423143
ident_type
31433144
= name:ident_name !{ return reservedMap[name.toUpperCase()] === true; } {
@@ -4171,7 +4172,7 @@ proc_primary
41714172
}
41724173

41734174
proc_func_name
4174-
= dt:ident_without_kw_type tail:(__ DOT __ ident_without_kw_type)? {
4175+
= dt:(ident_name_type / backticks_quoted_ident) tail:(__ DOT __ ((ident_name_type / backticks_quoted_ident)))? {
41754176
const result = { name: [dt] }
41764177
if (tail !== null) {
41774178
result.schema = dt

test/mysql-mariadb.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,16 @@ describe('mysql', () => {
10841084
"ALTER TABLE `a` MODIFY COLUMN `b` VARCHAR(200) GENERATED ALWAYS AS (json_unquote(json_extract(`json`, '$.b'))) STORED COMMENT 'some comment'"
10851085
]
10861086
},
1087+
{
1088+
title: 'function name can be wrapped with brackets only',
1089+
sql: [
1090+
`insert into \`test\` (\`t1\`,\`t2\`,\`t3\`,\`t4\`,\`t5\`) values
1091+
(0,1,334,'21.42',' '),
1092+
(0,1,335,'23.lua',' select(\\'#\\', ...)'),
1093+
(0,1,334,'21.42',' ');`,
1094+
"INSERT INTO `test` (t1, t2, t3, t4, t5) VALUES (0,1,334,'21.42',' '), (0,1,335,'23.lua',' select(\\'#\\', ...)'), (0,1,334,'21.42',' ')"
1095+
]
1096+
},
10871097
]
10881098
SQL_LIST.forEach(sqlInfo => {
10891099
const { title, sql } = sqlInfo

0 commit comments

Comments
 (0)