sqlite pragma

pull/194/head
M66B 5 years ago
parent 95bc640c52
commit 512541483b

@ -113,6 +113,7 @@ public abstract class DB extends RoomDatabase {
private static final String DB_NAME = "fairemail"; private static final String DB_NAME = "fairemail";
private static final int DB_CHECKPOINT = 1000; // requery/sqlite-android default private static final int DB_CHECKPOINT = 1000; // requery/sqlite-android default
private static final int DB_CACHE_SIZE = -5000; // https://www.sqlite.org/pragma.html#pragma_cache_size
private static final String[] DB_TABLES = new String[]{ private static final String[] DB_TABLES = new String[]{
"identity", "account", "folder", "message", "attachment", "operation", "contact", "certificate", "answer", "rule", "log"}; "identity", "account", "folder", "message", "attachment", "operation", "contact", "certificate", "answer", "rule", "log"};
@ -124,7 +125,7 @@ public abstract class DB extends RoomDatabase {
File dbfile = configuration.context.getDatabasePath(DB_NAME); File dbfile = configuration.context.getDatabasePath(DB_NAME);
if (dbfile.exists()) { if (dbfile.exists()) {
try (SQLiteDatabase db = SQLiteDatabase.openDatabase(dbfile.getPath(), null, SQLiteDatabase.OPEN_READWRITE)) { try (SQLiteDatabase db = SQLiteDatabase.openDatabase(dbfile.getPath(), null, SQLiteDatabase.OPEN_READWRITE)) {
Log.i("DB checkpoint=" + DB_CHECKPOINT); Log.i("Set PRAGMA wal_autocheckpoint=" + DB_CHECKPOINT);
try (Cursor cursor = db.rawQuery("PRAGMA wal_autocheckpoint=" + DB_CHECKPOINT + ";", null)) { try (Cursor cursor = db.rawQuery("PRAGMA wal_autocheckpoint=" + DB_CHECKPOINT + ";", null)) {
cursor.moveToNext(); // required cursor.moveToNext(); // required
} }
@ -280,12 +281,25 @@ public abstract class DB extends RoomDatabase {
" version=" + db.getVersion() + " version=" + db.getVersion() +
" WAL=" + db.isWriteAheadLoggingEnabled()); " WAL=" + db.isWriteAheadLoggingEnabled());
try (Cursor cursor = db.query("PRAGMA journal_mode;")) { // https://www.sqlite.org/pragma.html
Log.i("journal_mode=" + (cursor.moveToNext() ? cursor.getString(0) : "?")); for (String pragma : new String[]{
"journal_mode", "journal_size_limit",
"wal_checkpoint", "wal_autocheckpoint",
"page_count", "page_size",
"default_cache_size", "cache_size"})
try (Cursor cursor = db.query("PRAGMA " + pragma + ";")) {
Log.i("Get PRAGMA " + pragma + "=" + (cursor.moveToNext() ? cursor.getString(0) : "?"));
} }
try (Cursor cursor = db.query("PRAGMA wal_autocheckpoint;")) { if (BuildConfig.DEBUG) {
Log.i("wal_autocheckpoint=" + (cursor.moveToNext() ? cursor.getInt(0) : "?")); Log.i("Set PRAGMA cache_size=" + DB_CACHE_SIZE);
try (Cursor cursor = db.query("PRAGMA cache_size=" + DB_CACHE_SIZE + ";", null)) {
cursor.moveToNext(); // required
}
try (Cursor cursor = db.query("PRAGMA cache_size;")) {
Log.i("Get PRAGMA cache_size=" + (cursor.moveToNext() ? cursor.getInt(0) : "?"));
}
} }
if (BuildConfig.DEBUG && false) { if (BuildConfig.DEBUG && false) {

Loading…
Cancel
Save