Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d2b505e3
提交
d2b505e3
authored
6月 02, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support of CONTINUE | RESTART IDENTITY to TRUNCATE TABLE
上级
fe655e2b
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
101 行增加
和
1 行删除
+101
-1
help.csv
h2/src/docsrc/help/help.csv
+2
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+11
-0
TruncateTable.java
h2/src/main/org/h2/command/ddl/TruncateTable.java
+20
-0
truncateTable.sql
h2/src/test/org/h2/test/scripts/ddl/truncateTable.sql
+68
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
d2b505e3
...
@@ -974,7 +974,7 @@ DROP VIEW TEST_VIEW
...
@@ -974,7 +974,7 @@ DROP VIEW TEST_VIEW
"
"
"Commands (DDL)","TRUNCATE TABLE","
"Commands (DDL)","TRUNCATE TABLE","
TRUNCATE TABLE tableName
TRUNCATE TABLE tableName
[ [ CONTINUE | RESTART ] IDENTITY ]
","
","
Removes all rows from a table.
Removes all rows from a table.
Unlike DELETE FROM without where clause, this command can not be rolled back.
Unlike DELETE FROM without where clause, this command can not be rolled back.
...
@@ -982,6 +982,7 @@ This command is faster than DELETE without where clause.
...
@@ -982,6 +982,7 @@ This command is faster than DELETE without where clause.
Only regular data tables without foreign key constraints can be truncated
Only regular data tables without foreign key constraints can be truncated
(except if referential integrity is disabled for this database or for this table).
(except if referential integrity is disabled for this database or for this table).
Linked tables can't be truncated.
Linked tables can't be truncated.
If RESTART IDENTITY is specified next values for auto-incremented columns are restarted.
This command commits an open transaction in this connection.
This command commits an open transaction in this connection.
","
","
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
d2b505e3
...
@@ -1578,8 +1578,19 @@ public class Parser {
...
@@ -1578,8 +1578,19 @@ public class Parser {
private
Prepared
parseTruncate
()
{
private
Prepared
parseTruncate
()
{
read
(
"TABLE"
);
read
(
"TABLE"
);
Table
table
=
readTableOrView
();
Table
table
=
readTableOrView
();
boolean
restart
;
if
(
readIf
(
"CONTINUE"
))
{
read
(
"IDENTITY"
);
restart
=
false
;
}
else
if
(
readIf
(
"RESTART"
))
{
read
(
"IDENTITY"
);
restart
=
true
;
}
else
{
restart
=
false
;
}
TruncateTable
command
=
new
TruncateTable
(
session
);
TruncateTable
command
=
new
TruncateTable
(
session
);
command
.
setTable
(
table
);
command
.
setTable
(
table
);
command
.
setRestart
(
restart
);
return
command
;
return
command
;
}
}
...
...
h2/src/main/org/h2/command/ddl/TruncateTable.java
浏览文件 @
d2b505e3
...
@@ -10,6 +10,8 @@ import org.h2.command.CommandInterface;
...
@@ -10,6 +10,8 @@ import org.h2.command.CommandInterface;
import
org.h2.engine.Right
;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.schema.Sequence
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.table.Table
;
/**
/**
...
@@ -20,6 +22,8 @@ public class TruncateTable extends DefineCommand {
...
@@ -20,6 +22,8 @@ public class TruncateTable extends DefineCommand {
private
Table
table
;
private
Table
table
;
private
boolean
restart
;
public
TruncateTable
(
Session
session
)
{
public
TruncateTable
(
Session
session
)
{
super
(
session
);
super
(
session
);
}
}
...
@@ -28,6 +32,10 @@ public class TruncateTable extends DefineCommand {
...
@@ -28,6 +32,10 @@ public class TruncateTable extends DefineCommand {
this
.
table
=
table
;
this
.
table
=
table
;
}
}
public
void
setRestart
(
boolean
restart
)
{
this
.
restart
=
restart
;
}
@Override
@Override
public
int
update
()
{
public
int
update
()
{
session
.
commit
(
true
);
session
.
commit
(
true
);
...
@@ -37,6 +45,18 @@ public class TruncateTable extends DefineCommand {
...
@@ -37,6 +45,18 @@ public class TruncateTable extends DefineCommand {
session
.
getUser
().
checkRight
(
table
,
Right
.
DELETE
);
session
.
getUser
().
checkRight
(
table
,
Right
.
DELETE
);
table
.
lock
(
session
,
true
,
true
);
table
.
lock
(
session
,
true
,
true
);
table
.
truncate
(
session
);
table
.
truncate
(
session
);
if
(
restart
)
{
for
(
Column
column
:
table
.
getColumns
())
{
Sequence
sequence
=
column
.
getSequence
();
if
(
sequence
!=
null
)
{
long
min
=
sequence
.
getMinValue
();
if
(
min
!=
sequence
.
getCurrentValue
())
{
sequence
.
modify
(
min
,
null
,
null
,
null
);
session
.
getDatabase
().
updateMeta
(
session
,
sequence
);
}
}
}
}
return
0
;
return
0
;
}
}
...
...
h2/src/test/org/h2/test/scripts/ddl/truncateTable.sql
浏览文件 @
d2b505e3
...
@@ -55,3 +55,71 @@ DROP TABLE CHILD;
...
@@ -55,3 +55,71 @@ DROP TABLE CHILD;
DROP
TABLE
PARENT
;
DROP
TABLE
PARENT
;
>
ok
>
ok
CREATE
SEQUENCE
SEQ2
;
>
ok
CREATE
SEQUENCE
SEQ3
;
>
ok
CREATE
TABLE
TEST
(
ID1
BIGINT
AUTO_INCREMENT
NOT
NULL
,
ID2
BIGINT
NOT
NULL
DEFAULT
NEXT
VALUE
FOR
SEQ2
NULL_TO_DEFAULT
SEQUENCE
SEQ2
,
ID3
BIGINT
NOT
NULL
DEFAULT
NEXT
VALUE
FOR
SEQ3
NULL_TO_DEFAULT
,
VALUE
INT
NOT
NULL
);
>
ok
INSERT
INTO
TEST
(
VALUE
)
VALUES
(
1
),
(
2
);
>
update
count
:
2
SELECT
*
FROM
TEST
ORDER
BY
VALUE
;
>
ID1
ID2
ID3
VALUE
>
--- --- --- -----
>
1
1
1
1
>
2
2
2
2
>
rows
(
ordered
):
2
TRUNCATE
TABLE
TEST
;
>
ok
INSERT
INTO
TEST
(
VALUE
)
VALUES
(
1
),
(
2
);
>
update
count
:
2
SELECT
*
FROM
TEST
ORDER
BY
VALUE
;
>
ID1
ID2
ID3
VALUE
>
--- --- --- -----
>
3
3
3
1
>
4
4
4
2
>
rows
(
ordered
):
2
TRUNCATE
TABLE
TEST
CONTINUE
IDENTITY
;
>
ok
INSERT
INTO
TEST
(
VALUE
)
VALUES
(
1
),
(
2
);
>
update
count
:
2
SELECT
*
FROM
TEST
ORDER
BY
VALUE
;
>
ID1
ID2
ID3
VALUE
>
--- --- --- -----
>
5
5
5
1
>
6
6
6
2
>
rows
(
ordered
):
2
TRUNCATE
TABLE
TEST
RESTART
IDENTITY
;
>
ok
INSERT
INTO
TEST
(
VALUE
)
VALUES
(
1
),
(
2
);
>
update
count
:
2
SELECT
*
FROM
TEST
ORDER
BY
VALUE
;
>
ID1
ID2
ID3
VALUE
>
--- --- --- -----
>
1
1
7
1
>
2
2
8
2
>
rows
(
ordered
):
2
DROP
TABLE
TEST
;
>
ok
DROP
SEQUENCE
SEQ3
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论