Search in sources :

Example 16 with MSSQLDatabase

use of liquibase.database.core.MSSQLDatabase in project liquibase by liquibase.

the class UpdateGeneratorTest method testGenerateSqlWithParamPlaceholders.

@Test
public void testGenerateSqlWithParamPlaceholders() {
    // given
    Database database = new MSSQLDatabase();
    UpdateStatement statement = new UpdateStatement(null, null, "DATABASECHANGELOG").addNewColumnValue("MD5SUM", "7:e27bf9c0c2313160ef960a15d44ced47").setWhereClause(database.escapeObjectName("ID", Column.class) + " = ? " + "AND " + database.escapeObjectName("AUTHOR", Column.class) + " = ? " + "AND " + database.escapeObjectName("FILENAME", Column.class) + " = ?").addWhereParameters("SYPA: AUTO_START tüüp INT -> TEXT, vaartus 0 00 17 * * ?", "martin", "db/changelog.xml");
    UpdateGenerator generator = new UpdateGenerator();
    // when
    Sql[] sqls = generator.generateSql(statement, database, null);
    // then
    assertEquals("UPDATE [DATABASECHANGELOG] " + "SET [MD5SUM] = '7:e27bf9c0c2313160ef960a15d44ced47' " + "WHERE [ID] = N'SYPA: AUTO_START tüüp INT -> TEXT, vaartus 0 00 17 * * ?' " + "AND [AUTHOR] = 'martin' " + "AND [FILENAME] = 'db/changelog.xml'", sqls[0].toSql());
}
Also used : UpdateStatement(liquibase.statement.core.UpdateStatement) Column(liquibase.structure.core.Column) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Database(liquibase.database.Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Example 17 with MSSQLDatabase

use of liquibase.database.core.MSSQLDatabase in project liquibase by liquibase.

the class UpdateExecutablePreparedStatementTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    given(connection.prepareStatement(anyString())).willReturn(ps);
    database = new MSSQLDatabase();
    preparedStatementFactory = new PreparedStatementFactory(connection);
}
Also used : PreparedStatementFactory(liquibase.database.PreparedStatementFactory) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Before(org.junit.Before)

Example 18 with MSSQLDatabase

use of liquibase.database.core.MSSQLDatabase in project liquibase by liquibase.

the class InsertOrUpdateGeneratorMSSQLTest method getUpdate.

@Test
public void getUpdate() {
    InsertOrUpdateGeneratorMSSQL generator = new InsertOrUpdateGeneratorMSSQL();
    MSSQLDatabase database = new MSSQLDatabase();
    InsertOrUpdateStatement statement = new InsertOrUpdateStatement("mycatalog", "myschema", "mytable", "pk_col1");
    statement.addColumnValue("col2", "value2");
    String where = "1 = 1";
    Class c = InsertOrUpdateGenerator.class.getClass();
    //InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause, SqlGeneratorChain sqlGeneratorChain
    String insertStatement = (String) invokePrivateMethod(generator, "getUpdateStatement", new Object[] { statement, database, where, null });
    Integer lineNumber = 0;
    String[] lines = insertStatement.split("\n");
    assertEquals("BEGIN", lines[lineNumber]);
    lineNumber++;
    assertTrue(lines[lineNumber].startsWith("UPDATE"));
    lineNumber++;
    assertEquals("END", lines[lineNumber]);
}
Also used : InsertOrUpdateStatement(liquibase.statement.core.InsertOrUpdateStatement) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Test(org.junit.Test)

Example 19 with MSSQLDatabase

use of liquibase.database.core.MSSQLDatabase in project liquibase by liquibase.

the class InsertOrUpdateGeneratorMSSQLTest method getRecordCheck.

@Test
public void getRecordCheck() {
    InsertOrUpdateGeneratorMSSQL generator = new InsertOrUpdateGeneratorMSSQL();
    MSSQLDatabase database = new MSSQLDatabase();
    InsertOrUpdateStatement statement = new InsertOrUpdateStatement("mycatalog", "myschema", "mytable", "pk_col1");
    statement.addColumnValue("pk_col1", "value1");
    statement.addColumnValue("col2", "value2");
    String where = "1 = 1";
    String recordCheck = (String) invokePrivateMethod(generator, "getRecordCheck", new Object[] { statement, database, where });
    Integer lineNumber = 0;
    String[] lines = recordCheck.split("\n");
    assertEquals("DECLARE @reccount integer", lines[lineNumber]);
    lineNumber++;
    assertEquals("SELECT @reccount = count(*) FROM [mycatalog].[myschema].[mytable] WHERE " + where, lines[lineNumber]);
    lineNumber++;
    assertEquals("IF @reccount = 0", lines[lineNumber]);
}
Also used : InsertOrUpdateStatement(liquibase.statement.core.InsertOrUpdateStatement) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Test(org.junit.Test)

Example 20 with MSSQLDatabase

use of liquibase.database.core.MSSQLDatabase in project liquibase by liquibase.

the class InsertOrUpdateGeneratorMSSQLTest method getInsert.

@Test
public void getInsert() {
    InsertOrUpdateGeneratorMSSQL generator = new InsertOrUpdateGeneratorMSSQL();
    MSSQLDatabase database = new MSSQLDatabase();
    InsertOrUpdateStatement statement = new InsertOrUpdateStatement("mycatalog", "myschema", "mytable", "pk_col1");
    statement.addColumnValue("pk_col1", "value1");
    statement.addColumnValue("col2", "value2");
    String where = "1 = 1";
    Class c = InsertOrUpdateGenerator.class.getClass();
    //InsertOrUpdateStatement insertOrUpdateStatement, Database database, SqlGeneratorChain sqlGeneratorChain
    String insertStatement = (String) invokePrivateMethod(generator, "getInsertStatement", new Object[] { statement, database, null });
    Integer lineNumber = 0;
    String[] lines = insertStatement.split("\n");
    assertEquals("BEGIN", lines[lineNumber]);
    lineNumber++;
    assertTrue(lines[lineNumber].startsWith("INSERT"));
    lineNumber++;
    assertEquals("END", lines[lineNumber]);
}
Also used : InsertOrUpdateStatement(liquibase.statement.core.InsertOrUpdateStatement) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Test(org.junit.Test)

Aggregations

MSSQLDatabase (liquibase.database.core.MSSQLDatabase)38 Test (org.junit.Test)17 Sql (liquibase.sql.Sql)12 OracleDatabase (liquibase.database.core.OracleDatabase)11 Database (liquibase.database.Database)7 DB2Database (liquibase.database.core.DB2Database)7 MySQLDatabase (liquibase.database.core.MySQLDatabase)7 PostgresDatabase (liquibase.database.core.PostgresDatabase)7 RawSqlStatement (liquibase.statement.core.RawSqlStatement)6 Column (liquibase.structure.core.Column)6 ArrayList (java.util.ArrayList)5 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)5 DatabaseException (liquibase.exception.DatabaseException)5 Change (liquibase.change.Change)4 HsqlDatabase (liquibase.database.core.HsqlDatabase)4 SybaseDatabase (liquibase.database.core.SybaseDatabase)4 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)4 Executor (liquibase.executor.Executor)4 InsertOrUpdateStatement (liquibase.statement.core.InsertOrUpdateStatement)4 BigInteger (java.math.BigInteger)3