【问题标题】:Android, SQLite: no such table exception in attached databaseAndroid,SQLite:附加数据库中没有此类表异常
【发布时间】:2011-12-21 13:38:54
【问题描述】:

尝试将数据复制到附加数据库 (db) 中时,我收到“没有这样的表”异常,该数据库 (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());

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

【问题讨论】:

  • 你有没有想过这个问题?
  • 没有。不得不以某种方式解决它 - 不记得细节

标签: android database sqlite sqlcipher


【解决方案1】:

您能否验证您使用的是哪个版本的 SQLCipher for Android?我们最近发布了 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);

【讨论】:

  • 我正在使用 SQLCipher for Android v1 (0.0.6-RC1)
  • 你能在两个数据库上使用 SQLCipher 构建的 SQLite3 执行“.schema”命令吗?这将有助于验证两个架构是否相同。
  • 如果您愿意,也可以通过代码运行以下代码进行验证(用您的值替换 NEW_DB_ALIAS): select * from sqlite_master; select * from NEW_DB_ALIAS.sqlite_master;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-02
  • 2012-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多