public Sql[] generateSql( SelectFromDatabaseChangeLogStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { String sql = "SELECT " + StringUtils.join(statement.getColumnsToSelect(), ",").toUpperCase() + " FROM " + database.escapeTableName( database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName()); SelectFromDatabaseChangeLogStatement.WhereClause whereClause = statement.getWhereClause(); if (whereClause != null) { if (whereClause instanceof SelectFromDatabaseChangeLogStatement.ByTag) { sql += " WHERE TAG='" + ((SelectFromDatabaseChangeLogStatement.ByTag) whereClause).getTagName() + "'"; } else if (whereClause instanceof SelectFromDatabaseChangeLogStatement.ByNotNullCheckSum) { sql += " WHERE MD5SUM IS NOT NULL"; } else { throw new UnexpectedLiquibaseException( "Unknown where clause type: " + whereClause.getClass().getName()); } } if (statement.getOrderByColumns() != null && statement.getOrderByColumns().length > 0) { sql += " ORDER BY " + StringUtils.join(statement.getOrderByColumns(), ", ").toUpperCase(); } return new Sql[] {new UnparsedSql(sql)}; }
public ValidationErrors validate( SelectFromDatabaseChangeLogStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { ValidationErrors errors = new ValidationErrors(); errors.checkRequiredField("columnToSelect", statement.getColumnsToSelect()); return errors; }