Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
0e91d76a
Unverified
提交
0e91d76a
authored
2月 03, 2019
作者:
Evgenij Ryazanov
提交者:
GitHub
2月 03, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1713 from katzyn/value
Remove DataType.defaultDisplaySize and fix display size in TypeInfo
上级
992f5c7f
cf0283d6
显示空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
223 行增加
和
80 行删除
+223
-80
CustomDataTypesHandler.java
h2/src/main/org/h2/api/CustomDataTypesHandler.java
+13
-0
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
+76
-51
TestCustomDataTypesHandler.java
h2/src/test/org/h2/test/jdbc/TestCustomDataTypesHandler.java
+5
-1
TestDate.java
h2/src/test/org/h2/test/unit/TestDate.java
+2
-2
TestValue.java
h2/src/test/org/h2/test/unit/TestValue.java
+116
-0
没有找到文件。
h2/src/main/org/h2/api/CustomDataTypesHandler.java
浏览文件 @
0e91d76a
...
...
@@ -7,6 +7,8 @@ package org.h2.api;
import
org.h2.store.DataHandler
;
import
org.h2.value.DataType
;
import
org.h2.value.ExtTypeInfo
;
import
org.h2.value.TypeInfo
;
import
org.h2.value.Value
;
/**
...
...
@@ -36,6 +38,17 @@ public interface CustomDataTypesHandler {
*/
DataType
getDataTypeById
(
int
type
);
/**
* Get type info for the given data type identity.
*
* @param type identifier of a data type
* @param precision precision
* @param scale scale
* @param extTypeInfo the extended type information, or null
* @return type information
*/
TypeInfo
getTypeInfoById
(
int
type
,
long
precision
,
int
scale
,
ExtTypeInfo
extTypeInfo
);
/**
* Get order for custom data type given its integer id
*
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
0e91d76a
...
...
@@ -5899,7 +5899,7 @@ public class Parser {
String
columnName
=
"C"
+
(
i
+
1
);
if
(
rows
.
isEmpty
())
{
if
(
type
.
getValueType
()
==
Value
.
UNKNOWN
)
{
type
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
type
=
TypeInfo
.
TYPE_STRING
;
}
column
=
new
Column
(
columnName
,
type
);
columns
.
add
(
column
);
...
...
h2/src/main/org/h2/expression/BinaryOperation.java
浏览文件 @
0e91d76a
...
...
@@ -172,7 +172,7 @@ public class BinaryOperation extends Expression {
break
;
}
}
type
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
type
=
TypeInfo
.
TYPE_STRING
;
break
;
}
case
PLUS:
...
...
@@ -188,7 +188,7 @@ public class BinaryOperation extends Expression {
// string when text concatenation with + is enabled
if
(
opType
==
OpType
.
PLUS
&&
session
.
getDatabase
().
getMode
().
allowPlusForStringConcat
)
{
type
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
type
=
TypeInfo
.
TYPE_STRING
;
opType
=
OpType
.
CONCAT
;
}
else
{
type
=
TypeInfo
.
TYPE_DECIMAL_DEFAULT
;
...
...
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
0e91d76a
...
...
@@ -648,7 +648,7 @@ public class Aggregate extends AbstractAggregate {
}
switch
(
aggregateType
)
{
case
GROUP_CONCAT:
type
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
type
=
TypeInfo
.
TYPE_STRING
;
break
;
case
COUNT_ALL:
case
COUNT:
...
...
h2/src/main/org/h2/expression/function/Function.java
浏览文件 @
0e91d76a
...
...
@@ -2374,7 +2374,7 @@ public class Function extends Expression implements FunctionCall {
}
}
if
(
typeInfo
.
getValueType
()
==
Value
.
UNKNOWN
)
{
typeInfo
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
typeInfo
=
TypeInfo
.
TYPE_STRING
;
}
break
;
}
...
...
@@ -2406,7 +2406,7 @@ public class Function extends Expression implements FunctionCall {
}
}
if
(
typeInfo
.
getValueType
()
==
Value
.
UNKNOWN
)
{
typeInfo
=
TypeInfo
.
TYPE_STRING
_DEFAULT
;
typeInfo
=
TypeInfo
.
TYPE_STRING
;
}
break
;
}
...
...
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
0e91d76a
...
...
@@ -3187,12 +3187,12 @@ public class JdbcDatabaseMetaData extends TraceObject implements
public
ResultSet
getClientInfoProperties
()
throws
SQLException
{
Properties
clientInfo
=
conn
.
getClientInfo
();
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
(
"DEFAULT_VALUE"
,
"DEFAULT_VALUE"
,
TypeInfo
.
TYPE_STRING
_DEFAULT
);
result
.
addColumn
(
"DESCRIPTION"
,
"DESCRIPTION"
,
TypeInfo
.
TYPE_STRING
_DEFAULT
);
result
.
addColumn
(
"DEFAULT_VALUE"
,
"DEFAULT_VALUE"
,
TypeInfo
.
TYPE_STRING
);
result
.
addColumn
(
"DESCRIPTION"
,
"DESCRIPTION"
,
TypeInfo
.
TYPE_STRING
);
// 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
())
{
result
.
addRow
(
ValueString
.
get
((
String
)
entry
.
getKey
()),
ValueInt
.
get
(
Integer
.
MAX_VALUE
),
ValueString
.
EMPTY
,
ValueString
.
EMPTY
,
ValueString
.
get
((
String
)
entry
.
getValue
()));
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
0e91d76a
...
...
@@ -158,11 +158,6 @@ public class DataType {
*/
public
int
defaultScale
;
/**
* The default display size.
*/
public
int
defaultDisplaySize
;
/**
* If this data type should not be listed in the database meta data.
*/
...
...
@@ -185,7 +180,6 @@ public class DataType {
DataType
dataType
=
new
DataType
();
dataType
.
defaultPrecision
=
dataType
.
maxPrecision
=
ValueNull
.
PRECISION
;
dataType
.
defaultDisplaySize
=
ValueNull
.
DISPLAY_SIZE
;
add
(
Value
.
NULL
,
Types
.
NULL
,
dataType
,
new
String
[]{
"NULL"
},
...
...
@@ -337,7 +331,6 @@ public class DataType {
dataType
=
new
DataType
();
dataType
.
prefix
=
dataType
.
suffix
=
"'"
;
dataType
.
defaultPrecision
=
dataType
.
maxPrecision
=
ValueUuid
.
PRECISION
;
dataType
.
defaultDisplaySize
=
ValueUuid
.
DISPLAY_SIZE
;
add
(
Value
.
UUID
,
Types
.
BINARY
,
createString
(
false
),
// UNIQUEIDENTIFIER is the MSSQL mode equivalent
...
...
@@ -377,7 +370,7 @@ public class DataType {
32
);
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
,
dataType
,
new
String
[]{
"RESULT_SET"
},
...
...
@@ -441,9 +434,6 @@ public class DataType {
dataType
.
defaultScale
=
ValueInterval
.
DEFAULT_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
,
new
String
[]{(
"INTERVAL "
+
name
).
intern
()},
36
...
...
@@ -469,7 +459,6 @@ public class DataType {
dt
.
supportsScale
=
dataType
.
supportsScale
;
dt
.
defaultPrecision
=
dataType
.
defaultPrecision
;
dt
.
defaultScale
=
dataType
.
defaultScale
;
dt
.
defaultDisplaySize
=
dataType
.
defaultDisplaySize
;
dt
.
caseSensitive
=
dataType
.
caseSensitive
;
dt
.
hidden
=
i
>
0
;
dt
.
memory
=
memory
;
...
...
@@ -504,7 +493,6 @@ public class DataType {
dataType
.
maxPrecision
=
maxPrecision
;
dataType
.
defaultPrecision
=
defaultPrecision
;
dataType
.
defaultScale
=
defaultScale
;
dataType
.
defaultDisplaySize
=
defaultDisplaySize
;
if
(
needsPrecisionAndScale
)
{
dataType
.
params
=
"PRECISION,SCALE"
;
dataType
.
supportsPrecision
=
true
;
...
...
@@ -537,7 +525,6 @@ public class DataType {
dataType
.
maxScale
=
maxScale
;
dataType
.
defaultPrecision
=
precision
;
dataType
.
defaultScale
=
scale
;
dataType
.
defaultDisplaySize
=
precision
;
return
dataType
;
}
...
...
@@ -550,7 +537,6 @@ public class DataType {
dataType
.
supportsPrecision
=
true
;
dataType
.
maxPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
defaultPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
defaultDisplaySize
=
Integer
.
MAX_VALUE
;
return
dataType
;
}
...
...
@@ -568,7 +554,6 @@ public class DataType {
dataType
.
params
=
"TYPE,SRID"
;
dataType
.
maxPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
defaultPrecision
=
Integer
.
MAX_VALUE
;
dataType
.
defaultDisplaySize
=
Integer
.
MAX_VALUE
;
return
dataType
;
}
...
...
h2/src/main/org/h2/value/TypeInfo.java
浏览文件 @
0e91d76a
...
...
@@ -5,7 +5,9 @@
*/
package
org
.
h2
.
value
;
import
org.h2.api.CustomDataTypesHandler
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.IntervalQualifier
;
import
org.h2.message.DbException
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
...
...
@@ -50,6 +52,11 @@ public class TypeInfo {
*/
public
static
final
TypeInfo
TYPE_LONG
;
/**
* DECIMAL type with maximum parameters.
*/
public
static
final
TypeInfo
TYPE_DECIMAL
;
/**
* DECIMAL type with default parameters.
*/
...
...
@@ -66,7 +73,7 @@ public class TypeInfo {
public
static
final
TypeInfo
TYPE_FLOAT
;
/**
* TIME type with parameters.
* TIME type with
maximum
parameters.
*/
public
static
final
TypeInfo
TYPE_TIME
;
...
...
@@ -76,14 +83,14 @@ public class TypeInfo {
public
static
final
TypeInfo
TYPE_DATE
;
/**
* TIMESTAMP type with parameters.
* TIMESTAMP type with
maximum
parameters.
*/
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.
...
...
@@ -111,7 +118,7 @@ public class TypeInfo {
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
;
...
...
@@ -121,17 +128,17 @@ public class TypeInfo {
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
;
/**
* INTERVAL DAY TO SECOND type with parameters.
* INTERVAL DAY TO SECOND type with
maximum
parameters.
*/
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
;
...
...
@@ -153,40 +160,61 @@ public class TypeInfo {
private
final
ExtTypeInfo
extTypeInfo
;
static
{
DataType
[]
type
=
DataType
.
TYPES_BY_VALUE_TYPE
;
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_NULL
=
infos
[
Value
.
NULL
];
TYPE_BOOLEAN
=
infos
[
Value
.
BOOLEAN
];
TYPE_BYTE
=
infos
[
Value
.
BYTE
];
TYPE_SHORT
=
infos
[
Value
.
SHORT
];
TYPE_INT
=
infos
[
Value
.
INT
];
TYPE_LONG
=
infos
[
Value
.
LONG
];
TYPE_DECIMAL_DEFAULT
=
infos
[
Value
.
DECIMAL
];
TYPE_DOUBLE
=
infos
[
Value
.
DOUBLE
];
TYPE_FLOAT
=
infos
[
Value
.
FLOAT
];
TYPE_TIME
=
infos
[
Value
.
TIME
];
TYPE_DATE
=
infos
[
Value
.
DATE
];
TYPE_TIMESTAMP
=
infos
[
Value
.
TIMESTAMP
];
TYPE_STRING_DEFAULT
=
infos
[
Value
.
STRING
];
TYPE_ARRAY
=
infos
[
Value
.
ARRAY
];
TYPE_RESULT_SET
=
infos
[
Value
.
RESULT_SET
];
TYPE_JAVA_OBJECT
=
infos
[
Value
.
JAVA_OBJECT
];
TYPE_UUID
=
infos
[
Value
.
UUID
];
TYPE_GEOMETRY
=
infos
[
Value
.
GEOMETRY
];
TYPE_TIMESTAMP_TZ
=
infos
[
Value
.
TIMESTAMP_TZ
];
TYPE_ENUM_UNDEFINED
=
infos
[
Value
.
ENUM
];
infos
[
Value
.
NULL
]
=
TYPE_NULL
=
new
TypeInfo
(
Value
.
NULL
,
ValueNull
.
PRECISION
,
0
,
ValueNull
.
DISPLAY_SIZE
,
null
);
infos
[
Value
.
BOOLEAN
]
=
TYPE_BOOLEAN
=
new
TypeInfo
(
Value
.
BOOLEAN
,
ValueBoolean
.
PRECISION
,
0
,
ValueBoolean
.
DISPLAY_SIZE
,
null
);
infos
[
Value
.
BYTE
]
=
TYPE_BYTE
=
new
TypeInfo
(
Value
.
BYTE
,
ValueByte
.
PRECISION
,
0
,
ValueByte
.
DISPLAY_SIZE
,
null
);
infos
[
Value
.
SHORT
]
=
TYPE_SHORT
=
new
TypeInfo
(
Value
.
SHORT
,
ValueShort
.
PRECISION
,
0
,
ValueShort
.
DISPLAY_SIZE
,
null
);
infos
[
Value
.
INT
]
=
TYPE_INT
=
new
TypeInfo
(
Value
.
INT
,
ValueInt
.
PRECISION
,
0
,
ValueInt
.
DISPLAY_SIZE
,
null
);
infos
[
Value
.
LONG
]
=
TYPE_LONG
=
new
TypeInfo
(
Value
.
LONG
,
ValueLong
.
PRECISION
,
0
,
ValueLong
.
DISPLAY_SIZE
,
null
);
infos
[
Value
.
DECIMAL
]
=
TYPE_DECIMAL
=
new
TypeInfo
(
Value
.
DECIMAL
,
Integer
.
MAX_VALUE
,
Integer
.
MAX_VALUE
,
Integer
.
MAX_VALUE
,
null
);
TYPE_DECIMAL_DEFAULT
=
new
TypeInfo
(
Value
.
DECIMAL
,
ValueDecimal
.
DEFAULT_PRECISION
,
ValueDecimal
.
DEFAULT_SCALE
,
ValueDecimal
.
DEFAULT_PRECISION
+
2
,
null
);
infos
[
Value
.
DOUBLE
]
=
TYPE_DOUBLE
=
new
TypeInfo
(
Value
.
DOUBLE
,
ValueDouble
.
PRECISION
,
0
,
ValueDouble
.
DISPLAY_SIZE
,
null
);
infos
[
Value
.
FLOAT
]
=
TYPE_FLOAT
=
new
TypeInfo
(
Value
.
FLOAT
,
ValueFloat
.
PRECISION
,
0
,
ValueFloat
.
DISPLAY_SIZE
,
null
);
infos
[
Value
.
TIME
]
=
TYPE_TIME
=
new
TypeInfo
(
Value
.
TIME
,
ValueTime
.
MAXIMUM_PRECISION
,
ValueTime
.
MAXIMUM_SCALE
,
ValueTime
.
MAXIMUM_PRECISION
,
null
);
infos
[
Value
.
DATE
]
=
TYPE_DATE
=
new
TypeInfo
(
Value
.
DATE
,
ValueDate
.
PRECISION
,
0
,
ValueDate
.
PRECISION
,
null
);
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_TO_SECOND
=
infos
[
Value
.
INTERVAL_DAY_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
;
}
...
...
@@ -208,10 +236,11 @@ public class TypeInfo {
return
t
;
}
}
if
(
JdbcUtils
.
customDataTypesHandler
!=
null
)
{
DataType
dt
=
JdbcUtils
.
customDataTypesHandler
.
getDataTypeById
(
type
);
CustomDataTypesHandler
handler
=
JdbcUtils
.
customDataTypesHandler
;
if
(
handler
!=
null
)
{
DataType
dt
=
handler
.
getDataTypeById
(
type
);
if
(
dt
!=
null
)
{
return
createTypeInfo
(
type
,
dt
);
return
handler
.
getTypeInfoById
(
type
,
dt
.
maxPrecision
,
dt
.
maxScale
,
null
);
}
}
return
TYPE_NULL
;
...
...
@@ -289,7 +318,7 @@ public class TypeInfo {
return
new
TypeInfo
(
Value
.
BYTES
,
precision
,
0
,
MathUtils
.
convertLongToInt
(
precision
)
*
2
,
null
);
case
Value
.
STRING
:
if
(
precision
<
0
)
{
return
TYPE_STRING
_DEFAULT
;
return
TYPE_STRING
;
}
//$FALL-THROUGH$
case
Value
.
STRING_FIXED
:
...
...
@@ -325,7 +354,7 @@ public class TypeInfo {
case
Value
.
INTERVAL_DAY_TO_HOUR
:
case
Value
.
INTERVAL_DAY_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
;
}
return
new
TypeInfo
(
type
,
precision
,
0
,
ValueInterval
.
getDisplaySize
(
type
,
(
int
)
precision
,
0
),
null
);
...
...
@@ -333,7 +362,7 @@ public class TypeInfo {
case
Value
.
INTERVAL_DAY_TO_SECOND
:
case
Value
.
INTERVAL_HOUR_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
;
}
if
(
scale
<
0
||
scale
>
ValueInterval
.
MAXIMUM_SCALE
)
{
...
...
@@ -342,19 +371,15 @@ public class TypeInfo {
return
new
TypeInfo
(
type
,
precision
,
scale
,
ValueInterval
.
getDisplaySize
(
type
,
(
int
)
precision
,
scale
),
null
);
}
if
(
JdbcUtils
.
customDataTypesHandler
!=
null
)
{
DataType
dt
=
JdbcUtils
.
customDataTypesHandler
.
getDataTypeById
(
type
);
if
(
dt
!=
null
)
{
return
createTypeInfo
(
type
,
dt
);
CustomDataTypesHandler
handler
=
JdbcUtils
.
customDataTypesHandler
;
if
(
handler
!=
null
)
{
if
(
handler
.
getDataTypeById
(
type
)
!=
null
)
{
return
handler
.
getTypeInfoById
(
type
,
precision
,
scale
,
extTypeInfo
);
}
}
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.
*
...
...
h2/src/test/org/h2/test/jdbc/TestCustomDataTypesHandler.java
浏览文件 @
0e91d76a
...
...
@@ -191,7 +191,6 @@ public class TestCustomDataTypesHandler extends TestDb {
if
(
name
.
toLowerCase
(
Locale
.
ENGLISH
).
equals
(
COMPLEX_DATA_TYPE_NAME
))
{
return
complexDataType
;
}
return
null
;
}
...
...
@@ -203,6 +202,11 @@ public class TestCustomDataTypesHandler extends TestDb {
return
null
;
}
@Override
public
TypeInfo
getTypeInfoById
(
int
type
,
long
precision
,
int
scale
,
ExtTypeInfo
extTypeInfo
)
{
return
new
TypeInfo
(
type
,
0
,
0
,
ValueDouble
.
DISPLAY_SIZE
*
2
+
1
,
null
);
}
@Override
public
String
getDataTypeClassName
(
int
type
)
{
if
(
type
==
COMPLEX_DATA_TYPE_ID
)
{
...
...
h2/src/test/org/h2/test/unit/TestDate.java
浏览文件 @
0e91d76a
...
...
@@ -143,7 +143,7 @@ public class TestDate extends TestBase {
assertEquals
((
int
)
((
nanos
>>>
32
)
^
nanos
),
t1
.
hashCode
());
// Literals return maximum precision
TypeInfo
type
=
t1
.
getType
();
assertEquals
(
ValueTime
.
DEFAULT
_PRECISION
,
type
.
getDisplaySize
());
assertEquals
(
ValueTime
.
MAXIMUM
_PRECISION
,
type
.
getDisplaySize
());
assertEquals
(
ValueTime
.
MAXIMUM_PRECISION
,
type
.
getPrecision
());
assertEquals
(
"java.sql.Time"
,
t1
.
getObject
().
getClass
().
getName
());
ValueTime
t1b
=
ValueTime
.
parse
(
"11:11:11"
);
...
...
@@ -221,7 +221,7 @@ public class TestDate extends TestBase {
t1
.
hashCode
());
// Literals return maximum precision
TypeInfo
type
=
t1
.
getType
();
assertEquals
(
ValueTimestamp
.
DEFAULT
_PRECISION
,
type
.
getDisplaySize
());
assertEquals
(
ValueTimestamp
.
MAXIMUM
_PRECISION
,
type
.
getDisplaySize
());
assertEquals
(
ValueTimestamp
.
MAXIMUM_PRECISION
,
type
.
getPrecision
());
assertEquals
(
9
,
type
.
getScale
());
assertEquals
(
"java.sql.Timestamp"
,
t1
.
getObject
().
getClass
().
getName
());
...
...
h2/src/test/org/h2/test/unit/TestValue.java
浏览文件 @
0e91d76a
...
...
@@ -45,6 +45,7 @@ import org.h2.value.ValueDecimal;
import
org.h2.value.ValueDouble
;
import
org.h2.value.ValueFloat
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueInterval
;
import
org.h2.value.ValueJavaObject
;
import
org.h2.value.ValueLobDb
;
import
org.h2.value.ValueNull
;
...
...
@@ -83,6 +84,7 @@ public class TestValue extends TestDb {
testModulusDecimal
();
testModulusOperator
();
testLobComparison
();
testTypeInfo
();
}
private
void
testResultSetOperations
()
throws
SQLException
{
...
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论