DBIx::SQLite::Simple - easy access to SQLite databases using objects


DBIx-SQLite-Simple documentation Contained in the DBIx-SQLite-Simple distribution.

Index


Code Index:

NAME

Top

DBIx::SQLite::Simple - easy access to SQLite databases using objects

ATTRIBUTES

Top

db

Used to store the filename containing the SQLite database.

METHODS

Top

new(db => 'filename.db')

Object creator. Takes one argument, and sets the global variable $Dbo to the newly created database handler.

commit

Changes made on created database are not automatically commited. You must call this method if you want to commit pending changes.

close

When you're done using the database, you can disconnect from it. This method will not commit changes, so do it before closing.

AUTHOR

Top

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Top


DBIx-SQLite-Simple documentation Contained in the DBIx-SQLite-Simple distribution.
#
# $Id: Simple.pm,v 1.14 2007/01/27 13:35:02 gomor Exp $
#
package DBIx::SQLite::Simple;
use strict;
use warnings;
use Carp;

our $VERSION = '0.34';

require DBI;
require Class::Gomor::Array;
our @ISA = qw(Class::Gomor::Array);

our @AS = qw(
   db
   _dbh
);
__PACKAGE__->cgBuildIndices;
__PACKAGE__->cgBuildAccessorsScalar(\@AS);

our $Dbo;

sub new {
   my $self = shift->SUPER::new(@_);

   confess('Usage: new(db => $db)') unless $self->db;

   my $dbh = DBI->connect(
      'dbi:SQLite:dbname='. $self->db,
      '', '',
      {
         RaiseError => 0,
         PrintError => 0,
         PrintWarn  => 0,
         AutoCommit => 0,
      },
   ) or croak("new: ". $DBI::errstr);

   $self->_dbh($dbh);

   $Dbo = $self;
}

sub commit {
   my $self = shift;
   $self->_dbh->commit if $self->_dbh;
}

sub close {
   my $self = shift;
   $self->_dbh->disconnect if $self->_dbh;
   $self->_dbh(undef);
}

sub DESTROY {
   my $self = shift;

   if ($self->_dbh) {
      $self->commit;
      $self->close;
   }
}

1;