Skip to content

Commit f683373

Browse files
Merge pull request taozhi8833998#2127 from taozhi8833998/fix-convert-expr-mysql
fix: convert function with expr in mysql
2 parents 04ec6cf + c98cdf2 commit f683373

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

pegjs/mariadb.pegjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,7 +3127,7 @@ count_arg
31273127
star_expr
31283128
= "*" { return { type: 'star', value: '*' }; }
31293129
convert_args
3130-
= c:proc_primary __ COMMA __ ch:(character_string_type / datetime_type) __ cs:create_option_character_set_kw __ v:ident_without_kw_type {
3130+
= c:proc_additive_expr __ COMMA __ ch:(character_string_type / datetime_type) __ cs:create_option_character_set_kw __ v:ident_without_kw_type {
31313131
const { dataType, length } = ch
31323132
let dataTypeStr = dataType
31333133
if (length !== undefined) dataTypeStr = `${dataTypeStr}(${length})`
@@ -3146,7 +3146,7 @@ convert_args
31463146
]
31473147
}
31483148
}
3149-
/ c:proc_primary __ COMMA __ d:(signedness / data_type) {
3149+
/ c:proc_additive_expr __ COMMA __ d:(signedness / data_type) {
31503150
const dataType = typeof d === 'string' ? { dataType: d } : d
31513151
return {
31523152
type: 'expr_list',
@@ -3871,7 +3871,6 @@ proc_primary
38713871
e.parentheses = true;
38723872
return e;
38733873
}
3874-
38753874
proc_func_name
38763875
= dt:(ident_name_type / backticks_quoted_ident) tail:(__ DOT __ ((ident_name_type / backticks_quoted_ident)))? {
38773876
const result = { name: [dt] }

pegjs/mysql.pegjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,7 +3417,7 @@ star_expr
34173417
= "*" { return { type: 'star', value: '*' }; }
34183418

34193419
convert_args
3420-
= c:proc_primary __ COMMA __ ch:(character_string_type / datetime_type) __ cs:create_option_character_set_kw __ v:ident_without_kw_type {
3420+
= c:proc_additive_expr __ COMMA __ ch:(character_string_type / datetime_type) __ cs:create_option_character_set_kw __ v:ident_without_kw_type {
34213421
const { dataType, length } = ch
34223422
let dataTypeStr = dataType
34233423
if (length !== undefined) dataTypeStr = `${dataTypeStr}(${length})`
@@ -3436,7 +3436,7 @@ convert_args
34363436
]
34373437
}
34383438
}
3439-
/ c:proc_primary __ COMMA __ d:(signedness / data_type) {
3439+
/ c:proc_additive_expr __ COMMA __ d:(signedness / data_type) {
34403440
const dataType = typeof d === 'string' ? { dataType: d } : d
34413441
return {
34423442
type: 'expr_list',

test/mysql-mariadb.spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,12 +1109,19 @@ describe('mysql', () => {
11091109
]
11101110
},
11111111
{
1112-
title: 'covert to signed or unsigned',
1112+
title: 'convert to signed or unsigned',
11131113
sql: [
11141114
"SELECT * FROM `foo` WHERE CONVERT(REPLACE(id, '123', ''), SIGNED) > 0",
11151115
"SELECT * FROM `foo` WHERE CONVERT(REPLACE(`id`, '123', ''), SIGNED) > 0",
11161116
]
11171117
},
1118+
{
1119+
title: 'convert additive expr',
1120+
sql: [
1121+
'select convert(a-b,DECIMAL(10,2)) as a from test',
1122+
'SELECT CONVERT(`a` - `b`, DECIMAL(10, 2)) AS `a` FROM `test`'
1123+
]
1124+
},
11181125
]
11191126
SQL_LIST.forEach(sqlInfo => {
11201127
const { title, sql } = sqlInfo

0 commit comments

Comments
 (0)