Nic Wolff > HTML-DataTable-0.54 > HTML::DataTable::DBI

Download:
HTML-DataTable-0.54.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.54   Source  

NAME ^

HTML::DataTable::DBI - Print HTML tables from SQL queries

VERSION ^

Version 0.54

SYNOPSIS ^

  use HTML::DataTable::DBI;
  my $list = HTML::DataTable::DBI->new(
    data => $cgi_data,
    columns => [
      # hashrefs describing column formats
    ],
    sql => 'SELECT * FROM table_name WHERE foreign_key = ?',
    sql_params => [ $some_value ],
    delete => { } # Delete spec as shown below
  );
  print $list;

METHODS ^

Look in HTML::DataTable for column-definition and table formatting attributes

ADDITIONAL ATTRIBUTES

dsn

A list containing a DBI connect string, username, and password.

dbh

You can supply a live DBI database handle instead of a DSN.

sql

A SQL query with optional "?" placeholders, which will be run and its results formatted and shown in the table.

sql_params

An optional arrayref containing the actual parameters for the SQL query.

delete

An optional hashref telling the list what record to delete. If this is included, a column will be added to the table to show trash icons. The hashref can take either of two forms. If the SQL query for this table is not parameterized - that is, the record's ID is all we need to know which record to delete - then the hashref can simply map the column index of the record ID to the CGI argument that supplies the one to delete:

  delete => {
    sql => 'DELETE FROM table WHERE record_id = ?',
    id => [ 0 => $args{delete} ],
  }

whereas if the query had a parameter the delete hashref has to give both the local and foreign keys:

  delete => {
    sql => 'DELETE FROM table WHERE record_id = ? AND foreign_id = ?',
    local => [ record_id => $args{speaker_id} ],
    foreign => [ 0 => $args{delete} ],
  }

An optional "noun" attribute in that hashref can supply a word to replace "record" in the delete confirmation alert.

trash_icon

The URL of a trash can icon for use in the "Delete" column - defaults to /art/trash.gif.

ADDITIONAL COLUMN ATTRIBUTES

sql

A paramterized SQL query that will be run to get results for this column.

foreign_key_col

The index of the column in the results from the main table's SQL query that will be used in the column's query's parameter. Defaults to 0.

separator

A character string that will be used to concatenate the results of the columns's query. Defaults to ", ".

SEE ALSO ^

HTML::DataTable

AUTHORS ^

Nic Wolff <nic@angel.net> Jason Barden <jason@angel.net>

syntax highlighting: