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

The following examples show how to use android.database.sqlite.SQLiteDatabase#enableWriteAheadLogging() . 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 check out the related API usage on the sidebar.
Example 1
Source File: SqlHelper.java    From Aria with 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
Source File: SqliteDatabaseOpenHelper.java    From FileDownloader with 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) {
        setWriteAheadLoggingEnabled(true);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        db.enableWriteAheadLogging();
    }
}
 
Example 3
Source File: MainActivity.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
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 4
Source File: CPOrmDatabase.java    From CPOrm with 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 5
Source File: QuantumFluxDatabase.java    From QuantumFlux with 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 6
Source File: QuantumFluxDatabase.java    From QuantumFlux with 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 7
Source File: SQLiteDatabaseCompat.java    From stetho with 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 8
Source File: DevicesOpenHelper.java    From device-database with Apache License 2.0 5 votes vote down vote up
/**
 * 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 9
Source File: BreakpointSQLiteHelper.java    From okdownload with 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) {
        setWriteAheadLoggingEnabled(true);
    } else {
        db.enableWriteAheadLogging();
    }
}
 
Example 10
Source File: DatabaseHelper.java    From NetGuard with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onConfigure(SQLiteDatabase db) {
    db.enableWriteAheadLogging();
    super.onConfigure(db);
}
 
Example 11
Source File: DatabaseHelper.java    From tracker-control-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onConfigure(SQLiteDatabase db) {
    db.enableWriteAheadLogging();
    super.onConfigure(db);
}
 
Example 12
Source File: MobiComDatabaseHelper.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public SQLiteDatabase getReadableDatabase() {
    SQLiteDatabase database = super.getReadableDatabase();
    database.enableWriteAheadLogging();
    return database;
}
 
Example 13
Source File: MobiComDatabaseHelper.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public SQLiteDatabase getWritableDatabase() {
    SQLiteDatabase database = super.getWritableDatabase();
    database.enableWriteAheadLogging();
    return database;
}
 
Example 14
Source File: QiscusDbOpenHelper.java    From qiscus-sdk-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    QiscusLogger.print("Opening database.. ");
    db.enableWriteAheadLogging();
}
 
Example 15
Source File: DatabaseHelper.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
@Override
public SQLiteDatabase getReadableDatabase() {
    SQLiteDatabase db = super.getReadableDatabase();
    db.enableWriteAheadLogging();
    return db;
}
 
Example 16
Source File: DatabaseHelper.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
@Override
public SQLiteDatabase getWritableDatabase() {
    SQLiteDatabase db = super.getWritableDatabase();
    db.enableWriteAheadLogging();
    return db;
}
 
Example 17
Source File: AppModule.java    From open with 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 File: TestAppModule.java    From open with 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 File: CPOrmDatabase.java    From CPOrm with 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();
    }
}