Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QSqlDatabase and local Sqlite 3. Abnormal application stop.
I am trying to find information about handling Sqlite data restore issues if something goes wrong with application at time of writing to DB locally. For example: application writing into DB but occasionally the electricity switched off at the middle of writing and the questions:
- what will be happening in Sqlite?
- is there any documentation about restoring Sqlite after crash?
- is there something special in Qt for this case?
@bogong SQLite supports transactions, that means: if a write operation was not committed (because your app crashed or what ever) your database will be unchanged.
"what will be happening in Sqlite?" see above
"is there any documentation about restoring Sqlite after crash?" - no idea, you should check SQLite documentation, has nothing to do with Qt. Just search on the Web. For example https://www.recoveryandmanagement.com/repair-sqlite-database-manually/
"is there something special in Qt for this case?" - I don't think so, because there is no need to have something special in Qt for this.
bogong last edited by
@jsulm thx for reply. I know about transaction. I mean about db-file physically (my precautions might be overkill, but on other DB Engines I've seen corrupted file physically because of switched off electricity).
@bogong This is outside of Qts scope. You should search for this functionality in SQLite project and on the Web in general.
Also, since SQLite is file based you can easily create copies of the DB file and restore older one if the current gets corrupted.
- Lock DB
- Copy DB physical file somewhere
- Unlock DB
It's very similar to many others SQL DB Engines
I've been seeking something that already is in Qt Distribution because of SQlite plugin in Qt. Seems nothing changed for last 5 years. For me it's very curious because data backup point - is where I am always starting developing of any storage and it's doesn't matter on which language (but it's only my own opinion).
Copy DB physical file somewhere
You can already do this with Qt
@jsulm Is there backup-module implemented in-box for Qt where I only define directory and file for backup?
Is there backup-module implemented in-box for Qt
No, I don't see a reason why it should be in Qt. Doing a simple file copy every n minutes isn't really that hard...
bogong last edited by
@christian-ehrlicher You are very wrong about "very simple", and this is why:
- When you making DB lock you should care about cache where data preliminary storing for being added into when unlock, especially for embedded and mobile device if they working like data aggregator.
- If the data structure of the DB complicated and contain few related DB's you have to cary about the structure first
- The correct way for complex data might be not enough only physical copying files, it might to take time and load heavily - mean need to be implemented in thread within defined priority and if there are not enough battery you will kill backup and DB.
It's only few issues that I've been handling on SQlite.
When you really care about such a data integrity then SQLite is for sure not the correct choice...
@christian-ehrlicher In some cases it's only one way ... first of any - license ... That why I am asking and doing such complexity.