Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1eb9a748
提交
1eb9a748
authored
2月 17, 2016
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for ALTER TABLE ... RENAME CONSTRAINT .. TO ...
上级
ad857502
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
95 行增加
和
0 行删除
+95
-0
help.csv
h2/src/docsrc/help/help.csv
+9
-0
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
CommandInterface.java
h2/src/main/org/h2/command/CommandInterface.java
+5
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+12
-0
AlterTableRenameConstraint.java
...c/main/org/h2/command/ddl/AlterTableRenameConstraint.java
+59
-0
TestAlter.java
h2/src/test/org/h2/test/db/TestAlter.java
+8
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
1eb9a748
...
...
@@ -246,6 +246,15 @@ This command commits an open transaction in this connection.
ALTER TABLE TEST ADD CONSTRAINT NAME_UNIQUE UNIQUE(NAME)
"
"Commands (DDL)","ALTER TABLE RENAME CONSTRAINT","
ALTER TABLE tableName RENAME oldConstraintName TO newConstraintName
","
Renames a constraint.
This command commits an open transaction in this connection.
","
ALTER TABLE TEST RENAME CONSTRAINT FOO TO BAR
"
"Commands (DDL)","ALTER TABLE ALTER COLUMN","
ALTER TABLE tableName ALTER COLUMN columnName
{ { dataType [ DEFAULT expression ] [ [ NOT ] NULL ] [ AUTO_INCREMENT | IDENTITY ] }
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
1eb9a748
...
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Add support for ALTER TABLE ... RENAME CONSTRAINT .. TO ...
</li>
<li>
Add support for PostgreSQL ALTER TABLE ... RENAME COLUMN .. TO ...
</li>
<li>
Improve performance of cleaning up temp tables - patch from Eric Faulhaber.
...
...
h2/src/main/org/h2/command/CommandInterface.java
浏览文件 @
1eb9a748
...
...
@@ -451,6 +451,11 @@ public interface CommandInterface {
*/
int
SHUTDOWN_DEFRAG
=
84
;
/**
* The type of a ALTER TABLE RENAME CONSTRAINT statement.
*/
int
ALTER_TABLE_RENAME_CONSTRAINT
=
85
;
/**
* Get command type.
*
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
1eb9a748
...
...
@@ -25,6 +25,7 @@ import org.h2.command.ddl.AlterTableAlterColumn;
import
org.h2.command.ddl.AlterTableDropConstraint
;
import
org.h2.command.ddl.AlterTableRename
;
import
org.h2.command.ddl.AlterTableRenameColumn
;
import
org.h2.command.ddl.AlterTableRenameConstraint
;
import
org.h2.command.ddl.AlterUser
;
import
org.h2.command.ddl.AlterView
;
import
org.h2.command.ddl.Analyze
;
...
...
@@ -5434,6 +5435,17 @@ public class Parser {
String
newName
=
readColumnIdentifier
();
command
.
setNewColumnName
(
newName
);
return
command
;
}
else
if
(
readIf
(
"CONSTRAINT"
))
{
String
constraintName
=
readIdentifierWithSchema
(
table
.
getSchema
().
getName
());
checkSchema
(
table
.
getSchema
());
read
(
"TO"
);
AlterTableRenameConstraint
command
=
new
AlterTableRenameConstraint
(
session
,
table
.
getSchema
());
command
.
setConstraintName
(
constraintName
);
String
newName
=
readColumnIdentifier
();
command
.
setNewConstraintName
(
newName
);
return
command
;
}
else
{
read
(
"TO"
);
String
newName
=
readIdentifierWithSchema
(
table
.
getSchema
()
...
...
h2/src/main/org/h2/command/ddl/AlterTableRenameConstraint.java
0 → 100644
浏览文件 @
1eb9a748
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
command
.
ddl
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandInterface
;
import
org.h2.constraint.Constraint
;
import
org.h2.engine.Right
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.schema.Schema
;
/**
* This class represents the statement
* ALTER TABLE RENAME CONSTRAINT
*/
public
class
AlterTableRenameConstraint
extends
SchemaCommand
{
private
String
constraintName
;
private
String
newConstraintName
;
public
AlterTableRenameConstraint
(
Session
session
,
Schema
schema
)
{
super
(
session
,
schema
);
}
public
void
setConstraintName
(
String
string
)
{
constraintName
=
string
;
}
public
void
setNewConstraintName
(
String
newName
)
{
this
.
newConstraintName
=
newName
;
}
@Override
public
int
update
()
{
session
.
commit
(
true
);
Constraint
constraint
=
getSchema
().
findConstraint
(
session
,
constraintName
);
if
(
constraint
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
CONSTRAINT_NOT_FOUND_1
,
constraintName
);
}
if
(
getSchema
().
findConstraint
(
session
,
newConstraintName
)
!=
null
||
newConstraintName
.
equals
(
constraintName
))
{
throw
DbException
.
get
(
ErrorCode
.
CONSTRAINT_ALREADY_EXISTS_1
,
newConstraintName
);
}
session
.
getUser
().
checkRight
(
constraint
.
getTable
(),
Right
.
ALL
);
session
.
getUser
().
checkRight
(
constraint
.
getRefTable
(),
Right
.
ALL
);
session
.
getDatabase
().
renameSchemaObject
(
session
,
constraint
,
newConstraintName
);
return
0
;
}
@Override
public
int
getType
()
{
return
CommandInterface
.
ALTER_TABLE_RENAME_CONSTRAINT
;
}
}
h2/src/test/org/h2/test/db/TestAlter.java
浏览文件 @
1eb9a748
...
...
@@ -35,6 +35,7 @@ public class TestAlter extends TestBase {
deleteDb
(
getTestName
());
conn
=
getConnection
(
getTestName
());
stat
=
conn
.
createStatement
();
testAlterTableRenameConstraint
();
testAlterTableAlterColumnAsSelfColumn
();
testAlterTableDropColumnWithReferences
();
testAlterTableDropMultipleColumns
();
...
...
@@ -140,6 +141,13 @@ public class TestAlter extends TestBase {
stat
.
execute
(
"drop table test"
);
}
private
void
testAlterTableRenameConstraint
()
throws
SQLException
{
stat
.
execute
(
"create table test(id int, name varchar(255))"
);
stat
.
execute
(
"alter table test add constraint x check (id > name)"
);
stat
.
execute
(
"alter table test rename constraint x to x2"
);
stat
.
execute
(
"drop table test"
);
}
private
void
testAlterTableDropIdentityColumn
()
throws
SQLException
{
stat
.
execute
(
"create table test(id int auto_increment, name varchar)"
);
stat
.
execute
(
"alter table test drop column id"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论