Using prepared statement in Groovy

和自甴很熟 提交于 2019-12-08 13:59:50

问题


this is for testing purposes (automatic testing) SoapUI

def status = testRunner.testCase.getPropertyValue( "Status" )
def grid = testRunner.testCase.getPropertyValue( "Grid" )+"_V"
def grid1

if (["TABLE1","TABLE2"].contains(grid))
     grid1 ="HUBCFG."+grid
else grid1 = "SDM."+grid

Option1

sql.executeUpdate "UPDATE " +grid1+" t0 set XXX='$status' WHERE t0.YYY='$grid'"

Option2

String bql = "UPDATE $grid1 t0 set XXX='$status' WHERE t0.YYY='$grid'"
sql.executeUpdate bql
sql.commit()
log.info("Successfully committed "+grid1+ " To " + status)

i didnt find the answers clear cut anywhere, so i scraped them together.

Hope this helps someone


回答1:


You should do:

sql.executeUpdate "UPDATE ${Sql.expand(grid1)} t0 set XXX=$status WHERE t0.YYY=$grid"

Or

def bql = "UPDATE ${Sql.expand(grid1)} t0 set XXX=$status WHERE t0.YYY=$grid"

The single quotes will be added for you, and Sql.expand allows you to embed things like table names into the resultant templated Groovy String



来源:https://stackoverflow.com/questions/43782702/using-prepared-statement-in-groovy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!