Hello everyone.
After updating net.zetetic:android-database-sqlcipher:3.5.9@aar to net.zetetic:sqlcipher-android:4.5.6@aar in android project I have a problem.
My helper class:
public class DBHelperKey extends SQLiteOpenHelper {
private static DBHelperKey instance;
SQLiteDatabase db;
public DBHelperKey(Context context) {
super(context, "base.db", null, 1);
}
static public synchronized DBHelperKey getInstance(Context context) {
if (instance == null) {
instance = new DBHelperKey(context);
}
return instance;
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("Create table mysettings (id TEXT PRIMARY KEY,myvalue TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
onCreate(sqLiteDatabase);
sqLiteDatabase.execSQL("DROP table if exists mysettings");
}
public void set(String mykey, String myvalue) {
if (!exist(mykey)) {
db.execSQL("insert into mysettings(id,myvalue) values('" + mykey + "','" + myvalue + "')");
} else {
db.execSQL("update mysettings set myvalue='" + myvalue + "' where id='" + mykey + "'");
}
}
public void remove(String mykey) {
db.execSQL("delete from mysettings where id='" + mykey + "'");
}
public String get(String mykey) {
String res = null;
Cursor cursor = db.rawQuery("select myvalue from mysettings where id = '" + mykey + "'", null);
cursor.moveToLast();
try {
res = cursor.getString(cursor.getColumnIndex("myvalue"));
} catch (Exception ignored) {
}
cursor.close();
cursor.deactivate();
//db.close();
return res;
}
public Boolean exist(String mykey) {
boolean res = false;
Cursor cursor = db.rawQuery("select count(myvalue)as cnt from mysettings where id = '" + mykey + "'", null);
cursor.moveToLast();
if (Integer.parseInt(cursor.getString(cursor.getColumnIndex("cnt"))) > 0) {
res = true;
}
cursor.close();
cursor.deactivate();
return res;
}
public void openDB() {
Boolean res = false;
try {
db = instance.getWritableDatabase();
} catch (Exception ex) {
Log.e("openDB_ex", ex.toString());
}
}
}
Log message (openDB_ex) - openDB()
- android.database.sqlite.SQLiteException: file is not a database (code 26): , while compiling: PRAGMA journal_mode
.
Current db without password.
Please help me solve this problem