SQL execution
<name> is defined in the <dbName> database by sql "<selectStmt>"
Associates the result of an SQL database query to the given name in the global scope. The value is resolved every time the name is referenced.
<name> is defined in the <dbName> database by sql "<selectStmt>"
Where
<name>is the name to bind the SQL query result to<dbName>the name of the configured database to execute the query on<selectStmt>is the SQL query that will return the value to assign (can be in DocString position)
Configuration
- The
GWEN_CLASSPATHenvironment variable must be set to include a path to the JDBC driver JAR - A
gwen.db.<dbName>.driversetting must be set to the name of the JDBC driver implementation class - A
gwen.db.<dbName>.urlsetting must be set to the JDBC URL of the database
Optionally accepts the @Eager, @Lazy or @Masked annotations.
@Eagerimmediately evaluates the<expression>and binds the result to<name>@Lazyevaluates the<expression>and binds the result to<name>when it is first referenced- In the absence of either of the above annotations,
<expression>is evaluated every time<name>is referenced @Maskedmasks the captured value to prevent it from being logged as clear text
Example
Given the email address is defined in the feedback database by sql
"""
select email from comments
"""
Then the email address should be "some.person@example.com"
- Linux
- Windows
Set GWEN_CLASSPATH variable in the environment to include the JDBC driver JAR
export GWEN_CLASSPATH=/path-to-driver/mysql-connector-java-5.1.40-bin.jar
Set GWEN_CLASSPATH variable in the environment to include the JDBC driver JAR
set GWEN_CLASSPATH c:/path-to-driver/mysql-connector-java-5.1.40-bin.jar
Configure the database in your settings. In this example, <dbName>=feedback
gwen.db.feedback.driver = com.mysql.jdbc.Driver
gwen.db.feedback.url = jdbc:mysql://localhost/feedback?user=myUser&password=myPassword&
I update the <dbName> database by sql "<updateStmt>"
Executes an SQL udpate statement on a configured database.
I update the <dbName> database by sql "<updateStmt>"
Where
<dbName>the name of the configured database to run the update statement on<updateStmt>is the SQL update statement to execute (can be in DocString position)
Returns
<dbName> rows affected= the number of rows affected by the update
Configuration
- The
GWEN_CLASSPATHenvironment variable must be set to include a path to the JDBC driver JAR - A
gwen.db.<dbName>.driversetting must be set to the name of the JDBC driver implementation class - A
gwen.db.<dbName>.urlsetting must be set to the JDBC URL of the database
Example
When I update the feedback database by sql
"""
update comments set email='new@example.com' where email='old@example.com'
"""
Then feedback rows affected should be "1"
- Linux
- Windows
Set GWEN_CLASSPATH variable in the environment to include the JDBC driver JAR
export GWEN_CLASSPATH=/path-to-driver/mysql-connector-java-5.1.40-bin.jar
Set GWEN_CLASSPATH variable in the environment to include the JDBC driver JAR
set GWEN_CLASSPATH c:/path-to-driver/mysql-connector-java-5.1.40-bin.jar
Configure the database in your settings. In this example, <dbName>=feedback
gwen.db.feedback.driver = com.mysql.jdbc.Driver
gwen.db.feedback.url = jdbc:mysql://localhost/feedback?user=myUser&password=myPassword&