Java Code Examples for android.database.sqlite.SQLiteDatabase#enableWriteAheadLogging()

The following examples show how to use android.database.sqlite.SQLiteDatabase#enableWriteAheadLogging() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Aria   File: SqlHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取数据库连接
 */
SQLiteDatabase getDb() {
  SQLiteDatabase db;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    SQLiteDatabase.OpenParams params = new SQLiteDatabase.OpenParams.Builder().setOpenFlags(
        SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE |
            SQLiteDatabase.CREATE_IF_NECESSARY).build();
    setOpenParams(params);
    db = getWritableDatabase();
  } else {
    //SQLiteDatabase.openOrCreateDatabase()
    File dbFile = mContext.getDatabasePath(DBConfig.DB_NAME);
    if (!dbFile.exists()) {
      db = getWritableDatabase();
    } else {
      // 触发一次SQLiteOpenHelper的流程,再使用NO_LOCALIZED_COLLATORS标志打开数据库
      db = getReadableDatabase();
      db.close();
      db = SQLiteDatabase.openDatabase(dbFile.getPath(), null,
          SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE |
              SQLiteDatabase.CREATE_IF_NECESSARY);
    }
  }
  db.enableWriteAheadLogging();
  return db;
}
 
Example 2
@Override public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setWriteAheadLoggingEnabled(true);
    } else {
        db.enableWriteAheadLogging();
    }
}
 
Example 3
/**
 * Creates a new instance of the simple open helper.
 *
 * @param context Context to read assets. This will be helped by the
 *                instance.
 */
private DevicesOpenHelper(Context context) {
    super(context, DB_NAME, null, SCHEMA_VERSION);

    this.context = context;

    // This will happen in onConfigure for API >= 16
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        SQLiteDatabase db = getWritableDatabase();
        db.enableWriteAheadLogging();
        db.execSQL("PRAGMA foreign_keys = ON;");
    }
}
 
Example 4
Source Project: stetho   File: SQLiteDatabaseCompat.java    License: MIT License 5 votes vote down vote up
@Override
public void enableFeatures(@SQLiteOpenOptions int openOptions, SQLiteDatabase db) {
  if ((openOptions & ENABLE_WRITE_AHEAD_LOGGING) != 0) {
    db.enableWriteAheadLogging();
  }

  if ((openOptions & ENABLE_FOREIGN_KEY_CONSTRAINTS) != 0) {
    db.execSQL("PRAGMA foreign_keys = ON");
  }
}
 
Example 5
Source Project: QuantumFlux   File: QuantumFluxDatabase.java    License: Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onConfigure(SQLiteDatabase db) {
    super.onConfigure(db);
    if (!db.isReadOnly()) {
        db.enableWriteAheadLogging();
    }
}
 
Example 6
Source Project: QuantumFlux   File: QuantumFluxDatabase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        db.enableWriteAheadLogging();
    }
}
 
Example 7
@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setWriteAheadLoggingEnabled(true);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        db.enableWriteAheadLogging();
    }
}
 
Example 8
Source Project: CPOrm   File: CPOrmDatabase.java    License: MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onConfigure(SQLiteDatabase db) {

    super.onConfigure(db);
    if (!db.isReadOnly()) {
        db.enableWriteAheadLogging();
    }
}
 
Example 9
public void createSampleData() {
    MyDatabaseHelper helper = new MyDatabaseHelper(this);
    SQLiteDatabase db = helper.getWritableDatabase();
    long start = 0;
    try {
        // WALを有効にする
        db.enableWriteAheadLogging();
        Log.d(TAG, "WAL :" + db.isWriteAheadLoggingEnabled());
        db.beginTransaction();
        start = System.nanoTime();
        for (int i = 0; i < 10000; i++) {
            String name = NAMES[mRand.nextInt(NAMES.length)];
            int age = mRand.nextInt(80);
            ContentValues values = new ContentValues();
            values.put("NAME", name);
            values.put("AGE", age);
            db.insert("USERS", null, values);
        }
        start = printTimeLog("Insert処理", start, System.nanoTime());
        db.setTransactionSuccessful();
        start = printTimeLog("setTransactionSuccessful", start,
                System.nanoTime());
    } finally {
        db.endTransaction();
        start = printTimeLog("endTransaction", start, System.nanoTime());
        db.close();
        helper.close();
        printTimeLog("Close処理", start, System.nanoTime());
    }
}
 
Example 10
@Override
public void onConfigure(SQLiteDatabase db) {
    db.enableWriteAheadLogging();
    super.onConfigure(db);
}
 
Example 11
@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    QiscusLogger.print("Opening database.. ");
    db.enableWriteAheadLogging();
}
 
Example 12
@Override
public void onConfigure(SQLiteDatabase db) {
    db.enableWriteAheadLogging();
    super.onConfigure(db);
}
 
Example 13
@Override
public SQLiteDatabase getReadableDatabase() {
    SQLiteDatabase database = super.getReadableDatabase();
    database.enableWriteAheadLogging();
    return database;
}
 
Example 14
@Override
public SQLiteDatabase getWritableDatabase() {
    SQLiteDatabase database = super.getWritableDatabase();
    database.enableWriteAheadLogging();
    return database;
}
 
Example 15
@Override
public SQLiteDatabase getReadableDatabase() {
    SQLiteDatabase db = super.getReadableDatabase();
    db.enableWriteAheadLogging();
    return db;
}
 
Example 16
@Override
public SQLiteDatabase getWritableDatabase() {
    SQLiteDatabase db = super.getWritableDatabase();
    db.enableWriteAheadLogging();
    return db;
}
 
Example 17
Source Project: open   File: AppModule.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Provides @Singleton SQLiteDatabase provideDb() {
    DatabaseHelper databaseHelper = new DatabaseHelper(context);
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.enableWriteAheadLogging();
    return db;
}
 
Example 18
Source Project: open   File: TestAppModule.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Provides @Singleton SQLiteDatabase provideDb() {
    DatabaseHelper databaseHelper = new DatabaseHelper(context);
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.enableWriteAheadLogging();
    return db;
}
 
Example 19
Source Project: CPOrm   File: CPOrmDatabase.java    License: MIT License 3 votes vote down vote up
@Override
public void onOpen(SQLiteDatabase db) {

    super.onOpen(db);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {

        db.enableWriteAheadLogging();
    }
}