Using prepared statement in Groovy

2019-06-14 16:38发布

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条回答
狗以群分
2楼-- · 2019-06-14 17:11

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

查看更多
登录 后发表回答