/** * Utility function to modify column definitions to the MetatData DB tables * * <p>This is used from the ALTER TABLE MODIFY */ public static void modifyTableColumn(SqlCreateTableColumn columnDefinition, SysTable targetTable) throws Exception { StringBuffer sbStatement = new StringBuffer("UPDATE xsyscolumns SET "); SysColumn aSysCol = targetTable.getSysColumn(columnDefinition.columnName); sbStatement.append("coltype = ").append(columnDefinition.getColumnType()).append(", "); sbStatement.append("collength = "); int colLength = columnDefinition.getColumnLength(); if (colLength > -1) { sbStatement.append(colLength).append(", "); } else { sbStatement.append("null, "); } sbStatement.append("colscale = "); int colScale = columnDefinition.getColumnScale(); if (colScale > -1) { sbStatement.append(colScale).append(", "); } else { sbStatement.append("null, "); } sbStatement.append("colprecision = "); int colPrecision = columnDefinition.getColumnPrecision(); if (colPrecision > -1) { sbStatement.append(colPrecision).append(", "); } else { sbStatement.append("null, "); } sbStatement.append("isnullable = ").append(columnDefinition.isnullable).append(", "); sbStatement.append("isserial = ").append(columnDefinition.isSerial() ? "1" : "0").append(", "); sbStatement.append("defaultexpr = "); String defaultExpr = columnDefinition.getDefaultValue(); if (defaultExpr == null) { sbStatement.append("null, "); } else { sbStatement.append("'").append(defaultExpr.replaceAll("'", "''")).append("', "); } sbStatement .append("nativecoldef = '") .append(columnDefinition.rebuildString().replaceAll("'", "''")) .append("' "); sbStatement.append("WHERE colid = ").append(aSysCol.getColID()); MetaData.getMetaData().executeUpdate(sbStatement.toString()); }