Solved QSqlDatabase and local Sqlite 3. Abnormal application stop.
-
Hello!
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?
For this topic I found this https://stackoverflow.com/questions/1452790/will-database-file-of-sqlite3-be-damaged-when-suddenly-power-off-or-os-crash
-
@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. -
@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. -
@jsulm Ok. I know how to perform backup on SQlite (here everything described):
- 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).
-
@bogong said in QSqlDatabase and local Sqlite 3. Abnormal application stop.:
Lock DB
Copy DB physical file somewhere
Unlock DBYou 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?
-
@bogong said in QSqlDatabase and local Sqlite 3. Abnormal application stop.:
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...
-
@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.
- etc
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.