【问题标题】:GreenDAO cannot access existed database after upgrading sqlcipher from 3.5.2 to 4.0.1将 sqlcipher 从 3.5.2 升级到 4.0.1 后,GreenDAO 无法访问现有数据库
【发布时间】:2019-02-20 11:34:54
【问题描述】:

我正在使用 GreenDAOSQLCipher。 在我将SQLCipher 从 3.5.2 升级到 4.0.1 后,我的应用程序无法访问旧的加密数据库。 我已经搜索了一个解决方案,发现我需要在SQLiteDatabaseHookpostKey 中运行PRAGMA cipher_migrate 来迁移我的数据库。我试过这样,但没有任何改变。:

    SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
        @Override
        public void preKey(SQLiteDatabase database) {

        }

        @Override
        public void postKey(SQLiteDatabase database) {
            database.execSQL("PRAGMA key = '" + key + "';");
            database.execSQL("PRAGMA cipher_migrate;");
        }
    };
    Database db = new EncryptedDatabase(SQLiteDatabase.openOrCreateDatabase("DB.db", key, null, hook));
    return new DaoMaster(db).newSession();

【问题讨论】:

    标签: android greendao sqlcipher


    【解决方案1】:

    当它需要路径时,您将"DB.db" 传递给openOrCreateDatabase。你想做这样的事情:

        File dbPathFile = new File(path);
        if (!dbPathFile.exists()) {
          dbPathFile.getParentFile().mkdirs();
        }
    

    然后在 openOrCreateDatabase 中传递 "DB.db" 的地方传递 path

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-27
      • 2012-09-06
      • 2017-10-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多