Hakan Ardo > DBIx-HTMLView-LATEST > DBIx::HTMLView::Table

Download:
DBIx-HTMLView-LATEST.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

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 can be used to access the posts of that table.

METHODS ^

DBIx::HTMLView::Table->new($name, [$opt,] @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.

If $opt is a hash referencs and not a fld object its used to set a few options for the Table. Currently, the following options are defined:

  flds_to_view - An array specifying which Flds to view in a default 
    listing.
  rows - How many rows per page a default listing should contain.

$tab->initiate_js_onSubmit(); Initalize the js of the onSubmit looking for files with default name

$table->get_JSonSubmit() Returns the javascript code associated to the submit botton on edit/insert forms.

$table->set_JSonSubmit() Set the javascript code associated to the submit botton on edit/insert forms.

$table->set_JSonSubmit_name() Set the name of the function associated to the submit botton on edit/insert forms.

$table->get_JSonsubmit_name() Returns the name of the function associated to the submit botton on edit/insert forms.

$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->count($search, $extra)

Counts the numbers of 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.

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

Works in a similar way to $table->list, but it will not add the id field to flds select, and it will do a distinct select. The posts returned are some kind of pseudo posts. If you try to modify and update them and the new posts will be added to the db as they have no id.

Will currently not work with relations (FIXME). It will never work with N2N relations as they require the id selected in order to find the related posts.

$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 smoother 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.

$table->post_fmt($kind)

Returns a fmt for viewing a post from this table in the $kind format. It can be specified in ... FIXME: where?

$table->list_fmt($kind, $butt, $flds)

Returns a fmt for viewing a set of posts from this table in the $kind format. It can be specified in ... FIXME: where?

The default fmt will consist of a table with one colume per Fld specified in the arrayref $flds. If it is not defined all Fld will be viewed.

$butt can be used to specify the contents of an extra colum to the right of the rest. To for example contain the view, edit and delete buttons.

syntax highlighting: