NAME

SQLite::Abstract - Object oriented wrapper for SQLite

SYNOPSIS

use SQLite::Abstract;


my $sql = SQLite::Abstract->new($dbname);

my $table_name = "smt";

$SQLite::Abstract::glob->{'default_table'} = $table_name;

$sql->create($table);

$sql->insert($data);
$sql->search($search);
$sql->search({});

#the same

$sql->select({});
$sql->update({$data});
$sql->delete_insert($data);

$sql->drop;

DESCRIPTION

SQLite::Abstract is just another try to wrap sql and to be more concrete - SQLite. Primary goals are ease and speed in development of sql front-end with the excellent DBD::SQLite.

METHODS

Each method works into a single transaction.

new

$sql = SQLite::Abstract->new( $dbname );

Object creation expects database name in order to init DB connection. Database name must ne existing file.

Where argument must be e hash reference, containing 'where' and 'col' keys which are optional. Each key's name may be changed through the global %{$glob}:

where

specifies which rows you want

col

specifies the columns you want

$SQLite::Abstract::glob->{'where'} = 'what';
$what   = "where phone like %1% and name like %reni%";
$search = { 'what' => $what, 'col' => 'name, phone' };
$result = $sql->search($search);

print "name: $_->[0]\tphone: $_->[1]\n" for @$result;

select

Synonym for search

update

This method expects hash ref where the only one key is a column name and the value is WHERE clause. The key may be in comapy with 'set':

name

specifies which column you want to SET

where

specifies the row(s) you want to SET

$update = { 'name set', 'Reni where name like %reni%' }; #or
$update = { 'set name', 'Reni where name like %reni%' }; #or
$update = { 'name', 'RENI where name like %reni%' };

$result = $sql->update($update);

print "$result rows updates\n";

delete

The same method arguments as insert method except that the key does not have any special meaning - WHERE clause and value which contains the actual sql code:

Again

delete

specifies symbolic word for the action DELETE

where

specifies the row(s) you want to DELETE

#for more comfort
$SQLite::Abstract::glob->{'where'} = 'remove';

$delete = { 'remove', 'where name like %myself%' };
$result = $sql->delete($delete);

print "$result rows deleted\n";

insert

push my @$data, [("010010", "Tester", "st._one_test_1")];
$sql->insert( $data )

Where the array must contain the same number and order of columns as the table

delete_insert

$sql->delete_insert( @$data )

The same method as 'insert' except that DELETE the table before INSERT And because it's SQLite - speed is amazing.

create

This method needs table structure and eventually table name unless another global var is not set (by default):

$table_name = 'somewhere';
$SQLite::Abstract::glob->{'default_table'} = $table_name;

Than the table structure where the key 'struct' is also modules' $glob value

   $SQLite::Abstract::glob->{'struct'} = 'structure';
   $table = {
   	'tablename', $table_name,
   	'structure', [
                'phone',  [qw(INTEGER(32) NOT NULL)],
                'name',   [qw(VARCHAR(512) NOT NULL)],
                'address',[qw(VARCHAR(1024) NOT NULL)]
	
	]
   };

   $sql->create($table);

drop

$sql->drop( $table_name )

Pretty self explanatory

SEE ALSO

DBD::SQLite

AUTHOR

Vidul Petrov, vidul@cpan.org

COPYRIGHT AND LICENSE

Copyright 2005 by Vidul Petrov

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.