1

尝试将数据复制到附加数据库 () 中时,我收到“没有这样的表”异常,该数据库 ( db) 使用普通数据库 () 中的 SQLCipher 加密source

    StringBuilder attachDatabase = new StringBuilder();
    attachDatabase.append("ATTACH DATABASE '").append(this.db.getPath()).
                    append("' as ").append(NEW_DB_ALIAS).
                    append(" KEY '").append("123").append("';");
    source.execSQL(attachDatabase.toString());

    StringBuilder copyTable = new StringBuilder();
    String table = "t1";
    copyTable.append("INSERT INTO ").append(NEW_DB_ALIAS).append(".").append(table).
                append(" SELECT * FROM ").append(table).append(";");
    db.execSQL(copyTable.toString());

创建加密数据库并具有与未加密数据库相同的方案。可能是什么问题呢?

4

1 回答 1

0

您能否验证您使用的是哪个版本的 Android 版 SQLCipher?我们最近发布了 1.0 的库,您可以在此处获取:https ://github.com/downloads/guardianproject/android-database-sqlcipher/SQLCipherForAndroid-SDK-0.0.6-FINAL.zip

我刚刚经历了以下场景,其中新的数据库文件在执行之前不存在并且运行良好。您可以在不先使用架构创建新数据库的情况下尝试这样做吗:

    String newKey = "foo";
    File newDatabasePath = getDatabasePath("new.db");
    String attachCommand = "ATTACH DATABASE ? as encrypted KEY ?";
    String createCommand = "create table encrypted.t1(a,b)";
    String insertCommand = "insert into encrypted.t1 SELECT * from t1";
    String detachCommand = "DETACH DATABASE encrypted";
    encryptedDatabase.execSQL(attachCommand, new Object[]{newDatabasePath.getAbsolutePath(), newKey});
    encryptedDatabase.execSQL(createCommand);
    encryptedDatabase.execSQL(insertCommand);
    encryptedDatabase.execSQL(detachCommand);
于 2011-12-22T20:36:31.490 回答