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
diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java
index 7fe225e1..a6753a8 100644
--- a/core/java/android/database/sqlite/SQLiteDatabase.java
+++ b/core/java/android/database/sqlite/SQLiteDatabase.java
@@ -1861,6 +1861,11 @@
* @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 @@
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