예제 #1
0
 private static void prepareWAL(final SQLiteBridge bridge) {
   // Prepare for WAL mode. If we can, we switch to journal_mode=WAL, then
   // set the checkpoint size appropriately. If we can't, then we fall back
   // to truncating and synchronous writes.
   final Cursor cursor = bridge.internalQuery("PRAGMA journal_mode=WAL", null);
   try {
     if (cursor.moveToFirst()) {
       String journalMode = cursor.getString(0);
       Log.d(LOGTAG, "Journal mode: " + journalMode);
       if ("wal".equals(journalMode)) {
         // Success! Let's make sure we autocheckpoint at a reasonable interval.
         final int pageSizeBytes = bridge.getPageSizeBytes();
         final int checkpointPageCount = MAX_WAL_SIZE_BYTES / pageSizeBytes;
         bridge.internalQuery("PRAGMA wal_autocheckpoint=" + checkpointPageCount, null).close();
       } else {
         if (!"truncate".equals(journalMode)) {
           Log.w(LOGTAG, "Unable to activate WAL journal mode. Using truncate instead.");
           bridge.internalQuery("PRAGMA journal_mode=TRUNCATE", null).close();
         }
         Log.w(LOGTAG, "Not using WAL mode: using synchronous=FULL instead.");
         bridge.internalQuery("PRAGMA synchronous=FULL", null).close();
       }
     }
   } finally {
     cursor.close();
   }
 }
예제 #2
0
 /*
  * The second two parameters here are just provided for compatbility with SQLiteDatabase
  * Support for them is not currently implemented
  */
 public static SQLiteBridge openDatabase(
     String path, SQLiteDatabase.CursorFactory factory, int flags) throws SQLiteException {
   SQLiteBridge bridge = null;
   try {
     bridge = new SQLiteBridge(path);
     bridge.mDbPointer = SQLiteBridge.openDatabase(path);
   } catch (SQLiteBridgeException ex) {
     // catch and rethrow as a SQLiteException to match SQLiteDatabase
     throw new SQLiteException(ex.getMessage());
   }
   return bridge;
 }
예제 #3
0
  /*
   * The second two parameters here are just provided for compatibility with SQLiteDatabase
   * Support for them is not currently implemented.
   */
  public static SQLiteBridge openDatabase(
      String path, SQLiteDatabase.CursorFactory factory, int flags) throws SQLiteException {
    if (factory != null) {
      throw new RuntimeException("factory not supported.");
    }
    if (flags != 0) {
      throw new RuntimeException("flags not supported.");
    }

    SQLiteBridge bridge = null;
    try {
      bridge = new SQLiteBridge(path);
      bridge.mDbPointer = SQLiteBridge.openDatabase(path);
    } catch (SQLiteBridgeException ex) {
      // Catch and rethrow as a SQLiteException to match SQLiteDatabase.
      throw new SQLiteException(ex.getMessage());
    }

    prepareWAL(bridge);

    return bridge;
  }