33import net .sqlcipher .Cursor ;
44import net .sqlcipher .database .SQLiteDatabase ;
55import net .sqlcipher .database .SQLiteDatabaseHook ;
6+ import net .sqlcipher .database .SQLiteException ;
7+ import net .zetetic .QueryHelper ;
68import net .zetetic .ZeteticApplication ;
79
810import java .io .File ;
@@ -27,16 +29,25 @@ public boolean execute(SQLiteDatabase database) {
2729 database .execSQL ("insert into t1(a,b) values(?, ?);" , new Object []{"one for the money" , "two for the show" });
2830 database .close ();
2931
30- database = SQLiteDatabase .openDatabase (databaseFile .getAbsolutePath (), ZeteticApplication .DATABASE_PASSWORD ,
31- null , SQLiteDatabase .OPEN_READWRITE , hook );
32- if (database != null ){
33- Cursor cursor = database .rawQuery ("select * from t1;" , new String []{});
34- if (cursor != null ){
35- cursor .moveToFirst ();
36- String a = cursor .getString (0 );
37- String b = cursor .getString (1 );
38- status = "one for the money" .equals (a ) && "two for the show" .equals (b );
39- cursor .close ();
32+ try {
33+ database = SQLiteDatabase .openDatabase (databaseFile .getAbsolutePath (), ZeteticApplication .DATABASE_PASSWORD ,
34+ null , SQLiteDatabase .OPEN_READWRITE , null );
35+ return false ;
36+ } catch (SQLiteException ex ){
37+
38+ database = SQLiteDatabase .openDatabase (databaseFile .getAbsolutePath (), ZeteticApplication .DATABASE_PASSWORD ,
39+ null , SQLiteDatabase .OPEN_READWRITE , hook );
40+ if (database != null ){
41+ String cipher = QueryHelper .singleValueFromQuery (database , "PRAGMA cipher" );
42+ setMessage (String .format ("Cipher set to:%s" , cipher ));
43+ Cursor cursor = database .rawQuery ("select * from t1;" , new String []{});
44+ if (cursor != null ){
45+ cursor .moveToFirst ();
46+ String a = cursor .getString (0 );
47+ String b = cursor .getString (1 );
48+ status = "one for the money" .equals (a ) && "two for the show" .equals (b );
49+ cursor .close ();
50+ }
4051 }
4152 }
4253 return status ;
0 commit comments