From 625be0364614241b34e9637e67e4f68ba59f77fe Mon Sep 17 00:00:00 2001 From: Markus Spann Date: Fri, 12 Jul 2024 15:30:07 +0200 Subject: [PATCH] Issue #7: Upgrade HSQLDB dependency to org.hsqldb:hsqldb:jar:2.7.3 --- pom.xml | 2 +- .../ucanaccess/converters/Persist2Jet.java | 20 +++++++++++-------- .../net/ucanaccess/jdbc/AlterTableTest.java | 6 +++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index c05477a..04ad43f 100644 --- a/pom.xml +++ b/pom.xml @@ -100,7 +100,7 @@ 5.0.0-SNAPSHOT 4.0.2 - 2.7.1 + 2.7.3 2.0.13 diff --git a/src/main/java/net/ucanaccess/converters/Persist2Jet.java b/src/main/java/net/ucanaccess/converters/Persist2Jet.java index 51d276b..4c01b4e 100644 --- a/src/main/java/net/ucanaccess/converters/Persist2Jet.java +++ b/src/main/java/net/ucanaccess/converters/Persist2Jet.java @@ -644,16 +644,20 @@ public void createPrimaryKey(String tableName) throws IOException, SQLException String ntn = escape4Hsqldb(tableName); String tn = escape4Access(tableName); Table t = db.getTable(tn); - ResultSet pkrs = conn.getHSQLDBConnection().getMetaData().getPrimaryKeys(null, null, ntn.toUpperCase()); + Metadata md = new Metadata(conn); + List cols = new ArrayList<>(); - IndexBuilder ib = new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME).withPrimaryKey(); - while (pkrs.next()) { - String colName = pkrs.getString(COLUMN_NAME); - Metadata mt = new Metadata(conn); - colName = mt.getColumnName(ntn, colName); - cols.add(colName); + try (Statement st = conn.getHSQLDBConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + ResultSet rs = st.executeQuery("SELECT * FROM INFORMATION_SCHEMA.SYSTEM_PRIMARYKEYS " + + "WHERE TABLE_NAME = '" + ntn.toUpperCase() + "' ORDER BY KEY_SEQ")) { + while (rs.next()) { + cols.add(md.getColumnName(ntn, rs.getString(COLUMN_NAME))); + } } - ib.withColumns(cols).addToTable(t); + new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME) + .withPrimaryKey() + .withColumns(cols) + .addToTable(t); } public void createForeignKey(String tableName, String referencedTable) throws IOException, SQLException { diff --git a/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java b/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java index c27598c..86f1a0b 100644 --- a/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java +++ b/src/test/java/net/ucanaccess/jdbc/AlterTableTest.java @@ -141,10 +141,10 @@ void testCreatePk(AccessVersion _accessVersion) throws SQLException, IOException init(_accessVersion); try (UcanaccessStatement st = ucanaccess.createStatement()) { - String tbl = "AAA n"; - st.execute("ALTER TABLE [" + tbl + "] ADD PRIMARY KEY (baaaa, a)"); + st.execute("ALTER TABLE [AAA n] ADD PRIMARY KEY (baaaa, a)"); Database db = ucanaccess.getDbIO(); - assertThat(db.getTable(tbl).getPrimaryKeyIndex().getColumns().stream().map(Column::getName)) + Table tbl = db.getTable("AAA n"); + assertThat(tbl.getPrimaryKeyIndex().getColumns().stream().map(Column::getName)) .containsExactly("baaaa", "A"); st.execute("ALTER TABLE Sample ADD PRIMARY KEY (RegionId)");