File::Properties::Database - Perl module providing an interface to an SQLite database
use File::Properties::Database; my $db = File::Properties::Database->new('dbfile.db'); $db->definetable('TableName', ['Col1 INTEGER','Col2 TEXT']); $db->insert('TableName', {'Data' => ['1234', 'ABCD']}); my $ra = $db->retrieve('TableName', {'ReturnType' => 'Array', 'FirstRow' => 1, 'Where' => {'Col1' => '1234'}});
File::Properties::Database is a Perl module providing a simplified interface to an SQLite database.
File::Properties::Database provides a simplified interface to a SQLite database. The following methods are provided.
my $db = File::Properties::Database->new($path, $options);
Constructs a new File::Properties::Database object. The $path parameter specifies the path to an SQLite DB file and the optional $options hash may have the following entries:
The DB file $path should not be created if it does not already exist.
The DB file should be opened in read-only mode.
my $opt = $db->opts;
Access the options specified at initialisation
my $dbi = $db->dbi;
Access the DBI object used by File::Properties::Database object $db.
my $dc = $db->definedcolumns('TableName');
Get the an array of column names for the specified table.
$db->sql('CREATE TABLE tablename (Field1 INTEGER, Field2 TEXT)');
Execute an SQL statement string.
$db->definetable('TableName', ['Col1 INTEGER','Col2 TEXT']);
Define a table, which will be created if it does not already exist. Existing tables must also be defined using this method to provide information required by a number of other methods.
$db->insert('TableName', {'Columns' => ['Col1', 'Col2'], 'Data' => ['1234', 'ABCD']}); $db->insert('TableName', {'Columns' => ['Col1', 'Col2'], 'Data' => [['1234', 'ABCD'], ['9876', 'DEFG']]}); $db->insert('TableName', {'Data' => {'Col1' => '1234', 'Col2' => 'ABCD'}}); $db->insert('TableName', {'Data' => {'Col1' => ['1234', '9876'], 'Col2' => ['ABCD', 'DEFG']}});
Insert one or more rows into the specified table.
$db->update('TableName', {'Data' => {'Col2' => 'Abcd'}, 'Where' => 'Col1="1234"'});
Update one or more rows in the specified table.
my $row = $db->retrieve('TableName', {'ReturnType' => 'Array', 'FirstRow' => 1, 'Where' => {'Col1' => '1234'}}); my $rows = $db->retrieve('TableName', {'ReturnType' => 'Array', 'Where' => {'Col1' => '1234'}}); my $rows = $db->retrieve('TableName', {'ReturnType' => 'Hash', 'Where' => {'Col1' => '1234'}});
Retrieve one or more rows from the specified table.
$db->remove('TableName', {'Where' => {'Col1' => '1234'}}); $db->remove('TableName', {'RemoveAll' => 1});
Remove specified rows from the specified table.
my $tables = $db->tables;
Get names of tables in database.
my $cols = $db->columns('TableName');
Get names of columns in specified table.
my $exist = $db->tableexists('TableName');
Determine whether specified table exists.
DBI, DBD::SQLite
Brendt Wohlberg <wohl@cpan.org>
Copyright (C) 2010,2011 by Brendt Wohlberg
This library is available under the terms of the GNU General Public License (GPL), described in the LICENSE file included in this distribution.
To install File::Properties, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Properties
CPAN shell
perl -MCPAN -e shell install File::Properties
For more information on module installation, please visit the detailed CPAN module installation guide.