Search in sources :

Example 6 with SqlGeneratorChain

use of liquibase.sqlgenerator.SqlGeneratorChain in project liquibase by liquibase.

the class InsertOrUpdateGeneratorH2Test method testGenerateSql_notOnlyUpdate.

/**
 * Test method for {@link InsertOrUpdateGenerator#generateSql(InsertOrUpdateStatement, Database, SqlGeneratorChain)}.
 */
@Test
public void testGenerateSql_notOnlyUpdate() {
    final InsertOrUpdateGeneratorH2 generator = new InsertOrUpdateGeneratorH2();
    final InsertOrUpdateStatement insertOrUpdateStatement = new InsertOrUpdateStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME, "pk1");
    final Database database = new H2Database();
    final SqlGeneratorChain sqlGeneratorChain = null;
    ColumnConfig columnConfig;
    columnConfig = new ColumnConfig();
    columnConfig.setValue("keyvalue1");
    columnConfig.setName("pk1");
    insertOrUpdateStatement.addColumn(columnConfig);
    columnConfig = new ColumnConfig();
    columnConfig.setValue("value0");
    columnConfig.setName("col0");
    insertOrUpdateStatement.addColumn(columnConfig);
    // final String whereClause = generator.getWhereClause(insertOrUpdateStatement, database);
    Sql[] results = generator.generateSql(insertOrUpdateStatement, database, sqlGeneratorChain);
    assertThat(results, is(arrayWithSize(1)));
    assertEquals(String.format("MERGE INTO %s.%s (%s, %s) KEY(%s) VALUES ('%s', '%s');", SCHEMA_NAME, TABLE_NAME, "pk1", "col0", "pk1", "keyvalue1", "value0"), results[0].toSql());
}
Also used : InsertOrUpdateStatement(liquibase.statement.core.InsertOrUpdateStatement) ColumnConfig(liquibase.change.ColumnConfig) H2Database(liquibase.database.core.H2Database) Database(liquibase.database.Database) H2Database(liquibase.database.core.H2Database) SqlGeneratorChain(liquibase.sqlgenerator.SqlGeneratorChain) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Example 7 with SqlGeneratorChain

use of liquibase.sqlgenerator.SqlGeneratorChain in project liquibase by liquibase.

the class InsertOrUpdateGeneratorH2Test method testGetUpdateStatement_onlyUpdate.

/**
 * Test method for {@link InsertOrUpdateGeneratorH2#getUpdateStatement(InsertOrUpdateStatement, Database, String, SqlGeneratorChain)}.
 * @throws LiquibaseException
 */
@Test
public void testGetUpdateStatement_onlyUpdate() throws LiquibaseException {
    final InsertOrUpdateGeneratorH2 generator = new InsertOrUpdateGeneratorH2();
    final InsertOrUpdateStatement insertOrUpdateStatement = new InsertOrUpdateStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME, "pk1", true);
    final Database database = new H2Database();
    final SqlGeneratorChain sqlGeneratorChain = null;
    ColumnConfig columnConfig;
    columnConfig = new ColumnConfig();
    columnConfig.setValue("value0");
    columnConfig.setName("col0");
    insertOrUpdateStatement.addColumn(columnConfig);
    columnConfig = new ColumnConfig();
    columnConfig.setValue("keyvalue1");
    columnConfig.setName("pk1");
    insertOrUpdateStatement.addColumn(columnConfig);
    final String whereClause = generator.getWhereClause(insertOrUpdateStatement, database);
    String result = generator.getUpdateStatement(insertOrUpdateStatement, database, whereClause, sqlGeneratorChain);
    assertEquals(String.format("UPDATE %s.%s SET %s = '%s' WHERE %s = '%s';\n", SCHEMA_NAME, TABLE_NAME, "col0", "value0", "pk1", "keyvalue1"), result);
}
Also used : InsertOrUpdateStatement(liquibase.statement.core.InsertOrUpdateStatement) ColumnConfig(liquibase.change.ColumnConfig) H2Database(liquibase.database.core.H2Database) Database(liquibase.database.Database) H2Database(liquibase.database.core.H2Database) SqlGeneratorChain(liquibase.sqlgenerator.SqlGeneratorChain) Test(org.junit.Test)

Example 8 with SqlGeneratorChain

use of liquibase.sqlgenerator.SqlGeneratorChain in project liquibase by liquibase.

the class AddDefaultValueGeneratorInformixTest method shouldGenerateINT8TypeForBIGINTAndDefaultValue.

@Test
public void shouldGenerateINT8TypeForBIGINTAndDefaultValue() throws Exception {
    AddDefaultValueGeneratorInformix informix = new AddDefaultValueGeneratorInformix();
    AddDefaultValueStatement statement = new AddDefaultValueStatement(null, null, "tbl1", "id", "BIGINT", 1);
    InformixDatabase database = new InformixDatabase();
    SortedSet<SqlGenerator> sqlGenerators = new TreeSet<SqlGenerator>();
    SqlGeneratorChain sqlGenerationChain = new SqlGeneratorChain(sqlGenerators);
    Sql[] sqls = informix.generateSql(statement, database, sqlGenerationChain);
    assertEquals("ALTER TABLE tbl1 MODIFY (id INT8 DEFAULT 1)", sqls[0].toSql());
}
Also used : InformixDatabase(liquibase.database.core.InformixDatabase) SqlGenerator(liquibase.sqlgenerator.SqlGenerator) TreeSet(java.util.TreeSet) AddDefaultValueStatement(liquibase.statement.core.AddDefaultValueStatement) SqlGeneratorChain(liquibase.sqlgenerator.SqlGeneratorChain) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Aggregations

SqlGeneratorChain (liquibase.sqlgenerator.SqlGeneratorChain)8 Test (org.junit.Test)8 Database (liquibase.database.Database)7 ColumnConfig (liquibase.change.ColumnConfig)6 InsertOrUpdateStatement (liquibase.statement.core.InsertOrUpdateStatement)6 Sql (liquibase.sql.Sql)4 H2Database (liquibase.database.core.H2Database)3 MySQLDatabase (liquibase.database.core.MySQLDatabase)3 TreeSet (java.util.TreeSet)2 SqlGenerator (liquibase.sqlgenerator.SqlGenerator)2 InformixDatabase (liquibase.database.core.InformixDatabase)1 PostgresDatabase (liquibase.database.core.PostgresDatabase)1 AddDefaultValueStatement (liquibase.statement.core.AddDefaultValueStatement)1 DropIndexStatement (liquibase.statement.core.DropIndexStatement)1