karate - 当字符串值中包含“-”时,该值在 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'
解决方案
尝试将 SQL 中的字符串放在引号内:
* def sql = "select operatetime from sr_sendreceive_sample where sampleid = '" + sampleId + "'"
推荐阅读
- sql - 如何在sql代码中添加逻辑语句?
- jupyter-notebook - 单元运行完成,但内核仍在运行
- react-native - 世博会,React Native takePictureAsync 不返回
- laravel - Laravel Spatie Medialibrary:通过 REST API 上传多张图片
- android - 如何使用“cordova-android-play-services-gradle-release”调整“play-services-measurement-base”的版本?
- c# - 如何从平面列表构建嵌套的 HTML 列表
- c# - 如何在中间件中自动生成基于资源的 URI 以供前端使用?
- excel - 有选择地将行从一个工作表复制到新工作表上的新表
- dataframe - 在具有相同标题名称的单个数据框中按行连接多个文件
- ruby-on-rails - 在 Rails 中实现 Bootstrap 主题