提交 c7f8a6bf authored 作者: Thomas Mueller's avatar Thomas Mueller

DatabaseMetaData.getPrimaryKeys: the wrong constraint name was reported if there…

DatabaseMetaData.getPrimaryKeys: the wrong constraint name was reported if there was another constraint on the same table and columns.
上级 1b19a060
...@@ -733,8 +733,14 @@ public class MetaTable extends Table { ...@@ -733,8 +733,14 @@ public class MetaTable extends Table {
for (int k = 0; constraints != null && k < constraints.size(); k++) { for (int k = 0; constraints != null && k < constraints.size(); k++) {
Constraint constraint = constraints.get(k); Constraint constraint = constraints.get(k);
if (constraint.getUniqueIndex() == index) { if (constraint.getUniqueIndex() == index) {
if (index.getIndexType().isPrimaryKey()) {
if (constraint.getConstraintType().equals(Constraint.PRIMARY_KEY)) {
constraintName = constraint.getName(); constraintName = constraint.getName();
} }
} else {
constraintName = constraint.getName();
}
}
} }
IndexColumn[] cols = index.getIndexColumns(); IndexColumn[] cols = index.getIndexColumns();
for (int k = 0; k < cols.length; k++) { for (int k = 0; k < cols.length; k++) {
......
--- special grammar and test cases --------------------------------------------------------------------------------------------- --- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test(id int, constraint pk primary key(id), constraint x unique(id));
> ok
select constraint_name from information_schema.indexes where table_name = 'TEST';
> CONSTRAINT_NAME
> ---------------
> PK
> rows: 1
drop table test;
> ok
create table test(id int, name varchar);
> ok
alter table test alter column id identity;
> ok
drop table test;
> ok
create table test(id int primary key, name varchar);
> ok
alter table test alter column id int auto_increment;
> ok
drop table test;
> ok
create table test(id identity) as select x from system_range(1, 4); create table test(id identity) as select x from system_range(1, 4);
> ok > ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论