Skip to content

Commit

Permalink
Merge pull request #1605 from jim-lake/master
Browse files Browse the repository at this point in the history
allow db prefix in column_refs
  • Loading branch information
taozhi8833998 authored Oct 9, 2023
2 parents 14d2c34 + 002e4d2 commit 1a5767d
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ show_stmt
}
}
}
/ KW_SHOW __ k:(('CHARACTER'i __ 'SET'i) / 'COLLATION'i) __ e:(like_op_right / where_clause)? {
/ KW_SHOW __ k:(('CHARACTER'i __ 'SET'i) / 'COLLATION'i / 'DATABASES'i) __ e:(like_op_right / where_clause)? {
let keyword = Array.isArray(k) && k || [k]
return {
tableList: Array.from(tableList),
Expand Down Expand Up @@ -2017,18 +2017,30 @@ column_list_item
const { as, ...expr } = fs
return { expr, as }
}
/ tbl:(ident __ DOT)? __ STAR {
const table = tbl && tbl[0] || null
columnList.add(`select::${table}::(.*)`);
/ db:ident __ DOT __ table:ident __ DOT __ STAR {
columnList.add(`select::${db}::${table}::(.*)`);
return {
expr: {
type: 'column_ref',
db: db,
table: table,
column: '*'
},
as: null
};
}
/ table:(ident __ DOT)? __ STAR {
columnList.add(`select::${table}::(.*)`);
return {
expr: {
type: 'column_ref',
db: null,
table: table && table[0] || null,
column: '*'
},
as: null
};
}
/ a:select_assign_stmt {
return { expr: a, as: null }
}
Expand Down Expand Up @@ -2812,10 +2824,20 @@ column_ref
properties: a.map(item => item[2])
};
}
/ db:(ident_name / backticks_quoted_ident) __ DOT __ tbl:(ident_name / backticks_quoted_ident) __ DOT __ col:column_without_kw {
columnList.add(`select::${db}::${tbl}::${col}`);
return {
type: 'column_ref',
db: db,
table: tbl,
column: col
};
}
/ tbl:(ident_name / backticks_quoted_ident) __ DOT __ col:column_without_kw {
columnList.add(`select::${tbl}::${col}`);
return {
type: 'column_ref',
db: null,
table: tbl,
column: col
};
Expand All @@ -2824,6 +2846,7 @@ column_ref
columnList.add(`select::null::${col}`);
return {
type: 'column_ref',
db: null,
table: null,
column: col
};
Expand Down

0 comments on commit 1a5767d

Please sign in to comment.