SQLite::DB provides an object oriented wrapper to SQLite databases using DBI and DBD::SQLite modules.
use SQLite::DB; my $db = SQLite::DB->new('file'); $db->connect; $db->select("select * from table where field = value",{}) || print $db->get_error."\n"; $db->select("select * from table where field = ?",{},"value") || print $db->get_error."\n"; $result = $db->select_one_row("select max(field) as total FROM table"); print $$result{TOTAL}; $db->transaction_mode; $db->exec("INSERT (a,b,c) VALUES 'a','b','c'"); $db->exec("INSERT (a,b,c) VALUES ?,?,?",'a','b','c'); $db->exec("update table set field = value") || print $db->get_error."\n"; $db->commit || print $db->get_error."\n"; $db->rollback || print $db->get_error."\n"; my $resultset = $db->get_dblist("select * from table","display_field","keyfield"); if (!ref $resultset) { print $db->get_error."\n" } else { for (@$resultset) { print $resultset->[$_]->{id}." - ".$resultset->[$_]->{value}."\n"; } } $db->disconnect;
The goal is provide simple coding style to interact with SQLite databases.
SQLite::DB
DBI, DBD:SQLite
Construtor. $path is the full path to the db file.
Connect to the database. If it does not exists, it created an new database.
Disconnect to the database.
Define transaction mode. No commits will be done until get the commit function.
Commit an transaction. If is not in transaction mode, nothing happens.
Rollback an transaction. If is not in transaction mode, nothing happens.
Execute an query. Optional argumens are used when you want to bind params of your query.
Execute an select query.
$funcptr is an callback function pointer that received $sth object as argument, to process the rows of the select query.
Optional argumens are used when you want to bind params of your query.
Provides an easier way to retrieve one row queries. It returns an hash with field/values of the query.
Provided an easier way to retrive two columns queries.
It returns an array with hash itens with "id" and "value" itens.
Return last error.
$head2 get_affected_rows
Return the number of affected rows from the last exec query.
check_error
This method provide an common way to check DBI/DBD errors.
get_sql_type
This returns the type of an query.
$item * last_insert_rowid
Stores the last insert rowid.
None.
Vitor Serra Mori <vvvv767@hotmail.com.>
This package is free software. Tou can redistribute and/or modify it under the same terms as Perl itself.
# }}}
3 POD Errors
The following errors were encountered while parsing the POD:
=back without =over
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install SQLite::DB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SQLite::DB
CPAN shell
perl -MCPAN -e shell install SQLite::DB
For more information on module installation, please visit the detailed CPAN module installation guide.