DBIx-Browse

 view release on metacpan or  search on metacpan

Browse.pm  view on Meta::CPAN

#
# print_error: print an error.
#
sub print_error {
    my $self  = shift;
    my $error = shift;

    warn($error);
}

#########################################################################
1;
#
#
#
__END__

=head1 NAME

DBIx::Browse - Perl extension to browse tables.

=head1 SYNOPSIS

  use DBIx::Browse;
  my ($dbh, $dbb, $q);
  $dbh = DBI->connect("DBI:Pg:dbname=enterprise")
    or croak "Can't connect to database: $@";
 $dbixbr = new  DBIx::Browse({
    dbh => $dbh, 
    table => 'employee', 
    proper_fields => [ qw ( name fname ) ],
    linked_fields => [ qw ( department category office ) ], 
    linked_tables => [ qw ( department category office ) ], 
    linked_values => [ qw ( name       name     phone  ) ], 
    linked_refs   => [ qw ( id         id       ide    ) ],
    aliases       => [ qw ( name fname department category phone )],
    primary_key   => 'id'
});

    ## Insert a record
    $dbixbr->insert({
	name       => 'John',
        department => 'Sales',
        category   => 'Sales Representant',
	phone      => '1114'
    });

    ## Update a record
    $dbixbr->update({
	record => { phone => '1113', category => 'Sales Manager' }
	where  => 'id = 123 ' 
    });

...etc

=head1 DESCRIPTION

The purpose of DBIx::Browse is to handle the browsing of relational
tables.

DBIx::Browse transparently translates SELECTs, UPDATEs, DELETEs and INSERTs
from the desired "human view" to the values needed for the table. This is the
case when you have related tables (1 to n) where the detail table
has a reference (FOREIGN KEY) to a generic table (i.e. Customers and
Bills) with some index (tipically an integer).

=head1 METHODS

=over 4

=item B<new>

Creates a new DBIx::Browse object. The parameters are passed
through a hash with the following keys:

=over 4

=item I<dbh>

A DBI database handle already opened that will be used for all
database interaction.

=item I<table>

The main (detail) table to browse.

=item I<primary_key>

The primary key of the main I<table> (default: I<'id'>).

=item I<proper_fields>

An array ref of field names of the main table that are not related
to any other table.

=item I<linked_fields>

An array reference of field names of the main table that are related
to other tables.

=item I<linked_tables>

An array reference of related table names corresponding to each
element of the I<linked_fields> parameter (defaults to the
corresponding name in I<linked_fields>).

=item I<linked_values>

The "human" values of each I<linked_fields> (a field name of the
corresponding I<linked_tables> element, default: 'name').

=item I<linked_refs>

The foreign key field name that relates the values of the
I<linked_fields> with the I<linked_tables> (default: 'id').

If present, I<linked_tables>, I<linked_values> and I<linked_refs> must
have the same number of elements than I<linked_fields>.

=item I<aliases>



( run in 2.413 seconds using v1.01-cache-2.11-cpan-364913b4093 )