Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
68ec6cf3
提交
68ec6cf3
authored
2月 02, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove DataType.defaultDisplaySize and fix display size in TypeInfo
上级
23492d1a
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
194 行增加
和
70 行删除
+194
-70
Parser.java
h2/src/main/org/h2/command/Parser.java
+1
-1
BinaryOperation.java
h2/src/main/org/h2/expression/BinaryOperation.java
+2
-2
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+1
-1
Function.java
h2/src/main/org/h2/expression/function/Function.java
+2
-2
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+4
-4
DataType.java
h2/src/main/org/h2/value/DataType.java
+1
-16
TypeInfo.java
h2/src/main/org/h2/value/TypeInfo.java
+67
-44
TestValue.java
h2/src/test/org/h2/test/unit/TestValue.java
+116
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
68ec6cf3
...
@@ -5899,7 +5899,7 @@ public class Parser {
...
@@ -5899,7 +5899,7 @@ public class Parser {
String
columnName
=
"C"
+
(
i
+
1
);
String
columnName
=
"C"
+
(
i
+
1
);
if
(
rows
.
isEmpty
())
{
if
(
rows
.
isEmpty
())
{
if
(
type
.
getValueType
()
==
Value
.
UNKNOWN
)
{
if
(
type
.
getValueType
()
==
Value
.
UNKNOWN
)
{
type
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
type
=
TypeInfo
.
TYPE_STRING
;
}
}
column
=
new
Column
(
columnName
,
type
);
column
=
new
Column
(
columnName
,
type
);
columns
.
add
(
column
);
columns
.
add
(
column
);
...
...
h2/src/main/org/h2/expression/BinaryOperation.java
浏览文件 @
68ec6cf3
...
@@ -172,7 +172,7 @@ public class BinaryOperation extends Expression {
...
@@ -172,7 +172,7 @@ public class BinaryOperation extends Expression {
break
;
break
;
}
}
}
}
type
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
type
=
TypeInfo
.
TYPE_STRING
;
break
;
break
;
}
}
case
PLUS:
case
PLUS:
...
@@ -188,7 +188,7 @@ public class BinaryOperation extends Expression {
...
@@ -188,7 +188,7 @@ public class BinaryOperation extends Expression {
// string when text concatenation with + is enabled
// string when text concatenation with + is enabled
if
(
opType
==
OpType
.
PLUS
&&
session
.
getDatabase
().
if
(
opType
==
OpType
.
PLUS
&&
session
.
getDatabase
().
getMode
().
allowPlusForStringConcat
)
{
getMode
().
allowPlusForStringConcat
)
{
type
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
type
=
TypeInfo
.
TYPE_STRING
;
opType
=
OpType
.
CONCAT
;
opType
=
OpType
.
CONCAT
;
}
else
{
}
else
{
type
=
TypeInfo
.
TYPE_DECIMAL_DEFAULT
;
type
=
TypeInfo
.
TYPE_DECIMAL_DEFAULT
;
...
...
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
68ec6cf3
...
@@ -648,7 +648,7 @@ public class Aggregate extends AbstractAggregate {
...
@@ -648,7 +648,7 @@ public class Aggregate extends AbstractAggregate {
}
}
switch
(
aggregateType
)
{
switch
(
aggregateType
)
{
case
GROUP_CONCAT:
case
GROUP_CONCAT:
type
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
type
=
TypeInfo
.
TYPE_STRING
;
break
;
break
;
case
COUNT_ALL:
case
COUNT_ALL:
case
COUNT:
case
COUNT:
...
...
h2/src/main/org/h2/expression/function/Function.java
浏览文件 @
68ec6cf3
...
@@ -2374,7 +2374,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -2374,7 +2374,7 @@ public class Function extends Expression implements FunctionCall {
}
}
}
}
if
(
typeInfo
.
getValueType
()
==
Value
.
UNKNOWN
)
{
if
(
typeInfo
.
getValueType
()
==
Value
.
UNKNOWN
)
{
typeInfo
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
typeInfo
=
TypeInfo
.
TYPE_STRING
;
}
}
break
;
break
;
}
}
...
@@ -2406,7 +2406,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -2406,7 +2406,7 @@ public class Function extends Expression implements FunctionCall {
}
}
}
}
if
(
typeInfo
.
getValueType
()
==
Value
.
UNKNOWN
)
{
if
(
typeInfo
.
getValueType
()
==
Value
.
UNKNOWN
)
{
typeInfo
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
typeInfo
=
TypeInfo
.
TYPE_STRING
;
}
}
break
;
break
;
}
}
...
...
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
68ec6cf3
...
@@ -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"
,
TypeInfo
.
TYPE_STRING
_DEFAULT
);
result
.
addColumn
(
"NAME"
,
"NAME"
,
TypeInfo
.
TYPE_STRING
);
result
.
addColumn
(
"MAX_LEN"
,
"MAX_LEN"
,
TypeInfo
.
TYPE_INT
);
result
.
addColumn
(
"MAX_LEN"
,
"MAX_LEN"
,
TypeInfo
.
TYPE_INT
);
result
.
addColumn
(
"DEFAULT_VALUE"
,
"DEFAULT_VALUE"
,
TypeInfo
.
TYPE_STRING
_DEFAULT
);
result
.
addColumn
(
"DEFAULT_VALUE"
,
"DEFAULT_VALUE"
,
TypeInfo
.
TYPE_STRING
);
result
.
addColumn
(
"DESCRIPTION"
,
"DESCRIPTION"
,
TypeInfo
.
TYPE_STRING
_DEFAULT
);
result
.
addColumn
(
"DESCRIPTION"
,
"DESCRIPTION"
,
TypeInfo
.
TYPE_STRING
);
// Non-standard column
// Non-standard column
result
.
addColumn
(
"VALUE"
,
"VALUE"
,
TypeInfo
.
TYPE_STRING
_DEFAULT
);
result
.
addColumn
(
"VALUE"
,
"VALUE"
,
TypeInfo
.
TYPE_STRING
);
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
()));
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
68ec6cf3
...
@@ -158,11 +158,6 @@ public class DataType {
...
@@ -158,11 +158,6 @@ public class DataType {
*/
*/
public
int
defaultScale
;
public
int
defaultScale
;
/**
* The default display size.
*/
public
int
defaultDisplaySize
;
/**
/**
* If this data type should not be listed in the database meta data.
* If this data type should not be listed in the database meta data.
*/
*/
...
@@ -185,7 +180,6 @@ public class DataType {
...
@@ -185,7 +180,6 @@ public class DataType {
DataType
dataType
=
new
DataType
();
DataType
dataType
=
new
DataType
();
dataType
.
defaultPrecision
=
dataType
.
maxPrecision
=
ValueNull
.
PRECISION
;
dataType
.
defaultPrecision
=
dataType
.
maxPrecision
=
ValueNull
.
PRECISION
;
dataType
.
defaultDisplaySize
=
ValueNull
.
DISPLAY_SIZE
;
add
(
Value
.
NULL
,
Types
.
NULL
,
add
(
Value
.
NULL
,
Types
.
NULL
,
dataType
,
dataType
,
new
String
[]{
"NULL"
},
new
String
[]{
"NULL"
},
...
@@ -337,7 +331,6 @@ public class DataType {
...
@@ -337,7 +331,6 @@ public class DataType {
dataType
=
new
DataType
();
dataType
=
new
DataType
();
dataType
.
prefix
=
dataType
.
suffix
=
"'"
;
dataType
.
prefix
=
dataType
.
suffix
=
"'"
;
dataType
.
defaultPrecision
=
dataType
.
maxPrecision
=
ValueUuid
.
PRECISION
;
dataType
.
defaultPrecision
=
dataType
.
maxPrecision
=
ValueUuid
.
PRECISION
;
dataType
.
defaultDisplaySize
=
ValueUuid
.
DISPLAY_SIZE
;
add
(
Value
.
UUID
,
Types
.
BINARY
,
add
(
Value
.
UUID
,
Types
.
BINARY
,
createString
(
false
),
createString
(
false
),
// UNIQUEIDENTIFIER is the MSSQL mode equivalent
// UNIQUEIDENTIFIER is the MSSQL mode equivalent
...
@@ -377,7 +370,7 @@ public class DataType {
...
@@ -377,7 +370,7 @@ public class DataType {
32
32
);
);
dataType
=
new
DataType
();
dataType
=
new
DataType
();
dataType
.
maxPrecision
=
dataType
.
defaultPrecision
=
dataType
.
defaultDisplaySize
=
Integer
.
MAX_VALUE
;
dataType
.
maxPrecision
=
dataType
.
defaultPrecision
=
Integer
.
MAX_VALUE
;
add
(
Value
.
RESULT_SET
,
DataType
.
TYPE_RESULT_SET
,
add
(
Value
.
RESULT_SET
,
DataType
.
TYPE_RESULT_SET
,
dataType
,
dataType
,
new
String
[]{
"RESULT_SET"
},
new
String
[]{
"RESULT_SET"
},
...
@@ -441,9 +434,6 @@ public class DataType {
...
@@ -441,9 +434,6 @@ public class DataType {
dataType
.
defaultScale
=
ValueInterval
.
DEFAULT_SCALE
;
dataType
.
defaultScale
=
ValueInterval
.
DEFAULT_SCALE
;
dataType
.
maxScale
=
ValueInterval
.
MAXIMUM_SCALE
;
dataType
.
maxScale
=
ValueInterval
.
MAXIMUM_SCALE
;
}
}
dataType
.
defaultDisplaySize
=
ValueInterval
.
getDisplaySize
(
type
,
ValueInterval
.
DEFAULT_PRECISION
,
// Scale will be ignored if it is not supported
ValueInterval
.
DEFAULT_SCALE
);
add
(
type
,
Types
.
OTHER
,
dataType
,
add
(
type
,
Types
.
OTHER
,
dataType
,
new
String
[]{(
"INTERVAL "
+
name
).
intern
()},
new
String
[]{(
"INTERVAL "
+
name
).
intern
()},
36
36
...
@@ -469,7 +459,6 @@ public class DataType {
...
@@ -469,7 +459,6 @@ public class DataType {
dt
.
supportsScale
=
dataType
.
supportsScale
;
dt
.
supportsScale
=
dataType
.
supportsScale
;
dt
.
defaultPrecision
=
dataType
.
defaultPrecision
;
dt
.
defaultPrecision
=
dataType
.
defaultPrecision
;
dt
.
defaultScale
=
dataType
.
defaultScale
;
dt
.
defaultScale
=
dataType
.
defaultScale
;
dt
.
defaultDisplaySize
=
dataType
.
defaultDisplaySize
;
dt
.
caseSensitive
=
dataType
.
caseSensitive
;
dt
.
caseSensitive
=
dataType
.
caseSensitive
;
dt
.
hidden
=
i
>
0
;
dt
.
hidden
=
i
>
0
;
dt
.
memory
=
memory
;
dt
.
memory
=
memory
;
...
@@ -504,7 +493,6 @@ public class DataType {
...
@@ -504,7 +493,6 @@ public class DataType {
dataType
.
maxPrecision
=
maxPrecision
;
dataType
.
maxPrecision
=
maxPrecision
;
dataType
.
defaultPrecision
=
defaultPrecision
;
dataType
.
defaultPrecision
=
defaultPrecision
;
dataType
.
defaultScale
=
defaultScale
;
dataType
.
defaultScale
=
defaultScale
;
dataType
.
defaultDisplaySize
=
defaultDisplaySize
;
if
(
needsPrecisionAndScale
)
{
if
(
needsPrecisionAndScale
)
{
dataType
.
params
=
"PRECISION,SCALE"
;
dataType
.
params
=
"PRECISION,SCALE"
;
dataType
.
supportsPrecision
=
true
;
dataType
.
supportsPrecision
=
true
;
...
@@ -537,7 +525,6 @@ public class DataType {
...
@@ -537,7 +525,6 @@ public class DataType {
dataType
.
maxScale
=
maxScale
;
dataType
.
maxScale
=
maxScale
;
dataType
.
defaultPrecision
=
precision
;
dataType
.
defaultPrecision
=
precision
;
dataType
.
defaultScale
=
scale
;
dataType
.
defaultScale
=
scale
;
dataType
.
defaultDisplaySize
=
precision
;
return
dataType
;
return
dataType
;
}
}
...
@@ -550,7 +537,6 @@ public class DataType {
...
@@ -550,7 +537,6 @@ public class DataType {
dataType
.
supportsPrecision
=
true
;
dataType
.
supportsPrecision
=
true
;
dataType
.
maxPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
maxPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
defaultPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
defaultPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
defaultDisplaySize
=
Integer
.
MAX_VALUE
;
return
dataType
;
return
dataType
;
}
}
...
@@ -568,7 +554,6 @@ public class DataType {
...
@@ -568,7 +554,6 @@ public class DataType {
dataType
.
params
=
"TYPE,SRID"
;
dataType
.
params
=
"TYPE,SRID"
;
dataType
.
maxPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
maxPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
defaultPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
defaultPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
defaultDisplaySize
=
Integer
.
MAX_VALUE
;
return
dataType
;
return
dataType
;
}
}
...
...
h2/src/main/org/h2/value/TypeInfo.java
浏览文件 @
68ec6cf3
...
@@ -7,6 +7,7 @@ package org.h2.value;
...
@@ -7,6 +7,7 @@ package org.h2.value;
import
org.h2.api.CustomDataTypesHandler
;
import
org.h2.api.CustomDataTypesHandler
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.IntervalQualifier
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MathUtils
;
...
@@ -51,6 +52,11 @@ public class TypeInfo {
...
@@ -51,6 +52,11 @@ public class TypeInfo {
*/
*/
public
static
final
TypeInfo
TYPE_LONG
;
public
static
final
TypeInfo
TYPE_LONG
;
/**
* DECIMAL type with maximum parameters.
*/
public
static
final
TypeInfo
TYPE_DECIMAL
;
/**
/**
* DECIMAL type with default parameters.
* DECIMAL type with default parameters.
*/
*/
...
@@ -67,7 +73,7 @@ public class TypeInfo {
...
@@ -67,7 +73,7 @@ public class TypeInfo {
public
static
final
TypeInfo
TYPE_FLOAT
;
public
static
final
TypeInfo
TYPE_FLOAT
;
/**
/**
* TIME type with parameters.
* TIME type with
maximum
parameters.
*/
*/
public
static
final
TypeInfo
TYPE_TIME
;
public
static
final
TypeInfo
TYPE_TIME
;
...
@@ -77,14 +83,14 @@ public class TypeInfo {
...
@@ -77,14 +83,14 @@ public class TypeInfo {
public
static
final
TypeInfo
TYPE_DATE
;
public
static
final
TypeInfo
TYPE_DATE
;
/**
/**
* TIMESTAMP type with parameters.
* TIMESTAMP type with
maximum
parameters.
*/
*/
public
static
final
TypeInfo
TYPE_TIMESTAMP
;
public
static
final
TypeInfo
TYPE_TIMESTAMP
;
/**
/**
* STRING type with
default
parameters.
* STRING type with
maximum
parameters.
*/
*/
public
static
final
TypeInfo
TYPE_STRING
_DEFAULT
;
public
static
final
TypeInfo
TYPE_STRING
;
/**
/**
* ARRAY type with parameters.
* ARRAY type with parameters.
...
@@ -112,7 +118,7 @@ public class TypeInfo {
...
@@ -112,7 +118,7 @@ public class TypeInfo {
public
static
final
TypeInfo
TYPE_GEOMETRY
;
public
static
final
TypeInfo
TYPE_GEOMETRY
;
/**
/**
* TIMESTAMP WITH TIME ZONE type with parameters.
* TIMESTAMP WITH TIME ZONE type with
maximum
parameters.
*/
*/
public
static
final
TypeInfo
TYPE_TIMESTAMP_TZ
;
public
static
final
TypeInfo
TYPE_TIMESTAMP_TZ
;
...
@@ -122,17 +128,17 @@ public class TypeInfo {
...
@@ -122,17 +128,17 @@ public class TypeInfo {
public
static
final
TypeInfo
TYPE_ENUM_UNDEFINED
;
public
static
final
TypeInfo
TYPE_ENUM_UNDEFINED
;
/**
/**
* INTERVAL DAY type with parameters.
* INTERVAL DAY type with
maximum
parameters.
*/
*/
public
static
final
TypeInfo
TYPE_INTERVAL_DAY
;
public
static
final
TypeInfo
TYPE_INTERVAL_DAY
;
/**
/**
* INTERVAL DAY TO SECOND type with parameters.
* INTERVAL DAY TO SECOND type with
maximum
parameters.
*/
*/
public
static
final
TypeInfo
TYPE_INTERVAL_DAY_TO_SECOND
;
public
static
final
TypeInfo
TYPE_INTERVAL_DAY_TO_SECOND
;
/**
/**
* INTERVAL HOUR TO SECOND type with parameters.
* INTERVAL HOUR TO SECOND type with
maximum
parameters.
*/
*/
public
static
final
TypeInfo
TYPE_INTERVAL_HOUR_TO_SECOND
;
public
static
final
TypeInfo
TYPE_INTERVAL_HOUR_TO_SECOND
;
...
@@ -154,40 +160,61 @@ public class TypeInfo {
...
@@ -154,40 +160,61 @@ public class TypeInfo {
private
final
ExtTypeInfo
extTypeInfo
;
private
final
ExtTypeInfo
extTypeInfo
;
static
{
static
{
DataType
[]
type
=
DataType
.
TYPES_BY_VALUE_TYPE
;
TypeInfo
[]
infos
=
new
TypeInfo
[
Value
.
TYPE_COUNT
];
TypeInfo
[]
infos
=
new
TypeInfo
[
Value
.
TYPE_COUNT
];
for
(
int
i
=
0
;
i
<
type
.
length
;
i
++)
{
DataType
dt
=
type
[
i
];
if
(
dt
!=
null
)
{
Value
.
getOrder
(
i
);
infos
[
i
]
=
createTypeInfo
(
i
,
dt
);
}
}
TYPE_UNKNOWN
=
new
TypeInfo
(
Value
.
UNKNOWN
,
-
1L
,
-
1
,
-
1
,
null
);
TYPE_UNKNOWN
=
new
TypeInfo
(
Value
.
UNKNOWN
,
-
1L
,
-
1
,
-
1
,
null
);
TYPE_NULL
=
infos
[
Value
.
NULL
];
infos
[
Value
.
NULL
]
=
TYPE_NULL
=
new
TypeInfo
(
Value
.
NULL
,
ValueNull
.
PRECISION
,
0
,
ValueNull
.
DISPLAY_SIZE
,
null
);
TYPE_BOOLEAN
=
infos
[
Value
.
BOOLEAN
];
infos
[
Value
.
BOOLEAN
]
=
TYPE_BOOLEAN
=
new
TypeInfo
(
Value
.
BOOLEAN
,
ValueBoolean
.
PRECISION
,
0
,
TYPE_BYTE
=
infos
[
Value
.
BYTE
];
ValueBoolean
.
DISPLAY_SIZE
,
null
);
TYPE_SHORT
=
infos
[
Value
.
SHORT
];
infos
[
Value
.
BYTE
]
=
TYPE_BYTE
=
new
TypeInfo
(
Value
.
BYTE
,
ValueByte
.
PRECISION
,
0
,
ValueByte
.
DISPLAY_SIZE
,
null
);
TYPE_INT
=
infos
[
Value
.
INT
];
infos
[
Value
.
SHORT
]
=
TYPE_SHORT
=
new
TypeInfo
(
Value
.
SHORT
,
ValueShort
.
PRECISION
,
0
,
ValueShort
.
DISPLAY_SIZE
,
TYPE_LONG
=
infos
[
Value
.
LONG
];
null
);
TYPE_DECIMAL_DEFAULT
=
infos
[
Value
.
DECIMAL
];
infos
[
Value
.
INT
]
=
TYPE_INT
=
new
TypeInfo
(
Value
.
INT
,
ValueInt
.
PRECISION
,
0
,
ValueInt
.
DISPLAY_SIZE
,
null
);
TYPE_DOUBLE
=
infos
[
Value
.
DOUBLE
];
infos
[
Value
.
LONG
]
=
TYPE_LONG
=
new
TypeInfo
(
Value
.
LONG
,
ValueLong
.
PRECISION
,
0
,
ValueLong
.
DISPLAY_SIZE
,
null
);
TYPE_FLOAT
=
infos
[
Value
.
FLOAT
];
infos
[
Value
.
DECIMAL
]
=
TYPE_DECIMAL
=
new
TypeInfo
(
Value
.
DECIMAL
,
Integer
.
MAX_VALUE
,
Integer
.
MAX_VALUE
,
TYPE_TIME
=
infos
[
Value
.
TIME
];
Integer
.
MAX_VALUE
,
null
);
TYPE_DATE
=
infos
[
Value
.
DATE
];
TYPE_DECIMAL_DEFAULT
=
new
TypeInfo
(
Value
.
DECIMAL
,
ValueDecimal
.
DEFAULT_PRECISION
,
ValueDecimal
.
DEFAULT_SCALE
,
TYPE_TIMESTAMP
=
infos
[
Value
.
TIMESTAMP
];
ValueDecimal
.
DEFAULT_PRECISION
+
2
,
null
);
TYPE_STRING_DEFAULT
=
infos
[
Value
.
STRING
];
infos
[
Value
.
DOUBLE
]
=
TYPE_DOUBLE
=
new
TypeInfo
(
Value
.
DOUBLE
,
ValueDouble
.
PRECISION
,
0
,
TYPE_ARRAY
=
infos
[
Value
.
ARRAY
];
ValueDouble
.
DISPLAY_SIZE
,
null
);
TYPE_RESULT_SET
=
infos
[
Value
.
RESULT_SET
];
infos
[
Value
.
FLOAT
]
=
TYPE_FLOAT
=
new
TypeInfo
(
Value
.
FLOAT
,
ValueFloat
.
PRECISION
,
0
,
ValueFloat
.
DISPLAY_SIZE
,
TYPE_JAVA_OBJECT
=
infos
[
Value
.
JAVA_OBJECT
];
null
);
TYPE_UUID
=
infos
[
Value
.
UUID
];
infos
[
Value
.
TIME
]
=
TYPE_TIME
=
new
TypeInfo
(
Value
.
TIME
,
ValueTime
.
MAXIMUM_PRECISION
,
ValueTime
.
MAXIMUM_SCALE
,
TYPE_GEOMETRY
=
infos
[
Value
.
GEOMETRY
];
ValueTime
.
MAXIMUM_PRECISION
,
null
);
TYPE_TIMESTAMP_TZ
=
infos
[
Value
.
TIMESTAMP_TZ
];
infos
[
Value
.
DATE
]
=
TYPE_DATE
=
new
TypeInfo
(
Value
.
DATE
,
ValueDate
.
PRECISION
,
0
,
ValueDate
.
PRECISION
,
null
);
TYPE_ENUM_UNDEFINED
=
infos
[
Value
.
ENUM
];
infos
[
Value
.
TIMESTAMP
]
=
TYPE_TIMESTAMP
=
new
TypeInfo
(
Value
.
TIMESTAMP
,
ValueTimestamp
.
MAXIMUM_PRECISION
,
ValueTimestamp
.
MAXIMUM_SCALE
,
ValueTimestamp
.
MAXIMUM_PRECISION
,
null
);
infos
[
Value
.
BYTES
]
=
new
TypeInfo
(
Value
.
BYTES
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
);
infos
[
Value
.
STRING
]
=
TYPE_STRING
=
new
TypeInfo
(
Value
.
STRING
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
);
infos
[
Value
.
STRING_IGNORECASE
]
=
new
TypeInfo
(
Value
.
STRING_IGNORECASE
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
);
infos
[
Value
.
BLOB
]
=
new
TypeInfo
(
Value
.
BLOB
,
Long
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
);
infos
[
Value
.
CLOB
]
=
new
TypeInfo
(
Value
.
CLOB
,
Long
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
);
infos
[
Value
.
ARRAY
]
=
TYPE_ARRAY
=
new
TypeInfo
(
Value
.
ARRAY
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
);
infos
[
Value
.
RESULT_SET
]
=
TYPE_RESULT_SET
=
new
TypeInfo
(
Value
.
RESULT_SET
,
Integer
.
MAX_VALUE
,
Integer
.
MAX_VALUE
,
Integer
.
MAX_VALUE
,
null
);
infos
[
Value
.
JAVA_OBJECT
]
=
TYPE_JAVA_OBJECT
=
new
TypeInfo
(
Value
.
JAVA_OBJECT
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
);
infos
[
Value
.
UUID
]
=
TYPE_UUID
=
new
TypeInfo
(
Value
.
UUID
,
ValueUuid
.
PRECISION
,
0
,
ValueUuid
.
DISPLAY_SIZE
,
null
);
infos
[
Value
.
STRING_FIXED
]
=
new
TypeInfo
(
Value
.
STRING_FIXED
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
);
infos
[
Value
.
GEOMETRY
]
=
TYPE_GEOMETRY
=
new
TypeInfo
(
Value
.
GEOMETRY
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
);
infos
[
Value
.
TIMESTAMP_TZ
]
=
TYPE_TIMESTAMP_TZ
=
new
TypeInfo
(
Value
.
TIMESTAMP_TZ
,
ValueTimestampTimeZone
.
MAXIMUM_PRECISION
,
ValueTimestampTimeZone
.
MAXIMUM_SCALE
,
ValueTimestampTimeZone
.
MAXIMUM_PRECISION
,
null
);
infos
[
Value
.
ENUM
]
=
TYPE_ENUM_UNDEFINED
=
new
TypeInfo
(
Value
.
ENUM
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
);
for
(
int
i
=
Value
.
INTERVAL_YEAR
;
i
<=
Value
.
INTERVAL_MINUTE_TO_SECOND
;
i
++)
{
infos
[
i
]
=
new
TypeInfo
(
i
,
ValueInterval
.
MAXIMUM_PRECISION
,
IntervalQualifier
.
valueOf
(
i
-
Value
.
INTERVAL_YEAR
).
hasSeconds
()
?
ValueInterval
.
MAXIMUM_SCALE
:
0
,
ValueInterval
.
getDisplaySize
(
i
,
ValueInterval
.
MAXIMUM_PRECISION
,
// Scale will be ignored if it is not supported
ValueInterval
.
MAXIMUM_SCALE
),
null
);
}
TYPE_INTERVAL_DAY
=
infos
[
Value
.
INTERVAL_DAY
];
TYPE_INTERVAL_DAY
=
infos
[
Value
.
INTERVAL_DAY
];
TYPE_INTERVAL_DAY_TO_SECOND
=
infos
[
Value
.
INTERVAL_DAY_TO_SECOND
];
TYPE_INTERVAL_DAY_TO_SECOND
=
infos
[
Value
.
INTERVAL_DAY_TO_SECOND
];
TYPE_INTERVAL_HOUR_TO_SECOND
=
infos
[
Value
.
INTERVAL_HOUR_TO_SECOND
];
TYPE_INTERVAL_HOUR_TO_SECOND
=
infos
[
Value
.
INTERVAL_HOUR_TO_SECOND
];
TYPE_ROW
=
infos
[
Value
.
ROW
]
;
infos
[
Value
.
ROW
]
=
TYPE_ROW
=
new
TypeInfo
(
Value
.
ROW
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
null
)
;
TYPE_INFOS_BY_VALUE_TYPE
=
infos
;
TYPE_INFOS_BY_VALUE_TYPE
=
infos
;
}
}
...
@@ -291,7 +318,7 @@ public class TypeInfo {
...
@@ -291,7 +318,7 @@ public class TypeInfo {
return
new
TypeInfo
(
Value
.
BYTES
,
precision
,
0
,
MathUtils
.
convertLongToInt
(
precision
)
*
2
,
null
);
return
new
TypeInfo
(
Value
.
BYTES
,
precision
,
0
,
MathUtils
.
convertLongToInt
(
precision
)
*
2
,
null
);
case
Value
.
STRING
:
case
Value
.
STRING
:
if
(
precision
<
0
)
{
if
(
precision
<
0
)
{
return
TYPE_STRING
_DEFAULT
;
return
TYPE_STRING
;
}
}
//$FALL-THROUGH$
//$FALL-THROUGH$
case
Value
.
STRING_FIXED
:
case
Value
.
STRING_FIXED
:
...
@@ -327,7 +354,7 @@ public class TypeInfo {
...
@@ -327,7 +354,7 @@ public class TypeInfo {
case
Value
.
INTERVAL_DAY_TO_HOUR
:
case
Value
.
INTERVAL_DAY_TO_HOUR
:
case
Value
.
INTERVAL_DAY_TO_MINUTE
:
case
Value
.
INTERVAL_DAY_TO_MINUTE
:
case
Value
.
INTERVAL_HOUR_TO_MINUTE
:
case
Value
.
INTERVAL_HOUR_TO_MINUTE
:
if
(
precision
<
0
||
precision
>
ValueInterval
.
MAXIMUM_PRECISION
)
{
if
(
precision
<
1
||
precision
>
ValueInterval
.
MAXIMUM_PRECISION
)
{
precision
=
ValueInterval
.
MAXIMUM_PRECISION
;
precision
=
ValueInterval
.
MAXIMUM_PRECISION
;
}
}
return
new
TypeInfo
(
type
,
precision
,
0
,
ValueInterval
.
getDisplaySize
(
type
,
(
int
)
precision
,
0
),
null
);
return
new
TypeInfo
(
type
,
precision
,
0
,
ValueInterval
.
getDisplaySize
(
type
,
(
int
)
precision
,
0
),
null
);
...
@@ -335,7 +362,7 @@ public class TypeInfo {
...
@@ -335,7 +362,7 @@ public class TypeInfo {
case
Value
.
INTERVAL_DAY_TO_SECOND
:
case
Value
.
INTERVAL_DAY_TO_SECOND
:
case
Value
.
INTERVAL_HOUR_TO_SECOND
:
case
Value
.
INTERVAL_HOUR_TO_SECOND
:
case
Value
.
INTERVAL_MINUTE_TO_SECOND
:
case
Value
.
INTERVAL_MINUTE_TO_SECOND
:
if
(
precision
<
0
||
precision
>
ValueInterval
.
MAXIMUM_PRECISION
)
{
if
(
precision
<
1
||
precision
>
ValueInterval
.
MAXIMUM_PRECISION
)
{
precision
=
ValueInterval
.
MAXIMUM_PRECISION
;
precision
=
ValueInterval
.
MAXIMUM_PRECISION
;
}
}
if
(
scale
<
0
||
scale
>
ValueInterval
.
MAXIMUM_SCALE
)
{
if
(
scale
<
0
||
scale
>
ValueInterval
.
MAXIMUM_SCALE
)
{
...
@@ -353,10 +380,6 @@ public class TypeInfo {
...
@@ -353,10 +380,6 @@ public class TypeInfo {
return
TYPE_NULL
;
return
TYPE_NULL
;
}
}
private
static
TypeInfo
createTypeInfo
(
int
valueType
,
DataType
dataType
)
{
return
new
TypeInfo
(
valueType
,
dataType
.
maxPrecision
,
dataType
.
maxScale
,
dataType
.
defaultDisplaySize
,
null
);
}
/**
/**
* Creates new instance of data type with parameters.
* Creates new instance of data type with parameters.
*
*
...
...
h2/src/test/org/h2/test/unit/TestValue.java
浏览文件 @
68ec6cf3
...
@@ -45,6 +45,7 @@ import org.h2.value.ValueDecimal;
...
@@ -45,6 +45,7 @@ import org.h2.value.ValueDecimal;
import
org.h2.value.ValueDouble
;
import
org.h2.value.ValueDouble
;
import
org.h2.value.ValueFloat
;
import
org.h2.value.ValueFloat
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueInterval
;
import
org.h2.value.ValueJavaObject
;
import
org.h2.value.ValueJavaObject
;
import
org.h2.value.ValueLobDb
;
import
org.h2.value.ValueLobDb
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueNull
;
...
@@ -83,6 +84,7 @@ public class TestValue extends TestDb {
...
@@ -83,6 +84,7 @@ public class TestValue extends TestDb {
testModulusDecimal
();
testModulusDecimal
();
testModulusOperator
();
testModulusOperator
();
testLobComparison
();
testLobComparison
();
testTypeInfo
();
}
}
private
void
testResultSetOperations
()
throws
SQLException
{
private
void
testResultSetOperations
()
throws
SQLException
{
...
@@ -502,4 +504,118 @@ public class TestValue extends TestDb {
...
@@ -502,4 +504,118 @@ public class TestValue extends TestDb {
}
}
}
}
private
void
testTypeInfo
()
{
testTypeInfoCheck
(
Value
.
UNKNOWN
,
-
1
,
-
1
,
-
1
,
TypeInfo
.
TYPE_UNKNOWN
);
try
{
TypeInfo
.
getTypeInfo
(
Value
.
UNKNOWN
);
fail
();
}
catch
(
DbException
ex
)
{
assertEquals
(
ErrorCode
.
UNKNOWN_DATA_TYPE_1
,
ex
.
getErrorCode
());
}
testTypeInfoCheck
(
Value
.
NULL
,
1
,
0
,
4
,
TypeInfo
.
TYPE_NULL
,
TypeInfo
.
getTypeInfo
(
Value
.
NULL
));
testTypeInfoCheck
(
Value
.
BOOLEAN
,
1
,
0
,
5
,
TypeInfo
.
TYPE_BOOLEAN
,
TypeInfo
.
getTypeInfo
(
Value
.
BOOLEAN
));
testTypeInfoCheck
(
Value
.
BYTE
,
3
,
0
,
4
,
TypeInfo
.
TYPE_BYTE
,
TypeInfo
.
getTypeInfo
(
Value
.
BYTE
));
testTypeInfoCheck
(
Value
.
SHORT
,
5
,
0
,
6
,
TypeInfo
.
TYPE_SHORT
,
TypeInfo
.
getTypeInfo
(
Value
.
SHORT
));
testTypeInfoCheck
(
Value
.
INT
,
10
,
0
,
11
,
TypeInfo
.
TYPE_INT
,
TypeInfo
.
getTypeInfo
(
Value
.
INT
));
testTypeInfoCheck
(
Value
.
LONG
,
19
,
0
,
20
,
TypeInfo
.
TYPE_LONG
,
TypeInfo
.
getTypeInfo
(
Value
.
LONG
));
testTypeInfoCheck
(
Value
.
FLOAT
,
7
,
0
,
15
,
TypeInfo
.
TYPE_FLOAT
,
TypeInfo
.
getTypeInfo
(
Value
.
FLOAT
));
testTypeInfoCheck
(
Value
.
DOUBLE
,
17
,
0
,
24
,
TypeInfo
.
TYPE_DOUBLE
,
TypeInfo
.
getTypeInfo
(
Value
.
DOUBLE
));
testTypeInfoCheck
(
Value
.
DECIMAL
,
Integer
.
MAX_VALUE
,
Integer
.
MAX_VALUE
,
Integer
.
MAX_VALUE
,
TypeInfo
.
TYPE_DECIMAL
,
TypeInfo
.
getTypeInfo
(
Value
.
DECIMAL
));
testTypeInfoCheck
(
Value
.
DECIMAL
,
65_535
,
32_767
,
65_537
,
TypeInfo
.
TYPE_DECIMAL_DEFAULT
);
testTypeInfoCheck
(
Value
.
TIME
,
18
,
9
,
18
,
TypeInfo
.
TYPE_TIME
,
TypeInfo
.
getTypeInfo
(
Value
.
TIME
));
for
(
int
s
=
0
;
s
<=
9
;
s
++)
{
int
d
=
s
>
0
?
s
+
9
:
8
;
testTypeInfoCheck
(
Value
.
TIME
,
d
,
s
,
d
,
TypeInfo
.
getTypeInfo
(
Value
.
TIME
,
0
,
s
,
null
));
}
testTypeInfoCheck
(
Value
.
DATE
,
10
,
0
,
10
,
TypeInfo
.
TYPE_DATE
,
TypeInfo
.
getTypeInfo
(
Value
.
DATE
));
testTypeInfoCheck
(
Value
.
TIMESTAMP
,
29
,
9
,
29
,
TypeInfo
.
TYPE_TIMESTAMP
,
TypeInfo
.
getTypeInfo
(
Value
.
TIMESTAMP
));
for
(
int
s
=
0
;
s
<=
9
;
s
++)
{
int
d
=
s
>
0
?
s
+
20
:
19
;
testTypeInfoCheck
(
Value
.
TIMESTAMP
,
d
,
s
,
d
,
TypeInfo
.
getTypeInfo
(
Value
.
TIMESTAMP
,
0
,
s
,
null
));
}
testTypeInfoCheck
(
Value
.
TIMESTAMP_TZ
,
35
,
9
,
35
,
TypeInfo
.
TYPE_TIMESTAMP_TZ
,
TypeInfo
.
getTypeInfo
(
Value
.
TIMESTAMP_TZ
));
for
(
int
s
=
0
;
s
<=
9
;
s
++)
{
int
d
=
s
>
0
?
s
+
26
:
25
;
testTypeInfoCheck
(
Value
.
TIMESTAMP_TZ
,
d
,
s
,
d
,
TypeInfo
.
getTypeInfo
(
Value
.
TIMESTAMP_TZ
,
0
,
s
,
null
));
}
testTypeInfoCheck
(
Value
.
BYTES
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
getTypeInfo
(
Value
.
BYTES
));
testTypeInfoCheck
(
Value
.
BLOB
,
Long
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
getTypeInfo
(
Value
.
BLOB
));
testTypeInfoCheck
(
Value
.
CLOB
,
Long
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
getTypeInfo
(
Value
.
CLOB
));
testTypeInfoCheck
(
Value
.
STRING
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
TYPE_STRING
,
TypeInfo
.
getTypeInfo
(
Value
.
STRING
));
testTypeInfoCheck
(
Value
.
STRING_FIXED
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
getTypeInfo
(
Value
.
STRING_FIXED
));
testTypeInfoCheck
(
Value
.
STRING_IGNORECASE
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
getTypeInfo
(
Value
.
STRING_IGNORECASE
));
testTypeInfoCheck
(
Value
.
ARRAY
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
TYPE_ARRAY
,
TypeInfo
.
getTypeInfo
(
Value
.
ARRAY
));
testTypeInfoCheck
(
Value
.
RESULT_SET
,
Integer
.
MAX_VALUE
,
Integer
.
MAX_VALUE
,
Integer
.
MAX_VALUE
,
TypeInfo
.
TYPE_RESULT_SET
,
TypeInfo
.
getTypeInfo
(
Value
.
RESULT_SET
));
testTypeInfoCheck
(
Value
.
ROW
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
TYPE_ROW
,
TypeInfo
.
getTypeInfo
(
Value
.
ROW
));
testTypeInfoCheck
(
Value
.
JAVA_OBJECT
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
TYPE_JAVA_OBJECT
,
TypeInfo
.
getTypeInfo
(
Value
.
JAVA_OBJECT
));
testTypeInfoCheck
(
Value
.
UUID
,
16
,
0
,
36
,
TypeInfo
.
TYPE_UUID
,
TypeInfo
.
getTypeInfo
(
Value
.
UUID
));
testTypeInfoCheck
(
Value
.
GEOMETRY
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
TYPE_GEOMETRY
,
TypeInfo
.
getTypeInfo
(
Value
.
GEOMETRY
));
testTypeInfoCheck
(
Value
.
ENUM
,
Integer
.
MAX_VALUE
,
0
,
Integer
.
MAX_VALUE
,
TypeInfo
.
TYPE_ENUM_UNDEFINED
,
TypeInfo
.
getTypeInfo
(
Value
.
ENUM
));
testTypeInfoInterval1
(
Value
.
INTERVAL_YEAR
);
testTypeInfoInterval1
(
Value
.
INTERVAL_MONTH
);
testTypeInfoInterval1
(
Value
.
INTERVAL_DAY
);
testTypeInfoInterval1
(
Value
.
INTERVAL_HOUR
);
testTypeInfoInterval1
(
Value
.
INTERVAL_MINUTE
);
testTypeInfoInterval2
(
Value
.
INTERVAL_SECOND
);
testTypeInfoInterval1
(
Value
.
INTERVAL_YEAR_TO_MONTH
);
testTypeInfoInterval1
(
Value
.
INTERVAL_DAY_TO_HOUR
);
testTypeInfoInterval1
(
Value
.
INTERVAL_DAY_TO_MINUTE
);
testTypeInfoInterval2
(
Value
.
INTERVAL_DAY_TO_SECOND
);
testTypeInfoInterval1
(
Value
.
INTERVAL_HOUR_TO_MINUTE
);
testTypeInfoInterval2
(
Value
.
INTERVAL_HOUR_TO_SECOND
);
testTypeInfoInterval2
(
Value
.
INTERVAL_MINUTE_TO_SECOND
);
}
private
void
testTypeInfoInterval1
(
int
type
)
{
testTypeInfoCheck
(
type
,
18
,
0
,
ValueInterval
.
getDisplaySize
(
type
,
18
,
0
),
TypeInfo
.
getTypeInfo
(
type
));
for
(
int
p
=
1
;
p
<=
18
;
p
++)
{
testTypeInfoCheck
(
type
,
p
,
0
,
ValueInterval
.
getDisplaySize
(
type
,
p
,
0
),
TypeInfo
.
getTypeInfo
(
type
,
p
,
0
,
null
));
}
}
private
void
testTypeInfoInterval2
(
int
type
)
{
testTypeInfoCheck
(
type
,
18
,
9
,
ValueInterval
.
getDisplaySize
(
type
,
18
,
9
),
TypeInfo
.
getTypeInfo
(
type
));
for
(
int
p
=
1
;
p
<=
18
;
p
++)
{
for
(
int
s
=
0
;
s
<=
9
;
s
++)
{
testTypeInfoCheck
(
type
,
p
,
s
,
ValueInterval
.
getDisplaySize
(
type
,
p
,
s
),
TypeInfo
.
getTypeInfo
(
type
,
p
,
s
,
null
));
}
}
}
private
void
testTypeInfoCheck
(
int
valueType
,
long
precision
,
int
scale
,
int
displaySize
,
TypeInfo
...
typeInfos
)
{
for
(
TypeInfo
typeInfo
:
typeInfos
)
{
testTypeInfoCheck
(
valueType
,
precision
,
scale
,
displaySize
,
typeInfo
);
}
}
private
void
testTypeInfoCheck
(
int
valueType
,
long
precision
,
int
scale
,
int
displaySize
,
TypeInfo
typeInfo
)
{
assertEquals
(
valueType
,
typeInfo
.
getValueType
());
assertEquals
(
precision
,
typeInfo
.
getPrecision
());
assertEquals
(
scale
,
typeInfo
.
getScale
());
assertEquals
(
displaySize
,
typeInfo
.
getDisplaySize
());
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论