Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow WITH sql keyword for query action #985

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (log.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
Loading