Le 29/07/2013 15:46, Dave Cramer a écrit :
> Sylvain,
>
> I made the changes and added this test case
>
> https://github.com/davecramer/pgjdbc/compare/REL9_2_STABLE, can you check
> it to see if it makes sense ?
Your patch isn't right : the first pos.n must be removed so that the order is
"nspname,relname,con.conname,pos.n".
Your test doesn't use the order so it works equally before and after the patch. Replace the for
loop with this snippet :
final List<String> fkNames = new ArrayList<String>();
int lastFieldCount = -1;
while (rs.next()) {
// destination table (all foreign keys point to the same)
String pkTableName = rs.getString("PKTABLE_NAME");
assertEquals(tableName, pkTableName);
// destination fields
String pkColumnName = rs.getString("PKCOLUMN_NAME");
assertTrue("FIRST_NAME".equals(pkColumnName) || "LAST_NAME".equals(pkColumnName));
// source table (all foreign keys are in the same)
String fkTableName = rs.getString("FKTABLE_NAME");
assertEquals(tableName, fkTableName);
// foreign key name
String fkName = rs.getString("FK_NAME");
// sequence number within the foreign key
int seq = rs.getInt("KEY_SEQ");
if (seq == 1) {
// begin new foreign key
assertFalse(fkNames.contains(fkName));
fkNames.add(fkName);
// all foreign keys have 2 fields
assertTrue(lastFieldCount < 0 || lastFieldCount == 2);
} else {
// continue foreign key, i.e. fkName matches the last foreign key
assertEquals(fkNames.get(fkNames.size() - 1), fkName);
// seq always increases by 1
assertTrue(seq == lastFieldCount + 1);
}
lastFieldCount = seq;
}
// there's more than one foreign key from a table to another
assertEquals(2, fkNames.size());
Cheers,
Sylvain