[iOS] File is not a database error after successful migration from 3.x to 4.x

I have implemented the DM Migration from 3.x to 4.2 in iOS.
And below is the code that does the migration

-(BOOL) migrate
{
NSLog(@"Migrating 3.x Ciphers to 4.x Cipher");
BOOL mRC = YES;
BOOL *pRC = &mRC;
migrateGroup = dispatch_group_create();
dispatch_group_enter(migrateGroup);
dispatch_async(_databaseQueue, ^{
    NSLog(@"Calling sqlite3_exec migrate");
    sqlite3_exec(_db, [@"PRAGMA cipher_migrate;" UTF8String] , migrateCallback, NULL, NULL);
});
   long status = dispatch_group_wait(migrateGroup,
                    dispatch_time(DISPATCH_TIME_NOW,NSEC_PER_SEC * 120));
NSLog(@"Migration status %ld", status);
if (status != 0) {
    *pRC = NO;
}
NSLog(@"Migration Done with return code: [%d]", mRC);
return mRC;
}

Below is the callback function

static int migrateCallback(void *data, int argc, char **argv, char **azColName){
    int i;
    for(i=0; i<argc; i++){
        NSLog(@"Migration Status: %s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
    }
    dispatch_group_leave(migrateGroup);
    return 0;
}

When I use this migrate API I am getting a status code of 0 which indicates success.
But after this when trying to access the database I am getting File is not a database.

Unfortunately, we cannot share a re-creatable scenario or data that is causing the issue. All we can share is the logs that we have when we re-created the issue. If we can get any pointers or directions on why it is happening, it would help resolve the issue.

Here are the logs for the migration

Migrating 3.x Ciphers to 4.x Cipher
Calling sqlite3_exec migrate
Inside migrateCallback
Migration Status: cipher_migrate = 1
Migration status 0

Here are the logs we are getting when executing the SQL statement

create table ‘userProfileStore’ ( _id INTEGER primary key autoincrement, ‘username’ TEXT, json BLOB, _dirty REAL default 0, _deleted INTEGER default 0, _operation TEXT);
creating sql statement
Creation looks like a failure
Failure message → file is not a database

If the table already exists it should return Table already exists. But here I am getting a file is not a database error.

Hi @rajarahul

Thank you for your interest in SQLCipher and for posting to the discussion forum.

I think that you may be confusing result of the migration with the return from disaptch_group_wait. The return from dispatch_group_wait indicates whether the blocks finished before the timeout period.

Within your callback from sqlite_exec you can see that you’re getting a non-zero result code, which indicates that the migration is failing, possibly because the key is incorrect?