Skip to content

Commit fb51f07

Browse files
author
Chris Brody
committed
Check that db is closed if corruption was detected during an operation
1 parent dbc37e6 commit fb51f07

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/net/zetetic/tests/CorruptDatabaseTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ public boolean execute(SQLiteDatabase null_database_ignored) {
3737

3838
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(unencryptedDatabase, "", null);
3939

40-
// NOTE: database not expected to be null, but check:
40+
// NOTE: database not expected to be null, but double-check:
4141
if (database == null) {
4242
Log.e(TAG, "ERROR: got null database object");
4343
return false;
4444
}
4545

46+
// *Should* have been recovered:
4647
Cursor cursor = database.rawQuery("select * from sqlite_master;", null);
4748

4849
if (cursor == null) {
@@ -64,7 +65,11 @@ public boolean execute(SQLiteDatabase null_database_ignored) {
6465
Log.v(TAG, "Caught SQLiteDatabaseCorruptException as expected OK");
6566
}
6667

67-
database.close();
68+
// *Expected* to be closed now
69+
if (database.isOpen()) {
70+
Log.e(TAG, "NOT EXPECTED: database is still open");
71+
return false;
72+
}
6873

6974
return true;
7075
} catch (Exception ex) {

0 commit comments

Comments
 (0)