至于“嵌入式表达式规则”,字符串连接不起作用

时间:2019-05-23 08:41:41

标签: karate

我正在使用SQL从数据库中获取数据,我需要将变量传递给where子句,但是,我发现字符串连接不起作用,即使是官方示例也是如此

* def batchnum = "112344552"
* def getBatchIDSQL = '#("select id from sr_sendreceive where batchnum = " + batchnum)'
* print getBatchIDSQL
* def sendReceiveBatchid = db.readValue('#(getBatchIDSQL)')

然后,我尝试了官方示例:

      # wrong !
      * def foo = 'hello #(name)'
      # right !
      * def foo1 = '#("hello " + name)'
      * print foo1

      * def name = 'test name'
      * def temp = 'hello ' + name
      * def foo2 = '#(temp)'
      * print foo2

结果是:

#("select id from sr_sendreceive where batchnum =" + batchnum)
#("hello " + name)
#(temp)

1 个答案:

答案 0 :(得分:0)

对不起,文档有误。这仅适用于PERCENT = 'dataset'[SUMofAPPTS]/SUM('dataset'[SUMofAPPTS]) 的非JSON。像这样:

match

在JSON内将起作用:

* def batchnum = "112344552"
* def actual = 'select id from sr_sendreceive where batchnum = 112344552'
* match actual == '#("select id from sr_sendreceive where batchnum = " + batchnum)'

感谢您指出这一点,我将更新文档。