From 8d1110383d4437eeebae337026cd91449e4e55a5 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Tue, 22 Jun 2010 18:34:21 -0700 Subject: [PATCH] if attach database sql statement is exec'ed, disable write WAL an app can execute 'attach database..' statement anytime after WAL is enabled. since WAL doesn't work with atatched databases, disable WAL whenever the caller executes 'attach database' sql statement. Change-Id: I77dfcb744b59476c357d44296c14d63455985a7b --- .../android/database/sqlite/SQLiteDatabase.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java index 7fe225e15b116..a6753a8acfe24 100644 --- a/core/java/android/database/sqlite/SQLiteDatabase.java +++ b/core/java/android/database/sqlite/SQLiteDatabase.java @@ -1861,6 +1861,11 @@ public class SQLiteDatabase extends SQLiteClosable { * @throws SQLException If the SQL string is invalid for some reason */ public void execSQL(String sql) throws SQLException { + sql = sql.trim(); + String prefix = sql.substring(0, 6); + if (prefix.equalsIgnoreCase("ATTACH")) { + disableWriteAheadLogging(); + } verifyDbIsOpen(); BlockGuard.getThreadPolicy().onWriteToDisk(); long timeStart = SystemClock.uptimeMillis(); @@ -2345,6 +2350,14 @@ public class SQLiteDatabase extends SQLiteClosable { return true; } + private synchronized void disableWriteAheadLogging() { + if (mConnectionPool == null) { + return; + } + mConnectionPool.close(); + mConnectionPool = null; + } + /** * Sets the database connection handle pool size to the given value. * Database connection handle pool is enabled when the app calls