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