DataType type = c.getType();
int precision = -1; int type = column.getType().getSQLType(); switch ( type ) { case java.sql.Types.CHAR:
private boolean isRichText(Column c) throws IOException { if (c == null) { return false; } PropertyMap m = c.getProperties(); if (m == null) { return false; } if (c.getType() == null || ! c.getType().equals(DataType.MEMO)) { return false; } Object b = m.getValue(TEXT_FORMAT_KEY); if (b instanceof Byte) { if (((Byte)b).byteValue() == RICH_TEXT_FORMAT) { return true; } } return false; }
public static boolean isMultiValueColumn(Table typeObjTable) { // if we found a single value of a "simple" type, then we are dealing with // a multi-value column List<? extends Column> typeCols = typeObjTable.getColumns(); return ((typeCols.size() == 1) && MULTI_VALUE_TYPES.contains(typeCols.get(0).getType())); }
public VersionHistoryColumnInfoImpl(Column column, int complexId, Table typeObjTable, Table flatTable) throws IOException { super(column, complexId, typeObjTable, flatTable); Column valueCol = null; Column modifiedCol = null; for(Column col : getTypeColumns()) { switch(col.getType()) { case SHORT_DATE_TIME: modifiedCol = col; break; case MEMO: valueCol = col; break; default: // ignore } } _valueCol = valueCol; _modifiedCol = modifiedCol; }
public static boolean isVersionHistoryColumn(Table typeObjTable) { // version history data has these columns <value>(MEMO), // <modified>(SHORT_DATE_TIME) List<? extends Column> typeCols = typeObjTable.getColumns(); if(typeCols.size() < 2) { return false; } int numMemo = 0; int numDate = 0; for(Column col : typeCols) { switch(col.getType()) { case SHORT_DATE_TIME: ++numDate; break; case MEMO: ++numMemo; break; default: // ignore } } // be flexible, allow for extra columns... return((numMemo >= 1) && (numDate >= 1)); } }
private boolean isRichText(Column c) throws IOException { if (c == null) { return false; } PropertyMap m = c.getProperties(); if (m == null) { return false; } if (c.getType() == null || ! c.getType().equals(DataType.MEMO)) { return false; } Object b = m.getValue(TEXT_FORMAT_KEY); if (b instanceof Byte) { if (((Byte)b).byteValue() == RICH_TEXT_FORMAT) { return true; } } return false; }
private boolean isRichText(Column c) throws IOException { if (c == null) { return false; } PropertyMap m = c.getProperties(); if (m == null) { return false; } if (c.getType() == null || ! c.getType().equals(DataType.MEMO)) { return false; } Object b = m.getValue(TEXT_FORMAT_KEY); if (b instanceof Byte) { if (((Byte)b).byteValue() == RICH_TEXT_FORMAT) { return true; } } return false; }
public String defaultValue4SQL(Column cl) throws SQLException, IOException { PropertyMap pm = cl.getProperties(); Object defaulT = pm.getValue(PropertyMap.DEFAULT_VALUE_PROP); if (defaulT == null) { return null; } return this.tablesLoader.defaultValue4SQL(defaulT, cl.getType()); }
@Override public Object handleRowError(Column cl, byte[] bt, Location location, Exception ex) throws IOException { if (cl.getType().isTextual()) { Logger.logParametricWarning(Messages.INVALID_CHARACTER_SEQUENCE, cl.getTable().getName(), cl.getName(), new String(bt)); } throw new IOException(ex.getMessage()); } });
static void schema(File inputFile) throws IOException{ Database db = DatabaseBuilder.open(inputFile); try{ for(String tableName : db.getTableNames()){ Table table = db.getTable(tableName); System.out.println(String.format("CREATE TABLE %s (", tableName)); for(Column col : table.getColumns()){ System.out.println(String.format(" %s %s,", col.getName(), col.getType())); } System.out.println(")"); } }finally{ db.close(); } }
private static boolean hasAutoNumberColumn(Table t) { List<? extends Column> lc = t.getColumns(); for (Column cl : lc) { if (cl.isAutoNumber() || DataType.BOOLEAN.equals(cl.getType())) { return true; } } return false; }
@Override public boolean matches(Table table, String columnName, Object value1, Object value2) { if(!table.getColumn(columnName).getType().isTextual()) { // use simple equality return SimpleColumnMatcher.INSTANCE.matches(table, columnName, value1, value2); } // convert both values to Strings and compare case-insensitively try { CharSequence cs1 = ColumnImpl.toCharSequence(value1); CharSequence cs2 = ColumnImpl.toCharSequence(value2); return((cs1 == cs2) || ((cs1 != null) && (cs2 != null) && cs1.toString().equalsIgnoreCase(cs2.toString()))); } catch(IOException e) { throw new RuntimeIOException("Could not read column " + columnName + " value", e); } }
public BlobAction(Table _table, Object[] newValues) throws SQLException { this.table = _table; if (!BlobKey.hasPrimaryKey(_table)) { return; } Index pk = _table.getPrimaryKeyIndex(); HashSet<String> hsKey = new HashSet<String>(); for (Index.Column icl : pk.getColumns()) { hsKey.add(icl.getName()); } HashSet<String> hsBlob = new HashSet<String>(); int i = 0; HashMap<String, Object> keyMap = new HashMap<String, Object>(); for (Column cl : _table.getColumns()) { if (cl.getType().equals(DataType.OLE) && newValues[i] != null) { containsBlob = true; hsBlob.add(cl.getName()); } if (hsKey.contains(cl.getName())) { keyMap.put(cl.getName(), newValues[i]); } ++i; } for (String cln : hsBlob) { keys.add(new BlobKey(keyMap, table.getName(), cln)); } }
@Override public boolean matches(Table table, String columnName, Object value1, Object value2) { if(equals(value1, value2)) { return true; } if((value1 != null) && (value2 != null) && (value1.getClass() != value2.getClass())) { // the values aren't the same type, try coercing them to "internal" // values and try again DataType dataType = table.getColumn(columnName).getType(); try { DatabaseImpl db = (DatabaseImpl)table.getDatabase(); Object internalV1 = ColumnImpl.toInternalValue(dataType, value1, db); Object internalV2 = ColumnImpl.toInternalValue(dataType, value2, db); return equals(internalV1, internalV2); } catch(IOException e) { // ignored, just go with the original result } } return false; }
if (default4SQL != null || cl.getType().equals(DataType.BOOLEAN)) { try { defObj = default4SQL == null && cl.getType().equals(DataType.BOOLEAN) ? Boolean.FALSE : defObj; ps = conn.getHSQLDBConnection().prepareStatement( SQLConverter.convertSQL("UPDATE " + tableName + " SET " + columnName + "=" + "?").getSql());
@Override protected Schema getMainSchema() throws MetaModelException { Schema schema = new Schema(_file.getName()); Database db = getDatabase(); for (com.healthmarketscience.jackcess.Table mdbTable : db) { Table table = new Table(mdbTable.getName(), TableType.TABLE, schema); try { int i = 0; for (com.healthmarketscience.jackcess.Column mdbColumn : mdbTable .getColumns()) { ColumnType columnType = ColumnType .convertColumnType(mdbColumn.getSQLType()); Column column = new Column(mdbColumn.getName(), columnType, table, i, null); column.setColumnSize((int) mdbColumn.getLength()); column.setNativeType(mdbColumn.getType().name()); table.addColumn(column); i++; } schema.addTable(table); } catch (Exception e) { throw new MetaModelException(e); } } return schema; }
private String getHsqldbColumnType(Column cl) throws IOException { String htype; DataType dtyp = cl.getType(); DataType rtyp = getReturnType(cl); boolean calcType = false; if (rtyp != null) { dtyp = rtyp; calcType = true; } if (dtyp.equals(DataType.TEXT)) { int ln = ff1997 ? cl.getLength() : cl.getLengthInUnits(); htype = "VARCHAR(" + ln + ")"; } else if (dtyp.equals(DataType.NUMERIC) && (cl.getScale() > 0 || calcType)) { if (calcType) { htype = "NUMERIC(100 ,4)"; } else { htype = "NUMERIC(" + (cl.getPrecision() > 0 ? cl.getPrecision() : 100) + "," + cl.getScale() + ")"; } } else if (dtyp.equals(DataType.FLOAT) && calcType) { htype = "NUMERIC(" + (cl.getPrecision() > 0 ? cl.getPrecision() : 100) + "," + 4 + ")"; } else { htype = TypesMap.map2hsqldb(dtyp); } return htype; }
/** * Sets all attributes except name from the given Column template (including * all column properties except GUID). */ public ColumnBuilder setFromColumn(Column template) throws IOException { DataType type = template.getType(); setType(type); setLength(template.getLength()); setAutoNumber(template.isAutoNumber()); if(type.getHasScalePrecision()) { setScale(template.getScale()); setPrecision(template.getPrecision()); } setCalculated(template.isCalculated()); setCompressedUnicode(template.isCompressedUnicode()); setHyperlink(template.isHyperlink()); if(template instanceof ColumnImpl) { setTextSortOrder(((ColumnImpl)template).getTextSortOrder()); } PropertyMap colProps = template.getProperties(); for(PropertyMap.Property colProp : colProps) { // copy everything but guid if(!PropertyMap.GUID_PROP.equalsIgnoreCase(colProp.getName())) { setProperty(colProp.getName(), colProp); } } return this; }