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
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 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.
$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 is a DBI database handle. If supplied sets the database handle associated with the table. Returns the database handle associated with the table.
$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.
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.
Returns a list of attribute names for the table.
Returns HTML form fields for all attributes in the table.
$attribute is a DbFramework::Attribute object. Returns a list of DbFramework::ForeignKey objects which contain $attribute.
$attribute is a DbFramework::Attribute object. Returns true if $attribute is a part of the primary key in the table.
$attribute is a DbFramework::Attribute object. Returns true if $attribute is a part of a key (index) in the table.
$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.
Returns a list of DbFramework::Attribute objects which are not members of any key, primary key or foreign key.
Returns table details as a string.
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.
Returns a string which can be used to create a table in an SQL 'CREATE TABLE' statement.
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 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 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.
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)/;
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.
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";
Returns a string for use as a table heading row in an HTML table.
DbFramework::DefinitionObject, DbFramework::Attribute, DbFramework::DataModelObject and DbFramework::DataModel.
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.
To install DbFramework::Key, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DbFramework::Key
CPAN shell
perl -MCPAN -e shell install DbFramework::Key
For more information on module installation, please visit the detailed CPAN module installation guide.