DbFramework::Table - Table class |
is_identified_by($primary)
dbh($dbh)
belongs_to($dm)
get_attributes(@names)
attribute_names()
as_html_form()
in_foreign_key($attribute)
in_primary_key($attribute)
in_key($attribute)
in_any_key($attribute)
non_key_attributes()
as_string()
init_db_metadata($catalog)
as_sql()
delete($conditions)
insert(\%values)
update(\%values,$conditions)
select(\@columns,$conditions,$order)
select_loh(\@columns,$conditions,$order)
as_html_heading()
DbFramework::Table - Table class
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);
A DbFramework::Table object represents a database table (entity).
DbFramework::DefinitionObject
DbFramework::DataModelObject
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.
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 the DbFramework::Datamodel manpage). Other keys (indexes)
defined for a table can be accessed using the IS_ACCESSED_USING_L
attribute. See AUTOLOAD() in the DbFramework::Util manpage 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.
the DbFramework::DefinitionObject manpage, the DbFramework::Attribute manpage, the DbFramework::DataModelObject manpage and the DbFramework::DataModel manpage.
Paul Sharpe <paul@miraclefish.com>
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::Table - Table class |