NAME

Class::ReluctantORM::SQL::Column - Represent a Column in a SQL statement

SYNOPSIS

  use Class::ReluctantORM::SQL::Aliases;

  # Make a column
  my $col1 = Column->new(); # undetermined name
  my $col2 = Column->new(column => 'my_col'); # undetermined table
  my $col3 = Column->new(column => 'my_col', table => Table->new()); # fully specified

  # Use a column in a Where clause criterion ('foo' = ?)
  my $crit = Criterion->new('=', Column->new(column => 'foo'), Param->new());
  my $where = Where->new($crit);
  $sql->where($where);
  my @cols = $where->columns();

  # Use a column in an OrderBy clause
  my $ob = OrderBy->new();
  $ob->add($col, 'DESC');
  my @cols = $ob->columns;

  # Use the column as an output column
  my $sql = SQL->new(...);
  $sql->add_output($col);

DESCRIPTION

Represents a database column in a SQL statement. Used wehere you need to refer to a column, except for SELECT output columns (Which wraps Column in an OutputColumn to allow for an expression).

CONSTRUCTORS

$col = Column->new();

$col = Column->new(column => $column_name, [alias => 'col_alias']);

$col = Column->new(column => $column_name, table => $table, [alias => 'col_alias']);

Makes a new Column object.

In the first form, the column's identity is undetermined. You must call $col->column() before trying to render the SQL.

In the second and third forms, the columns name is provided. Optionally provide an alias for the column, which will be used in output and order_by roles. If the second form is used, attempts will be made to disambiguate the column by looking for matching tables as the SQL statement is built.

In the third form, a reference to a Table object is provided, fully determining the column's identity.

ACCESSORS AND MUTATORS

$col_alias_name = $col->alias();

$col->alias($col_alias_name);

Reads or sets the column alias.

@empty = $col->child_expressions();

Always returns an empty list. Required by the Expression interface.

$col_name = $col->column();

$col->column($col_name);

Reads or sets the case-insensitve column name.

$bool = $arg->is_column();

All objects of this class return true. The class adds this method to its parent class, making all other subclasses of return false.

$bool = $col->is_leaf_expression();

Always returns true for this class. Required by the Expression interface.

$value = $col->output_value();

$col->output_value($value);

Reads or sets the output value of the column. This only makes sense if the column was used as an output column on a SQL query. An undef should interpreted as NULL.

$str = $col->pretty_print();

Renders a human-readable representation of the Column.

$table = $col->table();

$col->table($table);

Reads or sets the Table object that the Column belongs to. On set, the table is checked to confirm that the column named is indeed a column of that table.

$clone = $col->clone()

Copies the column, by deeply cloning the table, and then directly copying the alias and column name.

$bool = $param->is_equivalent($expr);

Returns true if $expr is a Column, with matching column name. Alias is IGNORED.

If both columns have Tables, then the table name (and schema, if present) are compared. The table aliases are IGNORED. If only one column has a Table, that difference is IGNORED.

AUTHOR

Clinton Wolfe