Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/sqlParser.jison
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,7 @@
[#]\s.*\n /* skip sql comments */
\s+ /* skip whitespace */

[$][{](.*?)[}] return 'PLACE_HOLDER'
[`][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]*[`] return 'IDENTIFIER'
[\w]+[\u4e00-\u9fa5]+[0-9a-zA-Z_\u4e00-\u9fa5]* return 'IDENTIFIER'
[\u4e00-\u9fa5][0-9a-zA-Z_\u4e00-\u9fa5]* return 'IDENTIFIER'
Expand DownExpand Up@@ -304,6 +305,7 @@ literal
| number { $$ = $1 }
| boolean { $$ = $1 }
| null { $$ = $1 }
| place_holder { $$ = $1 }
;
function_call
: IDENTIFIER '(' function_call_param_list ')' { $$ = {type: 'FunctionCall', name: $1, params: $3} }
Expand DownExpand Up@@ -587,3 +589,6 @@ table_factor
| '(' selectClause ')' aliasOpt { $$ = { type: 'TableFactor', value: { type: 'SubQuery', value: $2 }, alias: $4.alias, hasAs: $4.hasAs} }
| '(' table_references ')' { $$ = $2; $$.hasParentheses = true }
;
place_holder
: PLACE_HOLDER { $$ = { type: 'PlaceHolder', value: $1, param: $1.slice(2, -1)} }
;
17 changes: 17 additions & 0 deletions src/stringify.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -551,3 +551,20 @@ Sql.prototype.travelSelectParenthesized = function(ast) {
this.travel(ast.value);
this.appendKeyword(')');
};
Sql.prototype.travelPlaceHolder = function (ast) {
if (ast.left) {
this.travel(ast.left);
}

if (ast.operator) {
this.append(ast.operator);
}

if (ast.right) {
this.append(ast.right);
}

if (ast.value) {
this.travel(ast.value);
}
};
5 changes: 5 additions & 0 deletions test/main.test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -411,6 +411,11 @@ describe('select grammar support', function () {
it('bugfix table alias2', function () {
testParser('select a.* from a t1 join b t2 on t1.a = t2.a')
});
it('place holder support', function() {
testParser(
"select sum(quota_value) value, busi_col2 as sh, ${a} as a, YEAR(now()) from der_quota_summary where table_ename = 'gshmyyszje_derivedidx' and cd = (select id from t1 where a = ${t1})"
)
});

it('support quoted alias: multiple alias and orderby support', function () {
testParser('select a as `A A`, b as `B B` from z');
Expand Down