Skip to content

Commit

Permalink
Merge pull request #42 from INPUTsys-Chris/close_on_error
Browse files Browse the repository at this point in the history
Fix #40
  • Loading branch information
Willena authored Jun 6, 2021
2 parents e9753ae + ff51b1e commit 53f7c32
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=3.35.5
artifactVersion=3.35.5.1
artifactVersion=3.35.5.2
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.willena</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.35.5.1</version>
<version>3.35.5.2</version>
<name>SQLite JDBC</name>
<description>SQLite JDBC library with encryption and authentication support</description>
<url>https://github.com/Willena/sqlite-jdbc-crypt</url>
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/sqlite/SQLiteConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ public SQLiteConnection(String url, String fileName) throws SQLException {
public SQLiteConnection(String url, String fileName, Properties prop) throws SQLException {
this.db = open(url, fileName, prop);
SQLiteConfig config = db.getConfig();
this.connectionConfig = db.getConfig().newConnectionConfig();

config.apply(this);
this.connectionConfig = config.newConnectionConfig();
try {
config.apply(this);
} catch (SQLException throwable) {
this.db.close();
throw throwable;
}
}

public SQLiteConnectionConfig getConnectionConfig() {
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/sqlite/SQLiteMCPragmaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,19 @@ public void crossCipherAlgorithmTest() throws IOException, SQLException {
// c.close();
}

@Test
public void closeDeleteTest() throws IOException, SQLException {
String dbfile = createFile();
String key = "key";
cipherDatabaseCreate(new SQLiteMCConfig(), dbfile, key);

Connection c = cipherDatabaseOpen(new SQLiteMCConfig(), dbfile, key);
assertTrue("Should be able to read the base db", databaseIsReadable(c));
c.close();

c = cipherDatabaseOpen(SQLiteMCRC4Config.getDefault(), dbfile, key);
assertNull("Should not be readable with RC4", c);
assertTrue("Connection must be closed, should be deleted", new File(dbfile).delete());
}

}

0 comments on commit 53f7c32

Please sign in to comment.