Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8fcda302 authored by Vasu Nori's avatar Vasu Nori
Browse files

on readonly databases, don't set journal mode and don't allow WAL

nothing should be 'set' on readonly databases
bug:3173033

Change-Id: I1143971f6d06139a7e1ef9e73a92e46342264075
parent db901563
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -1023,14 +1023,16 @@ public class SQLiteDatabase extends SQLiteClosable {

    private void setJournalMode(final String dbPath, final String mode) {
        // journal mode can be set only for non-memory databases
        if (!dbPath.equalsIgnoreCase(MEMORY_DB_PATH)) {
        // AND can't be set for readonly databases
        if (dbPath.equalsIgnoreCase(MEMORY_DB_PATH) || isReadOnly()) {
            return;
        }
        String s = DatabaseUtils.stringForQuery(this, "PRAGMA journal_mode=" + mode, null);
        if (!s.equalsIgnoreCase(mode)) {
            Log.e(TAG, "setting journal_mode to " + mode + " failed for db: " + dbPath +
                    " (on pragma set journal_mode, sqlite returned:" + s);
        }
    }
    }

    /**
     * Create a memory backed SQLite database.  Its contents will be destroyed
@@ -2317,6 +2319,10 @@ public class SQLiteDatabase extends SQLiteClosable {
     * @return true if write-ahead-logging is set. false otherwise
     */
    public boolean enableWriteAheadLogging() {
        // make sure the database is not READONLY. WAL doesn't make sense for readonly-databases.
        if (isReadOnly()) {
            return false;
        }
        // acquire lock - no that no other thread is enabling WAL at the same time
        lock();
        try {