Class SelectQuery

Description

Implements interfaces:

A SelectQuery class provides the tools to build a SELECT query.

Located in /harmoni/core/DBHandler/SelectQuery.class.php (line 27)

SObject
   |
   --QueryAbstract
      |
      --SelectQuery
Variable Summary
array $_columns
array $_condition
boolean $_distinct
array $_groupBy
array $_having
integer $_numberOfRows
array $_orderBy
integer $_startFromRow
string $_tables
Method Summary
SelectQuery SelectQuery ()
void addColumn (string $column, [optional $alias = ""], [optional $table = ""])
void addOrderBy (string $column, [integer $direction = ASCENDING])
void addTable (string $table, [integer $joinType = NO_JOIN], [string $joinCondition = ""], [string $alias = ""])
void addWhere (string $condition, [integer $logicalOperation = _AND])
void limitNumberOfRows (integer $numberOfRows)
void reset ()
void resetWhere ()
void setColumns (mixed $columns, array $column)
void setDistinct (boolean $distinct)
void setGroupBy (array $columns, [string $condition = ""])
void setWhere (string $condition)
void startFromRow (mixed $startFromRow, integer $startingRow)
Variables
array $_columns (line 55)

The list of columns we will be selecting.

The list of columns we will be selecting. This is an array of arrays. Each element in the outer array specifies one column. The first element of each inner array is the column name itself. The second element is the alias of that column and is optional. The third and last element is the name of the table where the column resides.

  • var: The list of columns we will be selecting.
  • access: private
array $_condition (line 65)

This will store the condition in the WHERE clause. Each element of this array stores 2 things: the condition itself, and the logical operator to use to join with the previous condition.

  • var: The condition in the WHERE clause.
  • access: private
boolean $_distinct (line 106)

Specifies whether distinct rows will be returned or not.

Specifies whether distinct rows will be returned or not. If TRUE, only unique rows will be returned by the query.

  • var: If true, then only unique rows will be returned.
array $_groupBy (line 74)

Will store the columns in the GROUP BY clause.

Will store the columns in the GROUP BY clause.

  • var: The columns in the GROUP BY clause.
array $_having (line 83)

Will store the condition in the HAVING clause.

Will store the condition in the HAVING clause.

  • var: The condition in the HAVING clause.
integer $_numberOfRows (line 114)

Stores the number of rows to return.

Stores the number of rows to return.

  • var: The number of rows to return.
array $_orderBy (line 96)

Will store the columns in the ORDER BY clause.

Will store the columns in the OREDER BY clause. This is an array of arrays. Each element in the outer arrays stores one entry in the ORDER BY clause. Each inner array holds two elements. The first one is the name of the column to order by. The second one specifies whether it is a ASCENDING or DESCENDING order.

  • var: The columns in the ORDER BY clause.
integer $_startFromRow (line 122)

Stores the number of the row to start from.

Stores the number of the row to start from.

  • var: The number of the row to start from.
string $_tables (line 42)

This array stores the tables in the FROM clause of the SELECT query.

This array stores the tables in the FROM clause of the SELECT query along with the join types, join conditions, and table alias.

Inherited Variables

Inherited from QueryAbstract

QueryAbstract::$_type
Methods
Constructor SelectQuery (line 131)

The constructor initializes the query object.

The constructor initializes the query object.

  • access: public
SelectQuery SelectQuery ()
addColumn (line 218)

Adds a new column to the SELECT query.

Adds a new column to the SELECT query. This method is an alternative to the setColumns() method. It adds one column at a time, and also provides the ability to explicitly specify the alias of the column to select. Note: addColumn() and setColumns() can be used together in any order. However, calling setColumns() after addColumn() resets the list of columns.

void addColumn (string $column, [optional $alias = ""], [optional $table = ""])
  • string $column: The name of the column.
  • optional $alias: string $alias The alias of the column.
  • optional $table: string $table An optional name of the table where the column resides. will be used.
addOrderBy (line 342)

Add a column to the ORDER BY clause.

This method adds a column to the ORDER BY clause of the SELECT statement. If the method is never called, no ORDER BY clause will be included. The order of the columns in the clause will coincide with the order, in which they were added with this method.

  • access: public
void addOrderBy (string $column, [integer $direction = ASCENDING])
  • string $column: A column to order by.
  • integer $direction: An optional parameter specifying ascending or descending sorting order. Allowed values are: ASCENDING, DESCENDING.
addTable (line 155)

Adds a table to the FROM clause of the SELECT query.

Adds a table to the FROM clause of the SELECT statement. At any moment, a current set of tables is maintained in the object, so when a new one is added, it is combined with the current set.

  • access: public
void addTable (string $table, [integer $joinType = NO_JOIN], [string $joinCondition = ""], [string $alias = ""])
  • string $table: The table to add to the FROM clause.
  • integer $joinType: Specifies what type of join to perform between the current set of tables and the table being added. Could be one of the following: NO_JOIN, LEFT_JOIN, INNER_JOIN, RIGHT_JOIN.
  • string $joinCondition: If a join is to be performed, then this will indicate the join condition.
  • string $alias: alias An alias for this table.
