织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

欧博娱乐Escaping single quotes in the PLACEHOLDER clau

时间:2025-08-07 10:28来源: 作者:admin 点击: 14 次
The implicit rule here - given by how the software is implemented - is that for parameter values of calculation views, the backslash \ is used to esca

The implicit rule here - given by how the software is implemented - is that for parameter values of calculation views, the backslash \ is used to escape the single quotation mark.

For all standard SQL string occurrences, using the single-quotation mark twice '' is the correct way to differentiate between syntax element and string literal.

As for the why:

the PLACEHOLDER syntax is not SQL, but a HANA-specific command extension. So, there is no general standard that the current implementation violates.

that given, this command extension is embedded into, respectively clamped onto the standard SQL syntax and has to be handled by the same parser.

But the parameters are not only parsed once, by the SQL parser but again by the component that instantiates the calculation scenario based on the calculation view. With a bit of squinting it's not hard to see that the parameters interface is a general key-value interface that allows for all sorts of information to be handed over to the calc. engine.

One might argue that the whole approach of providing parameters via key-value pairs is not consistent with the general SQL syntax approach and be correct. On the flip side, this approach allows for general flexibility for adding new command elements to the HANA-specific parts, without structurally changing the syntax (and with it the parser). The clear downside of this is that both the key names, as well as the values, are string-typed. To avoid losing the required escaping for the "inner string" an escape string different from the main SQL escape string needs to be used.

And here we are with two different ways of handing over a string value to be used as a filter condition.

Funny enough, both approaches may still lead to the same query execution plan.

As a matter of fact, in many scenarios with input parameters, the string value will be internally converted into a SQL conforming form. This is the case when the input parameter is used for filtering or in expressions in the calc. view that can be converted into SQL expressions.

For example

SELECT "AAA" FROM "_SYS_BIC"."sp/ESC" ('PLACEHOLDER' = ('$$IP_TEST$$', 'this is a test\''s test'));

shows the following execution plan on my system

OPERATOR_NAME OPERATOR_DETAILS PROJECT TEST.AAA COLUMN TABLE FILTER CONDITION: TEST.AAA = 'this is a test's test' (DETAIL: ([SCAN] TEST.AAA = 'this is a test's test'))

Note how the escape-\' has been removed.

All in all: when using PLACEHOLDER values, the \' escaping needs to be used and in all other cases, the '' escaping. That should not be terribly difficult to implement for a query builder as you can consider this when dealing with the PLACEHOLDER syntax.

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-08-10 21:08 最后登录:2025-08-10 21:08
栏目列表
推荐内容