DBIx::DataLookup

Perl extension for database view lookup table
Download

DBIx::DataLookup Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Vladimir Bogdanov
  • Publisher web site:
  • http://search.cpan.org/~vladb/

DBIx::DataLookup Tags


DBIx::DataLookup Description

Perl extension for database view lookup table DBIx::DataLookup is a Perl module remotely similar to DBIx::Cache but is very simpler and serves narrower purpose. This module allows you to both cache records pulled by an SQL statement from a database in the memory as well as look them up later at any time during execution of your script.This also speeds up access to your data at run-time and subsequently reduces load on the database.For example, in your scripts, you could simply aggregate every SQL statement inside a hash in a config file and use them later to initialize a number of DBIx::DataLookup objects. Later in the code, you would simply invoke the get_hashref() method of your DBIx::DataLookup object(s) to retrieve records matching certain key values.This module also supports alternative key mapping, which is not offered by any other module. A user of this module may add alternative key mappings at run-time to be able to link certain records with specific keys etc. For example, if you have to deal with data supplied to you by various providers (such as news/weather syndicates etc), there's a chance for minor irregularities in otherwise similar data (say, two vendors use different identification codes for one theater ...) So, when you are talking of only a dozen (or fewer) such differing keys, key mapping offered by this module becomes quite handy.SYNOPSISuse DataLookup; 1. Create a DBIx::DataLookup object: my $country_table = new DBIx::DataLookup( dbh => $dbh, statement => qq{ select countrycode countryname from countries }, );2. Lookup records with matching 'countrycode' field: my $country_rec = $country_table->get_hashref(countrycode => 'USA'); print "Country name: " . $country_rec->{COUNTRYNAME} . " ";Similarly, you may create DataLookup objects to allow you lookup records by multiple keys. Here's an example of just how you could do this:1. Again, create a DBIx::DataLookup object, but a little more complex than the one before: # # Note: '. . .' denotes SQL expression of any complexity you wish. # my $country_table = new DBIx::DataLookup( dbh => $dbh, statement => qq{ select provname, provcode, countryname, countrycode from . . . where . . . }, keys => , # lookup keys );2. (a) Lookup records with matching provcode (Province code): my $prov_rec = $country_table->get_hashref(provcode => 'BC'); print "First province name: " . $prov_rec->{PROVNAME} . " ";2. (b) Find all provinces (or states) that belong to specified country: my $prov_rec = $country_table->get_hashref(countrycode => 'USA'); foreach (@$prov_rec) { # $_ is a HASHREF to a hash representing # a matched record. } Requirements: · Perl


DBIx::DataLookup Related Software