Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5a481f85
提交
5a481f85
authored
3月 03, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Align precision and display size of date-time columns with JDBC specification
上级
a64c34d1
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
79 行增加
和
64 行删除
+79
-64
Parser.java
h2/src/main/org/h2/command/Parser.java
+3
-4
Function.java
h2/src/main/org/h2/expression/Function.java
+1
-1
TableLink.java
h2/src/main/org/h2/table/TableLink.java
+2
-2
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+1
-1
DataType.java
h2/src/main/org/h2/value/DataType.java
+13
-15
ValueDate.java
h2/src/main/org/h2/value/ValueDate.java
+4
-9
ValueTime.java
h2/src/main/org/h2/value/ValueTime.java
+15
-8
ValueTimestamp.java
h2/src/main/org/h2/value/ValueTimestamp.java
+15
-8
ValueTimestampTimeZone.java
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
+14
-7
TestMetaData.java
h2/src/test/org/h2/test/jdbc/TestMetaData.java
+2
-2
TestResultSet.java
h2/src/test/org/h2/test/jdbc/TestResultSet.java
+3
-3
TestDate.java
h2/src/test/org/h2/test/unit/TestDate.java
+6
-4
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
5a481f85
...
...
@@ -4433,7 +4433,6 @@ public class Parser {
if
(
t
==
Value
.
TIME
||
t
==
Value
.
TIMESTAMP
||
t
==
Value
.
TIMESTAMP_TZ
)
{
if
(
originalScale
>=
0
)
{
scale
=
originalScale
;
precision
=
dataType
.
defaultPrecision
;
switch
(
t
)
{
case
Value
.
TIME
:
if
(
original
.
equals
(
"TIME WITHOUT TIME ZONE"
))
{
...
...
@@ -4441,7 +4440,7 @@ public class Parser {
}
else
{
original
=
original
+
'('
+
originalScale
+
')'
;
}
displaySize
=
ValueTime
.
getDisplaySize
(
originalScale
);
precision
=
displaySize
=
ValueTime
.
getDisplaySize
(
originalScale
);
break
;
case
Value
.
TIMESTAMP
:
if
(
original
.
equals
(
"TIMESTAMP WITHOUT TIME ZONE"
))
{
...
...
@@ -4449,11 +4448,11 @@ public class Parser {
}
else
{
original
=
original
+
'('
+
originalScale
+
')'
;
}
displaySize
=
ValueTimestamp
.
getDisplaySize
(
originalScale
);
precision
=
displaySize
=
ValueTimestamp
.
getDisplaySize
(
originalScale
);
break
;
case
Value
.
TIMESTAMP_TZ
:
original
=
"TIMESTAMP("
+
originalScale
+
") WITH TIME ZONE"
;
displaySize
=
ValueTimestampTimeZone
.
getDisplaySize
(
originalScale
);
precision
=
displaySize
=
ValueTimestampTimeZone
.
getDisplaySize
(
originalScale
);
break
;
}
}
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
5a481f85
...
...
@@ -2590,7 +2590,7 @@ public class Function extends Expression implements FunctionCall {
t
=
Value
.
DATE
;
p
=
ValueDate
.
PRECISION
;
s
=
0
;
d
=
ValueDate
.
DISPLAY_SIZE
;
d
=
ValueDate
.
PRECISION
;
}
break
;
case
ABS:
...
...
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
5a481f85
...
...
@@ -295,10 +295,10 @@ public class TableLink extends Table {
precision
=
Math
.
max
(
ValueDate
.
PRECISION
,
precision
);
break
;
case
Types
.
TIMESTAMP
:
precision
=
Math
.
max
(
ValueTimestamp
.
PRECISION
,
precision
);
precision
=
Math
.
max
(
ValueTimestamp
.
MAXIMUM_
PRECISION
,
precision
);
break
;
case
Types
.
TIME
:
precision
=
Math
.
max
(
ValueTime
.
PRECISION
,
precision
);
precision
=
Math
.
max
(
ValueTime
.
MAXIMUM_
PRECISION
,
precision
);
break
;
}
return
precision
;
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
5a481f85
...
...
@@ -1421,7 +1421,7 @@ public class DateTimeUtils {
* @return formatted string
*/
public
static
String
timestampTimeZoneToString
(
long
dateValue
,
long
timeNanos
,
short
timeZoneOffsetMins
)
{
StringBuilder
buff
=
new
StringBuilder
(
ValueTimestampTimeZone
.
DISPLAY_SIZE
);
StringBuilder
buff
=
new
StringBuilder
(
ValueTimestampTimeZone
.
MAXIMUM_PRECISION
);
appendDate
(
buff
,
dateValue
);
buff
.
append
(
' '
);
appendTime
(
buff
,
timeNanos
,
true
);
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
5a481f85
...
...
@@ -282,24 +282,22 @@ public class DataType {
24
);
add
(
Value
.
TIME
,
Types
.
TIME
,
createDate
(
ValueTime
.
PRECISION
,
"TIME"
,
true
,
ValueTime
.
DEFAULT_SCALE
,
ValueTime
.
MAXIMUM_SCALE
,
ValueTime
.
DISPLAY_SIZE
),
createDate
(
ValueTime
.
MAXIMUM_PRECISION
,
ValueTime
.
DEFAULT_PRECISION
,
"TIME"
,
true
,
ValueTime
.
DEFAULT_SCALE
,
ValueTime
.
MAXIMUM_SCALE
),
new
String
[]{
"TIME"
,
"TIME WITHOUT TIME ZONE"
},
// 24 for ValueTime, 32 for java.sql.Time
56
);
add
(
Value
.
DATE
,
Types
.
DATE
,
createDate
(
ValueDate
.
PRECISION
,
"DATE"
,
false
,
0
,
0
,
ValueDate
.
DISPLAY_SIZE
),
createDate
(
ValueDate
.
PRECISION
,
ValueDate
.
PRECISION
,
"DATE"
,
false
,
0
,
0
),
new
String
[]{
"DATE"
},
// 24 for ValueDate, 32 for java.sql.Data
56
);
add
(
Value
.
TIMESTAMP
,
Types
.
TIMESTAMP
,
createDate
(
ValueTimestamp
.
PRECISION
,
"TIMESTAMP"
,
true
,
ValueTimestamp
.
DEFAULT_SCALE
,
ValueTimestamp
.
MAXIMUM_SCALE
,
ValueTimestamp
.
DISPLAY_SIZE
),
createDate
(
ValueTimestamp
.
MAXIMUM_PRECISION
,
ValueTimestamp
.
DEFAULT_PRECISION
,
"TIMESTAMP"
,
true
,
ValueTimestamp
.
DEFAULT_SCALE
,
ValueTimestamp
.
MAXIMUM_SCALE
),
new
String
[]{
"TIMESTAMP"
,
"TIMESTAMP WITHOUT TIME ZONE"
,
"DATETIME"
,
"DATETIME2"
,
"SMALLDATETIME"
},
// 24 for ValueTimestamp, 32 for java.sql.Timestamp
...
...
@@ -310,9 +308,9 @@ public class DataType {
// compile (on Java 1.7). Can be replaced with
// Types.TIMESTAMP_WITH_TIMEZONE once Java 1.8 is required.
add
(
Value
.
TIMESTAMP_TZ
,
2014
,
createDate
(
ValueTimestampTimeZone
.
PRECISION
,
"TIMESTAMP_TZ"
,
true
,
ValueTimestampTimeZone
.
DEFAULT_SCALE
,
ValueTimestampTimeZone
.
MAXIMUM
_SCALE
,
ValueTimestampTimeZone
.
DISPLAY_SIZ
E
),
createDate
(
ValueTimestampTimeZone
.
MAXIMUM_PRECISION
,
ValueTimestampTimeZone
.
DEFAULT_PRECISION
,
"TIMESTAMP_TZ"
,
true
,
ValueTimestampTimeZone
.
DEFAULT
_SCALE
,
ValueTimestampTimeZone
.
MAXIMUM_SCAL
E
),
new
String
[]{
"TIMESTAMP WITH TIME ZONE"
},
// 26 for ValueTimestampUtc, 32 for java.sql.Timestamp
58
...
...
@@ -466,17 +464,17 @@ public class DataType {
return
dataType
;
}
private
static
DataType
createDate
(
int
precision
,
String
prefix
,
boolean
supportsScale
,
int
scale
,
int
maxS
cale
,
int
displaySiz
e
)
{
private
static
DataType
createDate
(
int
maxPrecision
,
int
precision
,
String
prefix
,
boolean
supportsScale
,
int
s
cale
,
int
maxScal
e
)
{
DataType
dataType
=
new
DataType
();
dataType
.
prefix
=
prefix
+
" '"
;
dataType
.
suffix
=
"'"
;
dataType
.
maxPrecision
=
p
recision
;
dataType
.
maxPrecision
=
maxP
recision
;
dataType
.
supportsScale
=
supportsScale
;
dataType
.
maxScale
=
maxScale
;
dataType
.
defaultPrecision
=
precision
;
dataType
.
defaultScale
=
scale
;
dataType
.
defaultDisplaySize
=
displaySize
;
dataType
.
defaultDisplaySize
=
precision
;
return
dataType
;
}
...
...
h2/src/main/org/h2/value/ValueDate.java
浏览文件 @
5a481f85
...
...
@@ -19,15 +19,10 @@ import org.h2.util.DateTimeUtils;
public
class
ValueDate
extends
Value
{
/**
* The precision in digits.
*/
public
static
final
int
PRECISION
=
8
;
/**
* The display size of the textual representation of a date.
* The default precision and display size of the textual representation of a date.
* Example: 2000-01-02
*/
public
static
final
int
DISPLAY_SIZE
=
10
;
public
static
final
int
PRECISION
=
10
;
private
final
long
dateValue
;
...
...
@@ -97,7 +92,7 @@ public class ValueDate extends Value {
@Override
public
String
getString
()
{
StringBuilder
buff
=
new
StringBuilder
(
DISPLAY_SIZE
);
StringBuilder
buff
=
new
StringBuilder
(
PRECISION
);
DateTimeUtils
.
appendDate
(
buff
,
dateValue
);
return
buff
.
toString
();
}
...
...
@@ -114,7 +109,7 @@ public class ValueDate extends Value {
@Override
public
int
getDisplaySize
()
{
return
DISPLAY_SIZE
;
return
PRECISION
;
}
@Override
...
...
h2/src/main/org/h2/value/ValueTime.java
浏览文件 @
5a481f85
...
...
@@ -19,15 +19,16 @@ import org.h2.util.DateTimeUtils;
public
class
ValueTime
extends
Value
{
/**
* The precision in digits.
* The default precision and display size of the textual representation of a time.
* Example: 10:00:00
*/
public
static
final
int
PRECISION
=
9
;
public
static
final
int
DEFAULT_PRECISION
=
8
;
/**
* The display size of the textual representation of a time.
* Example: 10:00:00
* The
maximum precision and
display size of the textual representation of a time.
* Example: 10:00:00
.123456789
*/
static
final
int
DISPLAY_SIZE
=
8
;
public
static
final
int
MAXIMUM_PRECISION
=
1
8
;
/**
* The default scale for time.
...
...
@@ -134,7 +135,7 @@ public class ValueTime extends Value {
@Override
public
String
getString
()
{
StringBuilder
buff
=
new
StringBuilder
(
DISPLAY_SIZE
);
StringBuilder
buff
=
new
StringBuilder
(
MAXIMUM_PRECISION
);
DateTimeUtils
.
appendTime
(
buff
,
nanos
,
false
);
return
buff
.
toString
();
}
...
...
@@ -146,12 +147,18 @@ public class ValueTime extends Value {
@Override
public
long
getPrecision
()
{
return
PRECISION
;
return
MAXIMUM_
PRECISION
;
}
@Override
public
int
getDisplaySize
()
{
return
DISPLAY_SIZE
;
return
MAXIMUM_PRECISION
;
}
@Override
public
boolean
checkPrecision
(
long
precision
)
{
// TIME data type does not have precision parameter
return
true
;
}
@Override
...
...
h2/src/main/org/h2/value/ValueTimestamp.java
浏览文件 @
5a481f85
...
...
@@ -19,15 +19,16 @@ import org.h2.util.DateTimeUtils;
public
class
ValueTimestamp
extends
Value
{
/**
* The precision in digits.
* The default precision and display size of the textual representation of a timestamp.
* Example: 2001-01-01 23:59:59.123456
*/
public
static
final
int
PRECISION
=
23
;
public
static
final
int
DEFAULT_PRECISION
=
26
;
/**
* The display size of the textual representation of a timestamp.
* Example: 2001-01-01 23:59:59.
000
* The
maximum precision and
display size of the textual representation of a timestamp.
* Example: 2001-01-01 23:59:59.
123456789
*/
static
final
int
DISPLAY_SIZE
=
23
;
public
static
final
int
MAXIMUM_PRECISION
=
29
;
/**
* The default scale for timestamps.
...
...
@@ -179,7 +180,7 @@ public class ValueTimestamp extends Value {
@Override
public
String
getString
()
{
StringBuilder
buff
=
new
StringBuilder
(
DISPLAY_SIZE
);
StringBuilder
buff
=
new
StringBuilder
(
MAXIMUM_PRECISION
);
DateTimeUtils
.
appendDate
(
buff
,
dateValue
);
buff
.
append
(
' '
);
DateTimeUtils
.
appendTime
(
buff
,
timeNanos
,
true
);
...
...
@@ -193,7 +194,7 @@ public class ValueTimestamp extends Value {
@Override
public
long
getPrecision
()
{
return
PRECISION
;
return
MAXIMUM_
PRECISION
;
}
@Override
...
...
@@ -203,7 +204,13 @@ public class ValueTimestamp extends Value {
@Override
public
int
getDisplaySize
()
{
return
DISPLAY_SIZE
;
return
MAXIMUM_PRECISION
;
}
@Override
public
boolean
checkPrecision
(
long
precision
)
{
// TIMESTAMP data type does not have precision parameter
return
true
;
}
@Override
...
...
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
浏览文件 @
5a481f85
...
...
@@ -22,15 +22,16 @@ import org.h2.util.DateTimeUtils;
public
class
ValueTimestampTimeZone
extends
Value
{
/**
* The precision in digits.
* The default precision and display size of the textual representation of a timestamp.
* Example: 2001-01-01 23:59:59.123456+10:00
*/
public
static
final
int
PRECISION
=
30
;
public
static
final
int
DEFAULT_PRECISION
=
32
;
/**
* The
display size of the textual representation of a timestamp. Example:
*
2001-01-01 23:59:59.000
+10:00
* The
maximum precision and display size of the textual representation of a timestamp.
*
Example: 2001-01-01 23:59:59.123456789
+10:00
*/
public
static
final
int
DISPLAY_SIZE
=
30
;
public
static
final
int
MAXIMUM_PRECISION
=
35
;
/**
* The default scale for timestamps.
...
...
@@ -182,7 +183,7 @@ public class ValueTimestampTimeZone extends Value {
@Override
public
long
getPrecision
()
{
return
PRECISION
;
return
MAXIMUM_
PRECISION
;
}
@Override
...
...
@@ -192,7 +193,13 @@ public class ValueTimestampTimeZone extends Value {
@Override
public
int
getDisplaySize
()
{
return
DISPLAY_SIZE
;
return
MAXIMUM_PRECISION
;
}
@Override
public
boolean
checkPrecision
(
long
precision
)
{
// TIMESTAMP WITH TIME ZONE data type does not have precision parameter
return
true
;
}
@Override
...
...
h2/src/test/org/h2/test/jdbc/TestMetaData.java
浏览文件 @
5a481f85
...
...
@@ -723,9 +723,9 @@ public class TestMetaData extends TestBase {
""
+
DatabaseMetaData
.
columnNullable
,
""
,
null
,
""
+
numericType
,
"0"
,
"12"
,
"3"
,
"YES"
},
{
CATALOG
,
Constants
.
SCHEMA_MAIN
,
"TEST"
,
"DATE_V"
,
""
+
Types
.
TIMESTAMP
,
"TIMESTAMP"
,
"2
3"
,
"23
"
,
"6"
,
""
+
Types
.
TIMESTAMP
,
"TIMESTAMP"
,
"2
6"
,
"26
"
,
"6"
,
"10"
,
""
+
DatabaseMetaData
.
columnNullable
,
""
,
null
,
""
+
Types
.
TIMESTAMP
,
"0"
,
"2
3
"
,
"4"
,
"YES"
},
""
+
Types
.
TIMESTAMP
,
"0"
,
"2
6
"
,
"4"
,
"YES"
},
{
CATALOG
,
Constants
.
SCHEMA_MAIN
,
"TEST"
,
"BLOB_V"
,
""
+
Types
.
BLOB
,
"BLOB"
,
""
+
Integer
.
MAX_VALUE
,
""
+
Integer
.
MAX_VALUE
,
"0"
,
"10"
,
...
...
h2/src/test/org/h2/test/jdbc/TestResultSet.java
浏览文件 @
5a481f85
...
...
@@ -1280,11 +1280,11 @@ public class TestResultSet extends TestBase {
"TIMESTAMP '9999-12-31 23:59:59' VALUE FROM TEST ORDER BY ID"
);
assertResultSetMeta
(
rs
,
2
,
new
String
[]
{
"ID"
,
"VALUE"
},
new
int
[]
{
Types
.
INTEGER
,
Types
.
TIMESTAMP
},
new
int
[]
{
10
,
2
3
},
new
int
[]
{
0
,
9
});
new
int
[]
{
10
,
2
9
},
new
int
[]
{
0
,
9
});
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST ORDER BY ID"
);
assertResultSetMeta
(
rs
,
2
,
new
String
[]
{
"ID"
,
"VALUE"
},
new
int
[]
{
Types
.
INTEGER
,
Types
.
TIMESTAMP
},
new
int
[]
{
10
,
2
3
},
new
int
[]
{
0
,
6
});
new
int
[]
{
10
,
2
6
},
new
int
[]
{
0
,
6
});
rs
.
next
();
java
.
sql
.
Date
date
;
java
.
sql
.
Time
time
;
...
...
@@ -1494,7 +1494,7 @@ public class TestResultSet extends TestBase {
new
String
[]
{
"ID"
,
"D"
,
"T"
,
"TS"
},
new
int
[]
{
Types
.
INTEGER
,
Types
.
DATE
,
Types
.
TIME
,
Types
.
TIMESTAMP
},
new
int
[]
{
10
,
8
,
9
,
23
},
new
int
[]
{
0
,
0
,
0
,
9
});
new
int
[]
{
10
,
10
,
8
,
29
},
new
int
[]
{
0
,
0
,
0
,
9
});
rs
.
next
();
assertEquals
(
0
,
rs
.
getInt
(
1
));
...
...
h2/src/test/org/h2/test/unit/TestDate.java
浏览文件 @
5a481f85
...
...
@@ -163,8 +163,9 @@ public class TestDate extends TestBase {
assertEquals
(
Value
.
TIME
,
t1
.
getType
());
long
nanos
=
t1
.
getNanos
();
assertEquals
((
int
)
((
nanos
>>>
32
)
^
nanos
),
t1
.
hashCode
());
assertEquals
(
t1
.
getString
().
length
(),
t1
.
getDisplaySize
());
assertEquals
(
ValueTime
.
PRECISION
,
t1
.
getPrecision
());
// Literals return maximum precision
assertEquals
(
ValueTime
.
MAXIMUM_PRECISION
,
t1
.
getDisplaySize
());
assertEquals
(
ValueTime
.
MAXIMUM_PRECISION
,
t1
.
getPrecision
());
assertEquals
(
"java.sql.Time"
,
t1
.
getObject
().
getClass
().
getName
());
ValueTime
t1b
=
ValueTime
.
parse
(
"11:11:11"
);
assertTrue
(
t1
==
t1b
);
...
...
@@ -257,8 +258,9 @@ public class TestDate extends TestBase {
assertEquals
((
int
)
((
dateValue
>>>
32
)
^
dateValue
^
(
nanos
>>>
32
)
^
nanos
),
t1
.
hashCode
());
assertEquals
(
t1
.
getString
().
length
(),
t1
.
getDisplaySize
());
assertEquals
(
ValueTimestamp
.
PRECISION
,
t1
.
getPrecision
());
// Literals return maximum precision
assertEquals
(
ValueTimestamp
.
MAXIMUM_PRECISION
,
t1
.
getDisplaySize
());
assertEquals
(
ValueTimestamp
.
MAXIMUM_PRECISION
,
t1
.
getPrecision
());
assertEquals
(
9
,
t1
.
getScale
());
assertEquals
(
"java.sql.Timestamp"
,
t1
.
getObject
().
getClass
().
getName
());
ValueTimestamp
t1b
=
ValueTimestamp
.
parse
(
"2001-01-01 01:01:01.111"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论