NAME

NumberedTree::DBTree - a NumberedTree that is tied to a DB table.

SYNOPSIS

use NumberedTree::DBTree;
my $dbh = DBI->connect(...);

# The easy way:
my $tree = NumberedTree::DBTree->read($table, $dbh);

# The hard way:
my $tree = NumberedTree::DBTree->new(source_name => 'a_table', 
                                     source => $dbh);
while (I aint sick of it) {
	$tree->append($newValue);
}

etc.

DESCRIPTION

DBTree is a child class of NumberedTree.pm that supplies database tying (every change is immediately reflected in the database) and reading using tables that are built to store a tree (the structure is described below). It's basically the same as NumberedTree except for some methods. These, and arguments changes for inherited methods, are also described below. For the rest, please refer to the documentation for NumberedTree.pm.

CREATING A TABLE FOR THE TREE

A table used by this module must have at least 3 columns: the serial number column (by default 'serial'), the parent column (default - 'parent') and the value column (default - 'name'). If the default names don't suit you, don't worry - you can supply different names to the constructors). Serial numbers start from any number greater than zero and must be auto increment fields. Parent numbers of course are the serial numbers of the parent for each node - the root node always takes parent number 0.

 Example SQL statement to build the table:  
 create table places (serial int auto_increment primary key, 
 				  parent int not null, 
				  name varchar(20));

METHODS

This section only describes methods that are not the same as in NumberedTree.

Constructors

There are now two of them:

new (source => source, source_name => source_name)

creates a new tree object that uses an empty table named <source_name> using a database handle supplied via the source argument.

read (SOURCE_NAME, SOURCE);

creates a new tree object from a table that contains tree data as specified above. Arguments are the same as to new.

Other methods

Two methods are added to this class:

truncate

Activates the truncate SQL command, effectively deleting all data in a tree, but not the table. This also disposes of the tree object, so you'll have to build a new one after using this method.

revert

Removes information that is specific to this class and re-blesses the entire tree into the parent class.

BUGS

Please report through CPAN: <http://rt.cpan.org/NoAuth/Bugs.html?Dist=NumberedTree> or send mail to <bug-NumberedTree#rt.cpan.org>

SEE ALSO

NumberedTree.pm

AUTHOR

Yosef Meller, <mellerf@netvision.net.il>

COPYRIGHT AND LICENSE

Copyright 2003 by Yosef Meller

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.