Closed anshu781126 closed 7 years ago
We haven't provided this capability because it is a data management concern. But you can call out to external scripts (like sqlplus scripts for example) using the system process DSL as follows to achieve what you need:
I execute system process "insert call to script here"
@anshu781126, did you give the above a try?
Yes this works but for this I need to maintain a piece of code which invokes some sql client. It would be more convenient to directly use dsl; like other automation tool supports. Data Management can be part of testcases so in that case user will be at ease if he gets to do it by DSL rather than maintaining additional piece of code.
My concern is that this could open up a whole world of data management problems and issues that could result in high maintenance and instability for Gwen. Also, since you are using a native SQL client, it makes sense to call out to it through the system process DSL. That's the precise reason we provide that DSL; so native capabilities can be utilised in a way that they are not coupled to Gwen.
@anshu781126, we've given it some thought and propose to provide some basic support for executing SQL insert, update, or delete statements with the following DSL:
I update the <dbName> database by sql "<updateSmt>"
<dbName>
= the name of database to execute the query on. This name is used to configure the database as follows:GWEN_CLASSPATH
environment variable must be set to include a path to the JDBC driver JARgwen.db.<dbName>.driver
setting must be set to the name of the JDBC driver implementation classgwen.db.<dbName>.url
setting must be set to the JDBC URL of the database<updateStmt>
= the SQL insert, update, or delete statement (can be a DocString)Example using mysql:
GWEN_CLASSPATH
variable in the environment to include the JDBC driver JARGWEN_CLASSPATH=/path-to-driver/mysql-connector-java-5.1.40-bin.jar
set GWEN_CLASSPATH c:/path-to-driver/mysql-connector-java-5.1.40-bin.jar
<dbName>
=feedbackgwen.db.feedback.driver = com.mysql.jdbc.Driver
gwen.db.feedback.url = jdbc:mysql://localhost/feedback?user=myUser&password=myPassword&serverTimezone=UTC&useSSL=false
When I update the feedback database by sql
"""
update comments set email='new.email@server.com' where email='old.email@server.com'
"""
When I update the feedback database by sql "update comments set email='new.email@server.com' where email='old.email@server.com'"
Then feedback rows affected should be "1"
We've implemented this in the snapshot build below. Please download it and try it out (see example usage above):
Let us know how it goes.
Working fine for update.