Simon Slavin wrote: > On 29 Apr 2014, at 2:24pm, Drago, William @ MWG - NARDAEAST > <william.dr...@l-3com.com> wrote: > >> Does closing the connection force, or at least encourage, the OS to write to >> disk whatever it might have been caching? > > Closing a connection calls fclose() on the database file (as long as fopen() > was called because at least one operation was done on the database). So the > operating system does everything it would normally do in response to fclose().
No, sqlite does NOT use fopen/fclose, neither on unix, nor on windows, it uses lower-level interface (open(2)/close(2) on unix). AFAIK, close(2) normally does not attempt to write/flush/sync anything (it could be more complex with unusual fs, e.g. NFS, but sqlite is incompatible with NFS anyway). (No idea about MS Windows specifics). > This means closing a connection can take a long time because it does lots of > things. For example under Windows/Mac/Unix if the file has been changed it > changes the 'last modified' date on the file. Consequently you would not > want to keep opening and closing a connection in a program that made a lot of > changes to a SQLite database. AFAIK, on unix, "last modified" (st_mtime) is updated when write(2) is called, and not delayed till close(2). (Again, no idea about MS Windows specifics). I have not instrumented sqlite (and thus could be wrong), but I'd guess only "expensive" thing in database "connection" close is memory deallocation. On other hand, database "connection" open is much more expensive, as it requires re-reading and re-parsing database schema and various other things. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users