SOAPUI& Groovy Scripts,一次性执行多条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()
无法处理 ;
,这意味着我可以只使用第一个 DELETE
语句
我该如何解决这个问题?我不想单独加载每个属性并执行它们。理想情况下,我只想要一个属性,这样我就可以在将来添加更多删除语句
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一些 JDBC 驱动程序支持多个语句,然后可以通过 Groovy 的 Sql 类使用此功能,例如使用 MySql:
Some JDBC drivers support multiple statements and this functionality will then be available via Groovy's Sql class, e.g. with MySql:
难道你不能将它们存储在带有分号的属性文件中,然后在读取它们后将其删除,例如
Couldn't you just store them in the properties file with the semicolons, then remove them after reading them, e.g.
有时这还不够好。查看我的解决方案:从 Groovy 运行多个 SQL 语句
Sometimes that's not good enough. Check out my solution: Running multiple SQL statements from Groovy