我很久以前在我们的项目中集成了sqlcipher。由于一些安全问题,我们必须升级 sqlcipher 的版本。我已经通过以下链接
- https://discuss.zetetic.net/t/migrating-from-sqlcipher-3-5-1-to-4-1-3-in-android/3652
- https://discuss.zetetic.net/t/upgrading-sqlcipher-for-android-from-3-to-4/3580
但我不知道在哪里添加该代码。我如何将他们的代码与我的集成。
这是我的 Logcat
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.axis.leadsloans, PID: 8798
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.axis.leadsloans/com.axis.leadsloans.nnmnu}: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2928)
Caused by: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;
这是我的数据库相关代码。
public class CRMDB {
private SQLiteHelper sqLiteHelper;
public SQLiteDatabase sqLiteDatabase;
private Context context;
.
.
.
public CRMDB(Context c) {
context = c;
String s = "";
SQLiteDatabase.loadLibs(c);
SharedPreferences prefs = c.getSharedPreferences(Constants.PREFERENCE_NAME, Activity.MODE_PRIVATE);
empid = prefs.getString("empid", "");
}
public CRMDB openToWrite() throws SQLiteFullException {
sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME + "_" + empid + ".db", null, MYDATABASE_VERSION);
//App get crash on this line
sqLiteDatabase = sqLiteHelper.getWritableDatabase("password");
return this;
}
public CRMDB openToRead() throws SQLiteFullException {
sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME + "_" + empid + ".db", null, MYDATABASE_VERSION);
sqLiteDatabase = sqLiteHelper.getReadableDatabase("password");
return this;
}
public long insertData(String tablename, ContentValues contentvalue) {
return sqLiteDatabase.insert(tablename, null, contentvalue);
}
public Cursor getData(String query) {
Cursor c = sqLiteDatabase.rawQuery(query, null);
return c;
}
public long updateData(String tablename, ContentValues contentvalue, String where, String whereArgs[]) {
return sqLiteDatabase.update(tablename, contentvalue, where, whereArgs);
}
public class SQLiteHelper extends SQLiteOpenHelper {
public SQLiteHelper(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(tb_task_createtable);
db.execSQL(tb_calls_createtable);
db.execSQL(tb_messages_table);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
}
请帮助我理解这一点。