SQL::Schema::Table::Column - A column of a database table



NAME

SQL::Schema::Table::Column - A column of a database table


SYNOPSIS

  my $column = SQL::Schema::Table::Column->new(%attr);
  my $sql = $column->column_definition;
  print $sql;
  print "$column";


DESCRIPTION

SQL::Schema::Table::Column is a class for objects representing a database table's column. The methods of an instanciated object do allow to access the information within a database's data dictionary and to represent them as SQL create statements and the like using the proper SQL dialect.

Constructors

  $column = SQL::Schema::Table::Column->new(%attr);

The new method instanciates a column object. The object is an in memory representation of a (possible) database table's column. The attributes are given as key value pairs by the hash %attr. Possible keys are:

  key              required?   value description
  column_name      yes         The name of the table's column.
  data_type        yes         number
  data_length      no          number
  data_precision   no          number
  data_scale       no          number
  nullable         no          either `Y' o `N'; default: `Y'
  data_default     no          a character string approbriate as
                               expression after the `default' keyword
                               (might include quotes)

These keys and their possible values correspond exactly to the data dictionary view all_tab_columns and are described within Oracle's Server Reference.

  $column = SQL::Schema::Table::Column->select($dbh,$table_name,$column_name);

The select method fetches the attributes required by new from the database and returns the column object. (It calls new internally.)

If the column could not be found within the database, the method returns undef.

The method's arguments are as follows:

$dbh
A database handle as defined by DBI(3).

$table_name
The name of the table without preceeding schema name.

$column_name
The name of the column.

Methods

The following attribute methods do return the current value of the attributes (as handed over to the new method):

  $column_name = $column->name;
  $data_type = $column->data_type;
  $data_length = $column->data_length;
  $data_precision = $column->data_precision;
  $data_scale = $column->data_scale;
  $nullable = $column->nullable;
  $data_default = $column->data_default;

There does exist a speciallity for the data_default method: If the attribute data_default the method data_default returns the content of the attribute with eleminated trailing new line.

The return value of nullable is either Y or N. This is somewhat uncomfortable for perl programmers. You might want to use the following method instead:

  $nullable = $sequence->nullable_bool;

It does return 1 resp. 0 where its corresponding attribute method returns Y resp. N.

  $sql = $column->column_definition;
  $sql = "$column";

Returns a string containing the column definition which could be used as part of an SQL statements for creation of the corresponding column. This method is overloaded with the string operator. So the two examples above are equivalent.


AUTHOR AND COPYRIGHT

  SQL::Schema::Table::Column is Copyright (C) 2000,
    Torsten Hentschel
    Windmuehlenweg 47
    44141 Dortmund
    Germany
    Email: todd@bayleys.ping.de
  All rights reserved.
  You may distribute this package under the terms of either the GNU
  General Public License or the Artistic License, as specified in the
  Perl README file.


SEE ALSO

DBI(3), the SQL::Schema::Table(3) manpage

 SQL::Schema::Table::Column - A column of a database table