NAME
Synopsis#!/usr/bin/perl use DBIx::Table2Hash; my($key2value) = DBIx::Table2Hash -> new ( dbh => $dbh, table_name => $table_name, key_column => 'name', value_column => 'id' ) -> select(); # or my($key2hashref) = DBIx::Table2Hash -> new ( dbh => $dbh, table_name => $table_name, key_column => 'name', ) -> select_hashref(); # or my($key2tree) = DBIx::Table2Hash -> new ( dbh => $dbh, table_name => $table_name, key_column => 'name', child_column => 'id', parent_column => 'parent_id', skip_columns => ['code'] ) -> select_tree(); Description
This module reads a database table and stores keys and values in a hash. The aim is to create a hash which is a simple look-up table. To this end, the module allows the key_column to point to an SQL expression.
DistributionsThis module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file. See http://savage.net.au/Perl-modules.html for details. See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro. Constructor and initializationnew(...) returns a This is the class's contructor. Parameters: Note: These parameters are not checked until you call
Method: new(...)Returns a object of type See above, in the section called 'Constructor and initialization'. Method: select(%parameter)Returns a hash ref. Each key in the hash points to a single value. Named parameters, as documented above, can be passed in to this method. Calling The demo program test-table2hash.pl, in the examples/ directory, calls Method: select_hashref(%parameter)Returns a hash ref. Each key in the hash points to a hashref. Named parameters, as documented above, can be passed in to this method. Calling The demo program test-table2hash.pl, in the examples/ directory, calls Method: select_tree(%parameter)Returns a hash ref. Each key in the hash points to a hashref. Named parameters, as documented above, can be passed in to this method. Calling The demo program test-table2tree.pl, in the examples/ directory, calls DBIx::Table2Hash and CGI::ExplorerThe method Such a hash cannot be passed in to CGI::Explorer V 2.00+. Here's a way around this restriction: Create, on the fly, a hash key which is The Mother of All Roots. Eg: my($t2h) = DBIx::Table2Hash -> new(...);
my($tree) = $t2h -> select_tree(...);
my($exp) = CGI::Explorer -> new(...) -> from_hash(hashref => {OneAndOnly => $tree});
Required ModulesOnly those shipped with Perl. ChangesSee Changes.txt. FAQQ: What is the point of this module? A 1: To be able to restore a hash from a database rather than from a file. A 2: To be able to construct, from a database table, a hash suitable for passing in to CGI::Explorer V 2.00. Q: Can your other module A: Sure. Q: Do you ship demos for the 3 methods A: Yes. See the examples/ directory. If you installed this module locally via ppm, look in the x86/ directory for the file to unpack. If you installed this module remotely via ppm, you need to download and unpack the distro itself. Q: Are there any other modules with similar capabilities? A: Yes:
Author
Home page: http://savage.net.au/index.html CopyrightAustralian copyright © 2003, Ron Savage. All rights reserved. All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Artistic License, a copy of which is available at: http://www.opensource.org/licenses/index.html |
| Top of page |