ucanaccess icon indicating copy to clipboard operation
ucanaccess copied to clipboard

HSQLDB v2.7.2 incompatible

Open RohdeSchwarz-SDC opened this issue 1 year ago • 8 comments

Issue

Currently UCanAccess depends on HSQLDB v2.7.1, but at some point we will have to update this dependency.

I updated HSQLDB to v2.7.2, to check if it runs stable, but it doesn't.

→ Is there something we can do in the UCanAccess library to avoid the error (see below) or is it possibly a bug in HSQLDB?

Error

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::5.1.1 Cannot invoke "org.hsqldb.Statement.getTableNamesForRead()" because "<parameter1>.sessionContext.currentStatement" is null
    at net.ucanaccess.jdbc.UcanaccessSQLException.wrap(UcanaccessSQLException.java:123)
    at net.ucanaccess.util.Try.orThrow(Try.java:298)
    at net.ucanaccess.jdbc.UcanaccessStatement.tryCatch(UcanaccessStatement.java:406)
    at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:165)
    at my.namespace.MyTest.TestUCanAccessWithHSQLDBv272(MyTest.java:*)

Reproducer

@Test
public void TestUCanAccessWithHSQLDBv272() throws SQLException, IOException {
    try(var conn = openNewDatabase(); var stmt = conn.createStatement()) {
        // create new table and add some data
        stmt.executeUpdate("CREATE TABLE Tbl (ID INT NOT NULL PRIMARY KEY, Txt VARCHAR(255))");
        stmt.executeUpdate("INSERT INTO Tbl (ID, Txt) VALUES (1, 'One'), (2, 'Two'), (3, 'Tre')");
        
        // query data
        try(var row = stmt.executeQuery("SELECT ID, Txt FROM Tbl ORDER BY ID")) {
            assertTrue(row.next()); assertEquals(1, row.getInt(1)); assertEquals("One", row.getString(2));
            assertTrue(row.next()); assertEquals(2, row.getInt(1)); assertEquals("Two", row.getString(2));
            assertTrue(row.next()); assertEquals(3, row.getInt(1)); assertEquals("Tre", row.getString(2));
        }
        // update data
        stmt.executeUpdate("UPDATE Tbl SET Txt = 'Row ' || Txt");
        try(var row = stmt.executeQuery("SELECT Txt FROM Tbl ORDER BY ID")) {
            assertTrue(row.next()); assertEquals("Row One", row.getString(1));
            assertTrue(row.next()); assertEquals("Row Two", row.getString(1));
            assertTrue(row.next()); assertEquals("Row Tre", row.getString(1));
        }
        
        // remove data
        stmt.executeUpdate("DELETE FROM Tbl");
        try(var row = stmt.executeQuery("SELECT * FROM Tbl")) {
            assertFalse(row.next());    // no data
        }
    }
}

private static Connection openNewDatabase() throws SQLException, IOException {
    var tempDbFile = Path.of(System.getProperty("java.io.tmpdir"), "TestDatabase.accdb");
    var dbFileLocation = tempDbFile.toString().replace('\\', '/');
    
    tempDbFile.toFile().delete();    // delete from previous test run
    
    return DriverManager.getConnection("jdbc:ucanaccess://" + dbFileLocation + ";newdatabaseversion=V2016");
}

RohdeSchwarz-SDC avatar Feb 28 '24 18:02 RohdeSchwarz-SDC