Created
November 13, 2013 23:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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