Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6503d59

Browse files
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)

AltStyle によって変換されたページ (->オリジナル) /