From e495d1f74af13aec8d5d825e93e4cfe1e4fe7468 Mon Sep 17 00:00:00 2001
From: Vasu Nori <vnori@google.com>
Date: Wed, 6 Jan 2010 16:34:19 -0800
Subject: fix a bug in compiled-sql caching & hide public api
 setMaxSqlCacheSize

this is a clone of https://android-git.corp.google.com/g/#change,35174.
if the cache is full to its capacity and if a new statement is to be cached,
one of the entries in the cache is thrown out to make room for the new one.
but the one that is thrown out doesn't get deallocated by SQLiteProgram
because it doesn't know that it should.
fixed this by having SQLiteProgram finalize its sql statement in
releaseReference*() methods, if the statement is not in cache.
---
 .../src/com/android/unit_tests/DatabaseGeneralTest.java    | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

(limited to 'tests')

diff --git a/tests/AndroidTests/src/com/android/unit_tests/DatabaseGeneralTest.java b/tests/AndroidTests/src/com/android/unit_tests/DatabaseGeneralTest.java
index 7a4d934..69d55c1 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/DatabaseGeneralTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/DatabaseGeneralTest.java
@@ -987,4 +987,18 @@ public class DatabaseGeneralTest extends TestCase implements PerformanceTestCase
         ih.close();
     }
 
+    @MediumTest
+    public void testDbCloseReleasingAllCachedSql() {
+        mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, text1 TEXT, text2 TEXT, " +
+                "num1 INTEGER, num2 INTEGER, image BLOB);");
+        final String statement = "DELETE FROM test WHERE _id=?;";
+        SQLiteStatement statementDoNotClose = mDatabase.compileStatement(statement);
+        assertTrue(statementDoNotClose.getUniqueId() > 0);
+        int nStatement = statementDoNotClose.getUniqueId();
+        assertTrue(statementDoNotClose.getUniqueId() == nStatement);
+        /* do not close statementDoNotClose object. 
+         * That should leave it in SQLiteDatabase.mPrograms.
+         * mDatabase.close() in tearDown() should release it.
+         */
+    }
 }
-- 
cgit v1.1