Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

tomhukins (4457)

tomhukins
  (email not shown publicly)

Perl, Web, Database developer, and Milton Keynes Perl Monger [pm.org].

Journal of tomhukins (4457)

Tuesday October 31, 2006
07:36 AM

In-memory SQLite Databases

[ #31457 ]

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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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.