use of org.jooq.util.ColumnDefinition in project jOOQ by jOOQ.
the class SQLiteTableDefinition method getElements0.
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
int position = 0;
for (Record record : create().fetch("pragma table_info('" + getName() + "')")) {
position++;
String name = record.get("name", String.class);
String dataType = record.get("type", String.class).replaceAll("\\(\\d+(\\s*,\\s*\\d+)?\\)", "");
Number precision = parsePrecision(record.get("type", String.class));
Number scale = parseScale(record.get("type", String.class));
// SQLite identities are primary keys whose tables are mentioned in
// sqlite_sequence
int pk = record.get("pk", int.class);
boolean identity = pk > 0 && existsSqliteSequence() && create().fetchOne("select count(*) from sqlite_sequence where name = ?", getName()).get(0, Boolean.class);
DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), dataType, precision, precision, scale, !record.get("notnull", boolean.class), record.get("dflt_value", String.class));
ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), name, position, type, identity, null);
result.add(column);
}
return result;
}
use of org.jooq.util.ColumnDefinition in project jOOQ by jOOQ.
the class XMLTableDefinition method getElements0.
@Override
protected List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
for (Column column : info.getColumns()) {
if (StringUtils.equals(table.getTableCatalog(), column.getTableCatalog()) && StringUtils.equals(table.getTableSchema(), column.getTableSchema()) && StringUtils.equals(table.getTableName(), column.getTableName())) {
SchemaDefinition schema = getDatabase().getSchema(column.getTableSchema());
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), schema, column.getDataType(), unbox(column.getCharacterMaximumLength()), unbox(column.getNumericPrecision()), unbox(column.getNumericScale()), column.isIsNullable(), column.getColumnDefault());
result.add(new DefaultColumnDefinition(this, column.getColumnName(), unbox(column.getOrdinalPosition()), type, column.getIdentityGeneration() != null, ""));
}
}
return result;
}
Aggregations