Skip to content

Commit

Permalink
Merge pull request #985 from /issues/984-sql-action
Browse files Browse the repository at this point in the history
allow WITH sql keyword for query action
  • Loading branch information
bbortt authored Sep 18, 2023
2 parents 1a9ea4e + fed0d3a commit 45b6935
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,18 @@ public void doExecute(TestContext context) {
* @param context
*/
protected void executeStatements(List<String> statements, List<Map<String, Object>> allResultRows, Map<String, List<String>> columnValuesMap, TestContext context) {
for (String stmt : statements) {
validateSqlStatement(stmt);
final String toExecute;
if (getJdbcTemplate() == null) {
throw new CitrusRuntimeException("No JdbcTemplate configured for query execution!");
}

if (stmt.trim().endsWith(";")) {
toExecute = context.replaceDynamicContentInString(stmt.trim().substring(0, stmt.trim().length()-1));
for (String statement : statements) {
validateSqlStatement(statement);

final String toExecute;
if (statement.trim().endsWith(";")) {
toExecute = context.replaceDynamicContentInString(statement.trim().substring(0, statement.trim().length() - 1));
} else {
toExecute = context.replaceDynamicContentInString(stmt.trim());
toExecute = context.replaceDynamicContentInString(statement.trim());
}

if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -333,11 +337,12 @@ private void performControlResultSetValidation(final Map<String, List<String>> c

/**
* Does some simple validation on the SQL statement.
* @param stmt The statement which is to be validated.
* @param statement The statement which is to be validated.
*/
protected void validateSqlStatement(String stmt) {
if (!stmt.toLowerCase().startsWith("select")) {
throw new CitrusRuntimeException("Missing keyword SELECT in statement: " + stmt);
protected void validateSqlStatement(String statement) {
String trimmedStatement = statement.toLowerCase().trim();
if (!(trimmedStatement.startsWith("select") || trimmedStatement.startsWith("with"))) {
throw new CitrusRuntimeException("Missing SELECT or WITH keyword in statement: " + trimmedStatement);
}
}

Expand Down
Loading

0 comments on commit 45b6935

Please sign in to comment.