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

Fix for bug 2711: Error when calling a procedure with parameters on DB2Z #2765

Merged
merged 3 commits into from Jul 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,13 +4,14 @@
import liquibase.Scope;
import liquibase.GlobalConfiguration;
import liquibase.database.Database;
import liquibase.database.core.Db2zDatabase;
import liquibase.database.core.MSSQLDatabase;
import liquibase.database.core.PostgresDatabase;
import liquibase.exception.DatabaseException;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.exception.ValidationErrors;
import liquibase.exception.Warnings;
import liquibase.statement.SqlStatement;
import liquibase.statement.core.RawCompoundStatement;
import liquibase.statement.core.RawSqlStatement;
import liquibase.util.StringUtil;

Expand Down Expand Up @@ -249,7 +250,11 @@ public SqlStatement[] generateStatements(Database database) {
escapedStatement = statement;
}

returnStatements.add(new RawSqlStatement(escapedStatement, getEndDelimiter()));
if (database instanceof Db2zDatabase && escapedStatement.toUpperCase().startsWith("CALL")) {
returnStatements.add(new RawCompoundStatement(escapedStatement, getEndDelimiter()));
} else {
returnStatements.add(new RawSqlStatement(escapedStatement, getEndDelimiter()));
}
}

return returnStatements.toArray(new SqlStatement[returnStatements.size()]);
Expand Down
Expand Up @@ -26,6 +26,7 @@
import liquibase.util.StringUtil;

import java.sql.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -359,8 +360,13 @@ private void executeDb2ZosComplexStatement(SqlStatement sqlStatement) throws Dat
} else {
Statement stmt = null;
try {
stmt = ((JdbcConnection) con).getUnderlyingConnection().createStatement();
stmt.execute(sql.toSql());
if (sqlStatement instanceof CompoundStatement) {
stmt = ((JdbcConnection) con).getUnderlyingConnection().prepareStatement(sql.toSql());
((PreparedStatement)stmt).execute();
} else {
stmt = ((JdbcConnection) con).getUnderlyingConnection().createStatement();
stmt.execute(sql.toSql());
}
con.commit();
} finally {
JdbcUtil.closeStatement(stmt);
Expand Down
@@ -0,0 +1,14 @@
package liquibase.statement.core;

import liquibase.statement.CompoundStatement;

public class RawCompoundStatement extends RawSqlStatement implements CompoundStatement {

public RawCompoundStatement(String sql) {
super(sql);
}

public RawCompoundStatement(String sql, String endDelimiter) {
super(sql, endDelimiter);
}
}