Search in sources :

Example 6 with SybaseDatabase

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

the class GetViewDefinitionGeneratorSybaseTest method testGenerateSqlForDefaultSchema.

@Test
public void testGenerateSqlForDefaultSchema() {
    GetViewDefinitionGeneratorSybase generator = new GetViewDefinitionGeneratorSybase();
    GetViewDefinitionStatement statement = new GetViewDefinitionStatement(null, null, "view_name");
    Sql[] sql = generator.generateSql(statement, new SybaseDatabase(), null);
    assertEquals(1, sql.length);
    assertEquals("select text from syscomments where id = object_id('dbo.view_name') order by colid", sql[0].toSql());
}
Also used : SybaseDatabase(liquibase.database.core.SybaseDatabase) GetViewDefinitionStatement(liquibase.statement.core.GetViewDefinitionStatement) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Example 7 with SybaseDatabase

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

the class GetViewDefinitionGeneratorSybaseTest method testGenerateSqlForNamedSchema.

@Test
public void testGenerateSqlForNamedSchema() {
    GetViewDefinitionGeneratorSybase generator = new GetViewDefinitionGeneratorSybase();
    GetViewDefinitionStatement statement = new GetViewDefinitionStatement(null, "owner", "view_name");
    Sql[] sql = generator.generateSql(statement, new SybaseDatabase(), null);
    assertEquals(1, sql.length);
    assertEquals("select text from syscomments where id = object_id('OWNER.view_name') order by colid", sql[0].toSql());
}
Also used : SybaseDatabase(liquibase.database.core.SybaseDatabase) GetViewDefinitionStatement(liquibase.statement.core.GetViewDefinitionStatement) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Example 8 with SybaseDatabase

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

the class AddColumnGeneratorDefaultClauseBeforeNotNull method generateSingleColumnSQL.

@Override
protected String generateSingleColumnSQL(AddColumnStatement statement, Database database) {
    String alterTable = " ADD " + database.escapeColumnName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName(), statement.getColumnName()) + " " + DataTypeFactory.getInstance().fromDescription(statement.getColumnType() + (statement.isAutoIncrement() ? "{autoIncrement:true}" : ""), database).toDatabaseDataType(database);
    alterTable += getDefaultClauseBeforeNotNull(statement, database);
    if (primaryKeyBeforeNotNull(database)) {
        if (statement.isPrimaryKey()) {
            alterTable += " PRIMARY KEY";
        }
    }
    if (statement.isAutoIncrement()) {
        AutoIncrementConstraint autoIncrementConstraint = statement.getAutoIncrementConstraint();
        alterTable += " " + database.getAutoIncrementClause(autoIncrementConstraint.getStartWith(), autoIncrementConstraint.getIncrementBy(), autoIncrementConstraint.getGenerationType(), autoIncrementConstraint.getDefaultOnNull());
    }
    if (!statement.isNullable()) {
        alterTable += " NOT NULL";
    } else if ((database instanceof SybaseDatabase) || (database instanceof SybaseASADatabase)) {
        alterTable += " NULL";
    }
    if (!primaryKeyBeforeNotNull(database)) {
        if (statement.isPrimaryKey()) {
            alterTable += " PRIMARY KEY";
        }
    }
    return alterTable;
}
Also used : SybaseASADatabase(liquibase.database.core.SybaseASADatabase) AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) SybaseDatabase(liquibase.database.core.SybaseDatabase)

Example 9 with SybaseDatabase

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

the class CreateTableGeneratorTest method testAutoIncrementSybaseDatabase.

@Test
public void testAutoIncrementSybaseDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof SybaseDatabase) {
            CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1));
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("Error with " + database, "CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGINT IDENTITY NULL)", generatedSql[0].toSql());
        }
    }
}
Also used : SybaseDatabase(liquibase.database.core.SybaseDatabase) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) H2Database(liquibase.database.core.H2Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) SybaseDatabase(liquibase.database.core.SybaseDatabase) SybaseASADatabase(liquibase.database.core.SybaseASADatabase) Database(liquibase.database.Database) AbstractDb2Database(liquibase.database.core.AbstractDb2Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Aggregations

SybaseDatabase (liquibase.database.core.SybaseDatabase)9 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)7 Sql (liquibase.sql.Sql)7 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)6 OracleDatabase (liquibase.database.core.OracleDatabase)6 Test (org.junit.Test)6 AbstractDb2Database (liquibase.database.core.AbstractDb2Database)5 MySQLDatabase (liquibase.database.core.MySQLDatabase)5 PostgresDatabase (liquibase.database.core.PostgresDatabase)5 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)5 Database (liquibase.database.Database)4 DerbyDatabase (liquibase.database.core.DerbyDatabase)4 H2Database (liquibase.database.core.H2Database)4 HsqlDatabase (liquibase.database.core.HsqlDatabase)4 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)4 CreateTableStatement (liquibase.statement.core.CreateTableStatement)4 DatabaseException (liquibase.exception.DatabaseException)2 AutoIncrementConstraint (liquibase.statement.AutoIncrementConstraint)2 GetViewDefinitionStatement (liquibase.statement.core.GetViewDefinitionStatement)2 IOException (java.io.IOException)1