Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
0ea0365c
提交
0ea0365c
authored
3月 01, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add INFORMATION_SCHEMA.TABLE_CONSTRAINTS from the SQL standard
上级
65092a1d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
84 行增加
和
4 行删除
+84
-4
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+63
-4
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
+19
-0
没有找到文件。
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
0ea0365c
...
...
@@ -110,7 +110,8 @@ public class MetaTable extends Table {
private
static
final
int
SESSION_STATE
=
27
;
private
static
final
int
QUERY_STATISTICS
=
28
;
private
static
final
int
SYNONYMS
=
29
;
private
static
final
int
KEY_COLUMN_USAGE
=
30
;
private
static
final
int
TABLE_CONSTRAINTS
=
30
;
private
static
final
int
KEY_COLUMN_USAGE
=
31
;
private
static
final
int
META_TABLE_TYPE_COUNT
=
KEY_COLUMN_USAGE
+
1
;
private
final
int
type
;
...
...
@@ -558,6 +559,22 @@ public class MetaTable extends Table {
indexColumnName
=
"SYNONYM_NAME"
;
break
;
}
case
TABLE_CONSTRAINTS:
{
setObjectName
(
"TABLE_CONSTRAINTS"
);
cols
=
createColumns
(
"CONSTRAINT_CATALOG"
,
"CONSTRAINT_SCHEMA"
,
"CONSTRAINT_NAME"
,
"CONSTRAINT_TYPE"
,
"TABLE_CATALOG"
,
"TABLE_SCHEMA"
,
"TABLE_NAME"
,
"IS_DEFERRABLE"
,
"INITIALLY_DEFERRED"
);
indexColumnName
=
"TABLE_NAME"
;
break
;
}
case
KEY_COLUMN_USAGE:
{
setObjectName
(
"KEY_COLUMN_USAGE"
);
cols
=
createColumns
(
...
...
@@ -1924,9 +1941,51 @@ public class MetaTable extends Table {
}
break
;
}
case
TABLE_CONSTRAINTS:
{
for
(
SchemaObject
obj
:
database
.
getAllSchemaObjects
(
DbObject
.
CONSTRAINT
))
{
Constraint
constraint
=
(
Constraint
)
obj
;
Constraint
.
Type
constraintType
=
constraint
.
getConstraintType
();
Table
table
=
constraint
.
getTable
();
if
(
hideTable
(
table
,
session
))
{
continue
;
}
String
tableName
=
identifier
(
table
.
getName
());
if
(!
checkIndex
(
session
,
tableName
,
indexFrom
,
indexTo
))
{
continue
;
}
String
constraintTypeAsString
;
if
(
constraintType
==
Constraint
.
Type
.
PRIMARY_KEY
)
{
constraintTypeAsString
=
"PRIMARY KEY"
;
}
else
if
(
constraintType
==
Constraint
.
Type
.
REFERENTIAL
)
{
constraintTypeAsString
=
"FOREIGN KEY"
;
}
else
{
constraintTypeAsString
=
constraintType
.
name
();
}
add
(
rows
,
// CONSTRAINT_CATALOG
catalog
,
// CONSTRAINT_SCHEMA
identifier
(
constraint
.
getSchema
().
getName
()),
// CONSTRAINT_NAME
identifier
(
constraint
.
getName
()),
// CONSTRAINT_TYPE
constraintTypeAsString
,
// TABLE_CATALOG
catalog
,
// TABLE_SCHEMA
identifier
(
table
.
getSchema
().
getName
()),
// TABLE_NAME
tableName
,
// IS_DEFERRABLE
"NO"
,
// INITIALLY_DEFERRED
"NO"
);
}
break
;
}
case
KEY_COLUMN_USAGE:
{
for
(
SchemaObject
obj
:
database
.
getAllSchemaObjects
(
DbObject
.
CONSTRAINT
))
{
for
(
SchemaObject
obj
:
database
.
getAllSchemaObjects
(
DbObject
.
CONSTRAINT
))
{
Constraint
constraint
=
(
Constraint
)
obj
;
Constraint
.
Type
constraintType
=
constraint
.
getConstraintType
();
IndexColumn
[]
indexColumns
=
null
;
...
...
@@ -1969,7 +2028,7 @@ public class MetaTable extends Table {
ordinalPosition
,
// POSITION_IN_UNIQUE_CONSTRAINT
(
constraintType
==
Constraint
.
Type
.
REFERENTIAL
?
ordinalPosition
:
null
)
);
);
}
}
break
;
...
...
h2/src/test/org/h2/test/jdbc/TestMetaData.java
浏览文件 @
0ea0365c
...
...
@@ -1108,6 +1108,8 @@ public class TestMetaData extends TestBase {
rs
.
next
();
assertEquals
(
"TABLES"
,
rs
.
getString
(
"TABLE_NAME"
));
rs
.
next
();
assertEquals
(
"TABLE_CONSTRAINTS"
,
rs
.
getString
(
"TABLE_NAME"
));
rs
.
next
();
assertEquals
(
"TABLE_PRIVILEGES"
,
rs
.
getString
(
"TABLE_NAME"
));
rs
.
next
();
assertEquals
(
"TABLE_TYPES"
,
rs
.
getString
(
"TABLE_NAME"
));
...
...
h2/src/test/org/h2/test/scripts/information_schema.sql
浏览文件 @
0ea0365c
...
...
@@ -18,6 +18,25 @@ CREATE TABLE T2(C1 INT, C2 INT, C3 INT, C4 INT);
ALTER
TABLE
T2
ADD
CONSTRAINT
FK_1
FOREIGN
KEY
(
C3
,
C4
)
REFERENCES
T1
(
C1
,
C3
);
>
ok
ALTER
TABLE
T2
ADD
CONSTRAINT
CH_1
CHECK
C4
>
0
;
>
ok
SELECT
*
FROM
INFORMATION_SCHEMA
.
TABLE_CONSTRAINTS
LIMIT
0
;
>
CONSTRAINT_CATALOG
CONSTRAINT_SCHEMA
CONSTRAINT_NAME
CONSTRAINT_TYPE
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
IS_DEFERRABLE
INITIALLY_DEFERRED
>
------------------ ----------------- --------------- --------------- ------------- ------------ ---------- ------------- ------------------
>
rows
:
0
SELECT
CONSTRAINT_NAME
,
CONSTRAINT_TYPE
,
TABLE_NAME
,
IS_DEFERRABLE
,
INITIALLY_DEFERRED
FROM
INFORMATION_SCHEMA
.
TABLE_CONSTRAINTS
WHERE
CONSTRAINT_CATALOG
=
DATABASE
()
AND
CONSTRAINT_SCHEMA
=
SCHEMA
()
AND
TABLE_CATALOG
=
DATABASE
()
AND
TABLE_SCHEMA
=
SCHEMA
()
ORDER
BY
TABLE_NAME
,
CONSTRAINT_NAME
;
>
CONSTRAINT_NAME
CONSTRAINT_TYPE
TABLE_NAME
IS_DEFERRABLE
INITIALLY_DEFERRED
>
--------------- --------------- ---------- ------------- ------------------
>
PK_1
PRIMARY
KEY
T1
NO
NO
>
U_1
UNIQUE
T1
NO
NO
>
CH_1
CHECK
T2
NO
NO
>
FK_1
FOREIGN
KEY
T2
NO
NO
>
rows
(
ordered
):
4
SELECT
*
FROM
INFORMATION_SCHEMA
.
KEY_COLUMN_USAGE
LIMIT
0
;
>
CONSTRAINT_CATALOG
CONSTRAINT_SCHEMA
CONSTRAINT_NAME
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME
ORDINAL_POSITION
POSITION_IN_UNIQUE_CONSTRAINT
>
------------------ ----------------- --------------- ------------- ------------ ---------- ----------- ---------------- -----------------------------
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论