Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ public void testDefaultDatabaseErrorHandler() {
assertFalse(mDatabase.isOpen());
assertTrue(dbfile.exists());
try {
errorHandler.onCorruption(mDatabase);
errorHandler.onCorruption(mDatabase, new SQLiteException());
if(SQLiteDatabase.hasCodec()){
assertTrue(dbfile.exists());
} else {
Expand All @@ -976,7 +976,7 @@ public void testDefaultDatabaseErrorHandler() {
memoryDb.close();
assertFalse(memoryDb.isOpen());
try {
errorHandler.onCorruption(memoryDb);
errorHandler.onCorruption(memoryDb, new SQLiteException());
} catch (Exception e) {
fail("unexpected");
}
Expand All @@ -987,7 +987,7 @@ public void testDefaultDatabaseErrorHandler() {
assertNotNull(dbObj);
assertTrue(dbObj.isOpen());
try {
errorHandler.onCorruption(dbObj);
errorHandler.onCorruption(dbObj, new SQLiteException());
if(SQLiteDatabase.hasCodec()){
assertTrue(dbfile.exists());
} else{
Expand All @@ -1012,7 +1012,7 @@ public void testDefaultDatabaseErrorHandler() {
assertTrue(dbObj.isOpen());
List<Pair<String, String>> attachedDbs = dbObj.getAttachedDbs();
try {
errorHandler.onCorruption(dbObj);
errorHandler.onCorruption(dbObj, new SQLiteException());
if(SQLiteDatabase.hasCodec()){
assertTrue(dbfile.exists());
} else {
Expand Down Expand Up @@ -1047,7 +1047,7 @@ public void testDefaultDatabaseErrorHandler() {
assertTrue(dbObj.isOpen());
attachedDbs = dbObj.getAttachedDbs();
try {
errorHandler.onCorruption(dbObj);
errorHandler.onCorruption(dbObj, new SQLiteException());
if(SQLiteDatabase.hasCodec()){
assertTrue(dbfile.exists());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private class SqlCipherOpenHelper extends SQLiteOpenHelper {
private final String TAG = getClass().getSimpleName();

public SqlCipherOpenHelper(Context context) {
super(context, "test.db", "test", null, 1, 1, sqLiteDatabase -> Log.e(SQLCipherOpenHelperTest.this.TAG, "onCorruption()"), new SQLiteDatabaseHook() {
super(context, "test.db", "test", null, 1, 1, (sqLiteDatabase, ex) -> Log.e(SQLCipherOpenHelperTest.this.TAG, "onCorruption()"), new SQLiteDatabaseHook() {
@Override
public void preKey(SQLiteConnection sqLiteConnection) {
Log.d(SQLCipherOpenHelperTest.this.TAG, "preKey()");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package net.zetetic.database;

import android.database.sqlite.SQLiteException;

import net.zetetic.database.sqlcipher.SQLiteDatabase;

/**
Expand All @@ -32,6 +34,7 @@ public interface DatabaseErrorHandler {
* The method invoked when database corruption is detected.
* @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption
* is detected.
* @param exception the exception reported by sqlite that indicated the database was corrupted.
*/
void onCorruption(SQLiteDatabase dbObj);
void onCorruption(SQLiteDatabase dbObj, SQLiteException exception);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final class DefaultDatabaseErrorHandler implements DatabaseErrorHandler {
* @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption
* is detected.
*/
public void onCorruption(SQLiteDatabase dbObj) {
public void onCorruption(SQLiteDatabase dbObj, SQLiteException exception) {
Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath());

// If this is a SEE build, do not delete any database files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ String getLabel() {
/**
* Sends a corruption message to the database error handler.
*/
void onCorruption() {
void onCorruption(SQLiteException exception) {
EventLog.writeEvent(EVENT_DB_CORRUPT, getLabel());
mErrorHandler.onCorruption(this);
mErrorHandler.onCorruption(this, exception);
}

/**
Expand Down Expand Up @@ -1012,7 +1012,7 @@ private void open() {
try {
openInner();
} catch (SQLiteDatabaseCorruptException ex) {
onCorruption();
onCorruption(ex);
openInner();
}
} catch (SQLiteException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package net.zetetic.database.sqlcipher;

import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteException;
import android.os.CancellationSignal;

import androidx.sqlite.db.SupportSQLiteProgram;
Expand Down Expand Up @@ -113,8 +114,8 @@ protected final int getConnectionFlags() {
}

/** @hide */
protected final void onCorruption() {
mDatabase.onCorruption();
protected final void onCorruption(SQLiteException exception) {
mDatabase.onCorruption(exception);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ window, startPos, requiredPos, countAllRows, getConnectionFlags(),
mCancellationSignal);
return numRows;
} catch (SQLiteDatabaseCorruptException ex) {
onCorruption();
onCorruption(ex);
throw ex;
} catch (SQLiteException ex) {
Log.e(TAG, "exception: " + ex.getMessage() + "; query: " + getSql());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void executeRaw() {
try {
getSession().executeRaw(getSql(), getBindArgs(), getConnectionFlags(), null);
} catch (SQLiteDatabaseCorruptException ex) {
onCorruption();
onCorruption(ex);
throw ex;
} finally {
releaseReference();
Expand All @@ -69,7 +69,7 @@ public void execute() {
try {
getSession().execute(getSql(), getBindArgs(), getConnectionFlags(), null);
} catch (SQLiteDatabaseCorruptException ex) {
onCorruption();
onCorruption(ex);
throw ex;
} finally {
releaseReference();
Expand All @@ -90,7 +90,7 @@ public int executeUpdateDelete() {
return getSession().executeForChangedRowCount(
getSql(), getBindArgs(), getConnectionFlags(), null);
} catch (SQLiteDatabaseCorruptException ex) {
onCorruption();
onCorruption(ex);
throw ex;
} finally {
releaseReference();
Expand All @@ -112,7 +112,7 @@ public long executeInsert() {
return getSession().executeForLastInsertedRowId(
getSql(), getBindArgs(), getConnectionFlags(), null);
} catch (SQLiteDatabaseCorruptException ex) {
onCorruption();
onCorruption(ex);
throw ex;
} finally {
releaseReference();
Expand All @@ -133,7 +133,7 @@ public long simpleQueryForLong() {
return getSession().executeForLong(
getSql(), getBindArgs(), getConnectionFlags(), null);
} catch (SQLiteDatabaseCorruptException ex) {
onCorruption();
onCorruption(ex);
throw ex;
} finally {
releaseReference();
Expand All @@ -154,7 +154,7 @@ public String simpleQueryForString() {
return getSession().executeForString(
getSql(), getBindArgs(), getConnectionFlags(), null);
} catch (SQLiteDatabaseCorruptException ex) {
onCorruption();
onCorruption(ex);
throw ex;
} finally {
releaseReference();
Expand All @@ -175,7 +175,7 @@ public ParcelFileDescriptor simpleQueryForBlobFileDescriptor() {
return getSession().executeForBlobFileDescriptor(
getSql(), getBindArgs(), getConnectionFlags(), null);
} catch (SQLiteDatabaseCorruptException ex) {
onCorruption();
onCorruption(ex);
throw ex;
} finally {
releaseReference();
Expand Down