NAME
DbFramework::Table - Table class
SYNOPSIS
use DbFramework::Table;
$t = new DbFramework::Table new($name,\@attributes,$pk,$dbh,$dm);
$t->init_db_metadata($catalog);
$dbh = $t->dbh($dbh);
$pk = $t->is_identified_by($pk);
@fks = @{$t->has_foreign_keys_l};
%fks = %{$t->has_foreign_keys_h};
@keys = @{$t->is_accessed_using_l};
@a = $t->get_attributes(@names);
@n = $t->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);
@loh = $t->select_loh(\@columns,$conditions,$order);
@a = $t->non_key_attributes;
$dm = $t->belongs_to;
@fks = $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);
DESCRIPTION
A DbFramework::Table object represents a database table (entity).
SUPERCLASSES
DbFramework::DefinitionObject
DbFramework::DataModelObject
CLASS METHODS
new($name,\@attributes,$pk,$dbh,$dm)
Create a new DbFramework::Table object. $dbh is a DBI database handle which refers to a database containing a table named $name. @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). $dm is a DbFramework::DataModel object to which this table belongs.
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 DbFramework::DataModel 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.
dbh($dbh)
$dbh is a DBI database handle. If supplied sets the database handle associated with the table. Returns the database handle associated with the table.
belongs_to($dm)
$dm is a DbFramework::DataModel object. If supplied sets the data model to which the table belongs. Returns the data model to which the table belongs.
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.
attribute_names()
Returns a list of attribute names for the table.
as_html_form()
Returns HTML form fields for all attributes in the table.
in_foreign_key($attribute)
$attribute is a DbFramework::Attribute object. Returns a list of DbFramework::ForeignKey objects which contain $attribute.
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()
Returns table details as a string.
init_db_metadata($catalog)
Returns an initialised DbFramework::Table object for the table matching this object's name() in the database referenced by dbh(). $catalog is a DbFramework::Catalog object.
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 if supplied by the DBI driver.
insert(\%values)
INSERT INTO the table columns corresponding to the keys of %values the VALUES corresponding to the values of %values. Returns the primary key of the inserted row if it is a Mysql 'AUTO_INCREMENT' column or -1.
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 if supplied by the DBI driver.
select(\@columns,$conditions,$order)
Returns a list of lists of values by SELECTing values FROM @columns WHERE rows meet $conditions ORDERed BY the list of columns in $order. Strings in @columns can refer to functions supported by the database in a SELECT clause e.g.
@columns = q/sin(foo),cos(bar),tan(baz)/;
select_loh(\@columns,$conditions,$order)
Returns a list of hashrefs containing (column_name,value) pairs by SELECTing values FROM @columns WHERE rows meet $conditions ORDERed BY the list of columns in $order. Strings in @columns can refer to functions supported by the database in a SELECT clause e.g.
@columns = q/sin(foo),cos(bar),tan(baz)/;
The keys in the hashrefs will match the name of the function applied to the column i.e.
@loh = $foo->select(\@columns);
print "sin(foo) = $loh[0]->{sin(foo)}\n";
as_html_heading()
Returns a string for use as a table heading row in an HTML table.
SEE ALSO
DbFramework::DefinitionObject, DbFramework::Attribute, DbFramework::DataModelObject and DbFramework::DataModel.
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.