Sqlite as a replacement for fopen()? Sqlite as a replacement for fopen()? sqlite sqlite

Sqlite as a replacement for fopen()?


It depends. There are some contra-indications:

  • for configuration files, use of plain text or XML is much easier to debug or to alter than using a relational database, even one as lightweight as SQLite.

  • tree structures are easier to describe using (for example) XML than by using relational tables

  • the SQLite API is quite badly documented - there are not enough examples, and the hyperlinking is poor. OTOH, the information is all there if you care to dig for it.

  • use of app-specific binary formats directly will be faster than storing same format as a BLOB in a database

  • database corruption can mean the los of all your data rather than that in a single bad file

OTOH, if your internal data fits in well with the relational model and if there is a a lot of it, I'd recommend SQLite - I use it myself for one of my projects.

Regarding experience - I use it, it works well and is easy to integrate with existing code. If the documentation were easier to navigate I'd give it 5 stars - as it is I'd give it four.


As always it depends, there are no "one size fits all" solutions

If you need to store data in a stand-alone file and you can take advantage of relational database capabilities of an SQL database than SQLite is great.

If your data is not a good fit for a relational model (hierarchical data for example) or you want your data to be humanly readable (config files) or you need to interoperate with another system than SQLite won't be very helpful and XML might be better.

If on the other hand you need to access the data from multiple programs or computers at the same time than again SQLite is not an optimal choice and you need a "real" database server (MS SQL, Oracle, MySQL, PosgreSQL ...).


The atomicity of SQLite is a plus. Knowing that if you half-way write some data(maybe crash in the middle), that it won't corrupt your data file. I normally accomplish something similar with xml config files by backing up the file on a successful load, and any future failed load(indicating corruption) automatically restores the last backup. Of course it's not as granular nor is it atomic, but it is sufficient for my desires.