Skip to content

Commit

Permalink
Fix for bug 2711: Error when calling a procedure with parameters on D…
Browse files Browse the repository at this point in the history
…B2Z (#2765)

Co-authored-by: mkern <michael.kern@scoop-software.de>
  • Loading branch information
michaelmatthiaskern and mkern committed Jul 28, 2022
1 parent 46ccde7 commit 7315bf4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
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);
}
}

0 comments on commit 7315bf4

Please sign in to comment.