NAME

Site::SQLtable - Mostly painless SQL tables with auto-sorts, prev/next, etc.


SYNOPSIS

  use Site::SQLtable;

  $t = Site::SQLtable -> new( dbh => $dbh );
  $t -> table( 'customer_t' );
  $t -> addfields( { .. } );
  $t -> display();


DESCRIPTION

The SQLtable class handles the dirty underbelly of creating and using tables with SQL data. It can automatically do X per page lists with column headers that allow the data to be re-sorted easily with little programming effort. They can also be customized with forms to change the look and feel, see the section about templates for more information.

For basic fields information and how to get them in to an SQLtable, see the Site::SQLContainer docs.


display

Displays the current table.


wherecluase

Sets the where part of the table, without the word 'where'.

  $f -> whereclause( 'customerid=3' );


whereargs

Used with the whereclause(), these are the args to the DBI -> execute() call, should be an arrayref.

  $f -> whereclause( 'customerid=? AND useid=?' );
  $f -> whereargs( [ $custid, $useid ] );


where

Combines whereclause and whereargs in to 1 call:

  $f -> where( 'customerid=? AND useid=?', $custid, $useid );

is equivalent to the whereargs() example. You don't use an arrayref here.


order

An array ref specifying the default order (when no re-sorting has been done).

  $f -> order( [ 'lastname', 'firstname' ] );


perpage

Sets the number of rows per page. If 0, then show all rows. Default 0.


query

Normally the query is build from the table and fields properties, but you can override this by specifying an implicit query. This will be used and the field names will be bound to the correct fields. Mostly useful for presenting JOINed data. Note, you MUST NOT SPECIFY A WHERE OR ORDER BY CLAUSE!!

  $f -> query( qq{
select name, order_description, value
from customer join order using (customerid) } );


lookupobjects

If set to '1' and the table was created from a 'bind_sql_object' then the SQLtable will create (with new() and SQL_GET()) objects for each row to be used in a template. It's a performance hit, so if you don't need it then don't use it, however it makes the tables very powerful when used, for example to have extended logic within the table or calculated values or such.


forwardbutton/backbutton

The string to be used to create the 'NEXT'/'BACK' button link. It is a link too, not a form button. You could use an <IMG> if you want.


Templates

Templates work similar to SQLForm templates but there is the addition of headers and the loop'able rows.

The default template is:

 <t:iftrue name=expandedheaders>
 Showing <t:var name=startfrom/> through
  <t:var name=endon/> of <t:var name=total/>
 <t:iftrue name=perpage><BR>Page <t:var name=currentpage/> of 
  <t:var name=totalpages/></t:iftrue>
 </t:iftrue>

 <TABLE BORDER=0 WIDTH=<t:var name=width/>>
 <TR>
 <t:loop name=headers>
  <TD><t:var name=header/></tD>
 </t:loop>
 </TR>

 <t:loop name=rows>
 <TR>
 <t:loop name=fields>
 <TD VALIGN=TOP><t:var name=display/></TD>
 </t:loop>
 </TR>
 </t:loop>

 </TABLE>

 <t:iftrue name=perpage>
 <TABLE BORDER=0 WIDTH=100\%>
 <TR>
 <TD><t:var name=back/></TD>
 <TD ALIGN=RIGHT><t:var name=forward/></TD>
 </TR>
 </TABLE>
 </t:iftrue>

This can be customized by loading an external template.


expandedheaders

Just passed from the class, you can probably ignore it since you know if you need expanded headers or not. It was in the default template to allow somewhat easier settings from the class itself.


startfrom/endon/total/perpage/currentpage

All just informational things to be displayed to the user if you want.


headers

A loop'able variable containing all the headers, which is the re-sort links for the table. Under the headers is just a header variable.


byname/byboundto

At the very top level these are the HEADERS by name and boundto fields. Under the var is just the names, which are the headers for the fields.


rows

The rows to be displayed, under the rows you have several options:


object

If lookupobjects is '1' then this will contain an SQLObject for the current row.


fields

A loop'able var containing all the fields.


byname/byboundto

Fields by name and boundto field name.


THE FIELDS

The fields all contain a field, label, display, sqlvalue and header variable. That is for both fields and the boundto/name lists.


AUTHOR

Copyright (c) 2001 Steve Slaven <bpk@hoopajoo.net> All rights reserved.

This program is free software and is provided ``as is'' without express or implied warranty. You can redistribute it and/or modify it under the same terms as Perl itself.


SEE ALSO

perl(1).