diff --git a/src/sqlParser.jison b/src/sqlParser.jison index 86e13fc..4a8efbc 100644 --- a/src/sqlParser.jison +++ b/src/sqlParser.jison @@ -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' @@ -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} } @@ -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)} } + ; \ No newline at end of file diff --git a/src/stringify.js b/src/stringify.js index 57ea74e..635e801 100644 --- a/src/stringify.js +++ b/src/stringify.js @@ -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); + } +}; \ No newline at end of file diff --git a/test/main.test.js b/test/main.test.js index 188f57d..2ee9c1b 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -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'); 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