Class As_SelectQuery

Description

A simple SQL query object for SELECT statements.

Usage of this class in Cough allows for sharing base SQL so that less SQL code is copied and pasted amongst classes.

For example, if there is a Product object which has complicated SELECT SQL that joins into other tables, pulls extra data in the SELECT clause, includes a GROUP BY, and has default WHERE criteria like "is_retired = 0", then by using this you don't have to copy all those common parts into the all the collection static methods. Instead, they can share the base SQL and just add what they need. For example, to pull a single product one might do:

  1.      $sql Product::getLoadSql();
  2.      $sql->addWhere(array('product_id' => $productId));
  3.      echo $sql;

Another example might be pulling all products that have the same manufacturer ID:

  1.      Product_Collection::getProductsByManufacturer($manufId{
  2.          $sql Product::getLoadSql();
  3.          $sql->addWhere(array('manufacturer_id' => $manufId));
  4.          $collection new Product_Collection();
  5.          $collection->loadBySql($sql);
  6.          return $collection;
  7.      }

  • author: Anthony Bush

Located in /as_query/As_SelectQuery.class.php (line 37)

As_Query
   |
   --As_SelectQuery
Variable Summary
mixed $from
mixed $groupBy
mixed $having
mixed $limit
mixed $offset
mixed $orderBy
mixed $select
mixed $where
Method Summary
void addFrom ( $from)
void addGroupBy ( $groupBy)
void addHaving ( $having)
void addOrderBy ( $orderBy)
void addSelect ( $select)
void addSelectOption (string $selectOption)
void addWhere ( $where)
void getFrom ()
void getGroupBy ()
void getHaving ()
void getLimit ()
void getOffset ()
void getOrderBy ()
void getSelect ()
void getString ()
void getWhere ()
void setFrom ( $from)
void setGroupBy ( $groupBy)
void setHaving ( $having)
void setLimit ( $limit)
void setOffset ( $offset)
void setOrderBy ( $orderBy)
void setSelect ( $select)
void setWhere ( $where)
Variables
mixed $from = array() (line 41)
  • access: protected
mixed $groupBy = array() (line 43)
  • access: protected
mixed $having = array() (line 44)
  • access: protected
mixed $limit = '' (line 46)
  • access: protected
mixed $offset = '' (line 47)
  • access: protected
mixed $orderBy = array() (line 45)
  • access: protected
mixed $select = array() (line 39)
  • access: protected
mixed $selectOptions = array() (line 40)
  • access: protected
mixed $where = array() (line 42)
  • access: protected

Inherited Variables

Inherited from As_Query

As_Query::$db
Methods
addFrom (line 124)
  • access: public
void addFrom ( $from)
  • $from
addGroupBy (line 144)
  • access: public
void addGroupBy ( $groupBy)
  • $groupBy
addHaving (line 154)
  • access: public
void addHaving ( $having)
  • $having
addOrderBy (line 164)
  • access: public
void addOrderBy ( $orderBy)
  • $orderBy
addSelect (line 103)
  • access: public
void addSelect ( $select)
  • $select
addSelectOption (line 114)

Add optional select options, e.g. SQL_CALC_FOUND_ROWS, SQL_NO_CACHE

  • access: public
void addSelectOption (string $selectOption)
  • string $selectOption
addWhere (line 134)
  • access: public
void addWhere ( $where)
  • $where
getClone (line 288)

Hack for versions of PHP that do not work with clone

  • author: Anthony Bush
  • since: 2008-03-17
  • access: public
As_SelectQuery getClone ()
getFrom (line 61)
  • access: public
void getFrom ()
getGroupBy (line 71)
  • access: public
void getGroupBy ()
getHaving (line 76)
  • access: public
void getHaving ()
getLimit (line 86)
  • access: public
void getLimit ()
getOffset (line 91)
  • access: public
void getOffset ()
getOrderBy (line 81)
  • access: public
void getOrderBy ()
getSelect (line 51)
  • access: public
void getSelect ()
getSelectOptions (line 56)
  • access: public
void getSelectOptions ()
getString (line 179)
  • access: public
void getString ()

Redefinition of:
As_Query::getString()
getWhere (line 66)
  • access: public
void getWhere ()
setFrom (line 119)
  • access: public
void setFrom ( $from)
  • $from
setGroupBy (line 139)
  • access: public
void setGroupBy ( $groupBy)
  • $groupBy
setHaving (line 149)
  • access: public
void setHaving ( $having)
  • $having
setLimit (line 169)
  • access: public
void setLimit ( $limit)
  • $limit
setOffset (line 174)
  • access: public
void setOffset ( $offset)
  • $offset
setOrderBy (line 159)
  • access: public
void setOrderBy ( $orderBy)
  • $orderBy
setSelect (line 98)
  • access: public
void setSelect ( $select)
  • $select
setWhere (line 129)
  • access: public
void setWhere ( $where)
  • $where

Inherited Methods

Inherited From As_Query

As_Query::__construct()
As_Query::add()
As_Query::buildWhereSql()
As_Query::execute()
As_Query::getEqualityOperatorFromValue()
As_Query::getInsertQuery()
As_Query::getSelectQuery()
As_Query::getString()
As_Query::getUpdateQuery()
As_Query::remapCriteria()
As_Query::run()
As_Query::setDb()
As_Query::__toString()

Documentation generated on Fri, 19 Dec 2008 11:03:45 -0600 by phpDocumentor 1.4.0