Skip to content

Commit 6503d59

Browse files
committed
place holder support
${value} like value place holder support.
1 parent 315faf7 commit 6503d59

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/sqlParser.jison

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[#]\s.*\n /* skip sql comments */
1212
\s+ /* skip whitespace */
1313

14+
[$][{](.*?)[}] return 'PLACE_HOLDER'
1415
[`][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]*[`] return 'IDENTIFIER'
1516
[\w]+[\u4e00-\u9fa5]+[0-9a-zA-Z_\u4e00-\u9fa5]* return 'IDENTIFIER'
1617
[\u4e00-\u9fa5][0-9a-zA-Z_\u4e00-\u9fa5]* return 'IDENTIFIER'
@@ -305,6 +306,7 @@ literal
305306
| number { $$ = $1 }
306307
| boolean { $$ = $1 }
307308
| null { $$ = $1 }
309+
| place_holder { $$ = $1 }
308310
;
309311
function_call
310312
: IDENTIFIER '(' function_call_param_list ')' { $$ = {type: 'FunctionCall', name: $1, params: $3} }
@@ -588,3 +590,6 @@ table_factor
588590
| '(' selectClause ')' aliasOpt { $$ = { type: 'TableFactor', value: { type: 'SubQuery', value: $2 }, alias: $4.alias, hasAs: $4.hasAs} }
589591
| '(' table_references ')' { $$ = $2; $$.hasParentheses = true }
590592
;
593+
place_holder
594+
: PLACE_HOLDER { $$ = { type: 'PlaceHolder', value: $1, param: $1.slice(2, -1)} }
595+
;

src/stringify.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,20 @@ Sql.prototype.travelSelectParenthesized = function(ast) {
551551
this.travel(ast.value);
552552
this.appendKeyword(')');
553553
};
554+
Sql.prototype.travelPlaceHolder = function (ast) {
555+
if (ast.left) {
556+
this.travel(ast.left);
557+
}
558+
559+
if (ast.operator) {
560+
this.append(ast.operator);
561+
}
562+
563+
if (ast.right) {
564+
this.append(ast.right);
565+
}
566+
567+
if (ast.value) {
568+
this.travel(ast.value);
569+
}
570+
};

test/main.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,10 @@ describe('select grammar support', function() {
411411
it('bugfix table alias2', function() {
412412
testParser('select a.* from a t1 join b t2 on t1.a = t2.a')
413413
})
414+
415+
it('place holder support', function() {
416+
testParser(
417+
"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})"
418+
)
419+
})
414420
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy