0

I want to get the value from database using a SQL query (by sampleId which contains '-' sign), however, the query string is truncated.

Here is some of my script where the sampleId is fetched from the last API call:

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

Given path '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

Here is the specified log in the report:

09:00:06.130 [print] select operatetime from sr_sendreceive_sample where sampleid = 1cfacfa4-eb06-4413-b060-9507bdebd1eb

mainFlow.feature:72 - javascript evaluation failed: db.readValue(foo.getBatchIDSQL), StatementCallback; bad SQL grammar [select operatetime from sr_sendreceive_sample where sampleid = 1cfacfa4-eb06-4413-b060-9507bdebd1eb]; nested exception is java.sql.SQLSyntaxErrorException: Unknown column '1cfacfa4' in 'where clause'

My question: from the log, you see that unknown column '1cfacfa4' is not expected, it should be '1cfacfa4-eb06-4413-b060-9507bdebd1eb'

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bitlin Chen
  • 179
  • 8
  • OK,I see the query should be: select operatetime from sr_sendreceive_sample where sampleid = '1cfacfa4-eb06-4413-b060-9507bdebd1eb'. However, how should I get the sampleId single quotation marked? – Bitlin Chen May 28 '19 at 01:25
  • PLEASE read this very carefully: https://stackoverflow.com/a/52078427/143475 – Peter Thomas May 28 '19 at 04:40

1 Answers1

1

Try having the strings in SQL within quotes:

* def sql = "select operatetime from sr_sendreceive_sample where sampleid = '" + sampleId + "'"
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248