提交 41d238b1 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add TypeInfo and use it in Column

上级 734f8029
......@@ -226,6 +226,7 @@ import org.h2.value.DataType;
import org.h2.value.ExtTypeInfo;
import org.h2.value.ExtTypeInfoEnum;
import org.h2.value.ExtTypeInfoGeometry;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueBoolean;
......@@ -5355,13 +5356,14 @@ public class Parser {
Domain domain = database.findDomain(original);
if (domain != null) {
templateColumn = domain.getColumn();
dataType = DataType.getDataType(templateColumn.getType());
TypeInfo type = templateColumn.getType();
dataType = DataType.getDataType(type.getValueType());
comment = templateColumn.getComment();
original = forTable ? domain.getSQL() : templateColumn.getOriginalSQL();
precision = templateColumn.getPrecision();
displaySize = templateColumn.getDisplaySize();
scale = templateColumn.getScale();
extTypeInfo = templateColumn.getExtTypeInfo();
precision = type.getPrecision();
displaySize = type.getDisplaySize();
scale = type.getScale();
extTypeInfo = type.getExtTypeInfo();
} else {
Mode mode = database.getMode();
dataType = DataType.getTypeByName(original, mode);
......@@ -5863,10 +5865,11 @@ public class Parser {
.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
}
Column c = columns.get(i);
type = Value.getHigherOrder(c.getType(), type);
prec = Math.max(c.getPrecision(), prec);
scale = Math.max(c.getScale(), scale);
displaySize = Math.max(c.getDisplaySize(), displaySize);
TypeInfo t = c.getType();
type = Value.getHigherOrder(t.getValueType(), type);
prec = Math.max(t.getPrecision(), prec);
scale = Math.max(t.getScale(), scale);
displaySize = Math.max(t.getDisplaySize(), displaySize);
column = new Column(columnName, type, prec, scale, displaySize);
columns.set(i, column);
row.add(expr);
......@@ -5883,7 +5886,7 @@ public class Parser {
}
for (int i = 0; i < columnCount; i++) {
Column c = columns.get(i);
if (c.getType() == Value.UNKNOWN) {
if (c.getType().getValueType() == Value.UNKNOWN) {
c = new Column(c.getName(), Value.STRING, 0, 0, 0);
columns.set(i, c);
}
......
......@@ -105,7 +105,7 @@ public class Analyze extends DefineCommand {
StatementBuilder buff = new StatementBuilder("SELECT ");
for (Column col : columns) {
buff.appendExceptFirst(", ");
if (DataType.isLargeObject(col.getType())) {
if (DataType.isLargeObject(col.getType().getValueType())) {
// can not index LOB columns, so calculating
// the selectivity is not required
buff.append("MAX(NULL)");
......
......@@ -202,7 +202,7 @@ public class CreateTable extends CommandWithColumns {
int t = dt.type;
if (DataType.isExtInfoType(t)) {
if (expr instanceof ExpressionColumn) {
extTypeInfo = ((ExpressionColumn) expr).getColumn().getExtTypeInfo();
extTypeInfo = ((ExpressionColumn) expr).getColumn().getType().getExtTypeInfo();
} else if (t == Value.ENUM) {
/*
* Only columns of tables may be enumerated.
......
......@@ -216,7 +216,7 @@ public class ExpressionColumn extends Expression {
}
}
if (value != ValueNull.INSTANCE) {
ExtTypeInfo extTypeInfo = column.getExtTypeInfo();
ExtTypeInfo extTypeInfo = column.getType().getExtTypeInfo();
if (extTypeInfo != null) {
return extTypeInfo.cast(value);
}
......@@ -226,7 +226,7 @@ public class ExpressionColumn extends Expression {
@Override
public int getType() {
return column == null ? Value.UNKNOWN : column.getType();
return column == null ? Value.UNKNOWN : column.getType().getValueType();
}
@Override
......@@ -239,17 +239,17 @@ public class ExpressionColumn extends Expression {
@Override
public int getScale() {
return column.getScale();
return column.getType().getScale();
}
@Override
public long getPrecision() {
return column.getPrecision();
return column.getType().getPrecision();
}
@Override
public int getDisplaySize() {
return column.getDisplaySize();
return column.getType().getDisplaySize();
}
public String getOriginalColumnName() {
......@@ -360,7 +360,7 @@ public class ExpressionColumn extends Expression {
@Override
public void createIndexConditions(Session session, TableFilter filter) {
TableFilter tf = getTableFilter();
if (filter == tf && column.getType() == Value.BOOLEAN) {
if (filter == tf && column.getType().getValueType() == Value.BOOLEAN) {
IndexCondition cond = IndexCondition.get(
Comparison.EQUAL, this, ValueExpression.get(
ValueBoolean.TRUE));
......
......@@ -66,7 +66,7 @@ public class Parameter extends Expression implements ParameterInterface {
return value.getType();
}
if (column != null) {
return column.getType();
return column.getType().getValueType();
}
return Value.UNKNOWN;
}
......@@ -114,7 +114,7 @@ public class Parameter extends Expression implements ParameterInterface {
return value.getScale();
}
if (column != null) {
return column.getScale();
return column.getType().getScale();
}
return 0;
}
......@@ -125,7 +125,7 @@ public class Parameter extends Expression implements ParameterInterface {
return value.getPrecision();
}
if (column != null) {
return column.getPrecision();
return column.getType().getPrecision();
}
return 0;
}
......@@ -136,7 +136,7 @@ public class Parameter extends Expression implements ParameterInterface {
return value.getDisplaySize();
}
if (column != null) {
return column.getDisplaySize();
return column.getType().getDisplaySize();
}
return 0;
}
......
......@@ -38,7 +38,7 @@ class AggregateDataEnvelope extends AggregateData {
if (on instanceof ExpressionColumn) {
ExpressionColumn col = (ExpressionColumn) on;
Column column = col.getColumn();
if (column.getType() == Value.GEOMETRY) {
if (column.getType().getValueType() == Value.GEOMETRY) {
TableFilter filter = col.getTableFilter();
if (filter != null) {
ArrayList<Index> indexes = filter.getTable().getIndexes();
......
......@@ -206,7 +206,7 @@ public class CompareLike extends Condition {
// can't use an index
return;
}
if (!DataType.isStringType(l.getColumn().getType())) {
if (!DataType.isStringType(l.getColumn().getType().getValueType())) {
// column is not a varchar - can't use the index
return;
}
......
......@@ -235,7 +235,7 @@ public class Comparison extends Condition {
Column column = ((ExpressionColumn) left).getColumn();
right = ValueExpression.get(r.convertTo(resType,
MathUtils.convertLongToInt(left.getPrecision()),
session.getDatabase().getMode(), column, column.getExtTypeInfo()));
session.getDatabase().getMode(), column, column.getType().getExtTypeInfo()));
}
} else if (right instanceof Parameter) {
((Parameter) right).setColumn(
......
......@@ -57,7 +57,7 @@ public class ConditionInConstantSet extends Condition {
type = left.getType();
Mode mode = database.getMode();
if (type == Value.ENUM) {
extTypeInfo = ((ExpressionColumn) left).getColumn().getExtTypeInfo();
extTypeInfo = ((ExpressionColumn) left).getColumn().getType().getExtTypeInfo();
for (Expression expression : valueList) {
add(extTypeInfo.cast(expression.getValue(session)));
}
......
......@@ -62,6 +62,7 @@ import org.h2.util.StringUtils;
import org.h2.util.Utils;
import org.h2.value.DataType;
import org.h2.value.ExtTypeInfo;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueBoolean;
......@@ -2293,11 +2294,12 @@ public class Function extends Expression implements FunctionCall {
}
public void setDataType(Column col) {
dataType = col.getType();
precision = col.getPrecision();
displaySize = col.getDisplaySize();
scale = col.getScale();
extTypeInfo = col.getExtTypeInfo();
TypeInfo type = col.getType();
dataType = type.getValueType();
precision = type.getPrecision();
displaySize = type.getDisplaySize();
scale = type.getScale();
extTypeInfo = type.getExtTypeInfo();
}
@Override
......
......@@ -125,8 +125,8 @@ public class TableFunction extends Function {
Column c = columns[j];
v = l[row];
if (!unnest) {
v = c.convert(v).convertPrecision(c.getPrecision(), false)
.convertScale(true, c.getScale());
v = c.convert(v).convertPrecision(c.getType().getPrecision(), false)
.convertScale(true, c.getType().getScale());
}
}
r[j] = v;
......
......@@ -73,7 +73,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
*/
protected static void checkIndexColumnTypes(IndexColumn[] columns) {
for (IndexColumn c : columns) {
if (DataType.isLargeObject(c.column.getType())) {
if (DataType.isLargeObject(c.column.getType().getValueType())) {
throw DbException.getUnsupportedException(
"Index on BLOB or CLOB column: " + c.column.getCreateSQL());
}
......
......@@ -77,7 +77,7 @@ public class HashIndex extends BaseIndex {
* case we need to convert, otherwise the ValueHashMap will not find the
* result.
*/
v = v.convertTo(tableData.getColumn(indexColumn).getType(), database.getMode());
v = v.convertTo(tableData.getColumn(indexColumn).getType().getValueType(), database.getMode());
Row result;
Long pos = rows.get(v);
if (pos == null) {
......
......@@ -64,7 +64,7 @@ public class LinkedCursor implements Cursor {
current = tableLink.getTemplateRow();
for (int i = 0; i < current.getColumnCount(); i++) {
Column col = tableLink.getColumn(i);
Value v = DataType.readValue(session, rs, i + 1, col.getType());
Value v = DataType.readValue(session, rs, i + 1, col.getType().getValueType());
current.setValue(i, v);
}
return true;
......
......@@ -22,6 +22,7 @@ import org.h2.table.TableFilter;
import org.h2.table.TableLink;
import org.h2.util.StatementBuilder;
import org.h2.util.Utils;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueNull;
......@@ -131,12 +132,13 @@ public class LinkedIndex extends BaseIndex {
}
private void addParameter(StatementBuilder buff, Column col) {
if (col.getType() == Value.STRING_FIXED && link.isOracle()) {
TypeInfo type = col.getType();
if (type.getValueType() == Value.STRING_FIXED && link.isOracle()) {
// workaround for Oracle
// create table test(id int primary key, name char(15));
// insert into test values(1, 'Hello')
// select * from test where name = ? -- where ? = "Hello" > no rows
buff.append("CAST(? AS CHAR(").append(col.getPrecision()).append("))");
buff.append("CAST(? AS CHAR(").append(type.getPrecision()).append("))");
} else {
buff.append('?');
}
......
......@@ -101,7 +101,7 @@ public class NonUniqueHashIndex extends BaseIndex {
* case we need to convert, otherwise the ValueHashMap will not find the
* result.
*/
v = v.convertTo(tableData.getColumn(indexColumn).getType(), database.getMode());
v = v.convertTo(tableData.getColumn(indexColumn).getType().getValueType(), database.getMode());
ArrayList<Long> positions = rows.get(v);
return new NonUniqueHashCursor(session, tableData, positions);
}
......
......@@ -87,7 +87,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
}
this.needRebuild = create;
if (!database.isStarting()) {
if (columns[0].column.getType() != Value.GEOMETRY) {
if (columns[0].column.getType().getValueType() != Value.GEOMETRY) {
throw DbException.getUnsupportedException(
"spatial index on non-geometry column, " +
columns[0].column.getCreateSQL());
......
......@@ -30,6 +30,7 @@ import org.h2.table.Column;
import org.h2.table.IndexColumn;
import org.h2.table.TableFilter;
import org.h2.value.CompareMode;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueLong;
......@@ -288,7 +289,8 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
int idx = c.getColumnId();
Value v = r.getValue(idx);
if (v != null) {
array[i] = v.convertTo(c.getType(), -1, database.getMode(), null, c.getExtTypeInfo());
TypeInfo type = c.getType();
array[i] = v.convertTo(type.getValueType(), -1, database.getMode(), null, type.getExtTypeInfo());
}
}
array[keyColumns - 1] = key != null ? key : ValueLong.get(r.getKey());
......
......@@ -88,7 +88,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
throw DbException.getUnsupportedException(
"Nulls last is not supported");
}
if (col.column.getType() != Value.GEOMETRY) {
if (col.column.getType().getValueType() != Value.GEOMETRY) {
throw DbException.getUnsupportedException(
"Spatial index on non-geometry column, "
+ col.column.getCreateSQL());
......
......@@ -136,7 +136,7 @@ public class MVTable extends TableBase {
this.isHidden = data.isHidden;
boolean b = false;
for (Column col : getColumns()) {
if (DataType.isLargeObject(col.getType())) {
if (DataType.isLargeObject(col.getType().getValueType())) {
b = true;
break;
}
......
......@@ -28,6 +28,7 @@ import org.h2.util.MathUtils;
import org.h2.util.StringUtils;
import org.h2.value.DataType;
import org.h2.value.ExtTypeInfo;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueInt;
import org.h2.value.ValueLong;
......@@ -64,11 +65,7 @@ public class Column {
public static final int NULLABLE_UNKNOWN =
ResultSetMetaData.columnNullableUnknown;
private final int type;
private long precision;
private int scale;
private ExtTypeInfo extTypeInfo;
private int displaySize;
private final TypeInfo type;
private Table table;
private String name;
private int columnId;
......@@ -90,28 +87,28 @@ public class Column {
private boolean visible = true;
private Domain domain;
public Column(String name, int type) {
this(name, type, -1, -1, -1, null);
public Column(String name, int valueType) {
this(name, valueType, -1, -1, -1, null);
}
public Column(String name, int type, long precision, int scale,
int displaySize) {
this(name, type, precision, scale, displaySize, null);
public Column(String name, int valueType, long precision, int scale, int displaySize) {
this(name, valueType, precision, scale, displaySize, null);
}
public Column(String name, int type, long precision, int scale, int displaySize, ExtTypeInfo extTypeInfo) {
public Column(String name, int valueType, long precision, int scale, int displaySize, ExtTypeInfo extTypeInfo) {
this.name = name;
this.type = type;
if (precision == -1 && scale == -1 && displaySize == -1 && type != Value.UNKNOWN) {
DataType dt = DataType.getDataType(type);
if (precision == -1 && scale == -1 && displaySize == -1 && valueType != Value.UNKNOWN) {
DataType dt = DataType.getDataType(valueType);
precision = dt.defaultPrecision;
scale = dt.defaultScale;
displaySize = dt.defaultDisplaySize;
}
this.precision = precision;
this.scale = scale;
this.displaySize = displaySize;
this.extTypeInfo = extTypeInfo;
this.type = new TypeInfo(valueType, precision, scale, displaySize, extTypeInfo);
}
public Column(String name, TypeInfo type) {
this.name = name;
this.type = type;
}
@Override
......@@ -141,7 +138,7 @@ public class Column {
}
public Column getClone() {
Column newColumn = new Column(name, type, precision, scale, displaySize, extTypeInfo);
Column newColumn = new Column(name, type);
newColumn.copy(this);
return newColumn;
}
......@@ -167,7 +164,8 @@ public class Column {
*/
public Value convert(Value v, Mode mode) {
try {
return v.convertTo(type, MathUtils.convertLongToInt(precision), mode, this, extTypeInfo);
return v.convertTo(type.getValueType(), MathUtils.convertLongToInt(type.getPrecision()), mode, this,
type.getExtTypeInfo());
} catch (DbException e) {
if (e.getErrorCode() == ErrorCode.DATA_CONVERSION_ERROR_1) {
String target = (table == null ? "" : table.getName() + ": ") +
......@@ -271,30 +269,14 @@ public class Column {
return name;
}
public int getType() {
public TypeInfo getType() {
return type;
}
public long getPrecision() {
return precision;
}
public int getDisplaySize() {
return displaySize;
}
public int getScale() {
return scale;
}
public void setNullable(boolean b) {
nullable = b;
}
public ExtTypeInfo getExtTypeInfo() {
return extTypeInfo;
}
public boolean getVisible() {
return visible;
}
......@@ -350,9 +332,10 @@ public class Column {
}
if (value == ValueNull.INSTANCE && !nullable) {
if (mode.convertInsertNullToZero) {
DataType dt = DataType.getDataType(type);
int t = type.getValueType();
DataType dt = DataType.getDataType(t);
if (dt.decimal) {
value = ValueInt.get(0).convertTo(type);
value = ValueInt.get(0).convertTo(t);
} else if (dt.type == Value.TIMESTAMP) {
value = session.getCurrentCommandStart().convertTo(Value.TIMESTAMP);
} else if (dt.type == Value.TIMESTAMP_TZ) {
......@@ -362,7 +345,7 @@ public class Column {
} else if (dt.type == Value.DATE) {
value = session.getCurrentCommandStart().convertTo(Value.DATE);
} else {
value = ValueString.get("").convertTo(type);
value = ValueString.get("").convertTo(t);
}
} else {
throw DbException.get(ErrorCode.NULL_NOT_ALLOWED, name);
......@@ -382,7 +365,8 @@ public class Column {
checkConstraint.getSQL());
}
}
value = value.convertScale(mode.convertOnlyToSmallerScale, scale);
value = value.convertScale(mode.convertOnlyToSmallerScale, type.getScale());
long precision = type.getPrecision();
if (precision > 0) {
if (!value.checkPrecision(precision)) {
String s = value.getTraceSQL();
......@@ -393,8 +377,8 @@ public class Column {
getCreateSQL(), s + " (" + value.getPrecision() + ")");
}
}
if (value != ValueNull.INSTANCE && DataType.isExtInfoType(type) && extTypeInfo != null) {
value = extTypeInfo.cast(value);
if (value != ValueNull.INSTANCE && DataType.isExtInfoType(type.getValueType()) && type.getExtTypeInfo() != null) {
value = type.getExtTypeInfo().cast(value);
}
updateSequenceIfRequired(session, value);
return value;
......@@ -493,44 +477,7 @@ public class Column {
if (originalSQL != null) {
buff.append(originalSQL);
} else {
DataType dataType = DataType.getDataType(type);
if (type == Value.TIMESTAMP_TZ) {
buff.append("TIMESTAMP");
} else {
buff.append(dataType.name);
}
switch (type) {
case Value.DECIMAL:
buff.append('(').append(precision).append(", ").append(scale).append(')');
break;
case Value.GEOMETRY:
if (extTypeInfo == null) {
break;
}
//$FALL-THROUGH$
case Value.ENUM:
buff.append(extTypeInfo.getCreateSQL());
break;
case Value.BYTES:
case Value.STRING:
case Value.STRING_IGNORECASE:
case Value.STRING_FIXED:
if (precision < Integer.MAX_VALUE) {
buff.append('(').append(precision).append(')');
}
break;
case Value.TIME:
case Value.TIMESTAMP:
case Value.TIMESTAMP_TZ:
if (scale != dataType.defaultScale) {
buff.append('(').append(scale).append(')');
}
if (type == Value.TIMESTAMP_TZ) {
buff.append(" WITH TIME ZONE");
}
break;
default:
}
type.getSQL(buff);
}
if (!visible) {
......@@ -729,11 +676,11 @@ public class Column {
}
int getPrecisionAsInt() {
return MathUtils.convertLongToInt(precision);
return MathUtils.convertLongToInt(type.getPrecision());
}
DataType getDataType() {
return DataType.getDataType(type);
return DataType.getDataType(type.getValueType());
}
/**
......@@ -803,10 +750,10 @@ public class Column {
if (type != newColumn.type) {
return false;
}
if (precision > newColumn.precision) {
if (type.getPrecision() > newColumn.type.getPrecision()) {
return false;
}
if (scale != newColumn.scale) {
if (type.getScale() != newColumn.type.getScale()) {
return false;
}
if (nullable && !newColumn.nullable) {
......@@ -836,7 +783,7 @@ public class Column {
if (onUpdateExpression != null || newColumn.onUpdateExpression != null) {
return false;
}
if (!Objects.equals(extTypeInfo, newColumn.extTypeInfo)) {
if (!Objects.equals(type.getExtTypeInfo(), newColumn.type.getExtTypeInfo())) {
return false;
}
return true;
......@@ -850,11 +797,7 @@ public class Column {
public void copy(Column source) {
checkConstraint = source.checkConstraint;
checkConstraintSQL = source.checkConstraintSQL;
displaySize = source.displaySize;
name = source.name;
precision = source.precision;
extTypeInfo = source.extTypeInfo;
scale = source.scale;
// table is not set
// columnId is not set
nullable = source.nullable;
......
......@@ -849,7 +849,7 @@ public class MetaTable extends Table {
Domain domain = c.getDomain();
DataType dataType = c.getDataType();
ValueInt precision = ValueInt.get(c.getPrecisionAsInt());
ValueInt scale = ValueInt.get(c.getScale());
ValueInt scale = ValueInt.get(c.getType().getScale());
Sequence sequence = c.getSequence();
boolean hasDateTimePrecision;
int type = dataType.type;
......@@ -1792,7 +1792,7 @@ public class MetaTable extends Table {
// PRECISION
ValueInt.get(col.getPrecisionAsInt()),
// SCALE
ValueInt.get(col.getScale()),
ValueInt.get(col.getType().getScale()),
// TYPE_NAME
col.getDataType().name,
// SELECTIVITY INT
......
......@@ -78,7 +78,7 @@ public class RegularTable extends TableBase {
this.isHidden = data.isHidden;
boolean b = false;
for (Column col : getColumns()) {
if (DataType.isLargeObject(col.getType())) {
if (DataType.isLargeObject(col.getType().getValueType())) {
b = true;
break;
}
......
......@@ -454,7 +454,7 @@ public abstract class Table extends SchemaObjectBase {
}
for (int i = 0; i < columns.length; i++) {
Column col = columns[i];
int dataType = col.getType();
int dataType = col.getType().getValueType();
if (dataType == Value.UNKNOWN) {
throw DbException.get(
ErrorCode.UNKNOWN_DATA_TYPE_1, col.getSQL());
......
......@@ -51,7 +51,7 @@ public abstract class TableBase extends Table {
if (first.sortType != SortOrder.ASCENDING) {
return SearchRow.ROWID_INDEX;
}
switch (first.column.getType()) {
switch (first.column.getType().getValueType()) {
case Value.BYTE:
case Value.SHORT:
case Value.INT:
......
......@@ -184,7 +184,7 @@ public class TableView extends Table {
int type = Value.UNKNOWN;
if (columnTemplates != null && columnTemplates.length > i) {
name = columnTemplates[i].getName();
type = columnTemplates[i].getType();
type = columnTemplates[i].getType().getValueType();
}
if (name == null) {
name = expr.getAlias();
......@@ -199,7 +199,7 @@ public class TableView extends Table {
ExtTypeInfo extTypeInfo = null;
if (DataType.isExtInfoType(type)) {
if (expr instanceof ExpressionColumn) {
extTypeInfo = ((ExpressionColumn) expr).getColumn().getExtTypeInfo();
extTypeInfo = ((ExpressionColumn) expr).getColumn().getType().getExtTypeInfo();
}
}
Column col = new Column(name, type, precision, scale, displaySize, extTypeInfo);
......
/*
* Copyright 2004-2019 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.value;
/**
* Data type with parameters.
*/
public class TypeInfo {
private final int valueType;
private final long precision;
private final int scale;
private final int displaySize;
private final ExtTypeInfo extTypeInfo;
/**
* Creates new instance of data type with parameters.
*
* @param valueType
* the value type
* @param precision
* the precision
* @param scale
* the scale
* @param displaySize
* the display size in characters
* @param extTypeInfo
* the extended type information, or null
*/
public TypeInfo(int valueType, long precision, int scale, int displaySize, ExtTypeInfo extTypeInfo) {
this.valueType = valueType;
this.precision = precision;
this.scale = scale;
this.displaySize = displaySize;
this.extTypeInfo = extTypeInfo;
}
/**
* Returns the value type.
*
* @return the value type
*/
public int getValueType() {
return valueType;
}
/**
* Returns the precision.
*
* @return the precision
*/
public long getPrecision() {
return precision;
}
/**
* Returns the scale.
*
* @return the scale
*/
public int getScale() {
return scale;
}
/**
* Returns the display size in characters.
*
* @return the display size
*/
public int getDisplaySize() {
return displaySize;
}
/**
* Returns the extended type information, or null.
*
* @return the extended type information, or null
*/
public ExtTypeInfo getExtTypeInfo() {
return extTypeInfo;
}
/**
* Appends SQL representation of this object to the specified string
* builder.
*
* @param builder
* string builder
* @return the specified string builder
*/
public StringBuilder getSQL(StringBuilder builder) {
DataType dataType = DataType.getDataType(valueType);
if (valueType == Value.TIMESTAMP_TZ) {
builder.append("TIMESTAMP");
} else {
builder.append(dataType.name);
}
switch (valueType) {
case Value.DECIMAL:
builder.append('(').append(precision).append(", ").append(scale).append(')');
break;
case Value.GEOMETRY:
if (extTypeInfo == null) {
break;
}
//$FALL-THROUGH$
case Value.ENUM:
builder.append(extTypeInfo.getCreateSQL());
break;
case Value.BYTES:
case Value.STRING:
case Value.STRING_IGNORECASE:
case Value.STRING_FIXED:
if (precision < Integer.MAX_VALUE) {
builder.append('(').append(precision).append(')');
}
break;
case Value.TIME:
case Value.TIMESTAMP:
case Value.TIMESTAMP_TZ:
if (scale != dataType.defaultScale) {
builder.append('(').append(scale).append(')');
}
if (valueType == Value.TIMESTAMP_TZ) {
builder.append(" WITH TIME ZONE");
}
}
return builder;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论