1

sqlite JDBC metadata.getPrimaryKeys return info of foreign keys. e.g.,

create table Foo (id integer, bar_id integer, 
primary key(id), 
foreign key (bar_id) references Bar(id))

JDBC:

DatabaseMetaData databaseMetaData = connection.getMetaData();
ResultSet rs = databaseMetaData.getPrimaryKeys("c:/test_db", null, "Foo");
rs.next();
String columnName = rs.getString("COLUMN_NAME");
assertEquals("id", columnName);

Each primary key column description has the following columns:

TABLE_CAT String => table catalog (may be null)
TABLE_SCHEM String => table schema (may be null)
TABLE_NAME String => table name
COLUMN_NAME String => column name
KEY_SEQ short => sequence number within primary key( a value of 1 represents the first column of the primary key, a value of 2 would represent the second column within the primary key).
PK_NAME String => primary key name (may be null)

org.junit.ComparisonFailure: expected:<[]id> but was:<[foreign key (bar_]id>

eastwater
  • 4,624
  • 9
  • 49
  • 118
  • Reproduced with sqlite-jdbc-3.21.0.1.jar. Looks like a bug to me. You may want to raise an [issue](https://github.com/xerial/sqlite-jdbc/issues) with the developers. – Gord Thompson Feb 19 '18 at 21:58

0 Answers0