Skip to content

fix: convert function with expr in mysql #2127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3127,7 +3127,7 @@ count_arg
star_expr
= "*" { return { type: 'star', value: '*' }; }
convert_args
= c:proc_primary __ COMMA __ ch:(character_string_type / datetime_type) __ cs:create_option_character_set_kw __ v:ident_without_kw_type {
= c:proc_additive_expr __ COMMA __ ch:(character_string_type / datetime_type) __ cs:create_option_character_set_kw __ v:ident_without_kw_type {
const { dataType, length } = ch
let dataTypeStr = dataType
if (length !== undefined) dataTypeStr = `${dataTypeStr}(${length})`
Expand All @@ -3146,7 +3146,7 @@ convert_args
]
}
}
/ c:proc_primary __ COMMA __ d:(signedness / data_type) {
/ c:proc_additive_expr __ COMMA __ d:(signedness / data_type) {
const dataType = typeof d === 'string' ? { dataType: d } : d
return {
type: 'expr_list',
Expand Down Expand Up @@ -3871,7 +3871,6 @@ proc_primary
e.parentheses = true;
return e;
}

proc_func_name
= dt:(ident_name_type / backticks_quoted_ident) tail:(__ DOT __ ((ident_name_type / backticks_quoted_ident)))? {
const result = { name: [dt] }
Expand Down
4 changes: 2 additions & 2 deletions pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3417,7 +3417,7 @@ star_expr
= "*" { return { type: 'star', value: '*' }; }

convert_args
= c:proc_primary __ COMMA __ ch:(character_string_type / datetime_type) __ cs:create_option_character_set_kw __ v:ident_without_kw_type {
= c:proc_additive_expr __ COMMA __ ch:(character_string_type / datetime_type) __ cs:create_option_character_set_kw __ v:ident_without_kw_type {
const { dataType, length } = ch
let dataTypeStr = dataType
if (length !== undefined) dataTypeStr = `${dataTypeStr}(${length})`
Expand All @@ -3436,7 +3436,7 @@ convert_args
]
}
}
/ c:proc_primary __ COMMA __ d:(signedness / data_type) {
/ c:proc_additive_expr __ COMMA __ d:(signedness / data_type) {
const dataType = typeof d === 'string' ? { dataType: d } : d
return {
type: 'expr_list',
Expand Down
9 changes: 8 additions & 1 deletion test/mysql-mariadb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,12 +1109,19 @@ describe('mysql', () => {
]
},
{
title: 'covert to signed or unsigned',
title: 'convert to signed or unsigned',
sql: [
"SELECT * FROM `foo` WHERE CONVERT(REPLACE(id, '123', ''), SIGNED) > 0",
"SELECT * FROM `foo` WHERE CONVERT(REPLACE(`id`, '123', ''), SIGNED) > 0",
]
},
{
title: 'convert additive expr',
sql: [
'select convert(a-b,DECIMAL(10,2)) as a from test',
'SELECT CONVERT(`a` - `b`, DECIMAL(10, 2)) AS `a` FROM `test`'
]
},
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
Expand Down