The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

  DBIx::HTMLView::Table - A table within a generic DBI databse

SYNOPSIS

my $table=$dbi->tab('Test');

# List all posts my $hits=$table->list();

# Get post with id 7 my $post=$table->get(7);

DESCRIPTION

This object is supposed to be created inside a database description as described in the DBIx::HTMLView::DB man page to represent a table and it's fields and relations. Then it's can be used to access the posts of that table.

METHODS

DBIx::HTMLView::Table->new($name, @flds)

Creates a new table representation for a table named $name. This has to be the same name as the database engine has for the table. @flds is an array of DBIx::HTMLView::Fld objects which represent the separate fields and relations of the table.

$table->id

Returns the DBIx::HTMLView::Fld object that is used as the id field for this table.

$table->name

Returns the name of this table.

$table->set_db($db)

Use by the parent DBIx::HTMLView::DB object to inform this object which databse it belongs to ($db). It should not be used elsewhere.

$table->list($search, $extra, $flds)

Returns a DBIx::HTMLView::PostSet object with the posts matching the $search string (see the DBIx::HTMLView::Selection man page for a description of the search language, it is close to SQL). $extra will be apended to the SQL select command before it is sent to the databse it can be used to specify a ORDER BY clause for example.

$flds is for optimisations. If it is not defined all fileds of the posts are retrieved from the datbase. If it is an array ref only the fields who's names are listed in there are retrieved. If a search string is specied the fields used in that string will also be retrieved.

The PostSet object return is placed in no-save mode, which means that you will be able to itterate through the posts once and then they are gone. This is becaue there can be quite a lot of data returned from the database server and there is usualy no reason to store it all in memory.

To create a PostSet object in save mode with the result you could do something like:

$post_set=$table->list; $post_set_save=DBIx::HTMLView::PostSet->new; while (defined $post=$self->get_next) { $post_set_save->add($post); }

$table->sql_list($select)

Sends $select, which should be a select clause on this table,to the database and turns the result into a DBIx::HTMLView::PostSet object. You should use the list method insted. It gives you a smooter interface.

$table->new_post(...)

Creates a new DBIx::HTMLView::Post object linked to this table (all posts must be linked to a table). All arguments are passed on to the new method.

$table->new_fld($fld,$val)

Creates a copy of the DBIx::HTMLView::Fld object named $fld and gives it the value $val. It is used by the DBIx::HTMLView::Post objects to create objects representing the diffrent values of the fields and does not make much sense elsewhere.

For fields data ($val) is specified as a string or as the first item of a array referenced to by $val. Relations are represented as a reference to an array of the id's of the posts being related to.

$table->fld_names

Returns an array of the names of all the fields and relation in this table.

$table->fld($fld)

Returns the DBIx::HTMLView::Fld object of the field or relation named $fld.

$table->got_fld($fld)

Returns true if this table has a field or relation named $fld.

$table->fld($fld)

Returns an array of DBIx::HTMLView::Fld objects of all the fields and relations in this table.

$table->db

Returns the DBIx::HTMLView::DB object this table belongs to.

$table->del($id)

Deletes the post with id $id.

$table->update($post) =head2 $table->change($post)

Updates the data in the database of the post represented by $post (a DBIx::HTMLView::Post object) with the data contained in the object.

$table->add($post) =head2 $table->insert($post)

Inserts the post $post (a DBIx::HTMLView::Post object) into the database.

$table->get($id)

Returns a DBIx::HTMLView::Post object representing the post with id $id.

$table->msql_create

Will create the tabel using SQL commands that works with msql.