Skip to content

SQLite support for reporting #185

Description

I'm working on a port of the OpenDMARC database and utilities to SQLite. I have one more to port -- opendmarc-reports. It's been pretty straightforward work. The biggest differences I've found are:

  • SQLite only allows one key per table. Multiple keys are simulated with indexes.
  • There's no TINYINT in SQLite. All these have been promoted to INTEGERs.
  • There's no UNSIGNED INTEGER in SQLite. This has been simulated with CHECK constraints.
  • SQLite doesn't have the plethora of DATE/TIME formats that MySQL has so all dates/times are stored in the database as Unix epoch times. This pushes the issue of date/time formatting onto the perl(1) utilities.

I've made no changes at all to the daemon. The command-line switches to the perl(1) utilities have only changed because of the nature of SQLite...there's no dbhost, dbuser, deport, etc.

In the perl(1) utilities, I use constants to highlight the differences with the following BEGIN block:

BEGIN {

    my $me = basename($0);      # local to block
    
    use constant MYSQL  => 0;
    use constant SQLITE => 1;    
    
    if ( ! (MYSQL || SQLITE) )
    {
        print STDERR "$me: You must set one of MYSQL or SQLITE.\n";
        exit(1);
    }
    
    if ( MYSQL && SQLITE )
    {
        print STDERR "$me: You must set ONLY one of MYSQL or SQLITE.\n";
        exit(1);
    }

}

Database-dependent code sections look like this:

### begin DB dependent
#
if ( MYSQL )
{
     ...MySQL stuff...    
}

if ( SQLITE )
{
     ...SQLite stuff...    
}
#
### end DB dependent

so as to not lose anyone else's hard work...and to make the same code work with both.

Anyway, when I'm done, I can contribute this to the project. It's all mine and I will disclaim ownership -- using whatever mechanism you like -- if you accept it into the trunk. Caveat: I don't have any way to test MySQL...

I'm not very handy with GitHub but I can create a pull request if you like.

I've attached the SQLite schema for your amusement. Thanks in advance..

-- cc

opendmarc.txt

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions