Search in sources :

Example 1 with DataType

use of com.wplatform.ddal.value.DataType in project jdbc-shards by wplatform.

the class CreateTableExecutor method generateColumnsFromQuery.

private void generateColumnsFromQuery() {
    int columnCount = prepared.getQuery().getColumnCount();
    ArrayList<Expression> expressions = prepared.getQuery().getExpressions();
    for (int i = 0; i < columnCount; i++) {
        Expression expr = expressions.get(i);
        int type = expr.getType();
        String name = expr.getAlias();
        long precision = expr.getPrecision();
        int displaySize = expr.getDisplaySize();
        DataType dt = DataType.getDataType(type);
        if (precision > 0 && (dt.defaultPrecision == 0 || (dt.defaultPrecision > precision && dt.defaultPrecision < Byte.MAX_VALUE))) {
            // dont' set precision to MAX_VALUE if this is the default
            precision = dt.defaultPrecision;
        }
        int scale = expr.getScale();
        if (scale > 0 && (dt.defaultScale == 0 || (dt.defaultScale > scale && dt.defaultScale < precision))) {
            scale = dt.defaultScale;
        }
        if (scale > precision) {
            precision = scale;
        }
        Column col = new Column(name, type, precision, scale, displaySize);
        prepared.addColumn(col);
    }
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) IndexColumn(com.wplatform.ddal.dbobject.table.IndexColumn) Column(com.wplatform.ddal.dbobject.table.Column) DataType(com.wplatform.ddal.value.DataType) AlterTableAddConstraint(com.wplatform.ddal.command.ddl.AlterTableAddConstraint)

Aggregations

AlterTableAddConstraint (com.wplatform.ddal.command.ddl.AlterTableAddConstraint)1 Expression (com.wplatform.ddal.command.expression.Expression)1 Column (com.wplatform.ddal.dbobject.table.Column)1 IndexColumn (com.wplatform.ddal.dbobject.table.IndexColumn)1 DataType (com.wplatform.ddal.value.DataType)1