Sqlcipher migration fails from 3.x to 4.x in iOS

Hi All,

I am trying to migrate my SQLCipher encrypted DB in iOS, it’s ending up with Create statement failed, message: [file is not a database] whenever I tried to run a simple query after the Migration.

I followed the steps as mentioned in the following doc Upgrading to SQLCipher 4

    PRAGMA key = "x'a651949519df3393a3dfe81b2a537b500914245974b35b780369b0fbadd36e49'";
    PRAGMA cipher_migrate;

Executed the above commands using following API
sqlite3_exec(); -> Returns 0

However, running a simple query in the DB after migration will end up in the above error.

Sample 3.x DB which I am trying with vittal.sqlite.zip (3.2 KB)

Key for the sample DB is pasted above

Any help is much appreciated.


Hi @vittalpai

Do you have any other non-default cipher settings being set to access your SQLCipher 3 database? The reason I ask is that I am unable to migrate your database using SQLCipher 4 from the command line:

sqlite3_exec may be returning 0, however, the result of the statement is actually reported via the callback function provided to sqlite3_exec. You can try passing a reference to a function like this to confirm on your end:

int result_callback(void *arg, int argc, char **argv, char **azColName){
  for(int index = 0; index < argc; index++) {
    printf("result:%s:%s",  azColName[index], argv[index]);
  return 0;
rc = sqlite3_exec(db, "PRAGMA cipher_migrate", &result_callback, NULL, NULL);

Hi developernotes,

Thanks for your quick reply, I have tried by adding the callback and am getting the 1 error code in the call back.

Also I am able to access this DB if I run it in backward compatibility mode.

PRAGMA cipher_compatibility = 3;

Any idea on how to resolve this ? Also Can you provide me objective C code snippet for custom export migration?

Hi @vittalpai

I am not able to access the database you uploaded above with the provided password and the cipher_compatibility set to 3.

Hi @developernotes,

Sorry, here is the DB which works fine for me with cipher_compatibility set to 3. However, it fails if I try to migrate with cipher_migrate.

vittal.sqlite.zip (3.2 KB)

PRAGMA key = "x'28185f415a2303dea6e695487dd3ea0b7a773aa733e9e71720a134d7d77cdbef'";

Hello @vittalpai - I downloaded the file you attached and was able to use cipher_migrate to update it to SQLCipher 4 without any problems. This tends to point to an application issue. Can you verify that you have available storage space for migration and that both the database and the folder it is stored in are writable by the application?

Thanks a lot, @developernotes and @sjlombardo.

The issue got resolved. My app code was asynchronous and It was checking for sqlite3_exec return code.

Changing the app code to run synchronously esp wait till it returns the value from callback of sqlite3_exec API resolved my issue.


Hi @vittalpai

Thanks for the update, we are happy to hear you were able to resolve the issue.