2

In my app, I would like to recognize when the database has been damaged and automatically repair it. Specifically, when the app is first opened I run an ANALYZE command and if it comes back with status 11 (database disk image is malformed), then I would like to have a way of recovering the data.

All the examples I find use the terminal to do a dump and then import of the subsequent SQL command file.

How can I do a dump of the db from within my own code since the command line isn't available on iOS?

Thanks

1
  • The .dump often does not work; it simply outputs everything that happens to be readable. Commented Feb 20, 2016 at 14:00

1 Answer 1

1

I think you can easily copy and save the database with another name (extend timestamp). You have to figure out when it is damaging(It should not damage it depends on your meaning of damage) and replace it.

NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *sqlpath = [documentsDirectory stringByAppendingPathComponent:@"Your-sqlitefile"];
NSString *sqldump = //append timestamp

[fileManager copyItemAtPath:sqlpath toPath:sqldump error:&error];

Edit:

Please refer below answer. I have not used by myself but hope it helps. https://stackoverflow.com/a/27453637/1881472

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.