Item5401: Support for SQLite

pencil
Priority: Enhancement
Current State: No Action Required
Released In:
Target Release: n/a
Applies To: Extension
Component: DatabasePlugin
Branches:
Reported By: TWiki:Main.LarsEik
Waiting For:
Last Change By: LarsEik
I finally managed to hack access to a local sqlite database file. But it seems that the perl syntax is different when connecting to sqlite, it uses "DBI:$this->{driver}:dbname=$this->{database}..etc where other databases uses database instead of dbname

A developer could fix this if it isn't already fixed in svn.

The file is "lib/TWiki/Plugins/DatabasePlugin/Connection.pm" and the sub connect

I used this code, not galant but it works with two simultanous db's, mysql and sqlite:
sub connect {
    my $this = shift;

    unless ($this->{db}) {
        my $sid = $this->{sid} ? ";sid=$this->{sid}" : '';
        my $dbn;
        if (lc( $this->{driver}) eq 'sqlite' ) {
                $dbn = "dbname";
        } else {
                $dbn = "database";
        }

        my $db = DBI->connect(
            # NEXT LINE WAS ORIGINAL, SECOND LINE USES $dbn FROM IF ABOVE INSTEAD
            #"DBI:$this->{driver}:database=$this->{database};host=$this->{hostname}$sid",   
            "DBI:$this->{driver}:$dbn=$this->{database};host=$this->{hostname}$sid",
            $this->{username}, $this->{password},
            {PrintError=>1, RaiseError=>1});
        if (! $db ) {
            die "Can't open database specified by description '$description'";
        }

        $this->{db} = $db;
    }
}

-- TWiki:Main/LarsEik - 29 Feb 2008

I got SQLite working without modification on trunk so this was either my RTFM or is solved otherwise.

-- Foswiki:Main.LarsEik - 02 Dec 2008

ItemTemplate edit

Summary Support for SQLite
ReportedBy TWiki:Main.LarsEik
Codebase
SVN Range TWiki-5.0.0, Wed, 23 Jan 2008, build 16283
AppliesTo Extension
Component DatabasePlugin
Priority Enhancement
CurrentState No Action Required
WaitingFor
Checkins
TargetRelease n/a
ReleasedIn
Topic revision: r2 - 02 Dec 2008, LarsEik
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy