as for “Rules for Embedded Expressions”, the string concatenation does not work

一笑奈何 提交于 2021-02-05 08:38:29

问题


I am fetching the data from database with SQL, I need pass a variable to the where clause, however, I find that the string concatenation doesn't work, even the official example

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

Then, I tried the official example:

      # 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

The result is :

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

回答1:


Sorry, the docs are wrong. This works for non-JSON only for match. Like this:

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

Inside JSON it will work:

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

Thanks for pointing this out, I will update the docs.



来源:https://stackoverflow.com/questions/56271303/as-for-rules-for-embedded-expressions-the-string-concatenation-does-not-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!