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;
my $table = {
'struct', [
'phone', [qw(INTEGER(32) NOT NULL)],
'name', [qw(VARCHAR(512) NOT NULL)],
'address',[qw(VARCHAR(1024) NOT NULL)]
]
};
$sql->create($table);
my ($phone, $name, $address, $data, %unique);
...
while (<FH>){
($name, $phone, $address) = split ';',$_ and
push @$data, [$phone, $name, $address];
}
$sql->insert($data);
#then select, update, insert again and so on ...
my $what = "where phone like %6% and name like %reni%";
my $search = { 'where' => $what, 'col' => 'name, phone' };
my $result = $sql->search($search);
#or just SELECT * FROM sm_table_name
$sql->search({});
my $update = { 'name set', 'RENI where name like %reni%' };
my $result = $sql->update($update);
#insert after delete - SQLite is fast enough
$sql->delete_insert($data);
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.
$sql = SQLite::Abstract->new( $dbname );
Object creation expects database name in order to init DB connection.
$sql->search( $search )
Where $search must be e hash reference, containing 'where' and 'col' keys which are optional. Each key's name may be changed through the global %{$glob}:
In brief
$SQLite::Abstract::glob->{'where'} = 'what';
$what = "where phone like %6% and name like %reni%";
$search = { 'what' => $what, 'col' => 'name, phone' };
$result = $sql->search($search);
where $result is print $_->[0], "\t", $_->[1], "\n" for @$result;
$sql->select( { } )
Synonym for search
$sql->update( { } )
This methos 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':
$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";
$sql->delete( { } )
The same mthod arguments as insert method except that the key does not have any special meaning - WHERE clause and value which contains the actual sql code:
#for more comfort
$SQLite::Abstract::glob->{'where'} = 'remove';
$delete = { 'remove', 'where name like %myself%' };
$result = $sql->delete($delete);
print "$result rows deleted\n";
$sql->insert( @$data )
Where the array must contain the same number of columns as the table
$sql->delete_insert( @$data )
The same methos as 'insert' except that DELETE the table before INSERT And because it's SQLite - speed is amazing.
$sql->create( $table )
This methos 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', [
'column_1', [qw( column_1 properties )],
'column_2', [qw( column_2 properties )]
#...
]
};
$sql->drop( $table_name )
Pretty self explanatory
$sql->create($table);
NOTES
The database is expected to be -e $file
SEE ALSO
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.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 512:
L<> starts or ends with whitespace
L<> starts or ends with whitespace