ccgus / fmdb

A Cocoa / Objective-C wrapper around SQLite
Other
13.84k stars 2.76k forks source link

sqlcipher not work? #387

Open xuzhiming opened 9 years ago

xuzhiming commented 9 years ago

Hi, I pod the FMDB/SQLCipher, and i use the FMDatabaseQueue like this:

[self.dbQueue inTransaction:^(FMDatabase *db, BOOL *rollback) {
      [db setKey:TEST_SECRET_KEY];
      //create table ...
    }];

then got the message: "Unknown error calling sqlite3_step (11: database disk image is malformed) eu". Btw, I looked up the setKey method, and here is the notation:

///-------------------------
/// @name Encryption methods
///-------------------------

/** Set encryption key.

 @param key The key to be used.

 @return `YES` if success, `NO` on error.

 @see http://www.sqlite-encrypt.com/develop-guide.htm

 @warning You need to have purchased the sqlite encryption extensions for this method to work.
 */
- (BOOL)setKey:(NSString*)key;

So could someone tell me 1.Do I need to purchase the encryption extension to make this work?(Or is there another way to use this?) 2.The link http://www.sqlite-encrypt.com/develop-guide.html seems can not open.

billymeltdown commented 9 years ago

I'm not exactly hip with the Cocoapods just yet so you'll need to look up the command syntax (perhaps someone else can chime in here?), but the FMDB podspec includes a subspec named SQLCipher to ensure that the library is built and added to your project when you use that option:

https://github.com/ccgus/fmdb/blob/master/FMDB.podspec

clemensg commented 9 years ago

@xuzhiming Please have a look at: https://www.zetetic.net/sqlcipher/open-source/

You do not have to buy it, but in that case you have to include their license text "prominently" in application and documentation.

You could be missing the SQLITE_TEMP_STORE=2 build flag. It is documented on the SQLCipher GitHub page. You could try cloning the FMDB repo, replacing line 50 in FMDB.podspec with ss.xcconfig = { 'OTHER_CFLAGS' => '$(inherited) -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2' } and then specifying the FMDB/SQLCipher dependency in your Podfile with a path argument to your local FMDB clone.