提交 e2dea134 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use TypeInfo in results

上级 f70ff5e2
...@@ -402,11 +402,8 @@ public abstract class Expression { ...@@ -402,11 +402,8 @@ public abstract class Expression {
Database db = session == null ? null : session.getDatabase(); Database db = session == null ? null : session.getDatabase();
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
String name = result.getColumnName(i); String name = result.getColumnName(i);
int type = result.getColumnType(i); TypeInfo type = result.getColumnType(i);
long precision = result.getColumnPrecision(i); Column col = new Column(name, type);
int scale = result.getColumnScale(i);
int displaySize = result.getDisplaySize(i);
Column col = new Column(name, type, precision, scale, displaySize);
Expression expr = new ExpressionColumn(db, col); Expression expr = new ExpressionColumn(db, col);
expressions[i] = expr; expressions[i] = expr;
} }
......
...@@ -72,7 +72,7 @@ public class ConditionInSelect extends Condition { ...@@ -72,7 +72,7 @@ public class ConditionInSelect extends Condition {
return ValueBoolean.TRUE; return ValueBoolean.TRUE;
} }
} else { } else {
int dataType = rows.getColumnType(0); int dataType = rows.getColumnType(0).getValueType();
if (dataType == Value.NULL) { if (dataType == Value.NULL) {
return ValueBoolean.FALSE; return ValueBoolean.FALSE;
} }
......
...@@ -15,6 +15,7 @@ import org.h2.api.ErrorCode; ...@@ -15,6 +15,7 @@ import org.h2.api.ErrorCode;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.message.TraceObject; import org.h2.message.TraceObject;
import org.h2.result.SimpleResult; import org.h2.result.SimpleResult;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
import org.h2.value.ValueLong; import org.h2.value.ValueLong;
...@@ -257,9 +258,9 @@ public class JdbcArray extends TraceObject implements Array { ...@@ -257,9 +258,9 @@ public class JdbcArray extends TraceObject implements Array {
private ResultSet getResultSetImpl(long index, int count) { private ResultSet getResultSetImpl(long index, int count) {
int id = getNextId(TraceObject.RESULT_SET); int id = getNextId(TraceObject.RESULT_SET);
SimpleResult rs = new SimpleResult(); SimpleResult rs = new SimpleResult();
rs.addColumn("INDEX", "INDEX", Value.LONG, 0, 0, ValueLong.DISPLAY_SIZE); rs.addColumn("INDEX", "INDEX", TypeInfo.TYPE_LONG);
// TODO array result set: there are multiple data types possible // TODO array result set: there are multiple data types possible
rs.addColumn("VALUE", "VALUE", Value.NULL, 0, 0, 15); rs.addColumn("VALUE", "VALUE", TypeInfo.TYPE_NULL);
if (value != ValueNull.INSTANCE) { if (value != ValueNull.INSTANCE) {
Value[] values = ((ValueArray) value).getList(); Value[] values = ((ValueArray) value).getList();
count = checkRange(index, count, values.length); count = checkRange(index, count, values.length);
......
...@@ -11,7 +11,6 @@ import java.sql.PreparedStatement; ...@@ -11,7 +11,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.RowIdLifetime; import java.sql.RowIdLifetime;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
...@@ -26,6 +25,7 @@ import org.h2.message.Trace; ...@@ -26,6 +25,7 @@ import org.h2.message.Trace;
import org.h2.message.TraceObject; import org.h2.message.TraceObject;
import org.h2.result.SimpleResult; import org.h2.result.SimpleResult;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.TypeInfo;
import org.h2.value.ValueInt; import org.h2.value.ValueInt;
import org.h2.value.ValueString; import org.h2.value.ValueString;
...@@ -3187,12 +3187,12 @@ public class JdbcDatabaseMetaData extends TraceObject implements ...@@ -3187,12 +3187,12 @@ public class JdbcDatabaseMetaData extends TraceObject implements
public ResultSet getClientInfoProperties() throws SQLException { public ResultSet getClientInfoProperties() throws SQLException {
Properties clientInfo = conn.getClientInfo(); Properties clientInfo = conn.getClientInfo();
SimpleResult result = new SimpleResult(); SimpleResult result = new SimpleResult();
result.addColumn("NAME", "NAME", Types.VARCHAR, 0, 0, Integer.MAX_VALUE); result.addColumn("NAME", "NAME", TypeInfo.TYPE_STRING_DEFAULT);
result.addColumn("MAX_LEN", "MAX_LEN", Types.INTEGER, 0, 0, ValueInt.DISPLAY_SIZE); result.addColumn("MAX_LEN", "MAX_LEN", TypeInfo.TYPE_INT);
result.addColumn("DEFAULT_VALUE", "DEFAULT_VALUE", Types.VARCHAR, 0, 0, Integer.MAX_VALUE); result.addColumn("DEFAULT_VALUE", "DEFAULT_VALUE", TypeInfo.TYPE_STRING_DEFAULT);
result.addColumn("DESCRIPTION", "DESCRIPTION", Types.VARCHAR, 0, 0, Integer.MAX_VALUE); result.addColumn("DESCRIPTION", "DESCRIPTION", TypeInfo.TYPE_STRING_DEFAULT);
// Non-standard column // Non-standard column
result.addColumn("VALUE", "VALUE", Types.VARCHAR, 0, 0, Integer.MAX_VALUE); result.addColumn("VALUE", "VALUE", TypeInfo.TYPE_STRING_DEFAULT);
for (Entry<Object, Object> entry : clientInfo.entrySet()) { for (Entry<Object, Object> entry : clientInfo.entrySet()) {
result.addRow(ValueString.get((String) entry.getKey()), ValueInt.get(Integer.MAX_VALUE), result.addRow(ValueString.get((String) entry.getKey()), ValueInt.get(Integer.MAX_VALUE),
ValueString.EMPTY, ValueString.EMPTY, ValueString.get((String) entry.getValue())); ValueString.EMPTY, ValueString.EMPTY, ValueString.get((String) entry.getValue()));
......
...@@ -102,7 +102,7 @@ public class JdbcResultSetMetaData extends TraceObject implements ...@@ -102,7 +102,7 @@ public class JdbcResultSetMetaData extends TraceObject implements
try { try {
debugCodeCall("getColumnType", column); debugCodeCall("getColumnType", column);
checkColumnIndex(column); checkColumnIndex(column);
int type = result.getColumnType(--column); int type = result.getColumnType(--column).getValueType();
return DataType.convertTypeToSQLType(type); return DataType.convertTypeToSQLType(type);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -121,7 +121,7 @@ public class JdbcResultSetMetaData extends TraceObject implements ...@@ -121,7 +121,7 @@ public class JdbcResultSetMetaData extends TraceObject implements
try { try {
debugCodeCall("getColumnTypeName", column); debugCodeCall("getColumnTypeName", column);
checkColumnIndex(column); checkColumnIndex(column);
int type = result.getColumnType(--column); int type = result.getColumnType(--column).getValueType();
return DataType.getDataType(type).name; return DataType.getDataType(type).name;
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -370,7 +370,7 @@ public class JdbcResultSetMetaData extends TraceObject implements ...@@ -370,7 +370,7 @@ public class JdbcResultSetMetaData extends TraceObject implements
try { try {
debugCodeCall("getColumnClassName", column); debugCodeCall("getColumnClassName", column);
checkColumnIndex(column); checkColumnIndex(column);
int type = result.getColumnType(--column); int type = result.getColumnType(--column).getValueType();
return DataType.getTypeClassName(type, true); return DataType.getTypeClassName(type, true);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -389,7 +389,7 @@ public class JdbcResultSetMetaData extends TraceObject implements ...@@ -389,7 +389,7 @@ public class JdbcResultSetMetaData extends TraceObject implements
try { try {
debugCodeCall("getPrecision", column); debugCodeCall("getPrecision", column);
checkColumnIndex(column); checkColumnIndex(column);
long prec = result.getColumnPrecision(--column); long prec = result.getColumnType(--column).getPrecision();
return MathUtils.convertLongToInt(prec); return MathUtils.convertLongToInt(prec);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -408,7 +408,7 @@ public class JdbcResultSetMetaData extends TraceObject implements ...@@ -408,7 +408,7 @@ public class JdbcResultSetMetaData extends TraceObject implements
try { try {
debugCodeCall("getScale", column); debugCodeCall("getScale", column);
checkColumnIndex(column); checkColumnIndex(column);
return result.getColumnScale(--column); return result.getColumnType(--column).getScale();
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -426,7 +426,7 @@ public class JdbcResultSetMetaData extends TraceObject implements ...@@ -426,7 +426,7 @@ public class JdbcResultSetMetaData extends TraceObject implements
try { try {
debugCodeCall("getColumnDisplaySize", column); debugCodeCall("getColumnDisplaySize", column);
checkColumnIndex(column); checkColumnIndex(column);
return result.getDisplaySize(--column); return result.getColumnType(--column).getDisplaySize();
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
......
...@@ -26,6 +26,7 @@ import org.h2.store.DataHandler; ...@@ -26,6 +26,7 @@ import org.h2.store.DataHandler;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.value.CompareMode; import org.h2.value.CompareMode;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
...@@ -417,10 +418,11 @@ public class ValueDataType implements DataType { ...@@ -417,10 +418,11 @@ public class ValueDataType implements DataType {
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
writeString(buff, result.getAlias(i)); writeString(buff, result.getAlias(i));
writeString(buff, result.getColumnName(i)); writeString(buff, result.getColumnName(i));
buff.putVarInt(result.getColumnType(i)). TypeInfo columnType = result.getColumnType(i);
putVarLong(result.getColumnPrecision(i)). buff.putVarInt(columnType.getValueType()).
putVarInt(result.getColumnScale(i)). putVarLong(columnType.getPrecision()).
putVarInt(result.getDisplaySize(i)); putVarInt(columnType.getScale()).
putVarInt(columnType.getDisplaySize());
} }
while (result.next()) { while (result.next()) {
buff.put((byte) 1); buff.put((byte) 1);
......
...@@ -8,6 +8,7 @@ package org.h2.result; ...@@ -8,6 +8,7 @@ package org.h2.result;
import org.h2.engine.SessionInterface; import org.h2.engine.SessionInterface;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
/** /**
...@@ -139,23 +140,8 @@ public abstract class LazyResult implements ResultInterface { ...@@ -139,23 +140,8 @@ public abstract class LazyResult implements ResultInterface {
} }
@Override @Override
public int getColumnType(int i) { public TypeInfo getColumnType(int i) {
return expressions[i].getValueType(); return expressions[i].getType();
}
@Override
public long getColumnPrecision(int i) {
return expressions[i].getType().getPrecision();
}
@Override
public int getColumnScale(int i) {
return expressions[i].getType().getScale();
}
@Override
public int getDisplaySize(int i) {
return expressions[i].getType().getDisplaySize();
} }
@Override @Override
......
...@@ -15,6 +15,7 @@ import org.h2.message.DbException; ...@@ -15,6 +15,7 @@ import org.h2.message.DbException;
import org.h2.mvstore.db.MVTempResult; import org.h2.mvstore.db.MVTempResult;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.util.ValueHashMap; import org.h2.util.ValueHashMap;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
...@@ -527,24 +528,14 @@ public class LocalResultImpl implements LocalResult { ...@@ -527,24 +528,14 @@ public class LocalResultImpl implements LocalResult {
return expressions[i].getSchemaName(); return expressions[i].getSchemaName();
} }
@Override
public int getDisplaySize(int i) {
return expressions[i].getType().getDisplaySize();
}
@Override @Override
public String getColumnName(int i) { public String getColumnName(int i) {
return expressions[i].getColumnName(); return expressions[i].getColumnName();
} }
@Override @Override
public int getColumnType(int i) { public TypeInfo getColumnType(int i) {
return expressions[i].getValueType(); return expressions[i].getType();
}
@Override
public long getColumnPrecision(int i) {
return expressions[i].getType().getPrecision();
} }
@Override @Override
...@@ -557,11 +548,6 @@ public class LocalResultImpl implements LocalResult { ...@@ -557,11 +548,6 @@ public class LocalResultImpl implements LocalResult {
return expressions[i].isAutoIncrement(); return expressions[i].isAutoIncrement();
} }
@Override
public int getColumnScale(int i) {
return expressions[i].getType().getScale();
}
/** /**
* Set the offset of the first row to return. * Set the offset of the first row to return.
* *
......
...@@ -40,8 +40,7 @@ public final class MergedResult { ...@@ -40,8 +40,7 @@ public final class MergedResult {
SimpleResult.Column[] cols = new SimpleResult.Column[count]; SimpleResult.Column[] cols = new SimpleResult.Column[count];
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
SimpleResult.Column c = new SimpleResult.Column(result.getAlias(i), result.getColumnName(i), SimpleResult.Column c = new SimpleResult.Column(result.getAlias(i), result.getColumnName(i),
result.getColumnType(i), result.getColumnPrecision(i), result.getColumnScale(i), result.getColumnType(i));
result.getDisplaySize(i));
cols[i] = c; cols[i] = c;
if (!columns.contains(c)) { if (!columns.contains(c)) {
columns.add(c); columns.add(c);
......
...@@ -8,6 +8,7 @@ package org.h2.result; ...@@ -8,6 +8,7 @@ package org.h2.result;
import java.io.IOException; import java.io.IOException;
import org.h2.value.Transfer; import org.h2.value.Transfer;
import org.h2.value.TypeInfo;
/** /**
* A result set column of a remote result. * A result set column of a remote result.
...@@ -35,24 +36,9 @@ public class ResultColumn { ...@@ -35,24 +36,9 @@ public class ResultColumn {
final String columnName; final String columnName;
/** /**
* The value type of this column. * The column type.
*/ */
final int columnType; final TypeInfo columnType;
/**
* The precision.
*/
final long precision;
/**
* The scale.
*/
final int scale;
/**
* The expected display size.
*/
final int displaySize;
/** /**
* True if this is an autoincrement column. * True if this is an autoincrement column.
...@@ -74,10 +60,11 @@ public class ResultColumn { ...@@ -74,10 +60,11 @@ public class ResultColumn {
schemaName = in.readString(); schemaName = in.readString();
tableName = in.readString(); tableName = in.readString();
columnName = in.readString(); columnName = in.readString();
columnType = in.readInt(); int valueType = in.readInt();
precision = in.readLong(); long precision = in.readLong();
scale = in.readInt(); int scale = in.readInt();
displaySize = in.readInt(); int displaySize = in.readInt();
columnType = new TypeInfo(valueType, precision, scale, displaySize, null);
autoIncrement = in.readBoolean(); autoIncrement = in.readBoolean();
nullable = in.readInt(); nullable = in.readInt();
} }
...@@ -95,10 +82,11 @@ public class ResultColumn { ...@@ -95,10 +82,11 @@ public class ResultColumn {
out.writeString(result.getSchemaName(i)); out.writeString(result.getSchemaName(i));
out.writeString(result.getTableName(i)); out.writeString(result.getTableName(i));
out.writeString(result.getColumnName(i)); out.writeString(result.getColumnName(i));
out.writeInt(result.getColumnType(i)); TypeInfo type = result.getColumnType(i);
out.writeLong(result.getColumnPrecision(i)); out.writeInt(type.getValueType());
out.writeInt(result.getColumnScale(i)); out.writeLong(type.getPrecision());
out.writeInt(result.getDisplaySize(i)); out.writeInt(type.getScale());
out.writeInt(type.getDisplaySize());
out.writeBoolean(result.isAutoIncrement(i)); out.writeBoolean(result.isAutoIncrement(i));
out.writeInt(result.getNullable(i)); out.writeInt(result.getNullable(i));
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
package org.h2.result; package org.h2.result;
import org.h2.engine.SessionInterface; import org.h2.engine.SessionInterface;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
/** /**
...@@ -123,31 +124,7 @@ public interface ResultInterface extends AutoCloseable { ...@@ -123,31 +124,7 @@ public interface ResultInterface extends AutoCloseable {
* @param i the column number (starting with 0) * @param i the column number (starting with 0)
* @return the column data type * @return the column data type
*/ */
int getColumnType(int i); TypeInfo getColumnType(int i);
/**
* Get the precision for this column.
*
* @param i the column number (starting with 0)
* @return the precision
*/
long getColumnPrecision(int i);
/**
* Get the scale for this column.
*
* @param i the column number (starting with 0)
* @return the scale
*/
int getColumnScale(int i);
/**
* Get the display size for this column.
*
* @param i the column number (starting with 0)
* @return the display size
*/
int getDisplaySize(int i);
/** /**
* Check if this is an auto-increment column. * Check if this is an auto-increment column.
......
...@@ -14,6 +14,7 @@ import org.h2.engine.SysProperties; ...@@ -14,6 +14,7 @@ import org.h2.engine.SysProperties;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.message.Trace; import org.h2.message.Trace;
import org.h2.value.Transfer; import org.h2.value.Transfer;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
/** /**
...@@ -77,25 +78,10 @@ public class ResultRemote implements ResultInterface { ...@@ -77,25 +78,10 @@ public class ResultRemote implements ResultInterface {
} }
@Override @Override
public int getColumnType(int i) { public TypeInfo getColumnType(int i) {
return columns[i].columnType; return columns[i].columnType;
} }
@Override
public long getColumnPrecision(int i) {
return columns[i].precision;
}
@Override
public int getColumnScale(int i) {
return columns[i].scale;
}
@Override
public int getDisplaySize(int i) {
return columns[i].displaySize;
}
@Override @Override
public boolean isAutoIncrement(int i) { public boolean isAutoIncrement(int i) {
return columns[i].autoIncrement; return columns[i].autoIncrement;
......
...@@ -10,6 +10,7 @@ import java.util.ArrayList; ...@@ -10,6 +10,7 @@ import java.util.ArrayList;
import org.h2.engine.SessionInterface; import org.h2.engine.SessionInterface;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
/** /**
...@@ -28,16 +29,7 @@ public class SimpleResult implements ResultInterface { ...@@ -28,16 +29,7 @@ public class SimpleResult implements ResultInterface {
final String columnName; final String columnName;
/** Column type. */ /** Column type. */
final int columnType; final TypeInfo columnType;
/** Column precision. */
final long columnPrecision;
/** Column scale. */
final int columnScale;
/** Displayed size of the column. */
final int displaySize;
Column(String alias, String columnName, int columnType, long columnPrecision, int columnScale, Column(String alias, String columnName, int columnType, long columnPrecision, int columnScale,
int displaySize) { int displaySize) {
...@@ -46,10 +38,16 @@ public class SimpleResult implements ResultInterface { ...@@ -46,10 +38,16 @@ public class SimpleResult implements ResultInterface {
} }
this.alias = alias; this.alias = alias;
this.columnName = columnName; this.columnName = columnName;
this.columnType = TypeInfo.getTypeInfo(columnType, columnPrecision, columnScale, displaySize, null);
}
Column(String alias, String columnName, TypeInfo columnType) {
if (alias == null || columnName == null) {
throw new NullPointerException();
}
this.alias = alias;
this.columnName = columnName;
this.columnType = columnType; this.columnType = columnType;
this.columnPrecision = columnPrecision;
this.columnScale = columnScale;
this.displaySize = displaySize;
} }
@Override @Override
...@@ -107,7 +105,7 @@ public class SimpleResult implements ResultInterface { ...@@ -107,7 +105,7 @@ public class SimpleResult implements ResultInterface {
* *
* @param alias Column's alias. * @param alias Column's alias.
* @param columnName Column's name. * @param columnName Column's name.
* @param columnType Column's type. * @param columnType Column's value type.
* @param columnPrecision Column's precision. * @param columnPrecision Column's precision.
* @param columnScale Column's scale. * @param columnScale Column's scale.
* @param displaySize Column's display data size. * @param displaySize Column's display data size.
...@@ -117,6 +115,17 @@ public class SimpleResult implements ResultInterface { ...@@ -117,6 +115,17 @@ public class SimpleResult implements ResultInterface {
addColumn(new Column(alias, columnName, columnType, columnPrecision, columnScale, displaySize)); addColumn(new Column(alias, columnName, columnType, columnPrecision, columnScale, displaySize));
} }
/**
* Add column to the result.
*
* @param alias Column's alias.
* @param columnName Column's name.
* @param columnType Column's type.
*/
public void addColumn(String alias, String columnName, TypeInfo columnType) {
addColumn(new Column(alias, columnName, columnType));
}
/** /**
* Add column to the result. * Add column to the result.
* *
...@@ -212,25 +221,10 @@ public class SimpleResult implements ResultInterface { ...@@ -212,25 +221,10 @@ public class SimpleResult implements ResultInterface {
} }
@Override @Override
public int getColumnType(int i) { public TypeInfo getColumnType(int i) {
return columns.get(i).columnType; return columns.get(i).columnType;
} }
@Override
public long getColumnPrecision(int i) {
return columns.get(i).columnPrecision;
}
@Override
public int getColumnScale(int i) {
return columns.get(i).columnScale;
}
@Override
public int getDisplaySize(int i) {
return columns.get(i).displaySize;
}
@Override @Override
public boolean isAutoIncrement(int i) { public boolean isAutoIncrement(int i) {
return false; return false;
......
...@@ -232,7 +232,7 @@ public class UpdatableRow { ...@@ -232,7 +232,7 @@ public class UpdatableRow {
} }
Value[] newRow = new Value[columnCount]; Value[] newRow = new Value[columnCount];
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
int type = result.getColumnType(i); int type = result.getColumnType(i).getValueType();
newRow[i] = DataType.readValue(conn.getSession(), rs, i + 1, type); newRow[i] = DataType.readValue(conn.getSession(), rs, i + 1, type);
} }
return newRow; return newRow;
......
...@@ -27,6 +27,7 @@ import org.h2.util.DateTimeUtils; ...@@ -27,6 +27,7 @@ import org.h2.util.DateTimeUtils;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
...@@ -679,10 +680,11 @@ public class Data { ...@@ -679,10 +680,11 @@ public class Data {
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
writeString(result.getAlias(i)); writeString(result.getAlias(i));
writeString(result.getColumnName(i)); writeString(result.getColumnName(i));
writeVarInt(result.getColumnType(i)); TypeInfo columnType = result.getColumnType(i);
writeVarLong(result.getColumnPrecision(i)); writeVarInt(columnType.getValueType());
writeVarInt(result.getColumnScale(i)); writeVarLong(columnType.getPrecision());
writeVarInt(result.getDisplaySize(i)); writeVarInt(columnType.getScale());
writeVarInt(columnType.getDisplaySize());
} }
while (result.next()) { while (result.next()) {
writeByte((byte) 1); writeByte((byte) 1);
...@@ -1166,10 +1168,11 @@ public class Data { ...@@ -1166,10 +1168,11 @@ public class Data {
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
len += getStringLen(result.getAlias(i)); len += getStringLen(result.getAlias(i));
len += getStringLen(result.getColumnName(i)); len += getStringLen(result.getColumnName(i));
len += getVarIntLen(result.getColumnType(i)); TypeInfo columnType = result.getColumnType(i);
len += getVarLongLen(result.getColumnPrecision(i)); len += getVarIntLen(columnType.getValueType());
len += getVarIntLen(result.getColumnScale(i)); len += getVarLongLen(columnType.getPrecision());
len += getVarIntLen(result.getDisplaySize(i)); len += getVarIntLen(columnType.getScale());
len += getVarIntLen(columnType.getDisplaySize());
} }
while (result.next()) { while (result.next()) {
len++; len++;
......
...@@ -67,11 +67,7 @@ public class FunctionTable extends Table { ...@@ -67,11 +67,7 @@ public class FunctionTable extends Table {
int columnCount = result.getVisibleColumnCount(); int columnCount = result.getVisibleColumnCount();
Column[] cols = new Column[columnCount]; Column[] cols = new Column[columnCount];
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
cols[i] = new Column(result.getColumnName(i), cols[i] = new Column(result.getColumnName(i), result.getColumnType(i));
result.getColumnType(i),
result.getColumnPrecision(i),
result.getColumnScale(i),
result.getDisplaySize(i));
} }
setColumns(cols); setColumns(cols);
} }
......
...@@ -509,6 +509,7 @@ public class DataType { ...@@ -509,6 +509,7 @@ public class DataType {
dataType.params = "PRECISION,SCALE"; dataType.params = "PRECISION,SCALE";
dataType.supportsPrecision = true; dataType.supportsPrecision = true;
dataType.supportsScale = true; dataType.supportsScale = true;
dataType.maxScale = maxPrecision;
} }
dataType.decimal = true; dataType.decimal = true;
dataType.autoIncrement = autoInc; dataType.autoIncrement = autoInc;
......
...@@ -512,18 +512,19 @@ public class Transfer { ...@@ -512,18 +512,19 @@ public class Transfer {
int columnCount = result.getVisibleColumnCount(); int columnCount = result.getVisibleColumnCount();
writeInt(columnCount); writeInt(columnCount);
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
TypeInfo columnType = result.getColumnType(i);
if (version >= Constants.TCP_PROTOCOL_VERSION_18) { if (version >= Constants.TCP_PROTOCOL_VERSION_18) {
writeString(result.getAlias(i)); writeString(result.getAlias(i));
writeString(result.getColumnName(i)); writeString(result.getColumnName(i));
writeInt(result.getColumnType(i)); writeInt(columnType.getValueType());
writeLong(result.getColumnPrecision(i)); writeLong(columnType.getPrecision());
writeInt(result.getColumnScale(i)); writeInt(columnType.getScale());
writeInt(result.getDisplaySize(i)); writeInt(columnType.getDisplaySize());
} else { } else {
writeString(result.getColumnName(i)); writeString(result.getColumnName(i));
writeInt(DataType.getDataType(result.getColumnType(i)).sqlType); writeInt(DataType.getDataType(columnType.getValueType()).sqlType);
writeInt(MathUtils.convertLongToInt(result.getColumnPrecision(i))); writeInt(MathUtils.convertLongToInt(columnType.getPrecision()));
writeInt(result.getColumnScale(i)); writeInt(columnType.getScale());
} }
} }
while (result.next()) { while (result.next()) {
......
...@@ -1335,8 +1335,7 @@ public abstract class Value extends VersionedValue { ...@@ -1335,8 +1335,7 @@ public abstract class Value extends VersionedValue {
private ValueResultSet convertToResultSet() { private ValueResultSet convertToResultSet() {
SimpleResult result = new SimpleResult(); SimpleResult result = new SimpleResult();
TypeInfo type = getType(); result.addColumn("X", "X", getType());
result.addColumn("X", "X", type.getValueType(), type.getPrecision(), type.getScale(), type.getDisplaySize());
result.addRow(this); result.addRow(this);
return ValueResultSet.get(result); return ValueResultSet.get(result);
} }
...@@ -1637,8 +1636,7 @@ public abstract class Value extends VersionedValue { ...@@ -1637,8 +1636,7 @@ public abstract class Value extends VersionedValue {
*/ */
public ResultInterface getResult() { public ResultInterface getResult() {
SimpleResult rs = new SimpleResult(); SimpleResult rs = new SimpleResult();
TypeInfo type = getType(); rs.addColumn("X", "X", getType());
rs.addColumn("X", "X", type.getValueType(), type.getPrecision(), type.getScale(), type.getDisplaySize());
rs.addRow(this); rs.addRow(this);
return rs; return rs;
} }
......
...@@ -64,7 +64,8 @@ public class ValueResultSet extends Value { ...@@ -64,7 +64,8 @@ public class ValueResultSet extends Value {
for (int i = 0; i < maxrows && rs.next(); i++) { for (int i = 0; i < maxrows && rs.next(); i++) {
Value[] list = new Value[columnCount]; Value[] list = new Value[columnCount];
for (int j = 0; j < columnCount; j++) { for (int j = 0; j < columnCount; j++) {
list[j] = DataType.convertToValue(session, rs.getObject(j + 1), simple.getColumnType(j)); list[j] = DataType.convertToValue(session, rs.getObject(j + 1),
simple.getColumnType(j).getValueType());
} }
simple.addRow(list); simple.addRow(list);
} }
...@@ -87,8 +88,7 @@ public class ValueResultSet extends Value { ...@@ -87,8 +88,7 @@ public class ValueResultSet extends Value {
int columnCount = result.getVisibleColumnCount(); int columnCount = result.getVisibleColumnCount();
SimpleResult simple = new SimpleResult(); SimpleResult simple = new SimpleResult();
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
simple.addColumn(result.getAlias(i), result.getColumnName(i), result.getColumnType(i), simple.addColumn(result.getAlias(i), result.getColumnName(i), result.getColumnType(i));
result.getColumnPrecision(i), result.getColumnScale(i), result.getDisplaySize(i));
} }
result.reset(); result.reset();
for (int i = 0; i < maxrows && result.next(); i++) { for (int i = 0; i < maxrows && result.next(); i++) {
......
...@@ -540,8 +540,8 @@ public class TestFunctions extends TestDb implements AggregateFunction { ...@@ -540,8 +540,8 @@ public class TestFunctions extends TestDb implements AggregateFunction {
stat.execute("create aggregate agg_sum for \""+getClass().getName()+"\""); stat.execute("create aggregate agg_sum for \""+getClass().getName()+"\"");
rs = stat.executeQuery("select agg_sum(1), sum(1.6) from dual"); rs = stat.executeQuery("select agg_sum(1), sum(1.6) from dual");
rs.next(); rs.next();
assertEquals(1, rs.getMetaData().getScale(2)); assertEquals(Integer.MAX_VALUE, rs.getMetaData().getScale(2));
assertEquals(32767, rs.getMetaData().getScale(1)); assertEquals(Integer.MAX_VALUE, rs.getMetaData().getScale(1));
stat.executeQuery("select * from information_schema.function_aliases"); stat.executeQuery("select * from information_schema.function_aliases");
conn.close(); conn.close();
} }
......
...@@ -37,6 +37,7 @@ import org.h2.test.utils.AssertThrows; ...@@ -37,6 +37,7 @@ import org.h2.test.utils.AssertThrows;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
import org.h2.util.Bits; import org.h2.util.Bits;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
import org.h2.value.ValueBytes; import org.h2.value.ValueBytes;
...@@ -253,16 +254,18 @@ public class TestValue extends TestDb { ...@@ -253,16 +254,18 @@ public class TestValue extends TestDb {
assertEquals(2, res.getVisibleColumnCount()); assertEquals(2, res.getVisibleColumnCount());
assertEquals("ID", res.getAlias(0)); assertEquals("ID", res.getAlias(0));
assertEquals("ID", res.getColumnName(0)); assertEquals("ID", res.getColumnName(0));
assertEquals(Value.INT, res.getColumnType(0)); TypeInfo type = res.getColumnType(0);
assertEquals(0, res.getColumnPrecision(0)); assertEquals(Value.INT, type.getValueType());
assertEquals(0, res.getColumnScale(0)); assertEquals(ValueInt.PRECISION, type.getPrecision());
assertEquals(fromSimple ? 15 : ValueInt.DISPLAY_SIZE, res.getDisplaySize(0)); assertEquals(0, type.getScale());
assertEquals(ValueInt.DISPLAY_SIZE, type.getDisplaySize());
assertEquals("NAME", res.getAlias(1)); assertEquals("NAME", res.getAlias(1));
assertEquals("NAME", res.getColumnName(1)); assertEquals("NAME", res.getColumnName(1));
assertEquals(Value.STRING, res.getColumnType(1)); type = res.getColumnType(1);
assertEquals(255, res.getColumnPrecision(1)); assertEquals(Value.STRING, type.getValueType());
assertEquals(0, res.getColumnScale(1)); assertEquals(255, type.getPrecision());
assertEquals(fromSimple ? 15 : 255, res.getDisplaySize(1)); assertEquals(0, type.getScale());
assertEquals(255, type.getDisplaySize());
if (count >= 1) { if (count >= 1) {
assertTrue(res.next()); assertTrue(res.next());
assertEquals(new Value[] {ValueInt.get(1), ValueString.get("Hello")}, res.currentRow()); assertEquals(new Value[] {ValueInt.get(1), ValueString.get("Hello")}, res.currentRow());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论