Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
42e33ea1
提交
42e33ea1
authored
11月 02, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Return same datetime values only within a command in compatibility modes
上级
e03d7a25
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
155 行增加
和
34 行删除
+155
-34
help.csv
h2/src/docsrc/help/help.csv
+8
-4
changelog.html
h2/src/docsrc/html/changelog.html
+6
-0
features.html
h2/src/docsrc/html/features.html
+8
-0
Mode.java
h2/src/main/org/h2/engine/Mode.java
+10
-0
Session.java
h2/src/main/org/h2/engine/Session.java
+15
-8
Function.java
h2/src/main/org/h2/expression/Function.java
+10
-4
DatabaseInfo.java
h2/src/main/org/h2/jmx/DatabaseInfo.java
+6
-9
Column.java
h2/src/main/org/h2/table/Column.java
+3
-3
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+1
-6
current_timestamp.sql
.../test/scripts/functions/timeanddate/current_timestamp.sql
+88
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
42e33ea1
...
...
@@ -4496,7 +4496,8 @@ CALL TRANSLATE('Hello world', 'eo', 'EO')
{ CURRENT_DATE [ () ] | CURDATE() | SYSDATE | TODAY }
","
Returns the current date.
This method always returns the same value within a transaction.
These methods always return the same value within a transaction (default)
or within a command depending on database mode.
","
CURRENT_DATE()
"
...
...
@@ -4509,7 +4510,8 @@ If fractional seconds precision is specified it should be from 0 to 9, 0 is defa
The specified value can be used only to limit precision of a result.
The actual maximum available precision depends on operating system and JVM and can be 3 (milliseconds) or higher.
Higher precision is not available before Java 9.
These methods always return the same value within a transaction.
These methods always return the same value within a transaction (default)
or within a command depending on database mode.
","
CURRENT_TIME()
"
...
...
@@ -4523,7 +4525,8 @@ If fractional seconds precision is specified it should be from 0 to 9, 6 is defa
The specified value can be used only to limit precision of a result.
The actual maximum available precision depends on operating system and JVM and can be 3 (milliseconds) or higher.
Higher precision is not available before Java 9.
This method always returns the same value within a transaction.
This method always returns the same value within a transaction (default)
or within a command depending on database mode.
","
CURRENT_TIMESTAMP()
"
...
...
@@ -4536,7 +4539,8 @@ If fractional seconds precision is specified it should be from 0 to 9, 6 is defa
The specified value can be used only to limit precision of a result.
The actual maximum available precision depends on operating system and JVM and can be 3 (milliseconds) or higher.
Higher precision is not available before Java 9.
These methods always return the same value within a transaction.
These methods always return the same value within a transaction (default)
or within a command depending on database mode.
","
LOCALTIMESTAMP()
"
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
42e33ea1
...
...
@@ -21,6 +21,12 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Issue #1536: CURRENT_TIMESTAMP result doesn't change under Transactions
</li>
<li>
Issue #239: Consider supporting Lucene 5 indexes
</li>
<li>
PR #1520: Fixes bug in PutIfAbsentDecisionMaker
</li>
<li>
Issue #1518: ENUM and VIEW with filtering on enum column
</li>
<li>
Issue #1516: Array element reference array[index] should be 1-based
...
...
h2/src/docsrc/html/features.html
浏览文件 @
42e33ea1
...
...
@@ -1056,6 +1056,7 @@ or the SQL statement <code>SET MODE DB2</code>.
results in the other value.
</li><li>
Support the pseudo-table SYSIBM.SYSDUMMY1.
</li><li>
Timestamps with dash between date and time are supported.
</li><li>
Datetime value functions return the same value within a command.
</li></ul>
<h3>
Derby Compatibility Mode
</h3>
...
...
@@ -1071,6 +1072,7 @@ or the SQL statement <code>SET MODE Derby</code>.
</li><li>
Concatenating
<code>
NULL
</code>
with another value
results in the other value.
</li><li>
Support the pseudo-table SYSIBM.SYSDUMMY1.
</li><li>
Datetime value functions return the same value within a command.
</li></ul>
<h3>
HSQLDB Compatibility Mode
</h3>
...
...
@@ -1086,6 +1088,7 @@ or the SQL statement <code>SET MODE HSQLDB</code>.
</li><li>
For unique indexes,
<code>
NULL
</code>
is distinct.
That means only one row with
<code>
NULL
</code>
in one of the columns is allowed.
</li><li>
Text can be concatenated using '+'.
</li><li>
Datetime value functions return the same value within a command.
</li></ul>
<h3>
MS SQL Server Compatibility Mode
</h3>
...
...
@@ -1106,6 +1109,7 @@ or the SQL statement <code>SET MODE MSSQLServer</code>.
data type.
</li><li><code>
IDENTITY
</code>
can be used for automatic id generation on column level.
</li><li>
Table hints are discarded. Example:
<code>
SELECT * FROM table WITH (NOLOCK)
</code>
.
</li><li>
Datetime value functions return the same value within a command.
</li></ul>
<h3>
MySQL Compatibility Mode
</h3>
...
...
@@ -1128,6 +1132,7 @@ or the SQL statement <code>SET MODE MySQL</code>. Use this mode for compatibilit
</li><li>
ON DUPLICATE KEY UPDATE is supported in INSERT statements.
</li><li>
INSERT IGNORE is partially supported and may be used to skip rows with duplicate keys if ON DUPLICATE KEY UPDATE is not specified.
</li><li>
REGEXP_REPLACE() uses \ for back-references for compatibility with MariaDB.
</li><li>
Datetime value functions return the same value within a command.
</li></ul>
<p>
Text comparison in MySQL is case insensitive by default, while in H2 it is case sensitive (as in most other databases).
...
...
@@ -1152,6 +1157,7 @@ or the SQL statement <code>SET MODE Oracle</code>.
</li><li>
Empty strings are treated like
<code>
NULL
</code>
values.
</li><li>
REGEXP_REPLACE() uses \ for back-references.
</li><li>
DATE data type is treated like TIMESTAMP(0) data type.
</li><li>
Datetime value functions return the same value within a command.
</li></ul>
<h3>
PostgreSQL Compatibility Mode
</h3>
...
...
@@ -1170,6 +1176,7 @@ or the SQL statement <code>SET MODE PostgreSQL</code>.
</li><li>
REGEXP_REPLACE() uses \ for back-references.
</li><li>
Fixed-width strings are padded with spaces.
</li><li>
MONEY data type is treated like NUMERIC(19, 2) data type.
</li><li>
Datetime value functions return the same value within a transaction.
</li></ul>
<h3>
Ignite Compatibility Mode
</h3>
...
...
@@ -1181,6 +1188,7 @@ or the SQL statement <code>SET MODE Ignite</code>.
<code>
INDEX(..)
</code>
or
<code>
KEY(..)
</code>
.
Example:
<code>
create table test(id int primary key, name varchar(255), key idx_name(name));
</code>
</li><li>
AFFINITY KEY and SHARD KEY keywords may be used in index definition.
</li><li>
Datetime value functions return the same value within a transaction.
</li></ul>
<h2
id=
"auto_reconnect"
>
Auto-Reconnect
</h2>
...
...
h2/src/main/org/h2/engine/Mode.java
浏览文件 @
42e33ea1
...
...
@@ -202,6 +202,13 @@ public class Mode {
*/
public
boolean
charToBinaryInUtf8
;
/**
* If {@code true}, datetime value function return the same value within a
* transaction, if {@code false} datetime value functions return the same
* value within a command.
*/
public
boolean
dateTimeValueWithinTransaction
;
/**
* An optional Set of hidden/disallowed column types.
* Certain DBMSs don't support all column types provided by H2, such as
...
...
@@ -221,6 +228,7 @@ public class Mode {
static
{
Mode
mode
=
new
Mode
(
ModeEnum
.
REGULAR
);
mode
.
nullConcatIsNull
=
true
;
mode
.
dateTimeValueWithinTransaction
=
true
;
add
(
mode
);
mode
=
new
Mode
(
ModeEnum
.
DB2
);
...
...
@@ -345,12 +353,14 @@ public class Mode {
dt
.
sqlType
=
Types
.
NUMERIC
;
dt
.
name
=
"MONEY"
;
mode
.
typeByNameMap
.
put
(
"MONEY"
,
dt
);
mode
.
dateTimeValueWithinTransaction
=
true
;
add
(
mode
);
mode
=
new
Mode
(
ModeEnum
.
Ignite
);
mode
.
nullConcatIsNull
=
true
;
mode
.
allowAffinityKey
=
true
;
mode
.
indexDefinitionInCreateTable
=
true
;
mode
.
dateTimeValueWithinTransaction
=
true
;
add
(
mode
);
}
...
...
h2/src/main/org/h2/engine/Session.java
浏览文件 @
42e33ea1
...
...
@@ -117,7 +117,7 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
private
boolean
closed
;
private
final
long
sessionStart
=
System
.
currentTimeMillis
();
private
ValueTimestampTimeZone
transactionStart
;
private
long
currentCommandStart
;
private
ValueTimestampTimeZone
currentCommandStart
;
private
HashMap
<
String
,
Value
>
variables
;
private
HashSet
<
ResultInterface
>
temporaryResults
;
private
int
queryTimeout
;
...
...
@@ -1205,8 +1205,8 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
* Wait for some time if this session is throttled (slowed down).
*/
public
void
throttle
()
{
if
(
currentCommandStart
==
0
)
{
currentCommandStart
=
System
.
currentTimeMillis
();
if
(
currentCommandStart
==
null
)
{
currentCommandStart
=
CurrentTimestamp
.
get
();
}
if
(
throttleNs
==
0
)
{
return
;
...
...
@@ -1246,10 +1246,14 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
if
(
command
!=
null
&&
!
command
.
isQuery
())
{
getGeneratedKeys
().
clear
(
generatedKeysRequest
);
}
if
(
queryTimeout
>
0
&&
command
!=
null
)
{
currentCommandStart
=
System
.
currentTimeMillis
();
long
now
=
System
.
nanoTime
();
cancelAtNs
=
now
+
TimeUnit
.
MILLISECONDS
.
toNanos
(
queryTimeout
);
if
(
command
!=
null
)
{
if
(
queryTimeout
>
0
)
{
currentCommandStart
=
CurrentTimestamp
.
get
();
long
now
=
System
.
nanoTime
();
cancelAtNs
=
now
+
TimeUnit
.
MILLISECONDS
.
toNanos
(
queryTimeout
);
}
else
{
currentCommandStart
=
null
;
}
}
state
=
command
==
null
?
State
.
SLEEP
:
State
.
RUNNING
;
}
...
...
@@ -1285,7 +1289,10 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
return
currentCommand
;
}
public
long
getCurrentCommandStart
()
{
public
ValueTimestampTimeZone
getCurrentCommandStart
()
{
if
(
currentCommandStart
==
null
)
{
currentCommandStart
=
CurrentTimestamp
.
get
();
}
return
currentCommandStart
;
}
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
42e33ea1
...
...
@@ -831,22 +831,28 @@ public class Function extends Expression implements FunctionCall {
}
case
CURDATE:
case
CURRENT_DATE:
{
result
=
session
.
getTransactionStart
().
convertTo
(
Value
.
DATE
);
result
=
(
database
.
getMode
().
dateTimeValueWithinTransaction
?
session
.
getTransactionStart
()
:
session
.
getCurrentCommandStart
()).
convertTo
(
Value
.
DATE
);
break
;
}
case
CURTIME:
case
CURRENT_TIME:
{
ValueTime
vt
=
(
ValueTime
)
session
.
getTransactionStart
().
convertTo
(
Value
.
TIME
);
ValueTime
vt
=
(
ValueTime
)
(
database
.
getMode
().
dateTimeValueWithinTransaction
?
session
.
getTransactionStart
()
:
session
.
getCurrentCommandStart
()).
convertTo
(
Value
.
TIME
);
result
=
vt
.
convertScale
(
false
,
v0
==
null
?
0
:
v0
.
getInt
());
break
;
}
case
LOCALTIMESTAMP:
{
Value
vt
=
session
.
getTransactionStart
().
convertTo
(
Value
.
TIMESTAMP
);
Value
vt
=
(
database
.
getMode
().
dateTimeValueWithinTransaction
?
session
.
getTransactionStart
()
:
session
.
getCurrentCommandStart
()).
convertTo
(
Value
.
TIMESTAMP
);
result
=
vt
.
convertScale
(
false
,
v0
==
null
?
6
:
v0
.
getInt
());
break
;
}
case
CURRENT_TIMESTAMP:
{
ValueTimestampTimeZone
vt
=
session
.
getTransactionStart
();
ValueTimestampTimeZone
vt
=
database
.
getMode
().
dateTimeValueWithinTransaction
?
session
.
getTransactionStart
()
:
session
.
getCurrentCommandStart
();
result
=
vt
.
convertScale
(
false
,
v0
==
null
?
6
:
v0
.
getInt
());
break
;
}
...
...
h2/src/main/org/h2/jmx/DatabaseInfo.java
浏览文件 @
42e33ea1
...
...
@@ -250,15 +250,12 @@ public class DatabaseInfo implements DatabaseInfoMBean {
append
(
'\n'
);
Command
command
=
session
.
getCurrentCommand
();
if
(
command
!=
null
)
{
buff
.
append
(
"statement: "
).
append
(
session
.
getCurrentCommand
()).
append
(
'\n'
);
long
commandStart
=
session
.
getCurrentCommandStart
();
if
(
commandStart
!=
0
)
{
buff
.
append
(
"started: "
).
append
(
new
Timestamp
(
commandStart
)).
append
(
'\n'
);
}
buff
.
append
(
"statement: "
)
.
append
(
command
)
.
append
(
'\n'
)
.
append
(
"started: "
)
.
append
(
session
.
getCurrentCommandStart
().
getString
())
.
append
(
'\n'
);
}
Table
[]
t
=
session
.
getLocks
();
if
(
t
.
length
>
0
)
{
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
42e33ea1
...
...
@@ -362,13 +362,13 @@ public class Column {
if
(
dt
.
decimal
)
{
value
=
ValueInt
.
get
(
0
).
convertTo
(
type
);
}
else
if
(
dt
.
type
==
Value
.
TIMESTAMP
)
{
value
=
session
.
get
Transaction
Start
().
convertTo
(
Value
.
TIMESTAMP
);
value
=
session
.
get
CurrentCommand
Start
().
convertTo
(
Value
.
TIMESTAMP
);
}
else
if
(
dt
.
type
==
Value
.
TIMESTAMP_TZ
)
{
value
=
session
.
get
Transaction
Start
();
value
=
session
.
get
CurrentCommand
Start
();
}
else
if
(
dt
.
type
==
Value
.
TIME
)
{
value
=
ValueTime
.
fromNanos
(
0
);
}
else
if
(
dt
.
type
==
Value
.
DATE
)
{
value
=
session
.
get
Transaction
Start
().
convertTo
(
Value
.
DATE
);
value
=
session
.
get
CurrentCommand
Start
().
convertTo
(
Value
.
DATE
);
}
else
{
value
=
ValueString
.
get
(
""
).
convertTo
(
type
);
}
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
42e33ea1
...
...
@@ -1848,14 +1848,9 @@ public class MetaTable extends Table {
break
;
}
case
SESSIONS:
{
long
now
=
System
.
currentTimeMillis
();
for
(
Session
s
:
database
.
getSessions
(
false
))
{
if
(
admin
||
s
==
session
)
{
Command
command
=
s
.
getCurrentCommand
();
long
start
=
s
.
getCurrentCommandStart
();
if
(
start
==
0
)
{
start
=
now
;
}
int
blockingSessionId
=
s
.
getBlockingSessionId
();
add
(
rows
,
// ID
...
...
@@ -1867,7 +1862,7 @@ public class MetaTable extends Table {
// STATEMENT
command
==
null
?
null
:
command
.
toString
(),
// STATEMENT_START
DateTimeUtils
.
timestampTimeZoneFromMillis
(
start
),
command
==
null
?
null
:
s
.
getCurrentCommandStart
(
),
// CONTAINS_UNCOMMITTED
ValueBoolean
.
get
(
s
.
containsUncommitted
()),
// STATE
...
...
h2/src/test/org/h2/test/scripts/functions/timeanddate/current_timestamp.sql
浏览文件 @
42e33ea1
...
...
@@ -11,3 +11,91 @@ SELECT CAST(CURRENT_TIMESTAMP(0) AS TIMESTAMP(9)) = LOCALTIMESTAMP(0);
SELECT
CAST
(
CURRENT_TIMESTAMP
(
9
)
AS
TIMESTAMP
(
9
))
=
LOCALTIMESTAMP
(
9
);
>>
TRUE
@
reconnect
off
SET
AUTOCOMMIT
OFF
;
>
ok
CREATE
ALIAS
SLEEP
FOR
"java.lang.Thread.sleep(long)"
;
>
ok
CREATE
TABLE
TEST
(
I
IDENTITY
PRIMARY
KEY
,
T
TIMESTAMP
(
9
)
WITH
TIME
ZONE
);
>
ok
INSERT
INTO
TEST
(
T
)
VALUES
(
CURRENT_TIMESTAMP
(
9
)),
(
CURRENT_TIMESTAMP
(
9
));
>
update
count
:
2
CALL
SLEEP
(
10
);
>>
null
INSERT
INTO
TEST
(
T
)
VALUES
(
CURRENT_TIMESTAMP
(
9
));
>
update
count
:
1
COMMIT
;
>
ok
INSERT
INTO
TEST
(
T
)
VALUES
(
CURRENT_TIMESTAMP
(
9
));
>
update
count
:
1
COMMIT
;
>
ok
-- same statement
SELECT
(
SELECT
T
FROM
TEST
WHERE
I
=
1
)
=
(
SELECT
T
FROM
TEST
WHERE
I
=
2
);
>>
TRUE
-- same transaction
SELECT
(
SELECT
T
FROM
TEST
WHERE
I
=
2
)
=
(
SELECT
T
FROM
TEST
WHERE
I
=
3
);
>>
TRUE
-- another transaction
SELECT
(
SELECT
T
FROM
TEST
WHERE
I
=
3
)
=
(
SELECT
T
FROM
TEST
WHERE
I
=
4
);
>>
FALSE
SET
MODE
MySQL
;
>
ok
INSERT
INTO
TEST
(
T
)
VALUES
(
CURRENT_TIMESTAMP
(
9
)),
(
CURRENT_TIMESTAMP
(
9
));
>
update
count
:
2
CALL
SLEEP
(
10
);
>>
null
INSERT
INTO
TEST
(
T
)
VALUES
(
CURRENT_TIMESTAMP
(
9
));
>
update
count
:
1
COMMIT
;
>
ok
INSERT
INTO
TEST
(
T
)
VALUES
(
CURRENT_TIMESTAMP
(
9
));
>
update
count
:
1
COMMIT
;
>
ok
-- same statement
SELECT
(
SELECT
T
FROM
TEST
WHERE
I
=
5
)
=
(
SELECT
T
FROM
TEST
WHERE
I
=
6
);
>>
TRUE
-- same transaction
SELECT
(
SELECT
T
FROM
TEST
WHERE
I
=
6
)
=
(
SELECT
T
FROM
TEST
WHERE
I
=
7
);
>>
FALSE
-- another transaction
SELECT
(
SELECT
T
FROM
TEST
WHERE
I
=
7
)
=
(
SELECT
T
FROM
TEST
WHERE
I
=
8
);
>>
FALSE
SET
MODE
Regular
;
>
ok
DROP
TABLE
TEST
;
>
ok
DROP
ALIAS
SLEEP
;
>
ok
SET
AUTOCOMMIT
ON
;
>
ok
@
reconnect
on
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论