5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FMDBとSQLCipherを合わせて使う

Last updated at Posted at 2014-05-23

ほとんどこちら -> (http://labs.torques.jp/2012/11/19/3018/ )に書かれてた通りだけど詰まったとこのメモ。

Xcodeでのsqlcipherのビルド時にエラー

clang: error: no such file or directory: ..../sqlite.c

先にmakeする。
-> http://stackoverflow.com/questions/19490208/unable-to-build-sqlcipher-in-xcode-missing-sqlite3-c

PodFile

pod 'FMDB'
pod 'FMDB/SQLCipher'

て両方するのかと勘違いしていたが、

pod 'FMDB/SQLCipher'

だけでOK。

[FMDatabaseQueue inTransaction:]でsetKeyするとエラー

エラーの出た例

FMDatabaseQueue *q = [[FMDatabaseQueue alloc] initWithPath:@"DB_PATH"];
[q inTransaction:^(FMDatabase *db, BOOL rollback){
  [db setKey:@"SECRET"];
  // ほげほげする
}];

Unknown error calling sqlite3_step (11: database disk image is malformed) eu
(最後のeuてなんだかよく分からないけど付いてたママ)

[FMDatabaseQueue inTransaction:]に入った時点で、begin transactionされちゃっているので、その前に[FMDatabase setKey:]しないとダメ

FMDatabaseQueue *q = [[FMDatabaseQueue alloc] initWithPath:@"DB_PATH"];
[q inDatabase:^(FMDatabase *db){
  [db setKey:@"SECRET"];
}];
// ↑を1回最初にしてから

[q inTransaction:^(FMDatabase *db, BOOL rollback){
  // ほげほげする
}];
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?