Search in sources :

Example 31 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class DatabasePlatformTest method testExportDefaultValueWithUnderscores.

@Test
public void testExportDefaultValueWithUnderscores() {
    Table table = new Table("TEST_DEFAULT_UNDERSCORES");
    table.addColumn(new Column("ID", true));
    table.getColumnWithName("ID").setTypeCode(Types.INTEGER);
    table.getColumnWithName("ID").setRequired(true);
    table.addColumn(new Column("NOTES"));
    table.getColumnWithName("NOTES").setTypeCode(Types.VARCHAR);
    table.getColumnWithName("NOTES").setSize("20");
    table.getColumnWithName("NOTES").setDefaultValue("this_has_underscores");
    Table tableFromDatabase = dropCreateAndThenReadTable(table);
    assertEquals(table.getColumnWithName("NOTES").getDefaultValue(), tableFromDatabase.getColumnWithName("NOTES").getDefaultValue());
}
Also used : Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column) Test(org.junit.Test)

Example 32 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class DatabasePlatformTest method testNvarcharType.

@Test
public void testNvarcharType() {
    Table table = new Table("test_nvarchar");
    table.addColumn(new Column("id", true, Types.INTEGER, 0, 0));
    table.addColumn(new Column("note", false, ColumnTypes.NVARCHAR, 100, 0));
    platform.createTables(true, false, table);
}
Also used : Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column) Test(org.junit.Test)

Example 33 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class DatabasePlatformTest method testUpgradePrimaryKeyAutoIncrementFromIntToBigInt.

@Test
public void testUpgradePrimaryKeyAutoIncrementFromIntToBigInt() throws Exception {
    boolean upgradeSupported = !platform.getName().equals(DatabaseNamesConstants.DERBY) && !platform.getName().equals(DatabaseNamesConstants.HSQLDB2) && !platform.getName().equals(DatabaseNamesConstants.INFORMIX) && !platform.getName().equals(DatabaseNamesConstants.DB2) && !platform.getName().equals(DatabaseNamesConstants.ASE) && !platform.getName().equals(DatabaseNamesConstants.MSSQL2000) && !platform.getName().equals(DatabaseNamesConstants.MSSQL2005) && !platform.getName().equals(DatabaseNamesConstants.MSSQL2008) && !platform.getName().equals(DatabaseNamesConstants.SQLANYWHERE);
    if (upgradeSupported) {
        Table table = new Table("TEST_UPGRADE");
        table.addColumn(new Column("ID", true));
        table.getColumnWithName("ID").setTypeCode(Types.INTEGER);
        table.getColumnWithName("ID").setAutoIncrement(true);
        table.getColumnWithName("ID").setRequired(true);
        table.addColumn(new Column("NOTES"));
        table.getColumnWithName("NOTES").setTypeCode(Types.VARCHAR);
        table.getColumnWithName("NOTES").setSize("100");
        Table tableFromDatabase = dropCreateAndThenReadTable(table);
        assertNotNull(tableFromDatabase);
        assertTrue(tableFromDatabase.getColumnWithName("ID").isPrimaryKey());
        String insertSql = "insert into \"TEST_UPGRADE\" (\"ID\",\"NOTES\") values(null,?)";
        insertSql = insertSql.replaceAll("\"", platform.getDatabaseInfo().getDelimiterToken());
        long id1 = platform.getSqlTemplate().insertWithGeneratedKey(insertSql, "ID", getSequenceName(platform), new Object[] { "test" }, new int[] { Types.VARCHAR });
        table.getColumnWithName("ID").setTypeCode(Types.BIGINT);
        IDdlBuilder builder = platform.getDdlBuilder();
        String alterSql = builder.alterTable(tableFromDatabase, table);
        assertFalse(alterSql, alterSql.toLowerCase().contains("create table"));
        new SqlScript(alterSql, platform.getSqlTemplate(), true, platform.getSqlScriptReplacementTokens()).execute(true);
        tableFromDatabase = platform.getTableFromCache(table.getName(), true);
        assertEquals(Types.BIGINT, table.getColumnWithName("ID").getMappedTypeCode());
        assertTrue(tableFromDatabase.getColumnWithName("ID").isPrimaryKey());
        long id2 = platform.getSqlTemplate().insertWithGeneratedKey(insertSql, "ID", getSequenceName(platform), new Object[] { "test" }, new int[] { Types.VARCHAR });
        assertNotSame(id1, id2);
    }
}
Also used : Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column) IDdlBuilder(org.jumpmind.db.platform.IDdlBuilder) SqlScript(org.jumpmind.db.sql.SqlScript) Test(org.junit.Test)

