Skip to content

Instantly share code, notes, and snippets.

@developernotes
Created November 13, 2013 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developernotes/7458248 to your computer and use it in GitHub Desktop.
Save developernotes/7458248 to your computer and use it in GitHub Desktop.
Sample test for opening a SQLCipher 3.0.0 database for the SQLCipher mailing list.
package net.zetetic.tests;
import android.util.Log;
import net.sqlcipher.Cursor;
import net.sqlcipher.database.SQLiteDatabase;
import net.zetetic.ZeteticApplication;
import java.io.File;
import java.io.IOException;
public class SampleTest extends SQLCipherTest {
String db = "parking-enc.s3db";
String password = "xxxxx";
@Override
public boolean execute(SQLiteDatabase database) {
database.close();
try {
ZeteticApplication.getInstance().extractAssetToDatabaseDirectory(db);
File other = ZeteticApplication.getInstance().getDatabasePath(db);
database = SQLiteDatabase.openOrCreateDatabase(other, password, null);
Cursor cursor = database.rawQuery("select * from sqlite_master where type = 'table';", new String[]{});
while(cursor.moveToNext()){
String table = cursor.getString(cursor.getColumnIndex("name"));
Log.i(TAG, String.format("Table found:%s", table));
}
cursor.close();
database.close();
return true;
} catch (IOException e) {
return false;
}
}
@Override
public String getName() {
return "Sample Test";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment