SQLite::Abstract - Object-oriented wrapper for SQLite
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);
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.
Each method works into a single transaction.
Object creation expects database name in order to init DB connection.
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}:
speciafies which rows you want
specifies the columns you want
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;
Synonym for search
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";
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";
Where the array must contain the same number of columns as the table
The same methos as 'insert' except that DELETE the table before INSERT And because it's SQLite - speed is amazing.
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 )] #... ] };
Pretty self explanatory
$sql->create($table);
The database is expected to be -e $file
" DBI ", " DBD::SQLite "
Vidul Petrov, <vidul@cpan.org>
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:
L<> starts or ends with whitespace
To install SQLite::Abstract, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SQLite::Abstract
CPAN shell
perl -MCPAN -e shell install SQLite::Abstract
For more information on module installation, please visit the detailed CPAN module installation guide.