Skip to content

Commit d4b3e06

Browse files
committed
fix: convert fun with number args in mysql
1 parent f0df0b7 commit d4b3e06

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

pegjs/mariadb.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,7 +2454,7 @@ count_arg
24542454
star_expr
24552455
= "*" { return { type: 'star', value: '*' }; }
24562456
convert_args
2457-
= c:(column_ref / literal_string) __ COMMA __ ch:character_string_type __ cs:create_option_character_set_kw __ v:ident_name {
2457+
= c:(column_ref / literal_string / literal_numeric) __ COMMA __ ch:character_string_type __ cs:create_option_character_set_kw __ v:ident_name {
24582458
const { dataType, length } = ch
24592459
let dataTypeStr = dataType
24602460
if (length !== undefined) dataTypeStr = `${dataTypeStr}(${length})`
@@ -2469,13 +2469,13 @@ convert_args
24692469
]
24702470
}
24712471
}
2472-
/ c:(column_ref / literal_string) __ COMMA __ d:data_type {
2472+
/ c:(column_ref / literal_string / literal_numeric) __ COMMA __ d:data_type {
24732473
return {
24742474
type: 'expr_list',
24752475
value: [c, { type: 'datatype', ...d, }]
24762476
}
24772477
}
2478-
/ c:(column_ref / literal_string) __ KW_USING __ d:ident_name {
2478+
/ c:(column_ref / literal_string / literal_numeric) __ KW_USING __ d:ident_name {
24792479
c.suffix = `USING ${d}`
24802480
return {
24812481
type: 'expr_list',

pegjs/mysql.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,7 +2747,7 @@ star_expr
27472747
= "*" { return { type: 'star', value: '*' }; }
27482748

27492749
convert_args
2750-
= c:(column_ref / literal_string) __ COMMA __ ch:character_string_type __ cs:create_option_character_set_kw __ v:ident_name {
2750+
= c:(column_ref / literal_string / literal_numeric) __ COMMA __ ch:character_string_type __ cs:create_option_character_set_kw __ v:ident_name {
27512751
const { dataType, length } = ch
27522752
let dataTypeStr = dataType
27532753
if (length !== undefined) dataTypeStr = `${dataTypeStr}(${length})`
@@ -2762,13 +2762,13 @@ convert_args
27622762
]
27632763
}
27642764
}
2765-
/ c:(column_ref / literal_string) __ COMMA __ d:data_type {
2765+
/ c:(column_ref / literal_string / literal_numeric) __ COMMA __ d:data_type {
27662766
return {
27672767
type: 'expr_list',
27682768
value: [c, { type: 'datatype', ...d, }]
27692769
}
27702770
}
2771-
/ c:(column_ref / literal_string) __ KW_USING __ d:ident_name {
2771+
/ c:(column_ref / literal_string / literal_numeric) __ KW_USING __ d:ident_name {
27722772
c.suffix = `USING ${d}`
27732773
return {
27742774
type: 'expr_list',

test/mysql-mariadb.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,13 @@ describe('mysql', () => {
601601
'ALTER TABLE `table_name` ADD `column4` VARCHAR(255)'
602602
]
603603
},
604+
{
605+
title: 'convert number to data type',
606+
sql: [
607+
'select convert(150, char)',
608+
'SELECT CONVERT(150, CHAR)'
609+
]
610+
},
604611
]
605612
SQL_LIST.forEach(sqlInfo => {
606613
const { title, sql } = sqlInfo

0 commit comments

Comments
 (0)