Anteru's blog
  • Consulting
  • Research
    • Assisted environment probe placement
    • Assisted texture assignment
    • Edge-Friend: Fast and Deterministic Catmull-Clark Subdivision Surfaces
    • Error Metrics for Smart Image Refinement
    • High-Quality Shadows for Streaming Terrain Rendering
    • Hybrid Sample-based Surface Rendering
    • Interactive rendering of Giga-Particle Fluid Simulations
    • Quantitative Analysis of Voxel Raytracing Acceleration Structures
    • Real-time Hybrid Hair Rendering
    • Real-Time Procedural Generation with GPU Work Graphs
    • Scalable rendering for very large meshes
    • Spatiotemporal Variance-Guided Filtering for Motion Blur
    • Subpixel Reconstruction Antialiasing
    • Tiled light trees
    • Towards Practical Meshlet Compression
  • About
  • Archive

SQLite3

April 20, 2009
  • Programming
approximately 2 minutes to read

Since last week, SQLite3 is no longer just a library I’ve heard of, but an integral part of my current research work, where I decided to store the data between processing steps in SQLite3. Read on for a quick look at why I didn’t regret this choice yet ;)

First, if you have not heard about SQLite3 previously, check out their feature list: Basically, it is a tiny SQL database, written in C, which can be embedded into other applications. The database is self-contained in a single file, and is portable between different operating systems. Moreover, there are a wide range of bindings for SQLite, for example, Python 3.0 comes with it by default.

Getting started with it is easy, simply follow the C/C++ API introduction to SQLite3. What’s nice is that they provide a single source file which you include into your build, to get the whole database engine, so including is really straightforward and does not require binding against a library.

The library itself is very well designed, and robust: Every possible error is caught, and as long as you check the return codes of the library, you shouldn’t have any problems to use it (basically they do all the stuff I described once in my API design tips, and more ;) ). Setting up a database takes a line. Inserting data and retrieving is very straightforward, and can be done with minimal overhead (2 lines to set up your query, one for iteration, one per element retrieved, and one to terminate it – that’s it).

In my application I’ve set up a pipeline, where various C++ and Python tools process data in turn, and store their intermediate results in a SQL database. This has turned out to be a very good approach for data gathering, because you can rapidly check the data without writing visualisation tools, and writing those tools is very fast as you can use expressive SQL queries for your data.

A side note: You should wrap long inserts into a transaction, otherwise you’ll flush to disk after each row. The simplest way is to execute a BEGIN TRANSACTION using sqlite3_exec before your insert statements (for the insert, I tend to use a prepared statement), and issue an END TRANSACTION after finalizing the prepared statement. The difference between prepared statement and a direct execution is not big, but the difference between a single large transaction and several thousand smaller ones is really dramatic.

All in all, I’m very pleased so far with SQLite, and if you have structured data in your application, it is really worth a look. Especially as it is very fast, easy to integrate and well documented.

Update: Added a tip on the usage.

Previous post
Next post

Recent posts

  • Data formats: Why CSV and JSON aren't the best
    Posted on 2024-12-29
  • Replacing cron with systemd-timers
    Posted on 2024-04-21
  • Open Source Maintenance
    Posted on 2024-04-02
  • Angular, Caddy, Gunicorn and Django
    Posted on 2023-10-21
  • Effective meetings
    Posted on 2022-09-12
  • Older posts

Find me on the web

  • GitHub
  • GPU database
  • Projects

Follow me

Anteru NIV_Anteru
Contents © 2005-2025
Anteru
Imprint/Impressum
Privacy policy/Datenschutz
Made with Liara
Last updated February 03, 2019