Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
aab911e5
提交
aab911e5
authored
3月 15, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Column constraints are also visible in views (patch from Nicolas Fortin for H2GIS).
上级
4307ec5b
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
65 行增加
和
1 行删除
+65
-1
changelog.html
h2/src/docsrc/html/changelog.html
+2
-1
TableView.java
h2/src/main/org/h2/table/TableView.java
+21
-0
TestView.java
h2/src/test/org/h2/test/db/TestView.java
+42
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
aab911e5
...
...
@@ -18,7 +18,8 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
Granting a additional right to a role that already had a right for that table was not working.
<ul><li>
Column constraints are also visible in views (patch from Nicolas Fortin for H2GIS).
</li><li>
Granting a additional right to a role that already had a right for that table was not working.
</li><li>
Spatial index: a few bugs have been fixed (using spatial constraints in views,
transferring geometry objects over TCP/IP).
</li><li>
Issue 551: the datatype documentation was incorrect (found by Bernd Eckenfels).
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
aab911e5
...
...
@@ -16,7 +16,9 @@ import org.h2.engine.Constants;
import
org.h2.engine.DbObject
;
import
org.h2.engine.Session
;
import
org.h2.engine.User
;
import
org.h2.expression.Alias
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionColumn
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.expression.Parameter
;
import
org.h2.index.Index
;
...
...
@@ -39,6 +41,8 @@ import org.h2.value.Value;
/**
* A view is a virtual table that is defined by a query.
* @author Thomas Mueller
* @author Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
*/
public
class
TableView
extends
Table
{
...
...
@@ -168,6 +172,23 @@ public class TableView extends Table {
int
displaySize
=
expr
.
getDisplaySize
();
Column
col
=
new
Column
(
name
,
type
,
precision
,
scale
,
displaySize
);
col
.
setTable
(
this
,
i
);
// Fetch check constraint from view column source
ExpressionColumn
fromColumn
=
null
;
if
(
expr
instanceof
ExpressionColumn
)
{
fromColumn
=
(
ExpressionColumn
)
expr
;
}
else
if
(
expr
instanceof
Alias
)
{
Expression
aliasExpr
=
expr
.
getNonAliasExpression
();
if
(
aliasExpr
instanceof
ExpressionColumn
)
{
fromColumn
=
(
ExpressionColumn
)
aliasExpr
;
}
}
if
(
fromColumn
!=
null
)
{
Expression
checkExpression
=
fromColumn
.
getColumn
()
.
getCheckConstraint
(
session
,
name
);
if
(
checkExpression
!=
null
)
{
col
.
addCheckConstraint
(
session
,
checkExpression
);
}
}
list
.
add
(
col
);
}
cols
=
new
Column
[
list
.
size
()];
...
...
h2/src/test/org/h2/test/db/TestView.java
浏览文件 @
aab911e5
...
...
@@ -43,6 +43,7 @@ public class TestView extends TestBase {
testManyViews
();
testReferenceView
();
testViewAlterAndCommandCache
();
testViewConstraintFromColumnExpression
();
deleteDb
(
"view"
);
}
...
...
@@ -236,4 +237,45 @@ public class TestView extends TestBase {
deleteDb
(
"view"
);
}
/**
* Make sure that the table constraint is still available when create a view of other table.
*/
private
void
testViewConstraintFromColumnExpression
()
throws
SQLException
{
deleteDb
(
"view"
);
Connection
conn
=
getConnection
(
"view"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table t0(id1 int primary key CHECK ((ID1 % 2) = 0))"
);
stat
.
execute
(
"create table t1(id2 int primary key CHECK ((ID2 % 1) = 0))"
);
stat
.
execute
(
"insert into t0 values(0)"
);
stat
.
execute
(
"insert into t1 values(1)"
);
stat
.
execute
(
"create view v1 as select * from t0,t1"
);
// Check with ColumnExpression
ResultSet
rs
=
stat
.
executeQuery
(
"select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'V1'"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"ID1"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertEquals
(
"((ID1 % 2) = 0)"
,
rs
.
getString
(
"CHECK_CONSTRAINT"
));
assertTrue
(
rs
.
next
());
assertEquals
(
"ID2"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertEquals
(
"((ID2 % 1) = 0)"
,
rs
.
getString
(
"CHECK_CONSTRAINT"
));
// Check with AliasExpression
stat
.
execute
(
"create view v2 as select ID1 key1,ID2 key2 from t0,t1"
);
rs
=
stat
.
executeQuery
(
"select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'V2'"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"KEY1"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertEquals
(
"((KEY1 % 2) = 0)"
,
rs
.
getString
(
"CHECK_CONSTRAINT"
));
assertTrue
(
rs
.
next
());
assertEquals
(
"KEY2"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertEquals
(
"((KEY2 % 1) = 0)"
,
rs
.
getString
(
"CHECK_CONSTRAINT"
));
// Check hide of constraint if column is an Operation
stat
.
execute
(
"create view v3 as select ID1 + 1 ID1, ID2 + 1 ID2 from t0,t1"
);
rs
=
stat
.
executeQuery
(
"select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'V3'"
);
assertTrue
(
rs
.
next
());
assertEquals
(
"ID1"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertEquals
(
""
,
rs
.
getString
(
"CHECK_CONSTRAINT"
));
assertTrue
(
rs
.
next
());
assertEquals
(
"ID2"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertEquals
(
""
,
rs
.
getString
(
"CHECK_CONSTRAINT"
));
conn
.
close
();
deleteDb
(
"view"
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论