Skip to content

Commit 48ce188

Browse files
committed
fix: convert function to signed in mysql
1 parent a547abd commit 48ce188

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

pegjs/mariadb.pegjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,10 +3146,11 @@ convert_args
31463146
]
31473147
}
31483148
}
3149-
/ c:proc_primary __ COMMA __ d:data_type {
3149+
/ c:proc_primary __ COMMA __ d:(signedness / data_type) {
3150+
const dataType = typeof d === 'string' ? { dataType: d } : d
31503151
return {
31513152
type: 'expr_list',
3152-
value: [c, { type: 'datatype', ...d, }]
3153+
value: [c, { type: 'datatype', ...dataType, }]
31533154
}
31543155
}
31553156
/ c:or_and_where_expr __ KW_USING __ d:ident_name {
@@ -3320,7 +3321,7 @@ cast_expr
33203321
expr: e,
33213322
symbol: 'as',
33223323
target: {
3323-
dataType: s + (t ? ' ' + t: '')
3324+
dataType: [s, t].filter(Boolean).join(' ')
33243325
}
33253326
};
33263327
}
@@ -3491,7 +3492,7 @@ int
34913492
= digits
34923493
/ digit:digit
34933494
/ op:("-" / "+" ) digits:digits { return op + digits; }
3494-
/ op:("-" / "+" ) digit:digit { return op + digit; }
3495+
/ op:("-" / "+" ) digit:digit { return op + digit; }
34953496

34963497
frac
34973498
= "." digits:digits? {
@@ -3994,7 +3995,7 @@ character_string_type
39943995
}
39953996

39963997
numeric_type_suffix
3997-
= un: KW_UNSIGNED? __ ze: KW_ZEROFILL? {
3998+
= un:signedness? __ ze: KW_ZEROFILL? {
39983999
const result = []
39994000
if (un) result.push(un)
40004001
if (ze) result.push(ze)

pegjs/mysql.pegjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,10 +3436,11 @@ convert_args
34363436
]
34373437
}
34383438
}
3439-
/ c:proc_primary __ COMMA __ d:data_type {
3439+
/ c:proc_primary __ COMMA __ d:(signedness / data_type) {
3440+
const dataType = typeof d === 'string' ? { dataType: d } : d
34403441
return {
34413442
type: 'expr_list',
3442-
value: [c, { type: 'datatype', ...d, }]
3443+
value: [c, { type: 'datatype', ...dataType, }]
34433444
}
34443445
}
34453446
/ c:or_and_where_expr __ KW_USING __ d:ident_name {
@@ -3610,7 +3611,7 @@ cast_expr
36103611
expr: e,
36113612
symbol: 'as',
36123613
target: {
3613-
dataType: s + (t ? ' ' + t: '')
3614+
dataType: [s, t].filter(Boolean).join(' ')
36143615
}
36153616
};
36163617
}
@@ -4315,7 +4316,7 @@ character_string_type
43154316
}
43164317

43174318
numeric_type_suffix
4318-
= un: KW_UNSIGNED? __ ze: KW_ZEROFILL? {
4319+
= un:signedness? __ ze: KW_ZEROFILL? {
43194320
const result = []
43204321
if (un) result.push(un)
43214322
if (ze) result.push(ze)

test/mysql-mariadb.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,13 @@ describe('mysql', () => {
11081108
'CREATE TABLE `ys_map_info` (`detail` TEXT(65535))'
11091109
]
11101110
},
1111+
{
1112+
title: 'covert to signed or unsigned',
1113+
sql: [
1114+
"SELECT * FROM `foo` WHERE CONVERT(REPLACE(id, '123', ''), SIGNED) > 0",
1115+
"SELECT * FROM `foo` WHERE CONVERT(REPLACE(`id`, '123', ''), SIGNED) > 0",
1116+
]
1117+
},
11111118
]
11121119
SQL_LIST.forEach(sqlInfo => {
11131120
const { title, sql } = sqlInfo

0 commit comments

Comments
 (0)