Locale::Object::DB - do database lookups for Locale::Object modules


Locale-Object documentation  | view source Contained in the Locale-Object distribution.

Index


NAME

Top

Locale::Object::DB - do database lookups for Locale::Object modules

DESCRIPTION

Top

This module provides common functionality for the Locale::Object modules by doing lookups in the database that comes with them (which uses DBD::SQLite).

SYNOPSIS

Top

    use Locale::Object::DB;

    my $db = Locale::Object::DB->new();

    my $table = 'country';
    my $what  = 'name';
    my $value = 'Afghanistan';

    my @results = $db->lookup($table, $what, $value);

    my %countries;

    $table = 'continent';
    my $result_column = 'country_code';

    my $results = $db->lookup(
                              table         => $table, 
                              result_column => $result_column, 
                              search_column => $what, 
                              value         => $value
                             );

    foreach my $item (@{$results})
    {
      print $item->{$result_column};
    }

    $result = $db->lookup_dual(
                               table      => $table, 
                               result_col => $result_column, 
                               col_1      => $first_search_column, 
                               val_1      => $first_search_value,
                               col_2      => $second_search_column,
                               val_2      => $second_search_value
                              );

METHODS

Top

lookup()

    $db->lookup(
                table         => $table,
                result_column => $result_column,
                search_column => $search_column,
                value         => $value
               );

lookup will return a reference to an anonymous array of hashes. The hashes will contain the results for a query of the database for cells in $result_column in $table that are in a row that has $value in $search_column. Use '*' as a value for result_column if you want to retrieve whole rows.

For information on what db tables are available and where the data came from, see docs/database.pod.

IMPORTANT: The way of using this method has changed as of version 0.2, and in addition it supersedes the place formerly taken by lookup_all(). Apologies for any inconvenience.

lookup_dual()

    my $result = $db->lookup_dual(
                                  table      => $table, 
                                  result_col => $result_column, 
                                  col_1      => $first_search_column, 
                                  val_1      => $first_search_value,
                                  col_2      => $second_search_column,
                                  val_2      => $second_search_value
                                 );

lookup_dual will return a reference to an anonymous array of hashes. The hashes will contain the results for a query of the database for cells in $result_column in $table that are in a row that has two specified values in two specified columns. Use '*' as a value for $result_column if you want to retrieve whole rows.

NOTES

Top

The database file itself is named locale.db and must reside in the same directory as this module. If it's not present, the module will croak with a fatal error.

AUTHOR

Top

Earle Martin <hex@cpan.org>

http://downlode.org/Code/Perl/

CREDITS

Top

See the credits for Locale::Object.

LEGAL

Top


Locale-Object documentation  | view source Contained in the Locale-Object distribution.