Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
110e1596
提交
110e1596
authored
11 年前
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve error message when check constraint is broken, test case from Gili (cowwoc)
上级
c4a0d51f
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
47 行增加
和
1 行删除
+47
-1
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
_messages_en.prop
h2/src/docsrc/textbase/_messages_en.prop
+1
-0
ErrorCode.java
h2/src/main/org/h2/constant/ErrorCode.java
+6
-0
ConstraintCheck.java
h2/src/main/org/h2/constraint/ConstraintCheck.java
+7
-1
_messages_en.prop
h2/src/main/org/h2/res/_messages_en.prop
+1
-0
TestTriggersConstraints.java
h2/src/test/org/h2/test/db/TestTriggersConstraints.java
+31
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
110e1596
...
...
@@ -32,6 +32,7 @@ Change Log
</li><li>
Issue 474: H2 Mysql Compatibility code fails to ignore "COMMENT" in CREATE TABLE, patch from Aaron Azeckoski
</li><li>
Issue 476: Broken link in jaqu.html
</li><li>
Fix potential UTF8 encoding issue in org.h2.store.FileStore, reported by Juerg Spiess
</li><li>
Improve error message when check constraint is broken, test case from Gili (cowwoc)
</li></ul>
<h2>
Version 1.3.172 (2013-05-25)
</h2>
...
...
This diff is collapsed.
Click to expand it.
h2/src/docsrc/textbase/_messages_en.prop
浏览文件 @
110e1596
...
...
@@ -15,6 +15,7 @@
23506=Referential integrity constraint violation: {0}
23507=No default value is set for column {0}
23513=Check constraint violation: {0}
23514=Check constraint invalid: {0}
28000=Wrong user name or password
40001=Deadlock detected. The current transaction was rolled back. Details: {0}
42000=Syntax error in SQL statement {0}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/constant/ErrorCode.java
浏览文件 @
110e1596
...
...
@@ -224,6 +224,12 @@ public class ErrorCode {
*/
public
static
final
int
CHECK_CONSTRAINT_VIOLATED_1
=
23513
;
/**
* The error with code <code>23514</code> is thrown during evaluation of a check constraint
* if the SQL generates an error.
*/
public
static
final
int
CHECK_CONSTRAINT_INVALID
=
23514
;
// 28: invalid authorization specification
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/constraint/ConstraintCheck.java
浏览文件 @
110e1596
...
...
@@ -93,8 +93,14 @@ public class ConstraintCheck extends Constraint {
return
;
}
filter
.
set
(
newRow
);
Boolean
b
;
try
{
b
=
expr
.
getValue
(
session
).
getBoolean
();
}
catch
(
DbException
ex
)
{
throw
DbException
.
get
(
ErrorCode
.
CHECK_CONSTRAINT_INVALID
,
ex
,
getShortDescription
());
}
// Both TRUE and NULL are ok
if
(
Boolean
.
FALSE
.
equals
(
expr
.
getValue
(
session
).
getBoolean
()
))
{
if
(
Boolean
.
FALSE
.
equals
(
b
))
{
throw
DbException
.
get
(
ErrorCode
.
CHECK_CONSTRAINT_VIOLATED_1
,
getShortDescription
());
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/res/_messages_en.prop
浏览文件 @
110e1596
...
...
@@ -15,6 +15,7 @@
23506=Referential integrity constraint violation: {0}
23507=No default value is set for column {0}
23513=Check constraint violation: {0}
23514=Check constraint invalid: {0}
28000=Wrong user name or password
40001=Deadlock detected. The current transaction was rolled back. Details: {0}
42000=Syntax error in SQL statement {0}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestTriggersConstraints.java
浏览文件 @
110e1596
...
...
@@ -49,6 +49,7 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
testTriggerAlterTable
();
testTriggers
();
testConstraints
();
testCheckConstraintErrorMessage
();
testMultiPartForeignKeys
();
deleteDb
(
"trigger"
);
}
...
...
@@ -403,6 +404,36 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
conn
.
close
();
}
private
void
testCheckConstraintErrorMessage
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"trigger"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table companies(id identity)"
);
stat
.
execute
(
"create table departments(id identity, "
+
"company_id int not null, "
+
"foreign key(company_id) references companies(id))"
);
stat
.
execute
(
"create table connections (id identity, company_id int not null, "
+
"first int not null, second int not null, "
+
"foreign key (company_id) references companies(id), "
+
"foreign key (first) references departments(id), "
+
"foreign key (second) references departments(id), "
+
"check (select departments.company_id from departments, companies where "
+
" departments.id in (first, second)) = company_id)"
);
stat
.
execute
(
"insert into companies(id) values(1)"
);
stat
.
execute
(
"insert into departments(id, company_id) "
+
"values(10, 1)"
);
stat
.
execute
(
"insert into departments(id, company_id) "
+
"values(20, 1)"
);
assertThrows
(
ErrorCode
.
CHECK_CONSTRAINT_INVALID
,
stat
)
.
execute
(
"insert into connections(id, company_id, first, second) "
+
"values(100, 1, 10, 20)"
);
stat
.
execute
(
"drop table connections"
);
stat
.
execute
(
"drop table departments"
);
stat
.
execute
(
"drop table companies"
);
conn
.
close
();
}
/**
* Regression test: we had a bug where the AlterTableAddConstraint class
* used to sometimes pick the wrong unique index for a foreign key.
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论