summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/database/sqlite/SQLiteConnection.java4
-rw-r--r--core/java/android/database/sqlite/SQLiteConnectionPool.java10
-rw-r--r--core/java/android/database/sqlite/SQLiteDatabase.java6
3 files changed, 18 insertions, 2 deletions
diff --git a/core/java/android/database/sqlite/SQLiteConnection.java b/core/java/android/database/sqlite/SQLiteConnection.java
index 4b3eb3a000ff..45326610fbd0 100644
--- a/core/java/android/database/sqlite/SQLiteConnection.java
+++ b/core/java/android/database/sqlite/SQLiteConnection.java
@@ -1392,6 +1392,10 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
return sql.replaceAll("[\\s]*\\n+[\\s]*", " ");
}
+ void clearPreparedStatementCache() {
+ mPreparedStatementCache.evictAll();
+ }
+
/**
* Holder type for a prepared statement.
*
diff --git a/core/java/android/database/sqlite/SQLiteConnectionPool.java b/core/java/android/database/sqlite/SQLiteConnectionPool.java
index 069c264313e7..6023d66b9c88 100644
--- a/core/java/android/database/sqlite/SQLiteConnectionPool.java
+++ b/core/java/android/database/sqlite/SQLiteConnectionPool.java
@@ -1126,6 +1126,16 @@ public final class SQLiteConnectionPool implements Closeable {
mConnectionWaiterPool = waiter;
}
+ void clearAcquiredConnectionsPreparedStatementCache() {
+ synchronized (mLock) {
+ if (!mAcquiredConnections.isEmpty()) {
+ for (SQLiteConnection connection : mAcquiredConnections.keySet()) {
+ connection.clearPreparedStatementCache();
+ }
+ }
+ }
+ }
+
/**
* Dumps debugging information about this connection pool.
*
diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java
index c08294f42c45..db898c3b7b5d 100644
--- a/core/java/android/database/sqlite/SQLiteDatabase.java
+++ b/core/java/android/database/sqlite/SQLiteDatabase.java
@@ -2088,10 +2088,12 @@ public final class SQLiteDatabase extends SQLiteClosable {
try (SQLiteStatement statement = new SQLiteStatement(this, sql, bindArgs)) {
return statement.executeUpdateDelete();
} finally {
- // If schema was updated, close non-primary connections, otherwise they might
- // have outdated schema information
+ // If schema was updated, close non-primary connections and clear prepared
+ // statement caches of active connections, otherwise they might have outdated
+ // schema information.
if (statementType == DatabaseUtils.STATEMENT_DDL) {
mConnectionPoolLocked.closeAvailableNonPrimaryConnectionsAndLogExceptions();
+ mConnectionPoolLocked.clearAcquiredConnectionsPreparedStatementCache();
}
}
} finally {