NAME

File::Properties::Database - Perl module providing an interface to an SQLite database

SYNOPSIS

  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'}});

ABSTRACT

File::Properties::Database is a Perl module providing a simplified
interface to an SQLite database.

DESCRIPTION

File::Properties::Database provides a simplified interface to a
SQLite database. The following methods are provided.
new
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:

{'NoCreate' => 1}

The DB file $path should not be created if it does not already exist.

{'ReadOnly' => 0}

The DB file should be opened in read-only mode.

opts
my $opt = $db->opts;

Access the options specified at initialisation

dbi
my $dbi = $db->dbi;

Access the DBI object used by File::Properties::Database object $db.

definedcolumns
my $dc = $db->definedcolumns('TableName');

Get the an array of column names for the specified table.

sql
$db->sql('CREATE TABLE tablename (Field1 INTEGER, Field2 TEXT)');

Execute an SQL statement string.

definetable
$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.

insert
$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.

update
$db->update('TableName', {'Data' => {'Col2' => 'Abcd'},
                          'Where' => 'Col1="1234"'});

Update one or more rows in the specified table.

retrieve
  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.

remove
$db->remove('TableName', {'Where' => {'Col1' => '1234'}});
$db->remove('TableName', {'RemoveAll' => 1});

Remove specified rows from the specified table.

tables
my $tables = $db->tables;

Get names of tables in database.

columns
my $cols = $db->columns('TableName');

Get names of columns in specified table.

tableexists
my $exist = $db->tableexists('TableName');

Determine whether specified table exists.

SEE ALSO

DBI, DBD::SQLite

AUTHOR

Brendt Wohlberg <wohl@cpan.org>

COPYRIGHT AND LICENSE

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.