至于“嵌入式表达式规则",字符串连接不起作用 [英] as for "Rules for Embedded Expressions", the string concatenation does not work

查看:47
本文介绍了至于“嵌入式表达式规则",字符串连接不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

结果是:

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

推荐答案

对不起,文档错误.这仅适用于match的非JSON.像这样:

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)'

在JSON内将起作用:

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.

这篇关于至于“嵌入式表达式规则",字符串连接不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