NAME
DbFramework::Table - Table class
SYNOPSIS
use DbFramework::Table;
$t = new DbFramework::Table($name,,,$dbh,\%templates);
$t->init_db_metadata;
$pk = $t->is_identified_by($pk);
@fks = @{$t->has_foreign_keys_l};
@keys = @{$t->is_accessed_using_l};
@a = $t->get_attributes(@names);
@n = $t->get_attribute_names;
$html = $t->as_html_form;
$s = $t->as_string;
$sql = $t->as_sql;
$rows = $t->delete($conditions);
$pk = $t->insert(\%values);
$rows = $t->update(\%values,$conditions);
@lol = $t->select(\@columns,$conditions,$order);
$tmpl = $t->set_templates(\%templates);
$fill = $t->fill_template($template);
do_something if $t->in_foreign_key($attribute);
do_something if $t->in_key($attribute);
do_something if $t->in_primary_key($attribute);
do_something if $t->in_any_key($attribute);
@a = $t->non_key_attributes;
DESCRIPTION
A DbFramework::Table object represents n database table (entity).
SUPERCLASSES
DbFramework::DefinitionObject
DbFramework::DataModelObject
CLASS METHODS
new($name,\@attributes,$primary,$dbh,\%templates)
Create a new DbFramework::Table object. $dbh is a DBI database handle which refers to a database containing a table named $table. @attribues is a list of DbFramework::Attribute objects. $primary is a DbFramework::PrimaryKey object. @attributes and $primary can be omitted if you plan to use the init_db_metadata() object method (see below). %templates is a hash of template name value pairs (see the object method set_templates() below.)
OBJECT METHODS
Foreign keys in a table can be accessed using the HAS_FOREIGN_KEYS_L and HAS_FOREIGN_KEYS_H attributes. Note that foreign key objects will not be created automatically by calling init_db_metadata() on a table object. If you want to automatically create foreign key objects for your tables you should use call init_db_metadata() on a data model object (see "init_db_metadata()" in DbFramework::Datamodel). Other keys (indexes) defined for a table can be accessed using the IS_ACCESSED_USING_L attribute. See "AUTOLOAD()" in DbFramework::Util for the accessor methods for these attributes.
is_identified_by($primary)
$primary is a DbFramework::PrimaryKey object. If supplied, sets the table's primary key to $primary. Returns a DbFramework::PrimaryKey object with is the table's primary key.
get_attributes(@names)
Returns a list of DbFramework::Attribute objects. @names is a list of attribute names to return. If @names is undefined, all attributes associated with the table are returned.
get_attribute_names()
Returns a list of attribute names for the table.
as_html_form()
Returns HTML form fields for all non foreign key attributes in the table.
in_foreign_key($attribute)
$attribute is a DbFramework::Attribute object. Returns true if $attribute is a part of any foreign key in the table.
in_primary_key($attribute)
$attribute is a DbFramework::Attribute object. Returns true if $attribute is a part of the primary key in the table.
in_key($attribute)
$attribute is a DbFramework::Attribute object. Returns true if $attribute is a part of a key (index) in the table.
in_any_key($attribute)
$attribute is a DbFramework::Attribute object. Returns true if $attribute is a part of a key (index), a primary key or a foreign key in the table.
non_key_attributes()
Returns a list of DbFramework::Attribute objects which are not members of any key, primary key or foreign key.
as_string()
Return table details as a string.
init_db_metadata()
Returns an initialised DbFramework::Table object for the table matching this object's name() in the database referenced by dbh().
as_sql()
Returns a string which can be used to create a table in an SQL 'CREATE TABLE' statement.
delete($conditions)
DELETE rows FROM the table associated with this object WHERE the conditions in $conditions are met. Returns the number of rows deleted.
insert(\%values)
INSERT INTO the table columns corresponding to the keys of %values the VALUES corresponding to the values %values. Returns the primary key of the inserted row if it is a Mysql 'AUTO_INCREMENT' column.
update(\%values,$conditions)
UPDATE the table SETting the columns matching the keys in %values to the values in %values WHERE $conditions are met. Returns the number of rows updated.
select(\@columns,$conditions,$order)
Returns a list of lists of values by SELECTing rows FROM the table WHERE $conditions are met ORDERed BY $order.
fill_template($name,\%values)
Return the filled template named $name. A template can contain special placeholders representing columns in a database table. Placeholders in $template can take the following forms:
- <DbField table.column>
- <DbField table.column value=value>
- <DbField table.column value=value type=type>
- <DbValue table.column>
If the table's name() matches table in a DbField placeholder, the placeholder will be replaced with the corresponding HTML form field for the column named column with arguments value and type (see "html_form_field()" in DbFramework::Attribute). If %values is supplied, placeholders will have the values in %values added where a key in %values matches a column name in the table.
DbValue placeholders will be replaced with the values in %values where a key in %values matches a column name in the table.
set_templates(%templates)
Adds the contents of the files which are the values in %templates as templates named by the keys in %templates. Returns a reference to a hash of all templates.
SEE ALSO
DbFramework::DefinitionObject, DbFramework::Attribute and DbFramework::DataModelObject.
AUTHOR
Paul Sharpe <paul@miraclefish.com>
COPYRIGHT
Copyright (c) 1997,1998 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.