use of liquibase.sql.Sql in project liquibase by liquibase.
the class AddColumnGenerator method generateMultipleColumns.
private Sql[] generateMultipleColumns(List<AddColumnStatement> columns, Database database) {
List<Sql> result = new ArrayList<Sql>();
if (database instanceof MySQLDatabase) {
String alterTable = generateSingleColumBaseSQL(columns.get(0), database);
for (int i = 0; i < columns.size(); i++) {
alterTable += generateSingleColumnSQL(columns.get(i), database);
if (i < columns.size() - 1) {
alterTable += ",";
}
}
result.add(new UnparsedSql(alterTable, getAffectedColumns(columns)));
for (AddColumnStatement statement : columns) {
addUniqueConstrantStatements(statement, database, result);
addForeignKeyStatements(statement, database, result);
}
} else {
for (AddColumnStatement column : columns) {
result.addAll(Arrays.asList(generateSingleColumn(column, database)));
}
}
return result.toArray(new Sql[result.size()]);
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class FindForeignKeyConstraintsGeneratorOracle method generateSql.
@Override
public Sql[] generateSql(FindForeignKeyConstraintsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
CatalogAndSchema baseTableSchema = new CatalogAndSchema(statement.getBaseTableCatalogName(), statement.getBaseTableSchemaName()).customize(database);
StringBuilder sb = new StringBuilder();
sb.append("SELECT ");
sb.append("BASE.TABLE_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME).append(", ");
sb.append("BCOLS.COLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_COLUMN_NAME).append(", ");
sb.append("FRGN.TABLE_NAME ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_TABLE_NAME).append(", ");
sb.append("FCOLS.COLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_COLUMN_NAME).append(", ");
sb.append("BASE.CONSTRAINT_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME).append(" ");
sb.append("FROM ALL_CONSTRAINTS BASE,");
sb.append(" ALL_CONSTRAINTS FRGN,");
sb.append(" ALL_CONS_COLUMNS BCOLS,");
sb.append(" ALL_CONS_COLUMNS FCOLS ");
sb.append("WHERE BASE.R_OWNER = FRGN.OWNER ");
sb.append("AND BASE.R_CONSTRAINT_NAME = FRGN.CONSTRAINT_NAME ");
sb.append("AND BASE.OWNER = BCOLS.OWNER ");
sb.append("AND BASE.CONSTRAINT_NAME = BCOLS.CONSTRAINT_NAME ");
sb.append("AND FRGN.OWNER = FCOLS.OWNER ");
sb.append("AND FRGN.CONSTRAINT_NAME = FCOLS.CONSTRAINT_NAME ");
sb.append("AND BASE.TABLE_NAME = '").append(statement.getBaseTableName().toUpperCase()).append("' ");
sb.append("AND BASE.CONSTRAINT_TYPE = 'R' ");
sb.append("AND BASE.OWNER = '").append(baseTableSchema.getSchemaName()).append("'");
return new Sql[] { new UnparsedSql(sb.toString()) };
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class GetViewDefinitionGenerator method generateSql.
@Override
public Sql[] generateSql(GetViewDefinitionStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
CatalogAndSchema schema = new CatalogAndSchema(statement.getCatalogName(), statement.getSchemaName()).customize(database);
String sql;
if (database instanceof MSSQLDatabase)
sql = "select VIEW_DEFINITION from INFORMATION_SCHEMA.VIEWS where TABLE_NAME='" + database.correctObjectName(statement.getViewName(), View.class) + "'";
else
sql = "select view_definition from information_schema.views where table_name='" + database.correctObjectName(statement.getViewName(), View.class) + "'";
if (database instanceof MySQLDatabase) {
sql += " and table_schema='" + schema.getCatalogName() + "'";
} else {
if (database.supportsSchemas()) {
String schemaName = schema.getSchemaName();
if (schemaName != null) {
if (database instanceof MSSQLDatabase)
sql += " and TABLE_SCHEMA='" + schemaName + "'";
else
sql += " and table_schema='" + schemaName + "'";
}
}
if (database.supportsCatalogs()) {
String catalogName = schema.getCatalogName();
if (catalogName != null) {
if (database instanceof MSSQLDatabase)
sql += " and TABLE_CATALOG='" + catalogName + "'";
else
sql += " and table_catalog='" + catalogName + "'";
}
}
}
return new Sql[] { new UnparsedSql(sql) };
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class GetViewDefinitionGeneratorMSSQL method generateSql.
@Override
public Sql[] generateSql(GetViewDefinitionStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
CatalogAndSchema schema = new CatalogAndSchema(statement.getCatalogName(), statement.getSchemaName()).customize(database);
boolean sql2005OrLater = true;
try {
sql2005OrLater = database.getDatabaseMajorVersion() >= 9;
} catch (Exception ignored) {
// Assume 2005 or later
}
String viewNameEscaped = database.escapeObjectName(schema.getCatalogName(), schema.getSchemaName(), statement.getViewName(), View.class);
String sql;
if (sql2005OrLater) {
sql = "SELECT OBJECT_DEFINITION(OBJECT_ID(N'" + database.escapeStringForDatabase(viewNameEscaped) + "')) AS [ObjectDefinition]";
} else {
sql = "SELECT [c].[text] " + "FROM [dbo].[syscomments] AS [c] " + "WHERE [c].[id] = OBJECT_ID(N'" + database.escapeStringForDatabase(viewNameEscaped) + "') " + "ORDER BY [c].[colid]";
}
return new Sql[] { new UnparsedSql(sql) };
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class GetViewDefinitionGeneratorSybase method generateSql.
@Override
public Sql[] generateSql(GetViewDefinitionStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
CatalogAndSchema schema = new CatalogAndSchema(statement.getCatalogName(), statement.getSchemaName()).customize(database);
String schemaName = schema.getSchemaName();
if (schemaName == null) {
schemaName = database.getDefaultSchemaName();
}
if (schemaName == null) {
schemaName = "dbo";
}
String sql = "select text from syscomments where id = object_id('" + schemaName + "." + statement.getViewName() + "') order by colid";
return new Sql[] { new UnparsedSql(sql) };
}
Aggregations