Java Code Examples for io.requery.android.database.sqlite.SQLiteDatabase#openOrCreateDatabase()

The following examples show how to use io.requery.android.database.sqlite.SQLiteDatabase#openOrCreateDatabase() . 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: DatabaseGeneralTest.java    From sqlite-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    File dbDir = ApplicationProvider.getApplicationContext().getDir(this.getClass().getName(), Context.MODE_PRIVATE);
    mDatabaseFile = new File(dbDir, "database_test.db");
    if (mDatabaseFile.exists()) {
        mDatabaseFile.delete();
    }
    mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
    assertNotNull(mDatabase);
    mDatabase.setVersion(CURRENT_DATABASE_VERSION);
}
 
Example 2
Source File: DatabaseCursorTest.java    From sqlite-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    File dbDir = ApplicationProvider.getApplicationContext().getDir("tests", Context.MODE_PRIVATE);
    mDatabaseFile = new File(dbDir, "database_test.db");

    if (mDatabaseFile.exists()) {
        mDatabaseFile.delete();
    }
    mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
    assertNotNull(mDatabase);
    mDatabase.setVersion(CURRENT_DATABASE_VERSION);
}
 
Example 3
Source File: NewDatabasePerformanceTests.java    From sqlite-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ResultOfMethodCallIgnored")
@SuppressLint("SdCardPath")
@Before
public void setUp() {
    mDatabaseFile = new File("/sdcard", "perf_database_test.db");
    if (mDatabaseFile.exists()) {
        mDatabaseFile.delete();
    }
    mDatabase =
            SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(),
                    null);
    assertTrue(mDatabase != null);
    mDatabase.setVersion(CURRENT_DATABASE_VERSION);
}
 
Example 4
Source File: DatabaseStatementTest.java    From sqlite-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    File dbDir = ApplicationProvider.getApplicationContext().getDir("tests", Context.MODE_PRIVATE);
    mDatabaseFile = new File(dbDir, "database_test.db");

    if (mDatabaseFile.exists()) {
        mDatabaseFile.delete();
    }
    mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
    assertNotNull(mDatabase);
    mDatabase.setVersion(CURRENT_DATABASE_VERSION);
}
 
Example 5
Source File: DatabaseErrorHandlerTest.java    From sqlite-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    dbDir = ApplicationProvider.getApplicationContext().getDir(this.getClass().getName(), Context.MODE_PRIVATE);
    mDatabaseFile = new File(dbDir, DB_NAME);
    if (mDatabaseFile.exists()) {
        mDatabaseFile.delete();
    }
    mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null,
            new MyDatabaseCorruptionHandler());
    assertNotNull(mDatabase);
}
 
Example 6
Source File: DatabaseErrorHandlerTest.java    From sqlite-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testDatabaseIsCorrupt() throws IOException {
    mDatabase.execSQL("create table t (i int);");
    // write junk into the database file
    BufferedWriter writer = new BufferedWriter(new FileWriter(mDatabaseFile.getPath()));
    writer.write("blah");
    writer.close();
    assertTrue(mDatabaseFile.exists());
    // since the database file is now corrupt, doing any sql on this database connection
    // should trigger call to MyDatabaseCorruptionHandler.onCorruption
    try {
        mDatabase.execSQL("select * from t;");
        fail("expected exception");
    } catch (SQLiteDiskIOException e) {
        //
        // this test used to produce a corrupted db. but with new sqlite it instead reports
        // Disk I/O error. meh..
        // need to figure out how to cause corruption in db
        //
        // expected
        if (mDatabaseFile.exists()) {
            mDatabaseFile.delete();
        }
    } catch (SQLiteException ignored) {
        
    }
    // database file should be gone
    assertFalse(mDatabaseFile.exists());
    // after corruption handler is called, the database file should be free of
    // database corruption
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null,
            new MyDatabaseCorruptionHandler());
    assertTrue(db.isDatabaseIntegrityOk());
}