AsiaBSDCon 2017 Secure CGI

Database introduction

Database introduction


Work with a database to print out a counter. Use SQLite, as it's the simplest on-disc database. (Or is it?) To make things easier, use ksql(3). Why is this a good example? Because SQLite as a simple database is a lie.

The manner in which SQLite uses temporary files is not considered part of the contract that SQLite makes with applications. … [There] is no guarantee that future versions of SQLite will use temporary files in the same way. New kinds of temporary files might be employed and some of the current temporary file uses might be discontinued in future releases of SQLite.

So we need to deal with magically-appearing files. Thanks, SQLite!

How can we get around this? Use libpq(3) with an active PostgreSQL database.