On Tue, Feb 13, 2018 at 2:03 PM, Simon Slavin <slav...@bigfraud.org> wrote: > [...] > There are two possibilities: > > A) The SQLite API was used correctly, including being allowed to close all > files it opened. > B) Any other situation. > > If (A) happened, you can predict things about the database header and you can > rely on SQLite documentation about the format of files it uses. Otherwise > you can't.
Thanks Simon for the quick response. Can you clarify the following: - Does this imply that a SQLite database may be left in some kind of unrecoverable, corrupted, or otherwise invalid state in case an application would terminate without calling sqlite3_close() on all open database connections? - If yes, what can a programmer do to protect the data in case an application is abruptly terminated for any reason? - Would using SQLITE_DEFAULT_SYNCHRONOUS=3 (extra durable) help mitigate this kind of possible corruption? I think this is especially important for mobile apps which may be terminated without notice, especially when using hybrid app frameworks such as Cordova/PhoneGap. > However, the SQLite library goes through heroic measures > [...] I am sure that this was at the cost of many heroic programmer hours. > The SQLite header is less than 100 bytes long. It all fits within one sector > / page of a storage device i.e. the entire header is written in one > operation. If you ever discover an inconsistent header there's a bug in > SQLite. The contents of the header are listed in > > <https://sqlite.org/fileformat.html#the_database_header> Thanks for the clarification. >> - Any recommended explanations or resources to understand how it may >> be possible to obtain the correct sqlite database information (such as >> WAL or other journal mode, actual database size, number of pages, >> page/cache size, etc.)? > > PRAGMAs are available for retrieving all this information. See > > <https://sqlite.org/pragma.html#pragma_journal_mode> > <https://sqlite.org/pragma.html#pragma_page_count> > <https://sqlite.org/pragma.html#pragma_page_size> > > The size of the database is page_count * page_size. Other PRAGMAs on the > same page provide other information which might be covered in your "etc.". Makes sense ... assuming that the database is not corrupted beyond the heroic repair mechanism:) > If you have any other questions, please do not hesitate to ask them here. Will do. Looking forward to the requested clarification. Thanks for the answers so far. _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users