Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5d27e1e6
Unverified
提交
5d27e1e6
authored
2月 23, 2018
作者:
Noel Grandin
提交者:
GitHub
2月 23, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #898 from katzyn/datetime
Parse TIME WITHOUT TIME ZONE and fix TIMESTAMP as column name
上级
e861f6b5
82bfdacb
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
95 行增加
和
13 行删除
+95
-13
help.csv
h2/src/docsrc/help/help.csv
+2
-2
Parser.java
h2/src/main/org/h2/command/Parser.java
+34
-7
DataType.java
h2/src/main/org/h2/value/DataType.java
+4
-4
time.sql
h2/src/test/org/h2/test/scripts/datatypes/time.sql
+39
-0
timestamp.sql
h2/src/test/org/h2/test/scripts/datatypes/timestamp.sql
+16
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
5d27e1e6
...
...
@@ -2298,7 +2298,7 @@ Each table has a pseudo-column named ""_ROWID_"" that contains the unique row id
"
"Other Grammar","Time","
TIME 'hh:mm:ss[.nnnnnnnnn]'
TIME
[ WITHOUT TIME ZONE ]
'hh:mm:ss[.nnnnnnnnn]'
","
A time literal. A value is between 0:00:00 and 23:59:59.999999999
and has nanosecond resolution.
...
...
@@ -2433,7 +2433,7 @@ REAL
"
"Data Types","TIME Type","
TIME
TIME
[ WITHOUT TIME ZONE ]
","
The time data type. The format is hh:mm:ss[.nnnnnnnnn].
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
5d27e1e6
...
...
@@ -3137,6 +3137,23 @@ public class Parser {
read
(
"FOR"
);
Sequence
sequence
=
readSequence
();
r
=
new
SequenceValue
(
sequence
);
}
else
if
(
equalsToken
(
"TIME"
,
name
))
{
boolean
without
=
readIf
(
"WITHOUT"
);
if
(
without
)
{
read
(
"TIME"
);
read
(
"ZONE"
);
}
if
(
currentTokenType
!=
VALUE
||
currentValue
.
getType
()
!=
Value
.
STRING
)
{
if
(
without
)
{
throw
getSyntaxError
();
}
r
=
new
ExpressionColumn
(
database
,
null
,
null
,
name
);
}
else
{
String
time
=
currentValue
.
getString
();
read
();
r
=
ValueExpression
.
get
(
ValueTime
.
parse
(
time
));
}
}
else
if
(
equalsToken
(
"TIMESTAMP"
,
name
))
{
if
(
readIf
(
"WITH"
))
{
read
(
"TIME"
);
...
...
@@ -3149,17 +3166,22 @@ public class Parser {
read
();
r
=
ValueExpression
.
get
(
ValueTimestampTimeZone
.
parse
(
timestamp
));
}
else
{
if
(
readIf
(
"WITHOUT"
))
{
boolean
without
=
readIf
(
"WITHOUT"
);
if
(
without
)
{
read
(
"TIME"
);
read
(
"ZONE"
);
}
if
(
currentTokenType
!=
VALUE
||
currentValue
.
getType
()
!=
Value
.
STRING
)
{
throw
getSyntaxError
();
if
(
without
)
{
throw
getSyntaxError
();
}
r
=
new
ExpressionColumn
(
database
,
null
,
null
,
name
);
}
else
{
String
timestamp
=
currentValue
.
getString
();
read
();
r
=
ValueExpression
.
get
(
ValueTimestamp
.
parse
(
timestamp
,
database
.
getMode
()));
}
String
timestamp
=
currentValue
.
getString
();
read
();
r
=
ValueExpression
.
get
(
ValueTimestamp
.
parse
(
timestamp
,
database
.
getMode
()));
}
}
else
if
(
currentTokenType
==
VALUE
&&
currentValue
.
getType
()
==
Value
.
STRING
)
{
...
...
@@ -3168,8 +3190,7 @@ public class Parser {
String
date
=
currentValue
.
getString
();
read
();
r
=
ValueExpression
.
get
(
ValueDate
.
parse
(
date
));
}
else
if
(
equalsToken
(
"TIME"
,
name
)
||
equalsToken
(
"T"
,
name
))
{
}
else
if
(
equalsToken
(
"T"
,
name
))
{
String
time
=
currentValue
.
getString
();
read
();
r
=
ValueExpression
.
get
(
ValueTime
.
parse
(
time
));
...
...
@@ -4340,6 +4361,12 @@ public class Parser {
if
(
readIf
(
"VARYING"
))
{
original
+=
" VARYING"
;
}
}
else
if
(
readIf
(
"TIME"
))
{
if
(
readIf
(
"WITHOUT"
))
{
read
(
"TIME"
);
read
(
"ZONE"
);
original
+=
" WITHOUT TIME ZONE"
;
}
}
else
if
(
readIf
(
"TIMESTAMP"
))
{
if
(
readIf
(
"WITH"
))
{
read
(
"TIME"
);
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
5d27e1e6
...
...
@@ -66,9 +66,9 @@ public class DataType {
* The list of types. An ArrayList so that Tomcat doesn't set it to null
* when clearing references.
*/
private
static
final
ArrayList
<
DataType
>
TYPES
=
New
.
arrayList
(
);
private
static
final
HashMap
<
String
,
DataType
>
TYPES_BY_NAME
=
new
HashMap
<>();
private
static
final
HashMap
<
Integer
,
DataType
>
TYPES_BY_VALUE_TYPE
=
new
HashMap
<>();
private
static
final
ArrayList
<
DataType
>
TYPES
=
new
ArrayList
<>(
96
);
private
static
final
HashMap
<
String
,
DataType
>
TYPES_BY_NAME
=
new
HashMap
<>(
96
);
private
static
final
HashMap
<
Integer
,
DataType
>
TYPES_BY_VALUE_TYPE
=
new
HashMap
<>(
48
);
/**
* The value type of this data type.
...
...
@@ -289,7 +289,7 @@ public class DataType {
);
add
(
Value
.
TIME
,
Types
.
TIME
,
"Time"
,
createDate
(
ValueTime
.
PRECISION
,
"TIME"
,
0
,
ValueTime
.
DISPLAY_SIZE
),
new
String
[]{
"TIME"
},
new
String
[]{
"TIME"
,
"TIME WITHOUT TIME ZONE"
},
// 24 for ValueTime, 32 for java.sql.Time
56
);
...
...
h2/src/test/org/h2/test/scripts/datatypes/time.sql
浏览文件 @
5d27e1e6
...
...
@@ -2,3 +2,42 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
CREATE
TABLE
TEST
(
T1
TIME
,
T2
TIME
WITHOUT
TIME
ZONE
);
>
ok
INSERT
INTO
TEST
(
T1
,
T2
)
VALUES
(
TIME
'10:00:00'
,
TIME
WITHOUT
TIME
ZONE
'10:00:00'
);
>
update
count
:
1
SELECT
T1
,
T2
,
T1
=
T2
FROM
TEST
;
>
T1
T2
T1
=
T2
>
-------- -------- -------
>
10
:
00
:
00
10
:
00
:
00
TRUE
>
rows
:
1
SELECT
COLUMN_NAME
,
DATA_TYPE
,
TYPE_NAME
,
COLUMN_TYPE
FROM
INFORMATION_SCHEMA
.
COLUMNS
WHERE
TABLE_NAME
=
'TEST'
ORDER
BY
ORDINAL_POSITION
;
>
COLUMN_NAME
DATA_TYPE
TYPE_NAME
COLUMN_TYPE
>
----------- --------- --------- ----------------------
>
T1
92
TIME
TIME
>
T2
92
TIME
TIME
WITHOUT
TIME
ZONE
>
rows
(
ordered
):
2
DROP
TABLE
TEST
;
>
ok
-- Check that TIME is allowed as a column name
CREATE
TABLE
TEST
(
TIME
TIME
);
>
ok
INSERT
INTO
TEST
VALUES
(
TIME
'08:00:00'
);
>
update
count
:
1
SELECT
TIME
FROM
TEST
;
>
TIME
>
--------
>
08
:
00
:
00
>
rows
:
1
DROP
TABLE
TEST
;
>
ok
h2/src/test/org/h2/test/scripts/datatypes/timestamp.sql
浏览文件 @
5d27e1e6
...
...
@@ -25,3 +25,19 @@ SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.CO
DROP
TABLE
TEST
;
>
ok
-- Check that TIMESTAMP is allowed as a column name
CREATE
TABLE
TEST
(
TIMESTAMP
TIMESTAMP
);
>
ok
INSERT
INTO
TEST
VALUES
(
TIMESTAMP
'1999-12-31 08:00:00'
);
>
update
count
:
1
SELECT
TIMESTAMP
FROM
TEST
;
>
TIMESTAMP
>
---------------------
>
1999
-
12
-
31
08
:
00
:
00
.
0
>
rows
:
1
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论