Karate 至于「;“嵌入式表达式规则”;,字符串串联不起作用

Karate 至于「;“嵌入式表达式规则”;,字符串串联不起作用,karate,Karate,我使用SQL从数据库中获取数据,我需要将一个变量传递给where子句,但是,我发现字符串连接不起作用,即使是官方示例 * def batchnum = "112344552" * def getBatchIDSQL = '#("select id from sr_sendreceive where batchnum = " + batchnum)' * print getBatchIDSQL * def sendReceiveBatchid = db.readValue('#(getBatchI

我使用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)

对不起,文件错了。这仅适用于
匹配的非JSON。像这样:

* def batchnum = "112344552"
* def actual = 'select id from sr_sendreceive where batchnum = 112344552'
* match actual == '#("select id from sr_sendreceive where batchnum = " + batchnum)'
在JSON内部,它将工作:

* def foo = { bar: '#("select id from sr_sendreceive where batchnum = " + batchnum)' }
* print foo

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

对不起,文档是错误的。这仅适用于
匹配的非JSON。像这样:

* def batchnum = "112344552"
* def actual = 'select id from sr_sendreceive where batchnum = 112344552'
* match actual == '#("select id from sr_sendreceive where batchnum = " + batchnum)'
在JSON内部,它将工作:

* def foo = { bar: '#("select id from sr_sendreceive where batchnum = " + batchnum)' }
* print foo

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

另一种情况下,我的batchnum现在的格式是“0002d200-6d97-4228-97e4-8fffe1bf822d”。最后,我需要使用以下sql从mysql查询数据:选择batchnum from sr_sendreceive,其中id='0002d200-6d97-4228-97e4-8fffe1bf822d',它失败,id被截断为'0002d200'。@BitlinChen抱歉,这没有意义,如果需要,请问一个新问题-请记住空手道与sql无关另一个案例,我的batchnum现在的格式是“0002d200-6d97-4228-97e4-8fffe1bf822d”。最后,我需要使用以下sql从mysql查询数据:选择batchnum from sr_sendreceive,其中id='0002d200-6d97-4228-97e4-8fffe1bf822d',它失败了,id被截断为'0002d200'。@BitlinChen很抱歉,这没有意义,如果需要,请问一个新问题-请记住空手道与sql无关