Error: No such function: sqlcipher_export iOS


#1

I have installed SQLCipher via pod. but I am getting this error saying No such function: sqlcipher_export. I was using FMDB and for SQLCipher I am using the subspec of it i.e. FMDB/sqlcipher. I have added #import <SQLCipher/sqlite3.h> on top
below is my code:

NSString *docsDir;
NSArray *dirPaths; 
dirPaths = NSSearchPathForDirectoriesInDomains
(NSApplicationSupportDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];

databasePath = [[NSString alloc] initWithString:[docsDir stringByAppendingPathComponent: @"MyDB.db"]];

NSString *encryptDB = [docsDir stringByAppendingPathComponent:@"MyDB_enc.db"];

const char* sqlQ = [[NSString stringWithFormat:@"ATTACH DATABASE '%@' AS MyDB_enc KEY 'test123';",encryptDB] UTF8String];

//sqlite3 *unencrypted_DB;

if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
    
    // Attach empty encrypted database to unencrypted database
    sqlite3_exec(database, sqlQ, NULL, NULL, NULL);

    // export database
    sqlite3_exec(database, "SELECT sqlcipher_export('MyDB_enc');", NULL, NULL, NULL); //gives error
    
    // Detach encrypted database
    sqlite3_exec(database, "DETACH DATABASE MyDB_enc;", NULL, NULL, NULL);
    
    sqlite3_close(database);
}
else {
    sqlite3_close(database);
    NSAssert1(NO, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
}

databasePath = [docsDir stringByAppendingPathComponent:@"MyDB_enc.db"];

can anyone guide me on how to fix this issue


#2

Hello @Ajeet_Maurya

It sounds as if your project is not correctly including SQLCipher, or that you may have another dependency that is overriding SQLCipher, causing your application to link against another version of SQLite. You can check if your application is linking against SQLCipher by querying the library for the cipher version, this will only be reported by SQLCipher. Please execute the following command and share the results:

PRAGMA cipher_version;

#3

Hey @developernotes

I removed the pods and used the sqlite3.h from the binary and its working fine.
Thanks.


#4

Hello @Ajeet_Maurya

We are happy to hear everything is working properly for you now.