On 6 Apr 2017, at 2:38pm, Bob Friesenhahn <bfrie...@simple.dallas.tx.us> wrote:
> Is calling sqlite3_close() prior to exiting a requirement in general for > sqlite? I was not aware of this requirement. Do you explicitly call sqlite3_shutdown() ? If not, when are you expecting SQLite to close the file for you ? Do you also routinely omit close(), fclose(), and sync() ? Don’t you have problems with unflushed buffers ? > It is not uncommon for programs to quit without explicitly releasing all > resources (e.g. calling sqlite3_close()) when a problem occurs. It depends on whether the software understands the problem, and on whether that problem relates to SQLite. If your program crashed because of a divide-by-zero error you probably still want it to close any databases it was using. If it crashed because it ran out of disk space, you probably don’t. SQLite does not just release resources when you close a file. Depending on your settings it may make changes to journal files to so that when it reopens the file it knows it closed it properly instead of crashing. This means that when it reopens the file it knows whether it needs to check for journal entries and perhaps recover from corruption caused by a crash or power-failure. It may also recover unused space in its files, to release some extra disk space. Deleting a journal file which SQLite thinks its using can cause database corruption (see section 1.3 of <https://www.sqlite.org/howtocorrupt.html#_deleting_a_hot_journal>). But deleting the journal file of a database which SQLite knows is correctly closed cannot cause corruption. It is uncommon for SQLite programs not to close files correctly. The only time I see this done is code demonstrating a feature, where the file is never going to be used again. What’s not common is for programmers to issue sqlite3_initialize() or sqlite_shutdown(). Hardly anyone knows about these calls, because if you close your database files properly SQLite does everything needed without them. If you’re going to miss something out, miss out sqlite_shutdown(). Don’t miss out closing your files. > I do not see any admonishments about a requirement to call sqlite3_close() on > the documentation page at https://sqlite.org/c3ref/close.html. One of those things you expect programmers to know. If you start something finish it. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users