NAME

DBIx::SQLite::Simple::Table - superclass only used to handle SQL tables

SYNOPSIS

# Example of a table with a primary key

package TPub;

require DBIx::SQLite::Simple::Table;
require Class::Gomor::Hash;
our @ISA = qw(DBIx::SQLite::Simple::Table Class::Gomor::Hash);

our @AS = qw(
   idPub
   pub
);
__PACKAGE__->buildAccessorsScalar(\@AS);

# 'our $Id' and 'our @Fields' are named Id and Fields for a good
# reason, so do not name these variables by another name.
our $Id     = $AS[0];
our @Fields = @AS[1..$#AS];

1;

# Example of a table with no key at all

package TBeer;

require DBIx::SQLite::Simple::Table;
require Class::Gomor::Hash;
our @ISA = qw(DBIx::SQLite::Simple::Table Class::Gomor::Hash);

our @AS = qw(
   beer
   country
);
__PACKAGE__->buildAccessorsScalar(\@AS);

our @Fields = @AS;

1;

# Now, we have two tables, we can play with the database

package main;

require DBIx::SQLite::Simple;
my $db = DBIx::SQLite::Simple->new(db => 'sqlite.db');

# Create to object to play with the two tables
my $tPub = TPub->new;
my $tBeer = TBeer->new;

# Create tables
$tPub->create unless $tPub->exists;
$tBeer->create unless $tBeer->exists;

# Create some entries
my @pubEntries;
push @pubEntries, TPub->new(pub => $_) for (qw(corner friends));

my @beerEntries;
push @beerEntries, TBeer->new(beer => $_, country => 'BE')
   for (qw(grim leffe bud));

# Now insert those entries;
$tPub->insert(\@pubEntries);
$tBeer->insert(\@beerEntries);

# Get friends pub
my $friends = $tPub->select(pub => 'friends');

# Lookup id
my $id = $tPub->lookupId(pub => 'friends');

# Lookup string
my $str = $tPub->lookupString('pub', idPub => $id);

# Add a beer from 'chez moi'
my $dremwell = TBeer->new(beer => 'Dremwell', country => '?');
$tBeer->insert([ $dremwell ]);

$tPub->commit;
$tBeer->commit;

# Update Dremwell
my $dremwellOld = $dremwell->clone;
$dremwell->country('BZH');
$tBeer->update([ $dremwell ], $dremwellOld);
$tBeer->commit;

# Delete all pubs
$tPub->delete(\@pubEntries);

ATTRIBUTES

dbo

Stores a DBIx::SQLite::Simple object.

METHODS

new

Object creator. Will return an object used to access corresponding SQL table. You can pass an optional parameter: dbo. By default, it uses the global variable $DBIx::SQLite::Simple::Dbo.

clone

Create a copy of the object.

commit

Just a convenient method to commit pending changes to the whole database.

create

Method to create the table.

exists

Method to verify existence of a table.

select

If called without parameters, returns the whole content as an arrayref. If called with a hash as argument containing some table fields with values, it plays as multiple where clauses (return result as an arrayref also). See SYNOPSIS.

delete($arrayref)

Deletes all entries specified in the arrayref (they are all objects of type DBIx::SQLite::Simple::Table).

insert($arrayref)

Insert all entries specified in the arrayref (they are all objects of type DBIx ::SQLite::Simple::Table).

update($arrayref)

Will update elements specified within the arrayref (they are all objects of type DBIx::SQLite::Simple::Table). If an additionnal argument is passed, it will act as a where clause. See SYNOPSIS.

lookupId(%hash)

Returns the the id if the specified field/value hash.

lookupString($field, field2 => value)

Returns the content of the specified field. See SYNOPSIS.

AUTHOR

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Copyright (c) 2005, Patrice <GomoR> Auffret

You may distribute this module under the terms of the Artistic license. See Copying file in the source distribution archive.