SOAPUI& Groovy脚本,一次执行多个SQL语句 [英] SOAPUI & Groovy Scripts, executing multiple SQL statements in one go

查看:493
本文介绍了SOAPUI& Groovy脚本,一次执行多个SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些soapUI测试,它使用groovy脚本首先将一些数据插入到表中。

以前,我一直使用下面的代码片段要做到这一点:

  def conn = context.dbConnEtopup 
conn.execute(INSERT INTO A(ID,NAME )VALUES(1,Johnny))

这很好,但是我有很多测试脚本现在做一个类似的(如果不是相同的)SQL语句,所以我试图通过从属性文件中加载它来实现,所以我的实际SQL语句只在一个地方,以便于编辑。



然而,我试图使用的SQL语句实际上是2个插入(或删除),所以被加载的属性为:

  DELETE * FROM TABLE_A; DELETE * FROM TABLE_B; 

conn.execute() can not处理; ,这意味着我只能使用第一个 DELETE 语句



我该如何解决这个问题?我不想单独加载每个属性并执行它们。理想情况下,我只想要一个属性,所以我可以在将来添加更多的删除语句

解决方案

难道你不能将它们存储在使用分号读取属性文件,然后在读取它们后将其删除,例如

 字符串sqlProperty = //从文件读取SQL属性
def statements = sqlProperty.split(;)

//使用conn(groov.sql.Sql的实例?)执行每个语句
statements.each {conn。执行(它);


I've got some soapUI tests, that use groovy scripts to first insert some data into a table

Previously, I've been using the following snippet of code to do this :

      def conn = context.dbConnEtopup
      conn.execute( "INSERT INTO A(ID, NAME) VALUES (1, "Johnny")" )

This works fine, however I have many test scripts that now do a similar (if not the same) SQL statements, so I'm trying to approach this by loading it in from a properties file, so my actual SQL statement is only in one place, for easier editing

However, my SQL statement that I'm trying to use is actually 2 inserts(or deletes), so the property being loaded in is :

DELETE * FROM TABLE_A; DELETE * FROM TABLE_B;

conn.execute() can't handle the ;, which means I could only use the first DELETE statement

How can I get around this? I don't want to have to load each property separately and execute them. Ideally I just want one property, so I can add further delete statements in the future

解决方案

Couldn't you just store them in the properties file with the semicolons, then remove them after reading them, e.g.

String sqlProperty = // read SQL property from file
def statements = sqlProperty.split(";")

// Execute each statment using conn (an instance of groov.sql.Sql?)
statements.each { conn.execute(it);

这篇关于SOAPUI& Groovy脚本,一次执行多个SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