From a8c24904ebb301d1a95f9c780aabbe4ebe7026c8 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Tue, 1 Jun 2010 11:30:27 -0700 Subject: [PATCH] set sqlite pagesize to the size, in bytes, of a block on "/data" Change-Id: I40b2bdac348a611eb9fe12ea05b6bd9a87f2310a --- .../android/database/sqlite/SQLiteDatabase.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java index e34e7768ca49a..886951b6ffe71 100644 --- a/core/java/android/database/sqlite/SQLiteDatabase.java +++ b/core/java/android/database/sqlite/SQLiteDatabase.java @@ -25,6 +25,7 @@ import android.database.DefaultDatabaseErrorHandler; import android.database.SQLException; import android.database.sqlite.SQLiteDebug.DbStats; import android.os.Debug; +import android.os.StatFs; import android.os.SystemClock; import android.os.SystemProperties; import android.text.TextUtils; @@ -236,6 +237,12 @@ public class SQLiteDatabase extends SQLiteClosable { /** Used to make temp table names unique */ /* package */ int mTempTableSequence = 0; + /** + * The size, in bytes, of a block on "/data". This corresponds to the Unix + * statfs.f_bsize field. note that this field is lazily initialized. + */ + private static int sBlockSize = 0; + /** The path for the database file */ private String mPath; @@ -858,6 +865,15 @@ public class SQLiteDatabase extends SQLiteClosable { errorHandler.onCorruption(sqliteDatabase); sqliteDatabase = new SQLiteDatabase(path, factory, flags); } + + // set sqlite pagesize to mBlockSize + if (sBlockSize == 0) { + // TODO: "/data" should be a static final String constant somewhere. it is hardcoded + // in several places right now. + sBlockSize = new StatFs("/data").getBlockSize(); + } + sqliteDatabase.setPageSize(sBlockSize); + ActiveDatabases.getInstance().mActiveDatabases.add( new WeakReference(sqliteDatabase)); return sqliteDatabase;