My Impressions about SQLite

Warning! Some information on this page is older than 6 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

Tue
20
Apr 2010

SQLite is a very strange library. It's a database engine that can store lots of data in a relational database and exposes API based on SQL language. On the other hand though, it's not a huge application that has to be installed in the system, work in the background and you have to connect to it via network interface, like MySQL or PostreSQL do. It's actually a lightweight library written in C that can be linked with your program and uses specified file as the database. It's fascinating that such a small library (there is even a preprocessed source version as a single 3.75 megabyte C file!) supports much of the SQL language.

The API of the SQLite library is similar to any other SQL-based database access API for any programming language. I've played with it a bit and here is my small sample code:

#include <sqlite3.h>

int main()
{
  sqlite3 *db;
  sqlite3_open_v2("D:\\tmp\\test.db", &db,
    SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);

  sqlite3_exec(db, "begin", NULL, NULL, NULL);
  
  sqlite3_stmt *stmt;
  sqlite3_prepare_v2(db, "insert into table1 (id) values (?)",
    -1, &stmt, NULL);

  for (int i = 0; i < 10; i++)
  {
    sqlite3_reset(stmt);
    sqlite3_bind_int(stmt, 1, i);
    sqlite3_step(stmt);
  }

  sqlite3_exec(db, "commit", NULL, NULL, NULL);

  sqlite3_finalize(stmt);

  sqlite3_close(db);
}

It's hard for me to think of any application for such a strange library. It offers too much when you just want to design your file format and too few if you need a fully-featured database, like for a web server. So why did I decide to get to know this library? It's all because of an interesting gamedev tool called Echo Chamber. It's a free data mining program that can visualize data from SQLite database files as many different kinds of plots, even 3D ones. So when you integrate logging some numeric data from your engine into an SQLite database you can easily do performance analysis with it.

Comments | #tools #libraries #sql Share

Comments

[Download] [Dropbox] [pub] [Mirror] [Privacy policy]
Copyright © 2004-2025