Example 34 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class JdbcPersistenceManagerTest method setup.

@Before
public void setup() throws Exception {
    manager = new JdbcPersistenceManager(createDatabasePlatform());
    testTableA = new Table("A");
    testTableA.addColumn(new Column("ID", true, Types.INTEGER, -1, -1));
    testTableA.addColumn(new Column("LAST_UPDATE_TIME", false, Types.TIMESTAMP, -1, -1));
    testTableA.addColumn(new Column("NOTE", false, Types.VARCHAR, 100, -1));
    manager.getDatabasePlatform().alterCaseToMatchDatabaseDefaultCase(testTableA);
    manager.getDatabasePlatform().createTables(true, true, testTableA);
}
Also used : Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column) Before(org.junit.Before)

Example 35 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class MySqlDdlReader method readColumn.

@Override
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException {
    Column column = super.readColumn(metaData, values);
    // is an illegal ISO value, so we replace it with NULL
    if ((column.getMappedTypeCode() == Types.TIMESTAMP) && "0000-00-00 00:00:00".equals(column.getDefaultValue())) {
        column.setDefaultValue(null);
    }
    // make sure the defaultvalue is null when an empty is returned.
    if ("".equals(column.getDefaultValue())) {
        column.setDefaultValue(null);
    }
    if (column.getJdbcTypeName().equalsIgnoreCase(TypeMap.POINT) || column.getJdbcTypeName().equalsIgnoreCase(TypeMap.LINESTRING) || column.getJdbcTypeName().equalsIgnoreCase(TypeMap.POLYGON)) {
        column.setJdbcTypeName(TypeMap.GEOMETRY);
    }
    if (column.getJdbcTypeName().equalsIgnoreCase("enum")) {
        ISqlTemplate template = platform.getSqlTemplate();
        String unParsedEnums = template.queryForString("SELECT SUBSTRING(COLUMN_TYPE,5) FROM information_schema.COLUMNS" + " WHERE TABLE_SCHEMA=? AND TABLE_NAME=? AND COLUMN_NAME=?", metaData.getCatalog(), (String) values.get("TABLE_NAME"), column.getName());
        if (unParsedEnums != null) {
            unParsedEnums = unParsedEnums.trim();
            if (unParsedEnums.startsWith("(")) {
                unParsedEnums = unParsedEnums.substring(1);
                if (unParsedEnums.endsWith(")")) {
                    unParsedEnums = unParsedEnums.substring(0, unParsedEnums.length() - 1);
                }
            }
            String[] parsedEnums = unParsedEnums.split(",");
            for (int i = 0; i < parsedEnums.length; i++) {
                String parsedEnum = parsedEnums[i];
                if (parsedEnum.startsWith("'")) {
                    parsedEnum = parsedEnum.substring(1);
                    if (parsedEnum.endsWith("'")) {
                        parsedEnum = parsedEnum.substring(0, parsedEnum.length() - 1);
                    }
                }
                parsedEnums[i] = parsedEnum;
            }
            column.setEnumValues(parsedEnums);
        }
    }
    return column;
}
Also used : ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) Column(org.jumpmind.db.model.Column)

Aggregations

Column (org.jumpmind.db.model.Column)179 Table (org.jumpmind.db.model.Table)78 ArrayList (java.util.ArrayList)34 IndexColumn (org.jumpmind.db.model.IndexColumn)23 PlatformColumn (org.jumpmind.db.model.PlatformColumn)21 Test (org.junit.Test)16 Row (org.jumpmind.db.sql.Row)15 LinkedHashMap (java.util.LinkedHashMap)12 ResultSet (java.sql.ResultSet)11 DmlStatement (org.jumpmind.db.sql.DmlStatement)10 SqlException (org.jumpmind.db.sql.SqlException)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IIndex (org.jumpmind.db.model.IIndex)9 HashMap (java.util.HashMap)8 ForeignKey (org.jumpmind.db.model.ForeignKey)8 CsvData (org.jumpmind.symmetric.io.data.CsvData)8 PreparedStatement (java.sql.PreparedStatement)7 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)6 Reference (org.jumpmind.db.model.Reference)6