Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e8934d75
提交
e8934d75
authored
3月 19, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use UNION in getTables() only if required
上级
77401651
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
48 行增加
和
40 行删除
+48
-40
JdbcDatabaseMetaData.java
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
+48
-40
没有找到文件。
h2/src/main/org/h2/jdbc/JdbcDatabaseMetaData.java
浏览文件 @
e8934d75
...
...
@@ -144,8 +144,43 @@ public class JdbcDatabaseMetaData extends TraceObject implements
}
checkClosed
();
int
typesLength
=
types
!=
null
?
types
.
length
:
0
;
boolean
includeSynonyms
=
types
==
null
||
Arrays
.
asList
(
types
).
contains
(
"SYNONYM"
);
String
tableSelect
=
"SELECT "
// (1024 - 16) is enough for the most cases
StringBuilder
select
=
new
StringBuilder
(
1008
);
if
(
includeSynonyms
)
{
select
.
append
(
"SELECT "
+
"TABLE_CAT, "
+
"TABLE_SCHEM, "
+
"TABLE_NAME, "
+
"TABLE_TYPE, "
+
"REMARKS, "
+
"TYPE_CAT, "
+
"TYPE_SCHEM, "
+
"TYPE_NAME, "
+
"SELF_REFERENCING_COL_NAME, "
+
"REF_GENERATION, "
+
"SQL "
+
"FROM ("
+
"SELECT "
+
"SYNONYM_CATALOG TABLE_CAT, "
+
"SYNONYM_SCHEMA TABLE_SCHEM, "
+
"SYNONYM_NAME as TABLE_NAME, "
+
"TYPE_NAME AS TABLE_TYPE, "
+
"REMARKS, "
+
"TYPE_NAME TYPE_CAT, "
+
"TYPE_NAME TYPE_SCHEM, "
+
"TYPE_NAME AS TYPE_NAME, "
+
"TYPE_NAME SELF_REFERENCING_COL_NAME, "
+
"TYPE_NAME REF_GENERATION, "
+
"NULL AS SQL "
+
"FROM INFORMATION_SCHEMA.SYNONYMS "
+
"WHERE SYNONYM_CATALOG LIKE ?1 ESCAPE ?4 "
+
"AND SYNONYM_SCHEMA LIKE ?2 ESCAPE ?4 "
+
"AND SYNONYM_NAME LIKE ?3 ESCAPE ?4 "
+
"UNION "
);
}
select
.
append
(
"SELECT "
+
"TABLE_CATALOG TABLE_CAT, "
+
"TABLE_SCHEMA TABLE_SCHEM, "
+
"TABLE_NAME, "
...
...
@@ -160,49 +195,22 @@ public class JdbcDatabaseMetaData extends TraceObject implements
+
"FROM INFORMATION_SCHEMA.TABLES "
+
"WHERE TABLE_CATALOG LIKE ?1 ESCAPE ?4 "
+
"AND TABLE_SCHEMA LIKE ?2 ESCAPE ?4 "
+
"AND TABLE_NAME LIKE ?3 ESCAPE ?4"
;
+
"AND TABLE_NAME LIKE ?3 ESCAPE ?4"
)
;
if
(
typesLength
>
0
)
{
StatementBuilder
buff
=
new
StatementBuilder
(
tableSelect
)
.
append
(
" AND TABLE_TYPE IN("
);
select
.
append
(
" AND TABLE_TYPE IN("
);
for
(
int
i
=
0
;
i
<
typesLength
;
i
++)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
'?'
).
append
(
i
+
5
);
if
(
i
>
0
)
{
select
.
append
(
", "
);
}
select
.
append
(
'?'
).
append
(
i
+
5
);
}
tableSelect
=
buff
.
append
(
')'
).
toString
(
);
select
.
append
(
')'
);
}
boolean
includeSynonyms
=
types
==
null
||
Arrays
.
asList
(
types
).
contains
(
"SYNONYM"
);
String
synonymSelect
=
"SELECT "
+
"SYNONYM_CATALOG TABLE_CAT, "
+
"SYNONYM_SCHEMA TABLE_SCHEM, "
+
"SYNONYM_NAME as TABLE_NAME, "
+
"TYPE_NAME AS TABLE_TYPE, "
+
"REMARKS, "
+
"TYPE_NAME TYPE_CAT, "
+
"TYPE_NAME TYPE_SCHEM, "
+
"TYPE_NAME AS TYPE_NAME, "
+
"TYPE_NAME SELF_REFERENCING_COL_NAME, "
+
"TYPE_NAME REF_GENERATION, "
+
"NULL AS SQL "
+
"FROM INFORMATION_SCHEMA.SYNONYMS "
+
"WHERE SYNONYM_CATALOG LIKE ?1 ESCAPE ?4 "
+
"AND SYNONYM_SCHEMA LIKE ?2 ESCAPE ?4 "
+
"AND SYNONYM_NAME LIKE ?3 ESCAPE ?4 "
+
"AND ("
+
includeSynonyms
+
") "
;
PreparedStatement
prep
=
conn
.
prepareAutoCloseStatement
(
"SELECT "
+
"TABLE_CAT, "
+
"TABLE_SCHEM, "
+
"TABLE_NAME, "
+
"TABLE_TYPE, "
+
"REMARKS, "
+
"TYPE_CAT, "
+
"TYPE_SCHEM, "
+
"TYPE_NAME, "
+
"SELF_REFERENCING_COL_NAME, "
+
"REF_GENERATION, "
+
"SQL "
+
"FROM ("
+
synonymSelect
+
" UNION "
+
tableSelect
+
") "
+
"ORDER BY TABLE_TYPE, TABLE_SCHEM, TABLE_NAME"
);
if
(
includeSynonyms
)
{
select
.
append
(
')'
);
}
PreparedStatement
prep
=
conn
.
prepareAutoCloseStatement
(
select
.
append
(
" ORDER BY TABLE_TYPE, TABLE_SCHEM, TABLE_NAME"
).
toString
());
prep
.
setString
(
1
,
getCatalogPattern
(
catalogPattern
));
prep
.
setString
(
2
,
getSchemaPattern
(
schemaPattern
));
prep
.
setString
(
3
,
getPattern
(
tableNamePattern
));
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论