Re: DatabaseMetaData getImportedKeys() order

From: Sylvain Cuaz <sylvain(at)ilm-informatique(dot)fr>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: DatabaseMetaData getImportedKeys() order
Date: 2013-08-05 07:20:57
Message-ID: 51FF5259.1050003@ilm-informatique.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2013-08-05 11:57:06 Re: Updated Website Layout Completed
Previous Message Tom Lane 2013-08-05 06:16:14 Re: JDBC driver 9.2 sending arbitrary timezone