Search in sources :

Example 1 with CreateProcedureStatement

use of liquibase.statement.core.CreateProcedureStatement in project liquibase by liquibase.

the class CreateProcedureChange method generateStatements.

protected SqlStatement[] generateStatements(String logicText, String endDelimiter, Database database) {
    CreateProcedureStatement statement = new CreateProcedureStatement(getCatalogName(), getSchemaName(), getProcedureName(), logicText, endDelimiter);
    statement.setReplaceIfExists(getReplaceIfExists());
    return new SqlStatement[] { statement };
}
Also used : SqlStatement(liquibase.statement.SqlStatement) CreateProcedureStatement(liquibase.statement.core.CreateProcedureStatement)

Example 2 with CreateProcedureStatement

use of liquibase.statement.core.CreateProcedureStatement in project liquibase by liquibase.

the class LoggingExecutor method outputStatement.

private void outputStatement(SqlStatement sql, List<SqlVisitor> sqlVisitors) throws DatabaseException {
    try {
        if (SqlGeneratorFactory.getInstance().generateStatementsVolatile(sql, database)) {
            throw new DatabaseException(sql.getClass().getSimpleName() + " requires access to up to date database metadata which is not available in SQL output mode");
        }
        if (sql instanceof ExecutablePreparedStatement) {
            output.write("WARNING: This statement uses a prepared statement which cannot be execute directly by this script. Only works in 'update' mode\n\n");
        }
        for (String statement : applyVisitors(sql, sqlVisitors)) {
            if (statement == null) {
                continue;
            }
            if (database instanceof OracleDatabase) {
                //remove trailing /
                while (statement.matches("(?s).*[\\s\\r\\n]*/[\\s\\r\\n]*$")) {
                    //all trailing /'s
                    statement = statement.replaceFirst("[\\s\\r\\n]*/[\\s\\r\\n]*$", "");
                }
            }
            output.write(statement);
            if (database instanceof MSSQLDatabase || database instanceof SybaseDatabase || database instanceof SybaseASADatabase) {
                output.write(StreamUtil.getLineSeparator());
                output.write("GO");
            //            } else if (database instanceof OracleDatabase) {
            //                output.write(StreamUtil.getLineSeparator());
            //                output.write("/");
            } else {
                String endDelimiter = ";";
                String potentialDelimiter = null;
                if (sql instanceof RawSqlStatement) {
                    potentialDelimiter = ((RawSqlStatement) sql).getEndDelimiter();
                } else if (sql instanceof CreateProcedureStatement) {
                    potentialDelimiter = ((CreateProcedureStatement) sql).getEndDelimiter();
                }
                if (potentialDelimiter != null) {
                    //ignore trailing $ as a regexp to determine if it should be output
                    potentialDelimiter = potentialDelimiter.replaceFirst("\\$$", "");
                    if (potentialDelimiter.replaceAll("\\n", "\n").replace("\\r", "\r").matches("[;/\r\n\\w@\\-]+")) {
                        endDelimiter = potentialDelimiter;
                    }
                }
                endDelimiter = endDelimiter.replace("\\n", "\n");
                endDelimiter = endDelimiter.replace("\\r", "\r");
                if (!statement.endsWith(endDelimiter)) {
                    output.write(endDelimiter);
                }
            }
            output.write(StreamUtil.getLineSeparator());
            output.write(StreamUtil.getLineSeparator());
        }
    } catch (IOException e) {
        throw new DatabaseException(e);
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) SybaseASADatabase(liquibase.database.core.SybaseASADatabase) RawSqlStatement(liquibase.statement.core.RawSqlStatement) SybaseDatabase(liquibase.database.core.SybaseDatabase) CreateProcedureStatement(liquibase.statement.core.CreateProcedureStatement) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) IOException(java.io.IOException) DatabaseException(liquibase.exception.DatabaseException) ExecutablePreparedStatement(liquibase.statement.ExecutablePreparedStatement)

Aggregations

CreateProcedureStatement (liquibase.statement.core.CreateProcedureStatement)2 IOException (java.io.IOException)1 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)1 OracleDatabase (liquibase.database.core.OracleDatabase)1 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)1 SybaseDatabase (liquibase.database.core.SybaseDatabase)1 DatabaseException (liquibase.exception.DatabaseException)1 ExecutablePreparedStatement (liquibase.statement.ExecutablePreparedStatement)1 SqlStatement (liquibase.statement.SqlStatement)1 RawSqlStatement (liquibase.statement.core.RawSqlStatement)1