The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Class::ReluctantORM::SQL::OutputColumn - Represent an Output Column from a SQL statment

SYNOPSIS

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

  # You get OutputColumns back from statements:
  my @ocs = $sql->output_columns();

  # You can make them implicitly
  my $oc = $sql->add_output(Column->new(column => 'foo'));
  my $oc = $sql->add_output($expression);

  # Or explcitly
  my $oc = OutputColumn->new($column);
  my $oc = OutputColumn->new($expression);
  $sql->add_output($oc);

  # Set/read column alias
  my $alias = $oc->alias();
  $oc->alias($new_alias);

  # Set/read PK flag (needed by some drivers)
  $oc->is_primary_key(1);

  # Get expression - the "payload" of the output
  # (usually just a Column)
  my $exp = $oc->expression();

  # TODO DOCS - aggregate support

  # Fetching results
  my $result = $oc->output_value();

  # Used in driver code when reading from a fetch
  $oc->output_value($value);

DESCRIPTION

Represents an output "column" in a SELECT SQL statement (or an UPDATE or INSERT when used with RETURNING). Contains the column or expression that is the source of the data, any column alias, and provides access to the column value.

CONSTRUCTORS

$col = OutputColumn->new($column);

$col = OutputColumn->new($expression);

$col = OutputColumn->new(expression => $expression, alias => $alias, is_primary_key => 0, ...);

Makes a new OutputColumn object.

In the first form, creates an OutputColumn sourced on the given Column.

In the first form, creates an OutputColumn sourced on the given Expression. Since a Column is a subclass of Expression, forms one and two are actually the same.

In the third form, the expression, column alias, and primary key flag are provided explicitly. Alias and primary key flag are optional.

In the first and second forms, a column alias will be generated at render time if one is not assigned before then.

ACCESSORS AND MUTATORS

$col_alias_name = $oc->alias();

$oc->alias($col_alias_name);

Reads or sets the column alias.

$exp = $oc->expression();

$oc->expression($expression);

Reads or sets the Expression that acts as the source for the data. $expression is commonly a simple Column.

$value = $oc->output_value();

$oc->output_value($value);

Reads or sets the output value of the column. An undef should interpreted as NULL.

$bool = $oc->is_primary_key();

$oc->is_primary_key($bool);

Reads or sets the primary key flag for the output column. Set to true if the column is a member of the primary key on the base table. Some drivers - those that don't support RETURNING clauses - require this to determine whether to do a second fetch to populate primary kyes ine memory.

$str = $oc->pretty_print();

Renders a human-readable representation of the OutputColumn.

$clone = $oc->clone()

Copies the output column, by deeply cloning the expression, and then directly copying the alias, is_primary_key flag, and output_value, if any.

AUTHOR

Clinton Wolfe