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());
}
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);
}
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]);
}
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]);
}
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]);
}
Aggregations