From: Sylvain Cuaz <sylvain@ilm-informatique.fr>
To: pgsql-jdbc@postgresql.org
Subject: Re: DatabaseMetaData getImportedKeys() order
Date: Mon, 05 Aug 2013 09:20:57 +0200
Message-ID: <51FF5259.1050003@ilm-informatique.fr> (raw)
In-Reply-To: <CADK3HHLG6QkfA7=sQtd7Jarb8TfWfYUUN4Ft3Q=FvF7tZ95C2A@mail.gmail.com>
References: <51ED4DBC.7020307@ilm-informatique.fr>
<CADK3HHLG6QkfA7=sQtd7Jarb8TfWfYUUN4Ft3Q=FvF7tZ95C2A@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: sylvain@ilm-informatique.fr
Subject: Re: DatabaseMetaData getImportedKeys() order
In-Reply-To: <51FF5259.1050003@ilm-informatique.fr>
References: <51ED4DBC.7020307@ilm-informatique.fr> <CADK3HHLG6QkfA7=sQtd7Jarb8TfWfYUUN4Ft3Q=FvF7tZ95C2A@mail.gmail.com> <51FF5259.1050003@ilm-informatique.fr>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox