NAME
Class::ReluctantORM::SQL::SubQuery - Represent a sub-SELECT in a FROM or WHERE clause
SYNOPSIS
use Class::ReluctantORM::SQL::Aliases;
# Make a SELECT as usual
my $select = SQL->new('select');
$select->from(Table->new(table => 'mytable');
$select->where(Criterion->new('=', 1,1));
# Make a subquery
my $subquery = SubQuery->new($select);
# Use it as an expression
my $in_crit = Criterion->new(
'IN',
'needle',
$subquery, # haystack
);
# Or use it as a JOIN relation
# TODO DOCS
DESCRIPTION
Wrapper around a SELECT statement, that implements both the Expression interface as well as the Relation interface, allowing it to be used in a WHERE clause or FROM clause.
CONSTRUCTOR
$sq = SubQuery->new($select);
Creates a new SubQuery containing the SQL object given by $select. The SQL object's operation must be 'SELECT'.
ACCESSORS
$sql = $sq->statement();
$sq->statement($sql);
Sets or reads the underlying SQL object.
$bool = $sq->is_subquery();
All objects of this class return true. The class adds this method to both Expression and Relation, making all other subclasses of them return false.
$sq->alias('my_alias');
$alias = $sq->alias();
From Relation interface.
Reads or sets the alias used for this relation in FROM clauses.
$str = $sq->pretty_print();
From both Expression and Relation interfaces.
Renders a human-readable version of the relation to a string.
@cols = $sq->columns()
Returns a list of re-aliased columns returned by the subquery. This presents the externally visible set of columns.
From Relation interface.
$bool = $sq->has_column('col_name')
Returns a boolean indicating whether a column is present in the external columns returned. The name will be the re-aliased name.
From Relation interface.
$bool = $sq->knows_all_columns()
Returns a boolean indicating whether all output columns are known in advance from this relation. Always returns true for SubQueries.
From Relation interface.
$bool = $sq->knows_any_columns()
Returns a boolean indicating whether any output columns are known in advance from this relation. Always returns true.
From Relation interface.
@tables = $sq->tables(%opts);
Returns a list of all tables referenced in the FROM clause of the subquery.
From the Relation interface.
If the exclude_subqueries option is enabled, this returns an empty list.
@rels = $sq->child_relations();
Always returns an empty list. If you want to access the relations in the subquery, use $sq->statement->from->child_relations().
From the Relation interface.
$bool = $sq->is_leaf_relation();
Indicates if the object is a terminal point on the From tree. Always returns true.
From the Relation interface.
$rel = $sq->parent_relation();
Returns the parent node of the object. If undefined, this is the root node.
From the Relation interface.
$bool = $sq->is_leaf_expression();
Indicates if the object is a terminal point on the Expression tree. Always returns true.
@exps = $sq->child_expressions();
Always returns an empty list.
$exp = $sq->parent_expression();
Returns the parent node of the expression. If undefined, this is the root node.
$clone = $sq->clone()
Creates a new SubQuery whose statement is a clone of the original's statement.
AUTHOR
Clinton Wolfe January 2010