[英]JOOQ get Columns from a Table
i try to get all Columns
of a Table
with JOOQ
from a H2
database (for testing - later it might be something like MySQL
or PostGRE
)我尝试从H2
数据库中使用JOOQ
获取Table
所有Columns
(用于测试 - 稍后它可能类似于MySQL
或PostGRE
)
all is fine, but when i loop through my retrieved Columns
and log the results to console i noticed a Problem (probably a BUG?)一切都很好,但是当我遍历检索到的Columns
并将结果记录到控制台时,我注意到了一个问题(可能是 BUG?)
my log code looks like this:我的日志代码如下所示:
System.out.println(String.format("%d > [%s].[%s].[%s]", col.getOrdinalPosition(), col.getTableCatalog(), col.getTableName(), col.getColumnName()));
and the Output of my Table is this:我的表的输出是这样的:
0 > [TEST].[PERSON].[PERSON]
1 > [TEST].[PERSON].[PERSON]
2 > [TEST].[PERSON].[PERSON]
i expected it to be:我希望它是:
0 > [TEST].[PERSON].[ID]
1 > [TEST].[PERSON].[FIRSTNAME]
2 > [TEST].[PERSON].[LASTNAME]
as the create script for the table is:因为表的创建脚本是:
CREATE TABLE PERSON
(
ID INTEGER NOT NULL,
FIRSTNAME VARCHAR(255),
LASTNAME VARCHAR(255)
);
ALTER TABLE PERSON
ADD PRIMARY KEY (ID);
so finally my question is: how do i get the 'real' Column-Name?所以最后我的问题是:我如何获得“真实”的列名?
EDIT: tried using JOOQ
version 3.9.0 and 3.9.1编辑:尝试使用JOOQ
版本 3.9.0 和 3.9.1
UPDATE: I found another way to retrieve the Column-Names:更新:我找到了另一种检索列名的方法:
if you already have the instance of Table<?>
you can use this code to 'fix' the bug如果您已经拥有Table<?>
的实例,您可以使用此代码来“修复”该错误
// ordinal position starts at 1 but the fields-array starts at 0!
Field<?> f = tbl.fields()[col.getOrdinalPosition() - 1];
// this is needed due a bug in JOOQ, where the ColumnName is returned incorrect
col.setColumnName(f.getName());
Question: Where does Column come from?问题:列从哪里来? Answer:回答:
DSLContext dslCtx = DSL.using(cfg);
InformationSchema is = dslCtx.informationSchema(tbl);
List<Column> columns = is.getColumns();
the Class Column
is out of JOOQ
's org.jooq.util.xml.jaxb.Column
package;类Column
是出来JOOQ
的org.jooq.util.xml.jaxb.Column
包;
这是 jOOQ 3.9.1 中的一个错误,将在 3.10.0 和 3.9.2 中修复: https : //github.com/jOOQ/jOOQ/issues/5812
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.