0

I need to recreate a SQLite database programmatically under iOS from a malformed database using this command. Which is original from: How to recover a corrupt SQLite3 database?

$ sqlite3 mydata.db ".dump" | sqlite3 new.db

or a equivalent command like this.

$ sqlite3 test.db '.dump' > dbbackup

Scenario: I need a function in my App which could detect the malformed Sqlite database and repair it self.

I used the sqlite3_backup- functions to recreate it, but the recreated database also malformed. But the database which was created with the help of the first command seems to be ok.

But the command is only for terminal and how can I trigger using iOS programmatically?

NB: Any other way to solve the problem also welcomed.

Community
  • 1
  • 1
Goppinath
  • 10,569
  • 4
  • 22
  • 45
  • Why do you need this? SQLite, by default, is ACID compliant; it should never become corrupt, even if the program crashes or your device suddenly loses power. – Colonel Thirty Two Oct 27 '16 at 12:31
  • @ColonelThirtyTwo, I have no idea how it is happening, but it is happening. If you want I can provide one sample. – Goppinath Oct 27 '16 at 12:36
  • See [How To Corrupt An SQLite Database File](http://www.sqlite.org/howtocorrupt.html). Anyway, you cannot simply copy commands blindly from some answer, read the text. – CL. Oct 27 '16 at 12:37
  • Basically I am working with three different Apps. Two of them are using my own SQLite wrapper where I am handling opening and closing carefully. But the very 1st one I undertook from other developer where he handles the open and close functions in an inappropriate manner and I strongly suspect that could be the reason. Because with the other two Apps I never had complain about malformation. The company does't want to do any modification with the existing code and I am suppose to find a workaround for that. – Goppinath Oct 27 '16 at 12:47
  • @CL. Are there any way to trigger your command programmatically under iOS? – Goppinath Oct 27 '16 at 12:48

0 Answers0