Skip to content

Instantly share code, notes, and snippets.

@developernotes
Created June 14, 2012 15:46
Show Gist options
  • Select an option

  • Save developernotes/2931079 to your computer and use it in GitHub Desktop.

Select an option

Save developernotes/2931079 to your computer and use it in GitHub Desktop.
package net.zetetic.tests;
import android.content.Context;
import android.database.Cursor;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
import net.zetetic.ZeteticApplication;
public class ReadableWritableAccessTest extends SQLCipherTest {
@Override
public boolean execute(SQLiteDatabase database) {
database.close();
ZeteticApplication.getInstance().deleteDatabaseFileAndSiblings(ZeteticApplication.DATABASE_NAME);
DatabaseHelper databaseHelper = new DatabaseHelper(ZeteticApplication.getInstance());
SQLiteDatabase writableDatabase = databaseHelper.getWritableDatabase(ZeteticApplication.DATABASE_PASSWORD);
SQLiteDatabase readableDatabase1 = databaseHelper.getReadableDatabase(ZeteticApplication.DATABASE_PASSWORD);
SQLiteDatabase readableDatabase2 = databaseHelper.getReadableDatabase(ZeteticApplication.DATABASE_PASSWORD);
Cursor results = readableDatabase1.rawQuery("select count(*) from t1", new String[]{});
results.moveToFirst();
int firstRowCount = results.getInt(0);
results.close();
writableDatabase.execSQL("insert into t1(a,b) values(?, ?)", new Object[]{"three to get ready",
"and four to go"});
results = readableDatabase2.rawQuery("select count(*) from t1", new String[]{});
results.moveToFirst();
int secondRowCount = results.getInt(0);
results.close();
return firstRowCount == 1 && secondRowCount == 2;
}
@Override
public String getName() {
return "Readable/Writable Access Test";
}
private class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper(Context context) {
super(context, ZeteticApplication.DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL("create table t1(a,b)");
database.execSQL("insert into t1(a,b) values(?, ?)", new Object[]{"one for the money",
"two for the show"});
}
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment