1

In the device settings,AutoLock is 5 minutes, and Passcode Lock is Immediatly.

Suppose user clicked the power button of device when application is processing a large xml from server and insert/update database file. (the device will be in a locaked state when user click power button) When the device is locked, we are seeing the errors like

failed to CREATE statement with message 'unable to open database file'.' or disk I/O error

We are performing sqlite3_step, sqlite3_exec, sqlite3_prepare_v2 operations when process xml.

tried these..

  1. open database file when application launches and close when application terminates. So we we can keep the database open when user lock the device..

below is the source code to open database file, this is the code in application delegate class to return the database file. We are calling this method from different classes. databasemain is the instance of sqlite3 * declared in AplicationDelegate.h file.

- (sqlite3 *) getMainDatabase{
    if(databasemain == nil){
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:@"mydb.sqlite"];
        if (sqlite3_open_v2([dbPath UTF8String], &databasemain, SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE|SQLITE_OPEN_FILEPROTECTION_COMPLETEUNLESSOPEN, NULL) == SQLITE_OK){

        }else{
    MyLogAll(@"db not opened");
        }
    }
    return databasemain;
}
  1. Also tried with SQLITE_OPEN_FILEPROTECTION_NONE, but no change..

  2. Also tried with no encryption parameter

    if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

    }


in the device lock state, also loosing the values stored in NSUserDefaults.

Please share your experience to guide me the right direction.

Looking for a way to handle this situation of immediate passcode lock..

zx81
  • 41,100
  • 9
  • 89
  • 105
david
  • 66
  • 6

1 Answers1

3

If has passcode and device is locked,write to the database(file) will get disk I/O error. For some device you can modify open flag(SQLITE_OPEN_FILEPROTECTION_NONE) to solve the problem.But this method is invalid in some other device.Then you can modify the upper directory FileProtection attribute, for example:

[[NSFileManager defaultManager] setAttributes:[NSDictionary dictionaryWithObject:NSFileProtectionNone forKey:NSFileProtectionKey] ofItemAtPath:[NSHomeDirectory() stringByAppendingFormat:@"/Documents"] error:NULL];