DBIx::DBSchema::Table - Table objects


DBIx::DBSchema::Table - Table objects


  use DBIx::DBSchema::Table;
  #old style (depriciated)
  $table = new DBIx::DBSchema::Table (
  #new style (preferred), pass a hashref of parameters
  $table = new DBIx::DBSchema::Table (
      name        => "table_name",
      primary_key => "primary_key",
      unique      => $dbix_dbschema_colgroup_unique_object,
      'index'     => $dbix_dbschema_colgroup_index_object,
      columns     => \@dbix_dbschema_column_objects,
  $table->addcolumn ( $dbix_dbschema_column_object );
  $table_name = $table->name;
  $primary_key = $table->primary_key;
  $dbix_dbschema_colgroup_unique_object = $table->unique;
  $table->unique( $dbix_dbschema__colgroup_unique_object );
  $dbix_dbschema_colgroup_index_object = $table->index;
  $table->index( $dbix_dbschema_colgroup_index_object );
  @column_names = $table->columns;
  $dbix_dbschema_column_object = $table->column("column");
  @sql_statements = $table->sql_create_table( $dbh );
  @sql_statements = $table->sql_create_table( $datasrc, $username, $password );
  #possible problems
  @sql_statements = $table->sql_create_table( $datasrc );
  @sql_statements = $table->sql_create_table;


DBIx::DBSchema::Table objects represent a single database table.


new [ TABLE_NAME [ , PRIMARY_KEY [ , UNIQUE [ , INDEX [ , COLUMN... ] ] ] ] ]
Creates a new DBIx::DBSchema::Table object. The preferred usage is to pass a hash reference of named parameters.
    name        => TABLE_NAME,
    primary_key => PRIMARY_KEY,
    unique      => UNIQUE,
    'index'     => INDEX,
    columns     => COLUMNS

TABLE_NAME is the name of the table. PRIMARY_KEY is the primary key (may be empty). UNIQUE is a DBIx::DBSchema::ColGroup::Unique object (see the DBIx::DBSchema::ColGroup::Unique manpage). INDEX is a DBIx::DBSchema::ColGroup::Index object (see the DBIx::DBSchema::ColGroup::Index manpage). COLUMNS is a reference to an array of DBIx::DBSchema::Column objects (see the DBIx::DBSchema::Column manpage).

Creates a new DBIx::DBSchema::Table object from the supplied DBI database handle for the specified table. This uses the experimental DBI type_info method to create a table with standard (ODBC) SQL column types that most closely correspond to any non-portable column types. Use this to import a schema that you wish to use with many different database engines. Although primary key and (unique) index information will only be imported from databases with DBIx::DBSchema::DBD drivers (currently MySQL and PostgreSQL), import of column names and attributes *should* work for any database.

Creates a new DBIx::DBSchema::Table object from the supplied DBI database handle for the specified table. This uses database-native methods to read the schema, and will preserve any non-portable column types. The method is only available if there is a DBIx::DBSchema::DBD for the corresponding database engine (currently, MySQL and PostgreSQL).

addcolumn COLUMN
Adds this DBIx::DBSchema::Column object.

delcolumn COLUMN_NAME
Deletes this column. Returns false if no column of this name was found to remove, true otherwise.

name [ TABLE_NAME ]
Returns or sets the table name.

primary_key [ PRIMARY_KEY ]
Returns or sets the primary key.

unique [ UNIQUE ]
Returns or sets the DBIx::DBSchema::ColGroup::Unique object.

index [ INDEX ]
Returns or sets the DBIx::DBSchema::ColGroup::Index object.

Returns a list consisting of the names of all columns.

Returns the column object (see the DBIx::DBSchema::Column manpage) for the specified COLUMN_NAME.

Returns a list of SQL statments to create this table.

The data source can be specified by passing an open DBI database handle, or by passing the DBI data source name, username and password.

Although the username and password are optional, it is best to call this method with a database handle or data source including a valid username and password - a DBI connection will be opened and the quoting and type mapping will be more reliable.

If passed a DBI data source (or handle) such as `DBI:mysql:database', will use MySQL- or PostgreSQL-specific syntax. Non-standard syntax for other engines (if applicable) may also be supported in the future.


Ivan Kohler <ivan-dbix-dbschema@420.am>

Thanks to Mark Ethan Trostler <mark@zzo.com> for a patch to allow tables with no indices.


Copyright (c) 2000 Ivan Kohler Copyright (c) 2000 Mail Abuse Prevention System LLC All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


sql_create_table() has database-specific foo that probably ought to be abstracted into the DBIx::DBSchema::DBD:: modules.

sql_create_table may change or destroy the object's data. If you need to use the object after sql_create_table, make a copy beforehand.

Some of the logic in new_odbc might be better abstracted into Column.pm etc.


the DBIx::DBSchema manpage, the DBIx::DBSchema::ColGroup::Unique manpage, the DBIx::DBSchema::ColGroup::Index manpage, the DBIx::DBSchema::Column manpage, the DBI manpage

 DBIx::DBSchema::Table - Table objects