提交 7b7afcc4 authored 作者: Thomas Mueller's avatar Thomas Mueller

DatabaseMetaData.getPrimaryKeys: The column PK_NAME now contains the constraint name.

上级 0717e820
......@@ -156,9 +156,12 @@ public class ViewIndex extends BaseIndex {
for (int i = 0; originalParameters != null && i < originalParameters.size(); i++) {
Parameter orig = (Parameter) originalParameters.get(i);
int idx = orig.getIndex();
Parameter param = (Parameter) paramList.get(idx);
Value value = orig.getValue(session);
param.setValue(value);
// the parameter may have been optimized away
if (idx < paramList.size()) {
Parameter param = (Parameter) paramList.get(idx);
Value value = orig.getValue(session);
param.setValue(value);
}
}
int len;
if (first != null) {
......
......@@ -358,7 +358,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
+ "TABLE_NAME, "
+ "COLUMN_NAME, "
+ "ORDINAL_POSITION KEY_SEQ, "
+ "INDEX_NAME PK_NAME "
+ "IFNULL(CONSTRAINT_NAME, INDEX_NAME) PK_NAME "
+ "FROM INFORMATION_SCHEMA.INDEXES "
+ "WHERE TABLE_CATALOG LIKE ? "
+ "AND TABLE_SCHEMA LIKE ? "
......
......@@ -187,7 +187,8 @@ public class MetaTable extends Table {
"REMARKS",
"SQL",
"ID INT",
"SORT_TYPE INT"
"SORT_TYPE INT",
"CONSTRAINT_NAME"
});
indexColumnName = "TABLE_NAME";
break;
......@@ -726,12 +727,20 @@ public class MetaTable extends Table {
if (!checkIndex(session, tableName, indexFrom, indexTo)) {
continue;
}
ObjectArray idx = table.getIndexes();
for (int j = 0; idx != null && j < idx.size(); j++) {
Index index = (Index) idx.get(j);
ObjectArray indexes = table.getIndexes();
ObjectArray constraints = table.getConstraints();
for (int j = 0; indexes != null && j < indexes.size(); j++) {
Index index = (Index) indexes.get(j);
if (index.getCreateSQL() == null) {
continue;
}
String constraintName = null;
for (int k = 0; constraints != null && k < constraints.size(); k++) {
Constraint constraint = (Constraint) constraints.get(k);
if (constraint.getUniqueIndex() == index) {
constraintName = constraint.getName();
}
}
IndexColumn[] cols = index.getIndexColumns();
for (int k = 0; k < cols.length; k++) {
IndexColumn idxCol = cols[k];
......@@ -775,6 +784,8 @@ public class MetaTable extends Table {
"" + index.getId(),
// SORT_TYPE
"" + idxCol.sortType,
// CONSTRAINT_NAME
constraintName
});
}
}
......
......@@ -7,6 +7,7 @@
package org.h2.test.db;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
......@@ -28,11 +29,25 @@ public class TestView extends TestBase {
}
public void test() throws SQLException {
testInSelect();
testUnionReconnect();
testManyViews();
deleteDb("view");
}
private void testInSelect() throws SQLException {
deleteDb("view");
Connection conn = getConnection("view");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key) as select 1");
PreparedStatement prep = conn.prepareStatement(
"select * from test t where t.id in (select t2.id from test t2 where t2.id in (?, ?))");
prep.setInt(1, 1);
prep.setInt(2, 2);
prep.execute();
conn.close();
}
private void testUnionReconnect() throws SQLException {
if (config.memory) {
return;
......
......@@ -704,7 +704,7 @@ public class TestMetaData extends TestBase {
"PK_NAME" }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
Types.VARCHAR }, null, null);
assertResultSetOrdered(rs,
new String[][] { { catalog, Constants.SCHEMA_MAIN, "TEST", "ID", "1", "PRIMARY_KEY_2" }, });
new String[][] { { catalog, Constants.SCHEMA_MAIN, "TEST", "ID", "1", "CONSTRAINT_2" }, });
trace("getTables - using a wildcard");
stat.executeUpdate("CREATE TABLE T_2(B INT,A VARCHAR(6),C INT,PRIMARY KEY(C,A,B))");
stat.executeUpdate("CREATE TABLE TX2(B INT,A VARCHAR(6),C INT,PRIMARY KEY(C,A,B))");
......@@ -758,9 +758,9 @@ public class TestMetaData extends TestBase {
trace("getPrimaryKeys");
rs = meta.getPrimaryKeys(null, null, "T_2");
assertResultSetOrdered(rs, new String[][] {
{ catalog, Constants.SCHEMA_MAIN, "T_2", "A", "2", "PRIMARY_KEY_1" },
{ catalog, Constants.SCHEMA_MAIN, "T_2", "B", "3", "PRIMARY_KEY_1" },
{ catalog, Constants.SCHEMA_MAIN, "T_2", "C", "1", "PRIMARY_KEY_1" }, });
{ catalog, Constants.SCHEMA_MAIN, "T_2", "A", "2", "CONSTRAINT_1" },
{ catalog, Constants.SCHEMA_MAIN, "T_2", "B", "3", "CONSTRAINT_1" },
{ catalog, Constants.SCHEMA_MAIN, "T_2", "C", "1", "CONSTRAINT_1" }, });
stat.executeUpdate("DROP TABLE TX2");
stat.executeUpdate("DROP TABLE T_2");
stat.executeUpdate("CREATE TABLE PARENT(ID INT PRIMARY KEY)");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论