In-memory SQLite Databases

tomhukins on 2006-10-31T12:36:31

Like many people, I use DBD::SQLite in my unit tests so I don't need to rely on a live database.

I've been using File::Temp::tempfile() to create temporary files for me use as SQLite database files. Yesterday, I noticed that tempfile() and DBD::SQLite don't play nicely together. I could use tmpnam(), but as this doesn't create the temporary file a small race condition exists.

I discussed this with Matts last night and he pointed me towards SQLite's in-memory databases. My test cases don't use huge amounts of data, so I can run everything in memory and avoid hitting the disk:

DBI->connect('dbi:SQLite:dbname=:memory:', '', '');

This means I don't need to bother with temporary files any more, making my tests simpler and faster.


Cool!

jk2addict on 2006-10-31T14:07:56

I have no idea about that one either. All of my tests have been using these to help with the IO:
    $schema->storage->on_connect_do([
        'PRAGMA synchronous = OFF',
        'PRAGMA temp_store = MEMORY'
    ]);
Most dists, like Handel and DBIC have rolled their own schema/var/temp.db creation/cleanup routines for the tests suites. It would't suck if this could replace all that mess; or at least the file parts.