public Column getClone() { Column newColumn = new Column(name, type, precision, scale, displaySize); newColumn.copy(this); return newColumn; }
/** * Create a new range with the given start and end expressions. * * @param schema the schema (always the main schema) * @param min the start expression * @param max the end expression * @param noColumns whether this table has no columns */ public RangeTable(Schema schema, Expression min, Expression max, boolean noColumns) { super(schema, NAME); Column[] cols = noColumns ? new Column[0] : new Column[] { new Column("X", Value.LONG) }; this.min = min; this.max = max; setColumns(cols); }
private Column[] createColumns(String... names) { Column[] cols = new Column[names.length]; for (int i = 0; i < names.length; i++) { String nameType = names[i]; int idx = nameType.indexOf(' '); int dataType; String name; if (idx < 0) { dataType = database.getMode().lowerCaseIdentifiers ? Value.STRING_IGNORECASE : Value.STRING; name = nameType; } else { dataType = DataType.getTypeByName(nameType.substring(idx + 1)).type; name = nameType.substring(0, idx); } cols[i] = new Column(name, dataType); } return cols; }
/** * Get the system columns that this table understands. This is used for * compatibility with other databases. The columns are only returned if the * current mode supports system columns. * * @return the system columns */ @Override public Column[] getSystemColumns() { if (!session.getDatabase().getMode().systemColumns) { return null; } Column[] sys = new Column[3]; sys[0] = new Column("oid", Value.INT); sys[0].setTable(table, 0); sys[1] = new Column("ctid", Value.STRING); sys[1].setTable(table, 0); sys[2] = new Column("CTID", Value.STRING); sys[2].setTable(table, 0); return sys; }
SelectListColumnResolver(Select select) { this.select = select; int columnCount = select.getColumnCount(); columns = new Column[columnCount]; expressions = new Expression[columnCount]; ArrayList<Expression> columnList = select.getExpressions(); for (int i = 0; i < columnCount; i++) { Expression expr = columnList.get(i); Column column = new Column(expr.getAlias(), Value.NULL); column.setTable(null, i); columns[i] = column; expressions[i] = expr.getNonAliasExpression(); } }
/** * Extracts expression columns from the given result set. * * @param session the session * @param rs the result set * @return an array of expression columns */ public static Expression[] getExpressionColumns(Session session, ResultSet rs) { try { ResultSetMetaData meta = rs.getMetaData(); int columnCount = meta.getColumnCount(); Expression[] expressions = new Expression[columnCount]; Database db = session == null ? null : session.getDatabase(); for (int i = 0; i < columnCount; i++) { String name = meta.getColumnLabel(i + 1); int type = DataType.getValueTypeFromResultSet(meta, i + 1); int precision = meta.getPrecision(i + 1); int scale = meta.getScale(i + 1); int displaySize = meta.getColumnDisplaySize(i + 1); Column col = new Column(name, type, precision, scale, displaySize); Expression expr = new ExpressionColumn(db, col); expressions[i] = expr; } return expressions; } catch (SQLException e) { throw DbException.convert(e); } }
@Override public Expression[] getExpressionColumns(Session session) { ExpressionColumn[] expr = new ExpressionColumn[list.length]; for (int i = 0; i < list.length; i++) { Expression e = list[i]; Column col = new Column("C" + (i + 1), e.getType(), e.getPrecision(), e.getScale(), e.getDisplaySize()); expr[i] = new ExpressionColumn(session.getDatabase(), col); } return expr; }
scale = dt.defaultScale; displaySize = dt.defaultDisplaySize; column = new Column(columnName, type, prec, scale, displaySize); columns.add(column); scale = Math.max(c.getScale(), scale); displaySize = Math.max(c.getDisplaySize(), displaySize); column = new Column(columnName, type, prec, scale, displaySize); columns.set(i, column); row.add(expr); Column c = columns.get(i); if (c.getType() == Value.UNKNOWN) { c = new Column(c.getName(), Value.STRING, 0, 0, 0); columns.set(i, c);
int scale = Math.max(l.getScale(), r.getScale()); int displaySize = Math.max(l.getDisplaySize(), r.getDisplaySize()); Column col = new Column(l.getAlias(), type, prec, scale, displaySize); Expression e = new ExpressionColumn(session.getDatabase(), col); expressions.add(e);
/** * Extracts expression columns from ValueArray * * @param session the current session * @param value the value to extract columns from * @return array of expression columns */ static Expression[] getExpressionColumns(Session session, ValueArray value) { Value[] list = value.getList(); ExpressionColumn[] expr = new ExpressionColumn[list.length]; for (int i = 0, len = list.length; i < len; i++) { Value v = list[i]; Column col = new Column("C" + (i + 1), v.getType(), v.getPrecision(), v.getScale(), v.getDisplaySize()); expr[i] = new ExpressionColumn(session.getDatabase(), col); } return expr; }
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); } }
Column[] cols = new Column[columnCount]; for (int i = 0; i < columnCount; i++) { cols[i] = new Column(meta.getColumnName(i + 1), DataType.getValueTypeFromResultSet(meta, i + 1), meta.getPrecision(i + 1),
@Override public ResultInterface query(int maxrows) { Column column = new Column("PLAN", Value.STRING); Database db = session.getDatabase(); ExpressionColumn expr = new ExpressionColumn(db, column); Expression[] expressions = {expr}; result = new LocalResult(session, expressions, 1); if (maxrows >= 0) { String plan; if (executeCommand) { if (command.isQuery()) { command.query(maxrows); } else { command.update(); } plan = command.explainPlan(); } else { plan = command.explainPlan(); } add(plan); } result.done(); return result; }
private Expression readConcat() { Expression r = readSum(); while (true) { if (readIf("||")) { r = new Operation(Operation.CONCAT, r, readSum()); } else if (readIf("~")) { if (readIf("*")) { Function function = Function.getFunction(database, "CAST"); function.setDataType(new Column("X", Value.STRING_IGNORECASE)); function.setParameter(0, r); r = function; } r = new CompareLike(database, r, readSum(), null, true); } else if (readIf("!~")) { if (readIf("*")) { Function function = Function.getFunction(database, "CAST"); function.setDataType(new Column("X", Value.STRING_IGNORECASE)); function.setParameter(0, r); r = function; } r = new ConditionNot(new CompareLike(database, r, readSum(), null, true)); } else { return r; } } }
String[] cols = parseColumnList(); for (String c : cols) { columns.add(new Column(c, Value.STRING));
")"); Column column = new Column(columnName, type, precision, scale, displaySize); column.setComment(comment);