DbFramework::PrimaryKey - Primary key class


NAME

DbFramework::PrimaryKey - Primary key class


SYNOPSIS

  use DbFramework::PrimaryKey;
  $pk   = new DbFramework::Primary(\@attributes,$table,\@labels);
  $sql  = $pk->as_sql;
  $html = $pk->html_select_field(\@column_names,$multiple,\@default);
  $html = $pk->as_html_heading;
  $html = $pk->as_hidden_html(\%values);
  $qw   = $pk->as_query_string(\%values);


DESCRIPTION

The DbFramework::PrimaryKey class implements primary keys for a table.


SUPERCLASSES

DbFramework::Key


CLASS METHODS

new(\@attributes,$table,\@labels)

Create a new DbFramework::PrimaryKey object. @attributes is a list of DbFramework::Attribute objects from a single DbFramework::Table object which make up the key. $table is the DbFramework::Table to which the primary key belongs. @labels is a list of column names which should be used as labels when calling html_select_field(). @labels will default to all columns in $table.


OBJECT METHODS

as_sql()

Returns a string which can be used in an SQL 'CREATE TABLE' statement to create the primary key.

html_select_field(\@column_names,$multiple,\@default,$name)

Returns an HTML form select field where the value consists of the values from the columns which make up the primary key and the labels consist of the corresponding values from @column_names. If @column_names is undefined the labels consist of the values from all column names. If $multiple is defined the field will allow multiple selections. @default is a list of values in the select field which should be selected by default. For fields which allow only a single selection the first value in @default will be used as the default. If $name is defined it will be used as the name of the select field, otherwise the name will consist of the attribute names of the primary key joined by ',' (comma) and the values will consist of the corresponding attribute values joined by ',' (comma).

as_html_heading()

Returns a string for use as a column heading cell in an HTML table;

as_query_string(\%values)

Returns a CGI query string consisting of attribute names from the primary key and their corresponding values from %values.

as_hidden_html(\%values)

Returns hidden HTML form fields for each primary key attribute. The field name is pk_$attribute_name. The field value is the value in %values whose key is $attribute_name. This method is useful for tracking the previous value of a primary key when you need to update a primary key.


SEE ALSO

the DbFramework::Key manpage


AUTHOR

Paul Sharpe <paul@miraclefish.com>


COPYRIGHT

Copyright (c) 1997,1998,1999 Paul Sharpe. England. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

 DbFramework::PrimaryKey - Primary key class