Skip to content

Commit

Permalink
fix: table name starts with number or lodash in mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed Nov 1, 2023
1 parent 5c043a6 commit 3e944d1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,8 @@ join_op
/ (KW_INNER __)? KW_JOIN { return 'INNER JOIN'; }

table_name
= dt:ident tail:(__ DOT __ ident)? {
= prefix:[_0-9]* part:ident tail:(__ DOT __ ident)? {
const dt = prefix ? `${prefix.join('')}${part}` : part
const obj = { db: null, table: dt };
if (tail !== null) {
obj.db = dt;
Expand Down
3 changes: 2 additions & 1 deletion pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2215,7 +2215,8 @@ join_op
/ (KW_INNER __)? KW_JOIN { return 'INNER JOIN'; }

table_name
= dt:ident tail:(__ DOT __ ident)? {
= prefix:[_0-9]* part:ident tail:(__ DOT __ ident)? {
const dt = prefix ? `${prefix.join('')}${part}` : part
const obj = { db: null, table: dt };
if (tail !== null) {
obj.db = dt;
Expand Down
2 changes: 1 addition & 1 deletion test/cmd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ describe('Command SQL', () => {
.to.equal(`SET @a.id = 123 ; SET @b.yy.xx = "mm"`);
})

it('should support set keyword variable definde', () => {
it('should support set keyword variable defined', () => {
const KEYWORDS = ['GLOBAL', 'SESSION', 'LOCAL', 'PERSIST', 'PERSIST_ONLY']
KEYWORDS.forEach(keyword => {
expect(getParsedSql(`set ${keyword} xx.yy = 123; set ${keyword} yy = "abc"`))
Expand Down
7 changes: 7 additions & 0 deletions test/mysql-mariadb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,13 @@ describe('mysql', () => {
"SELECT EXTRACT(YEAR_MONTH FROM '2023-10-10')"
]
},
{
title: 'table name starts with number or lodash',
sql: [
'SELECT * FROM 2023t',
'SELECT * FROM `2023t`'
]
},
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
Expand Down

0 comments on commit 3e944d1

Please sign in to comment.