Dave Rolsky > Fey-0.40 > Fey::SQL::Select

Download:
Fey-0.40.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  3
Open  2
View/Report Bugs
Module Version: 0.40   Source  

NAME ^

Fey::SQL::Select - Represents a SELECT query

VERSION ^

version 0.40

SYNOPSIS ^

  my $sql = Fey::SQL->new_select();

  # SELECT Part.part_id, Part.part_name
  #   FROM Part JOIN MachinePart
  #        ON Part.part_id = MachinePart.part_id
  #  WHERE MachinePart.machine_id = $value
  # ORDER BY Part.name DESC
  # LIMIT 10
  $sql->select( $part_id, $part_name );
  $sql->from( $Part, $MachinePart );
  $sql->where( $machine_id, '=', $value );
  $sql->order_by( $part_Name, 'DESC' );
  $sql->limit(10);

  print $sql->sql($dbh);

DESCRIPTION ^

This class represents a SELECT query.

METHODS ^

This class provides the following methods:

Constructor

To construct an object of this class, call $query->select() on a Fey::SQL object.

$select->select(...)

This method accepts a list of parameters, which are the things being selected.

The list can include the following types of elements:

$select->distinct()

If this is called, the generated SQL will start with SELECT DISTINCT. You cannot call both $select->distinct() and $select->distinct_on() for the same query.

$select->distinct_on($column)

If this is called, the generated SQL will start with SELECT DISTINCT ON (Table.column). You cannot call both $select->distinct() and $select->distinct_on() for the same query.

$select->from(...)

This method specifies the FROM clause of the query. It can accept a variety of argument lists.

The $select->from() method can be called multiple times with different join options. If you call the method with arguments that it has already seen, then it will effectively ignore that call.

$select->where(...)

See the Fey::SQL section on WHERE Clauses for more details.

$select->group_by(...)

This method accepts a list of elements. Each element can be a Fey::Column object, a column alias, or a literal function or term.

$select->having(...)

The $select->having() method accepts exactly the same arguments as the $select->where() method.

$select->order_by(...)

See the Fey::SQL section on ORDER BY Clauses for more details.

$select->limit(...)

See the Fey::SQL section on LIMIT Clauses for more details.

$select->sql($dbh)

Returns the full SQL statement which this object represents. A DBI handle must be passed so that identifiers can be properly quoted.

$select->bind_params()

See the Fey::SQL section on Bind Parameters for more details.

$select->select_clause_elements

Returns a list of objects, one for each element in the SELECT clause. These can be Fey::Columns, Fey::Column::Aliases, or any type of Fey::Literal.

These items are returned in the order in which they will be included in the SELECT clause.

$select->select_clause()

Returns the SELECT clause portion of the SQL statement as a string.

$select->from_clause()

Returns the FROM clause portion of the SQL statement as a string.

$select->where_clause()

Returns the WHERE clause portion of the SQL statement as a string.

$select->order_by_clause()

Returns the ORDER BY clause portion of the SQL statement as a string.

$select->group_by_clause()

Returns the GROUP BY clause portion of the SQL statement as a string.

$select->having_clause()

Returns the HAVING clause portion of the SQL statement as a string.

$select->limit_clause()

Returns the LIMIT clause portion of the SQL statement as a string.

$select->sql_or_alias()

$select->sql_with_alias()

Returns the appropriate SQL snippet. See Fey::Role::HasAliasName.

$select->id()

Returns a unique identifier for the select.

ROLES ^

BUGS ^

See Fey for details on how to report bugs.

AUTHOR ^

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE ^

This software is Copyright (c) 2011 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)
syntax highlighting: