首页 > 解决方案 > 当字符串值中包含“-”时,该值在 JSON 对象中被截断

问题描述

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

这是我sampleId从最后一个 API 调用中获取的一些脚本:

   * 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 [打印] 从 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'

标签: karate

解决方案


尝试将 SQL 中的字符串放在引号内:

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

推荐阅读