如何在 Groovy 脚本中的 sql where 子句中添加引号?

How to add quotes into sql where clause in Groovy script?

同学们,请帮我sql in Groovy。 在我的 SOAP UI groovy 脚本中,我有 sql 查询:

sql.eachRow('select top 1 '+     
              'Country, '+    
   'from dbo.Address where UPPER(Country) = "JAPAN" ORDER BY NEWID()')  

一切都很好,直到我在 where 子句中没有引号的情况下工作。在我添加 UPPER(Country) = "JAPAN" 之后,我收到一个 axception:

com.microsoft.sqlserver.jdbc.SQLServerException: Ivalid column name 'Japan'

如何在 where 子句中使用引号重写查询?

或者在 Groovy 代码中使用不同的引号字符:

sql.eachRow("select top 1 " +     
            "Country, " +    
            "from dbo.Address where UPPER(Country) = 'JAPAN' ORDER BY NEWID()")

或多行字符串:

sql.eachRow('''select top 1
               Country, 
               from dbo.Address where UPPER(Country) = 'JAPAN' ORDER BY NEWID()''')

或带边距的多行字符串:

sql.eachRow('''select top 1
              | Country, 
              | from dbo.Address where UPPER(Country) = 'JAPAN' ORDER BY NEWID()'''.stripMargin())

我更喜欢参数而不是文字,尤其是因为如果值来自用户输入或者值本身包含引号,它可以正常工作:

sql.eachRow('''select .... from dbo.Address 
     where UPPER(Country) = :country ...''', 
   [country: 'Japan'])