Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
67e7b4bd
提交
67e7b4bd
authored
3月 01, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS from the SQL standard
上级
b55500e7
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
69 行增加
和
2 行删除
+69
-2
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+52
-1
TestMetaData.java
h2/src/test/org/h2/test/jdbc/TestMetaData.java
+2
-0
information_schema.sql
h2/src/test/org/h2/test/scripts/information_schema.sql
+15
-1
没有找到文件。
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
67e7b4bd
...
@@ -112,7 +112,8 @@ public class MetaTable extends Table {
...
@@ -112,7 +112,8 @@ public class MetaTable extends Table {
private
static
final
int
SYNONYMS
=
29
;
private
static
final
int
SYNONYMS
=
29
;
private
static
final
int
TABLE_CONSTRAINTS
=
30
;
private
static
final
int
TABLE_CONSTRAINTS
=
30
;
private
static
final
int
KEY_COLUMN_USAGE
=
31
;
private
static
final
int
KEY_COLUMN_USAGE
=
31
;
private
static
final
int
META_TABLE_TYPE_COUNT
=
KEY_COLUMN_USAGE
+
1
;
private
static
final
int
REFERENTIAL_CONSTRAINTS
=
32
;
private
static
final
int
META_TABLE_TYPE_COUNT
=
REFERENTIAL_CONSTRAINTS
+
1
;
private
final
int
type
;
private
final
int
type
;
private
final
int
indexColumn
;
private
final
int
indexColumn
;
...
@@ -591,6 +592,21 @@ public class MetaTable extends Table {
...
@@ -591,6 +592,21 @@ public class MetaTable extends Table {
indexColumnName
=
"TABLE_NAME"
;
indexColumnName
=
"TABLE_NAME"
;
break
;
break
;
}
}
case
REFERENTIAL_CONSTRAINTS:
{
setObjectName
(
"REFERENTIAL_CONSTRAINTS"
);
cols
=
createColumns
(
"CONSTRAINT_CATALOG"
,
"CONSTRAINT_SCHEMA"
,
"CONSTRAINT_NAME"
,
"UNIQUE_CONSTRAINT_CATALOG"
,
"UNIQUE_CONSTRAINT_SCHEMA"
,
"UNIQUE_CONSTRAINT_NAME"
,
"MATCH_OPTION"
,
"UPDATE_RULE"
,
"DELETE_RULE"
);
break
;
}
default
:
default
:
throw
DbException
.
throwInternalError
(
"type="
+
type
);
throw
DbException
.
throwInternalError
(
"type="
+
type
);
}
}
...
@@ -2025,6 +2041,41 @@ public class MetaTable extends Table {
...
@@ -2025,6 +2041,41 @@ public class MetaTable extends Table {
}
}
break
;
break
;
}
}
case
REFERENTIAL_CONSTRAINTS:
{
for
(
SchemaObject
obj
:
database
.
getAllSchemaObjects
(
DbObject
.
CONSTRAINT
))
{
if
(((
Constraint
)
obj
).
getConstraintType
()
!=
Constraint
.
Type
.
REFERENTIAL
)
{
continue
;
}
ConstraintReferential
constraint
=
(
ConstraintReferential
)
obj
;
Table
table
=
constraint
.
getTable
();
if
(
hideTable
(
table
,
session
))
{
continue
;
}
Index
index
=
constraint
.
getUniqueIndex
();
add
(
rows
,
// CONSTRAINT_CATALOG
catalog
,
// CONSTRAINT_SCHEMA
identifier
(
constraint
.
getSchema
().
getName
()),
// CONSTRAINT_NAME
identifier
(
constraint
.
getName
()),
// UNIQUE_CONSTRAINT_CATALOG
catalog
,
// UNIQUE_CONSTRAINT_SCHEMA
identifier
(
index
.
getSchema
().
getName
()),
// UNIQUE_CONSTRAINT_NAME
// Should be name of referenced unique constraint, but H2 uses indexes instead
index
.
getName
(),
// MATCH_OPTION
"NONE"
,
// UPDATE_RULE
constraint
.
getUpdateAction
().
getSqlName
(),
// DELETE_RULE
constraint
.
getDeleteAction
().
getSqlName
()
);
}
break
;
}
default
:
default
:
DbException
.
throwInternalError
(
"type="
+
type
);
DbException
.
throwInternalError
(
"type="
+
type
);
}
}
...
...
h2/src/test/org/h2/test/jdbc/TestMetaData.java
浏览文件 @
67e7b4bd
...
@@ -1090,6 +1090,8 @@ public class TestMetaData extends TestBase {
...
@@ -1090,6 +1090,8 @@ public class TestMetaData extends TestBase {
rs
.
next
();
rs
.
next
();
assertEquals
(
"QUERY_STATISTICS"
,
rs
.
getString
(
"TABLE_NAME"
));
assertEquals
(
"QUERY_STATISTICS"
,
rs
.
getString
(
"TABLE_NAME"
));
rs
.
next
();
rs
.
next
();
assertEquals
(
"REFERENTIAL_CONSTRAINTS"
,
rs
.
getString
(
"TABLE_NAME"
));
rs
.
next
();
assertEquals
(
"RIGHTS"
,
rs
.
getString
(
"TABLE_NAME"
));
assertEquals
(
"RIGHTS"
,
rs
.
getString
(
"TABLE_NAME"
));
rs
.
next
();
rs
.
next
();
assertEquals
(
"ROLES"
,
rs
.
getString
(
"TABLE_NAME"
));
assertEquals
(
"ROLES"
,
rs
.
getString
(
"TABLE_NAME"
));
...
...
h2/src/test/org/h2/test/scripts/information_schema.sql
浏览文件 @
67e7b4bd
...
@@ -15,7 +15,7 @@ ALTER TABLE T1 ADD CONSTRAINT U_1 UNIQUE(C3, C4);
...
@@ -15,7 +15,7 @@ ALTER TABLE T1 ADD CONSTRAINT U_1 UNIQUE(C3, C4);
CREATE
TABLE
T2
(
C1
INT
,
C2
INT
,
C3
INT
,
C4
INT
);
CREATE
TABLE
T2
(
C1
INT
,
C2
INT
,
C3
INT
,
C4
INT
);
>
ok
>
ok
ALTER
TABLE
T2
ADD
CONSTRAINT
FK_1
FOREIGN
KEY
(
C3
,
C4
)
REFERENCES
T1
(
C1
,
C3
);
ALTER
TABLE
T2
ADD
CONSTRAINT
FK_1
FOREIGN
KEY
(
C3
,
C4
)
REFERENCES
T1
(
C1
,
C3
)
ON
DELETE
SET
NULL
;
>
ok
>
ok
ALTER
TABLE
T2
ADD
CONSTRAINT
CH_1
CHECK
C4
>
0
;
ALTER
TABLE
T2
ADD
CONSTRAINT
CH_1
CHECK
C4
>
0
;
...
@@ -55,6 +55,20 @@ SELECT CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, POSITION_IN_U
...
@@ -55,6 +55,20 @@ SELECT CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, POSITION_IN_U
>
FK_1
T2
C4
2
2
>
FK_1
T2
C4
2
2
>
rows
(
ordered
):
6
>
rows
(
ordered
):
6
SELECT
*
FROM
INFORMATION_SCHEMA
.
REFERENTIAL_CONSTRAINTS
LIMIT
0
;
>
CONSTRAINT_CATALOG
CONSTRAINT_SCHEMA
CONSTRAINT_NAME
UNIQUE_CONSTRAINT_CATALOG
UNIQUE_CONSTRAINT_SCHEMA
UNIQUE_CONSTRAINT_NAME
MATCH_OPTION
UPDATE_RULE
DELETE_RULE
>
------------------ ----------------- --------------- ------------------------- ------------------------ ---------------------- ------------ ----------- -----------
>
rows
:
0
-- H2 returns name of the index istead of name of the referenced constraint as UNIQUE_CONSTRAINT_NAME
SELECT
CONSTRAINT_NAME
,
SUBSTRING
(
UNIQUE_CONSTRAINT_NAME
,
0
,
11
)
AS
UCN_PART
,
MATCH_OPTION
,
UPDATE_RULE
,
DELETE_RULE
FROM
INFORMATION_SCHEMA
.
REFERENTIAL_CONSTRAINTS
WHERE
CONSTRAINT_CATALOG
=
DATABASE
()
AND
CONSTRAINT_SCHEMA
=
SCHEMA
()
AND
UNIQUE_CONSTRAINT_CATALOG
=
DATABASE
()
AND
UNIQUE_CONSTRAINT_SCHEMA
=
SCHEMA
()
ORDER
BY
CONSTRAINT_NAME
,
UNIQUE_CONSTRAINT_NAME
;
>
CONSTRAINT_NAME
UCN_PART
MATCH_OPTION
UPDATE_RULE
DELETE_RULE
>
--------------- ----------- ------------ ----------- -----------
>
FK_1
FK_1_INDEX_
NONE
RESTRICT
SET
NULL
>
rows
(
ordered
):
1
DROP
TABLE
T2
;
DROP
TABLE
T2
;
>
ok
>
ok
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论