当字符串值中包含“-”时,该值在JSON对象中被截断

时间:2019-05-28 01:16:29

标签: karate

我想使用SQL查询(通过sampleId包含'-'符号)从数据库中获取值,但是查询字符串被截断了。

这是我的一些脚本,其中从上一次API调用中提取了sampleId

   * json result = response[0].result
    * print result
    * def personId = result[0].personid
    * def sampleId = result[0].sampleid

给出路​​径“ srehr / SendSample”

    * def config = read('classpath:utils/yntestDBConfig.json')
    * def DbUtils = Java.type('utils.DBUtils')
    * def db = new DbUtils(config)

    * def foo = {getBatchIDSQL: '#("select operatetime from sr_sendreceive_sample where sampleid = " + sampleId)'}
    * print foo.getBatchIDSQL

这是报告中的指定日志:

  

09:00:06.130 [print]从sr_sendreceive_sample中选择操作时间,其中sampleid = 1cfacfa4-eb06-4413-b060-9507bdebd1eb

     

mainFlow.feature:72-JavaScript评估失败:db.readValue(foo.getBatchIDSQL),StatementCallback;错误的SQL语法[从sr_sendreceive_sample中选择操作时间,其中sampleid = 1cfacfa4-eb06-4413-b060-9507bdebd1eb);嵌套的异常是java.sql.SQLSyntaxErrorException:'where子句'中的未知列'1cfacfa4'

我的问题:从日志中,您不会看到未知的列'1cfacfa4',它应该是'1cfacfa4-eb06-4413-b060-9507bdebd1eb'

1 个答案:

答案 0 :(得分:1)

尝试将SQL中的字符串用引号引起来:

* def sql = "select operatetime from sr_sendreceive_sample where sampleid = '" + sampleId + "'"