storesafe / cordova-sqlite-storage

A Cordova/PhoneGap plugin to open and use sqlite databases on Android, iOS and Windows with HTML5/Web SQL API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EXTRA DURABLE build setting to improve robustness against corruption

brodybits opened this issue · comments

As discussed in http://sqlite.1065341.n5.nabble.com/Is-WAL-mode-more-robust-against-corruption-td99624.html:

From https://www.sqlite.org/pragma.html#pragma_synchronous the default PRAGMA synchronous setting is FULL, wonder if it should be EXTRA instead.

Also waiting for more feedback if anyone else on the sqlite-users mailing list can find any possible cause for database corruption in this project. A couple possible causes for corruption on iOS that were recently fixed:

UPDATE: it is desired to use compile-time option to enable this setting by default, details in comment below

ALSO WANTED: use recent SQLite version (3.22.0) to eliminate possibility of corruption due to outdated SQLite version

From https://www.sqlite.org/pragma.html#pragma_synchronous the default PRAGMA synchronous setting is FULL, wonder if it should be EXTRA instead.

Probably better to use SQLITE_DEFAULT_SYNCHRONOUS=3 setting ref:

NOTE that it looks like SQLITE_EXTRA_DURABLE is no longer supported ref: https://www.sqlite.org/compile.html#extra_durable (TBD information in https://www.sqlite.org/pragma.html#pragma_synchronous seems to be in conflict)

ADDITIONAL EXPLANATION: As I said after the response I got to http://sqlite.1065341.n5.nabble.com/Is-WAL-mode-more-robust-against-corruption-td99624.html I would expect that a mobile app may be terminated at any time and would not expect advanced notification to be 100% reliable, especially in a hybrid mobile stack, and should be robust against crashes including possible OS crashes due to bugs, battery issues, etc. This is why I am thinking it would be safest to use the compile-time equivalent to PRAGMA synchronous=3 (EXTRA).

Done in cordova-sqlite-storage & cordova-sqlite-ext, still needed in other plugin versions.

Also related: storesafe/cordova-sqlite-storage-help#34

This setting is now enabled.

For the sake of clarity, the following build-time definition is used on all platforms: SQLITE_DEFAULT_SYNCHRONOUS=3

This is the equivalent to using the following PRAGMA setting: PRAGMA schema.synchronous = EXTRA

ref: https://www.sqlite.org/pragma.html#pragma_synchronous