Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
eadac55f
提交
eadac55f
authored
5月 20, 2016
作者:
lukaseder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[#285] Add support for ALTER SEQUENCE IF EXISTS
上级
77609335
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
47 行增加
和
8 行删除
+47
-8
help.csv
h2/src/docsrc/help/help.csv
+1
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+4
-3
AlterSequence.java
h2/src/main/org/h2/command/dml/AlterSequence.java
+19
-3
help.csv
h2/src/main/org/h2/res/help.csv
+5
-1
testScript.sql
h2/src/test/org/h2/test/testScript.sql
+18
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
eadac55f
...
@@ -210,7 +210,7 @@ ALTER SCHEMA TEST RENAME TO PRODUCTION
...
@@ -210,7 +210,7 @@ ALTER SCHEMA TEST RENAME TO PRODUCTION
"
"
"Commands (DDL)","ALTER SEQUENCE","
"Commands (DDL)","ALTER SEQUENCE","
ALTER SEQUENCE sequenceName [ RESTART WITH long ] [ INCREMENT BY long ]
ALTER SEQUENCE
[ IF EXISTS ]
sequenceName [ RESTART WITH long ] [ INCREMENT BY long ]
[ MINVALUE long | NOMINVALUE | NO MINVALUE ]
[ MINVALUE long | NOMINVALUE | NO MINVALUE ]
[ MAXVALUE long | NOMAXVALUE | NO MAXVALUE ]
[ MAXVALUE long | NOMAXVALUE | NO MAXVALUE ]
[ CYCLE long | NOCYCLE | NO CYCLE ]
[ CYCLE long | NOCYCLE | NO CYCLE ]
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
eadac55f
...
@@ -4891,10 +4891,11 @@ public class Parser {
...
@@ -4891,10 +4891,11 @@ public class Parser {
}
}
private
AlterSequence
parseAlterSequence
()
{
private
AlterSequence
parseAlterSequence
()
{
boolean
ifExists
=
readIfExists
(
false
);
String
sequenceName
=
readIdentifierWithSchema
();
String
sequenceName
=
readIdentifierWithSchema
();
Sequence
sequence
=
getSchema
().
getSequence
(
sequenceName
);
AlterSequence
command
=
new
AlterSequence
(
session
,
getSchema
()
);
AlterSequence
command
=
new
AlterSequence
(
session
,
sequence
.
getSchema
()
);
command
.
setSequenceName
(
sequenceName
);
command
.
set
Sequence
(
sequence
);
command
.
set
IfExists
(
ifExists
);
while
(
true
)
{
while
(
true
)
{
if
(
readIf
(
"RESTART"
))
{
if
(
readIf
(
"RESTART"
))
{
read
(
"WITH"
);
read
(
"WITH"
);
...
...
h2/src/main/org/h2/command/dml/AlterSequence.java
浏览文件 @
eadac55f
...
@@ -24,7 +24,9 @@ import org.h2.table.Table;
...
@@ -24,7 +24,9 @@ import org.h2.table.Table;
*/
*/
public
class
AlterSequence
extends
SchemaCommand
{
public
class
AlterSequence
extends
SchemaCommand
{
private
boolean
ifExists
;
private
Table
table
;
private
Table
table
;
private
String
sequenceName
;
private
Sequence
sequence
;
private
Sequence
sequence
;
private
Expression
start
;
private
Expression
start
;
private
Expression
increment
;
private
Expression
increment
;
...
@@ -37,8 +39,12 @@ public class AlterSequence extends SchemaCommand {
...
@@ -37,8 +39,12 @@ public class AlterSequence extends SchemaCommand {
super
(
session
,
schema
);
super
(
session
,
schema
);
}
}
public
void
setSequence
(
Sequence
sequence
)
{
public
void
setIfExists
(
boolean
b
)
{
this
.
sequence
=
sequence
;
ifExists
=
b
;
}
public
void
setSequenceName
(
String
sequenceName
)
{
this
.
sequenceName
=
sequenceName
;
}
}
@Override
@Override
...
@@ -49,7 +55,7 @@ public class AlterSequence extends SchemaCommand {
...
@@ -49,7 +55,7 @@ public class AlterSequence extends SchemaCommand {
public
void
setColumn
(
Column
column
)
{
public
void
setColumn
(
Column
column
)
{
table
=
column
.
getTable
();
table
=
column
.
getTable
();
sequence
=
column
.
getSequence
();
sequence
=
column
.
getSequence
();
if
(
sequence
==
null
)
{
if
(
sequence
==
null
&&
!
ifExists
)
{
throw
DbException
.
get
(
ErrorCode
.
SEQUENCE_NOT_FOUND_1
,
column
.
getSQL
());
throw
DbException
.
get
(
ErrorCode
.
SEQUENCE_NOT_FOUND_1
,
column
.
getSQL
());
}
}
}
}
...
@@ -81,6 +87,16 @@ public class AlterSequence extends SchemaCommand {
...
@@ -81,6 +87,16 @@ public class AlterSequence extends SchemaCommand {
@Override
@Override
public
int
update
()
{
public
int
update
()
{
Database
db
=
session
.
getDatabase
();
Database
db
=
session
.
getDatabase
();
if
(
sequence
==
null
)
{
sequence
=
getSchema
().
findSequence
(
sequenceName
);
if
(
sequence
==
null
)
{
if
(!
ifExists
)
{
throw
DbException
.
get
(
ErrorCode
.
SEQUENCE_NOT_FOUND_1
,
sequenceName
);
}
else
{
return
0
;
}
}
}
if
(
table
!=
null
)
{
if
(
table
!=
null
)
{
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
}
}
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
eadac55f
...
@@ -75,7 +75,7 @@ ALTER SCHEMA schema RENAME TO newSchemaName
...
@@ -75,7 +75,7 @@ ALTER SCHEMA schema RENAME TO newSchemaName
","
","
Renames a schema."
Renames a schema."
"Commands (DDL)","ALTER SEQUENCE","
"Commands (DDL)","ALTER SEQUENCE","
ALTER SEQUENCE sequenceName [ RESTART WITH long ] [ INCREMENT BY long ]
ALTER SEQUENCE
[ IF EXISTS ]
sequenceName [ RESTART WITH long ] [ INCREMENT BY long ]
[ MINVALUE long | NOMINVALUE | NO MINVALUE ]
[ MINVALUE long | NOMINVALUE | NO MINVALUE ]
[ MAXVALUE long | NOMAXVALUE | NO MAXVALUE ]
[ MAXVALUE long | NOMAXVALUE | NO MAXVALUE ]
[ CYCLE long | NOCYCLE | NO CYCLE ]
[ CYCLE long | NOCYCLE | NO CYCLE ]
...
@@ -92,6 +92,10 @@ Adds a new column to a table."
...
@@ -92,6 +92,10 @@ Adds a new column to a table."
ALTER TABLE tableName ADD constraint [ CHECK | NOCHECK ]
ALTER TABLE tableName ADD constraint [ CHECK | NOCHECK ]
","
","
Adds a constraint to a table."
Adds a constraint to a table."
"Commands (DDL)","ALTER TABLE RENAME CONSTRAINT","
ALTER TABLE tableName RENAME oldConstraintName TO newConstraintName
","
Renames a constraint."
"Commands (DDL)","ALTER TABLE ALTER COLUMN","
"Commands (DDL)","ALTER TABLE ALTER COLUMN","
ALTER TABLE tableName ALTER COLUMN columnName
ALTER TABLE tableName ALTER COLUMN columnName
{ { dataType [ DEFAULT expression ] [ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] }
{ { dataType [ DEFAULT expression ] [ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] }
...
...
h2/src/test/org/h2/test/testScript.sql
浏览文件 @
eadac55f
...
@@ -4455,6 +4455,24 @@ create index if not exists idx_id on s.test(id);
...
@@ -4455,6 +4455,24 @@ create index if not exists idx_id on s.test(id);
alter index s.idx_id rename to s.index_id;
alter index s.idx_id rename to s.index_id;
> ok
> ok
alter sequence if exists s.seq restart with 10;
> ok
create sequence s.seq cache 0;
> ok
alter sequence if exists s.seq restart with 3;
> ok
select s.seq.nextval as x;
> X
> -
> 3
> rows: 1
drop sequence s.seq;
> ok
create sequence s.seq cache 0;
create sequence s.seq cache 0;
> ok
> ok
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论