Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
fb5b206f
Unverified
提交
fb5b206f
authored
4月 27, 2018
作者:
Noel Grandin
提交者:
GitHub
4月 27, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1092 from grandinj/230_fkconstraint
#230: Renaming a column does not update foreign key constraint
上级
6b33ddf0
87dcaa91
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
56 行增加
和
0 行删除
+56
-0
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
AlterTableRenameColumn.java
h2/src/main/org/h2/command/ddl/AlterTableRenameColumn.java
+11
-0
ConstraintReferential.java
h2/src/main/org/h2/constraint/ConstraintReferential.java
+11
-0
Table.java
h2/src/main/org/h2/table/Table.java
+4
-0
TestScript.java
h2/src/test/org/h2/test/scripts/TestScript.java
+1
-0
altertable-fk.sql
h2/src/test/org/h2/test/scripts/altertable-fk.sql
+27
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
fb5b206f
...
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Issue #230: Renaming a column does not update foreign key constraint
</li>
<li>
Issue #394: Recover tool places COLLATION and BINARY_COLLATION after temporary tables
</li>
<li>
Improve the script-based unit testing to check the error code of the exception thrown.
...
...
h2/src/main/org/h2/command/ddl/AlterTableRenameColumn.java
浏览文件 @
fb5b206f
...
...
@@ -7,6 +7,7 @@ package org.h2.command.ddl;
import
org.h2.api.ErrorCode
;
import
org.h2.command.CommandInterface
;
import
org.h2.constraint.ConstraintReferential
;
import
org.h2.engine.Database
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.Right
;
...
...
@@ -62,6 +63,7 @@ public class AlterTableRenameColumn extends SchemaCommand {
Column
column
=
table
.
getColumn
(
oldName
);
session
.
getUser
().
checkRight
(
table
,
Right
.
ALL
);
table
.
checkSupportAlter
();
// we need to update CHECK constraint
// since it might reference the name of the column
Expression
newCheckExpr
=
column
.
getCheckConstraint
(
session
,
newName
);
...
...
@@ -70,6 +72,15 @@ public class AlterTableRenameColumn extends SchemaCommand {
column
.
addCheckConstraint
(
session
,
newCheckExpr
);
table
.
setModified
();
db
.
updateMeta
(
session
,
table
);
// if we have foreign key constraints pointing at this table, we need to update them
for
(
DbObject
childDbObject
:
table
.
getChildren
())
{
if
(
childDbObject
instanceof
ConstraintReferential
)
{
ConstraintReferential
ref
=
(
ConstraintReferential
)
childDbObject
;
ref
.
updateOnTableColumnRename
();
}
}
for
(
DbObject
child
:
table
.
getChildren
())
{
if
(
child
.
getCreateSQL
()
!=
null
)
{
db
.
updateMeta
(
session
,
child
);
...
...
h2/src/main/org/h2/constraint/ConstraintReferential.java
浏览文件 @
fb5b206f
...
...
@@ -470,6 +470,17 @@ public class ConstraintReferential extends Constraint {
buildDeleteSQL
();
}
public
void
updateOnTableColumnRename
()
{
if
(
deleteAction
!=
null
)
{
deleteSQL
=
null
;
buildDeleteSQL
();
}
if
(
updateAction
!=
null
)
{
updateSQL
=
null
;
buildUpdateSQL
();
}
}
private
void
buildDeleteSQL
()
{
if
(
deleteAction
==
ConstraintActionType
.
RESTRICT
)
{
return
;
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
fb5b206f
...
...
@@ -85,6 +85,7 @@ public abstract class Table extends SchemaObjectBase {
*/
private
final
CopyOnWriteArrayList
<
TableView
>
dependentViews
=
new
CopyOnWriteArrayList
<>();
private
ArrayList
<
TableSynonym
>
synonyms
;
/** Is foreign key constraint checking enabled for this table. */
private
boolean
checkForeignKeyConstraints
=
true
;
private
boolean
onCommitDrop
,
onCommitTruncate
;
private
volatile
Row
nullRow
;
...
...
@@ -1065,6 +1066,9 @@ public abstract class Table extends SchemaObjectBase {
checkForeignKeyConstraints
=
enabled
;
}
/**
* @return is foreign key constraint checking enabled for this table.
*/
public
boolean
getCheckForeignKeyConstraints
()
{
return
checkForeignKeyConstraints
;
}
...
...
h2/src/test/org/h2/test/scripts/TestScript.java
浏览文件 @
fb5b206f
...
...
@@ -92,6 +92,7 @@ public class TestScript extends TestBase {
testScript
(
"joins.sql"
);
testScript
(
"range_table.sql"
);
testScript
(
"altertable-index-reuse.sql"
);
testScript
(
"altertable-fk.sql"
);
testScript
(
"default-and-on_update.sql"
);
testScript
(
"query-optimisations.sql"
);
String
decimal2
;
...
...
h2/src/test/org/h2/test/scripts/altertable-fk.sql
0 → 100644
浏览文件 @
fb5b206f
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
-- Check that constraints are properly renamed when we rename a column.
CREATE
TABLE
user_group
(
ID
decimal
PRIMARY
KEY
NOT
NULL
);
>
ok
CREATE
TABLE
login_message
(
ID
decimal
PRIMARY
KEY
NOT
NULL
,
user_group_id
decimal
);
>
ok
ALTER
TABLE
login_message
ADD
CONSTRAINT
FK_LOGIN_MESSAGE
FOREIGN
KEY
(
user_group_id
)
REFERENCES
user_group
(
id
)
ON
DELETE
CASCADE
;
>
ok
ALTER
TABLE
login_message
ALTER
COLUMN
user_group_id
RENAME
TO
user_group_id2
;
>
ok
INSERT
INTO
user_group
(
ID
)
VALUES
(
1
);
>
update
count
:
1
DELETE
FROM
user_group
;
>
update
count
:
1
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论