addWhere (line 274)

Adds a new condition in the WHERE clause.

The query will return only rows that fulfil the condition. If this method is never called, then the WHERE clause will not be included.

  • access: public
void addWhere (string $condition, [integer $logicalOperation = _AND])
  • string $condition: condition The WHERE clause condition to add.
  • integer $logicalOperation: logicalOperation The logical operation to use to connect this WHERE condition with the previous WHERE conditions. Allowed values:
    1. _AND
    and
    1. _OR
    .
limitNumberOfRows (line 383)

Limits the number of rows to the specified number.

Limits the number of rows returned by the SELECT query to the specified number.

  • access: public
void limitNumberOfRows (integer $numberOfRows)
  • integer $numberOfRows: The number of rows to return
reset (line 415)

Resets the query.

  • access: public
void reset ()

Redefinition of:
QueryAbstract::reset()
Resets the query.
resetWhere (line 296)

Resets the WHERE clause.

  • access: public
void resetWhere ()
setColumns (line 183)

*Deprecated* Sets the columns to select.

Sets the columns to select. Note: addColumn() and setColumns() can be used together in any order. However, calling setColumns() after addColumn() resets the list of columns.

void setColumns (mixed $columns, array $column)
  • array $column: The columns to select. This is a one-dimensional array of the column names. If you want aliases you have to include the alias in the column name itself. For example: array("user_id AS id", "user_name AS name") For a better approach, see addColumn().
setDistinct (line 363)

Specifies whether distinct rows will be returned.

Use this method to specify whether the rows returned by the SELECT query have to be distinct (i.e. only unique rows) or not. If the method is never called, then the default value is not distinct.

  • access: public
void setDistinct (boolean $distinct)
  • boolean $distinct: If true, then only unique rows will be returned.
setGroupBy (line 315)

Sets the GROUP BY and HAVING clause.

This method sets the GROUP BY clause of the SELECT statement. In addition, if $condition is specified, it includes the HAVING clause. If the method is never called, no GROUP BY or HAVING clause will be included.

  • access: public
void setGroupBy (array $columns, [string $condition = ""])
  • array $columns: An array of the columns to group by. Ideally, the columns should be in the list provided by setColumns().
  • string $condition: An optional condition to be included in the HAVING clause.
setWhere (line 246)

*Deprecated* Specifies the condition in the WHERE clause.

The query will return only rows that fulfil the condition. If this method is never called, then the WHERE clause will not be included.

  • access: public
  • deprecated: July 07, 2003 - Use addWhere() instead.
void setWhere (string $condition)
  • string $condition: condition The WHERE clause condition.
startFromRow (line 402)

Starts the results from the specified row.

Starts the results of the SELECT query from the specified row.

  • access: public
void startFromRow (mixed $startFromRow, integer $startingRow)
  • integer $startingRow: The number of the starting row. Numbers start with 1 for the first row, 2 for the second row, and so forth.

Inherited Methods

Inherited From QueryAbstract

QueryAbstract::addWhereComparison()
QueryAbstract::addWhereEqual()
QueryAbstract::addWhereGreaterThan()
QueryAbstract::addWhereGreaterThanOrEqual()
QueryAbstract::addWhereIn()
QueryAbstract::addWhereLessThan()
QueryAbstract::addWhereLessThanOrEqual()
QueryAbstract::addWhereNotEqual()
QueryAbstract::addWhereNotIn()
QueryAbstract::addWhereNotNull()
QueryAbstract::addWhereNull()
QueryAbstract::addWhereRawComparison()
QueryAbstract::addWhereRawEqual()
QueryAbstract::addWhereRawGreaterThan()
QueryAbstract::addWhereRawGreaterThanOrEqual()
QueryAbstract::addWhereRawIn()
QueryAbstract::addWhereRawLessThan()
QueryAbstract::addWhereRawLessThanOrEqual()
QueryAbstract::addWhereRawNotEqual()
QueryAbstract::addWhereRawNotIn()
QueryAbstract::asString()
QueryAbstract::cleanColumn()
QueryAbstract::getType()
QueryAbstract::reset()

Inherited From SObject

SObject::asA()
SObject::asString()
SObject::copy()
SObject::copySameFrom()
SObject::copyTwoLevel()
SObject::deepCopy()
SObject::isEqual()
SObject::isEqualTo()
SObject::isNotEqualTo()
SObject::isNotReferenceTo()
SObject::isReferenceTo()
SObject::newFrom()
SObject::postCopy()
SObject::printableString()
SObject::shallowCopy()
SObject::_deepCopyArray()

Documentation generated on Wed, 19 Sep 2007 10:26:22 -0400 by phpDocumentor 1.3.0RC3