Class: Doctrine_Query

Source Location: /Doctrine/Query.php

Class Doctrine_Query

Class Overview
Inherited Properties, Constants, and Methods
Inherited Properties Inherited Methods Inherited Constants

Inherited From Doctrine_Hydrate

Doctrine_Hydrate::$aggregateMap
Doctrine_Hydrate::$parts
Doctrine_Hydrate::$pendingAggregates
Doctrine_Hydrate::$type
Doctrine_Hydrate::$_aliasMap
Doctrine_Hydrate::$_cache
Doctrine_Hydrate::$_conn
Doctrine_Hydrate::$_expireCache
Doctrine_Hydrate::$_hydrationMode
Doctrine_Hydrate::$_options
Doctrine_Hydrate::$_params
Doctrine_Hydrate::$_sql
Doctrine_Hydrate::$_tableAliases
Doctrine_Hydrate::$_tableAliasSeeds
Doctrine_Hydrate::$_timeToLive
Doctrine_Hydrate::$_view

Inherited From Doctrine_Object

Doctrine_Object::$_null

Inherited From Doctrine_Query_Abstract

Doctrine_Query_Abstract::addFrom()
addFrom adds fields to the FROM part of the query
Doctrine_Query_Abstract::addGroupBy()
addGroupBy adds fields to the GROUP BY part of the query
Doctrine_Query_Abstract::addHaving()
addHaving adds conditions to the HAVING part of the query
Doctrine_Query_Abstract::addOrderBy()
addOrderBy adds fields to the ORDER BY part of the query
Doctrine_Query_Abstract::addSelect()
addSelect adds fields to the SELECT part of the query
Doctrine_Query_Abstract::addWhere()
addWhere adds conditions to the WHERE part of the query
Doctrine_Query_Abstract::delete()
delete sets the query type to DELETE
Doctrine_Query_Abstract::distinct()
distinct Makes the query SELECT DISTINCT.
Doctrine_Query_Abstract::forUpdate()
forUpdate Makes the query SELECT FOR UPDATE.
Doctrine_Query_Abstract::from()
from sets the FROM part of the query
Doctrine_Query_Abstract::groupBy()
groupBy sets the GROUP BY part of the query
Doctrine_Query_Abstract::having()
having sets the HAVING part of the query
Doctrine_Query_Abstract::innerJoin()
innerJoin appends an INNER JOIN to the FROM part of the query
Doctrine_Query_Abstract::leftJoin()
leftJoin appends a LEFT JOIN to the FROM part of the query
Doctrine_Query_Abstract::limit()
limit sets the Query query limit
Doctrine_Query_Abstract::offset()
offset sets the Query query offset
Doctrine_Query_Abstract::orderBy()
orderBy sets the ORDER BY part of the query
Doctrine_Query_Abstract::parseQueryPart()
parseQueryPart parses given DQL query part
Doctrine_Query_Abstract::select()
select sets the SELECT part of the query
Doctrine_Query_Abstract::set()
set sets the SET part of the query
Doctrine_Query_Abstract::update()
update sets the UPDATE part of the query
Doctrine_Query_Abstract::where()
where sets the WHERE part of the query
Doctrine_Query_Abstract::whereIn()
whereIn adds IN condition to the query WHERE part

Inherited From Doctrine_Hydrate

Doctrine_Hydrate::__construct()
constructor
Doctrine_Hydrate::addQueryPart()
addQueryPart adds a query part in the query part array
Doctrine_Hydrate::addTableAlias()
addTableAlias adds an alias for table and associates it with given component alias
Doctrine_Hydrate::applyInheritance()
applyInheritance applies column aggregation inheritance to DQL / SQL query
Doctrine_Hydrate::clear()
clear resets all the variables
Doctrine_Hydrate::convertEnums()
Doctrine_Hydrate::copyAliases()
copyAliases copy aliases from another Hydrate object
Doctrine_Hydrate::createSubquery()
createSubquery creates a subquery
Doctrine_Hydrate::execute()
execute executes the query and populates the data set
Doctrine_Hydrate::expireCache()
expireCache
Doctrine_Hydrate::fetchArray()
fetchArray Convenience method to execute using array fetching as hydration mode.
Doctrine_Hydrate::fetchOne()
fetchOne Convenience method to execute the query and return the first item of the collection.
Doctrine_Hydrate::generateNewTableAlias()
generateNewTableAlias generates a new alias from given table alias
Doctrine_Hydrate::generateTableAlias()
generateTableAlias generates a table alias from given table name and associates it with given component alias
Doctrine_Hydrate::getAliasDeclaration()
getAliasDeclaration get the declaration for given component alias
Doctrine_Hydrate::getAliasMap()
getAliasMap returns the component alias map
Doctrine_Hydrate::getCachedForm()
getCachedForm returns the cached form of this query for given resultSet
Doctrine_Hydrate::getCacheDriver()
getCacheDriver returns the cache driver associated with this object
Doctrine_Hydrate::getComponentAlias()
getComponentAlias get component alias associated with given table alias
Doctrine_Hydrate::getConnection()
getConnection
Doctrine_Hydrate::getParams()
getParams
Doctrine_Hydrate::getQueryPart()
setQueryPart sets a query part in the query part array
Doctrine_Hydrate::getRoot()
getRoot returns the root component for this object
Doctrine_Hydrate::getRootAlias()
getRootAlias returns the alias of the the root component
Doctrine_Hydrate::getRootDeclaration()
getRootDeclaration returns the root declaration
Doctrine_Hydrate::getSql()
getSql return the sql associated with this object
Doctrine_Hydrate::getTableAlias()
getTableAlias some database such as Oracle need the identifier lengths to be < ~30 chars hence Doctrine creates as short identifier aliases as possible
Doctrine_Hydrate::getTableAliases()
getTableAliases returns all table aliases
Doctrine_Hydrate::getTableAliasSeed()
getTableAliasSeed returns the alias seed for given table alias
Doctrine_Hydrate::getType()
getType
Doctrine_Hydrate::getView()
getView returns the view associated with this query object (if any)
Doctrine_Hydrate::hasAliasDeclaration()
hasAliasDeclaration whether or not this object has a declaration for given component alias
Doctrine_Hydrate::hasTableAlias()
hasTableAlias whether or not this object has given tableAlias
Doctrine_Hydrate::isLimitSubqueryUsed()
limitSubqueryUsed whether or not limit subquery was used
Doctrine_Hydrate::parseData2()
parseData parses the data returned by statement object
Doctrine_Hydrate::removeQueryPart()
removeQueryPart removes a query part from the query part array
Doctrine_Hydrate::serialize()
serialize this method is automatically called when this Doctrine_Hydrate is serialized
Doctrine_Hydrate::setAliasMap()
setAliasMap sets the whole component alias map
Doctrine_Hydrate::setCacheLifeSpan()
setCacheLifeSpan
Doctrine_Hydrate::setHydrationMode()
Sets the fetchmode.
Doctrine_Hydrate::setParams()
setParams
Doctrine_Hydrate::setQueryPart()
setQueryPart sets a query part in the query part array
Doctrine_Hydrate::setView()
setView sets a database view this query object uses this method should only be called internally by doctrine
Doctrine_Hydrate::unserialize()
unseralize this method is automatically called everytime a Doctrine_Hydrate object is unserialized
Doctrine_Hydrate::useCache()
useCache
Doctrine_Hydrate::_execute()
Doctrine_Hydrate::_setLastElement()
_setLastElement
Doctrine_Hydrate::__toString()

Inherited From Doctrine_Object

Doctrine_Object::getNullObject()
getNullObject returns the null object associated with this object
Doctrine_Object::initNullObject()
initNullObject initializes the null object

Inherited From Doctrine_Hydrate

Doctrine_Hydrate::CREATE
Doctrine_Hydrate::DELETE
Doctrine_Hydrate::HYDRATE_ARRAY
Doctrine_Hydrate::HYDRATE_RECORD
Doctrine_Hydrate::INSERT
Doctrine_Hydrate::SELECT
Doctrine_Hydrate::UPDATE

[ Top ]
Constant Summary
Property Summary
mixed   $isLimitSubqueryUsed  
mixed   $isSubquery  
mixed   $needsSubquery  
array   $pendingFields  
array   $pendingSubqueries  
mixed   $subqueryAliases  
array   $_dqlParts  
array   $_enumParams  
mixed   $_expressionMap  
array   $_neededTables  
array   $_parsers  
array   $_pendingJoinConditions  
mixed   $_state  

[ Top ]
Method Summary
static Doctrine_Query   create()   create returns a new Doctrine_Query object
Doctrine_Query   addEnumParam()   addEnumParam sets input parameter as an enumerated parameter
Doctrine_Query   addPendingJoinCondition()   addPendingJoinCondition
string   buildFromPart()   buildFromPart builds the from part of the query and returns it
array   convertEnums()   convertEnums convert enum parameters to their integer equivalents
void   copy()  
integer   count()   count fetches the count of the query
Doctrine_Query   free()   Frees the resources used by the query object. It especially breaks a cyclic reference between the query object and it's parsers. This enables PHP's current GC to reclaim the memory.
string   getAggregateAlias()   getAggregateAlias
string   getDql()   getDql returns the DQL query associated with this object
string   getDqlPart()   getDqlPart returns the given DQL query part
array   getEnumParams()   getEnumParams get all enumerated parameters
string   getLimitSubquery()   getLimitSubquery this is method is used by the record limit algorithm
Doctrine_Query_Part   getParser()   getParser parser lazy-loader
string   getQuery()   builds the sql query from the given parameters and applies things such as column aggregation inheritance and limit subqueries if needed
string   getQueryBase()   getQueryBase returns the base of the generated sql query On mysql driver special strategy has to be used for DELETE statements
boolean   isLimitSubqueryUsed()   limitSubqueryUsed
Doctrine_Query|bool   isSubquery()   isSubquery
void   load()  
void   loadRoot()   loadRoot
array   parseAggregateFunction()   parseAggregateFunction parses an aggregate function and returns the parsed form
string   parseClause()   parseClause parses given DQL clause
Doctrine_Query   parseQuery()   DQL PARSER
Doctrine_Query   parseQueryPart()   parseQueryPart parses given DQL query part
void   parseSelect()   parseSelect parses the query select part and adds selected fields to pendingFields array
void   parseSubselect()   parseSubselect
void   postQuery()   postQuery
void   preQuery()   preQuery
void   processPendingAggregates()   processPendingAggregates processes pending aggregate values for given component alias
void   processPendingFields()   processPendingFields the fields in SELECT clause cannot be parsed until the components in FROM clause are parsed, hence this method is called everytime a specific component is being parsed.
void   processPendingSubqueries()   processPendingSubqueries processes pending subqueries
mixed   query()   query query the database with DQL (Doctrine Query Language)
void   reset()  
Doctrine_Query   setOption()   setOption
array   tokenizeQuery()   tokenizeQuery

[ Top ]
Properties
mixed   $isLimitSubqueryUsed = false [line 55]
API Tags:
Access:  protected


[ Top ]
mixed   $isSubquery [line 53]
API Tags:
Access:  protected


[ Top ]
mixed   $needsSubquery = false [line 48]
API Tags:
Access:  protected


[ Top ]
array   $pendingFields = array() [line 63]
API Tags:
Access:  protected


[ Top ]
array   $pendingSubqueries = array() [line 68]
API Tags:
Access:  protected


[ Top ]
mixed   $subqueryAliases = array() [line 44]
API Tags:
Access:  protected


[ Top ]
array   $_dqlParts = array(
'select' => array(),'forUpdate'=>false,'from'=>array(),'set'=>array(),'join'=>array(),'where'=>array(),'groupby'=>array(),'having'=>array(),'orderby'=>array(),'limit'=>array(),'offset'=>array(),)
[line 81]
API Tags:
Access:  protected


[ Top ]
array   $_enumParams = array() [line 76]
API Tags:
Access:  protected


[ Top ]
mixed   $_expressionMap = array() [line 99]
API Tags:
Access:  protected


[ Top ]
array   $_neededTables = array() [line 59]
API Tags:
Access:  protected


[ Top ]
array   $_parsers = array() [line 72]
API Tags:
Access:  protected


[ Top ]
array   $_pendingJoinConditions = array() [line 97]
API Tags:
Access:  protected


[ Top ]
mixed   $_state = Doctrine_Query::STATE_CLEAN [line 101]
API Tags:
Access:  protected


[ Top ]
Methods
static method create  [line 110]

  static Doctrine_Query create( [Doctrine_Connection $conn = null]  )

create returns a new Doctrine_Query object

Parameters:
Doctrine_Connection   $conn:  optional connection parameter

API Tags:
Access:  public


[ Top ]
addEnumParam  [line 157]

  Doctrine_Query addEnumParam( string $key, [ $table = null], [ $column = null]  )

addEnumParam sets input parameter as an enumerated parameter

Parameters:
string   $key:  the key of the input parameter
   $table: 
   $column: 

API Tags:
Access:  public


[ Top ]
addPendingJoinCondition  [line 146]

  Doctrine_Query addPendingJoinCondition( string $componentAlias, string $joinCondition  )

addPendingJoinCondition

Parameters:
string   $componentAlias:  component alias
string   $joinCondition:  dql join condition

API Tags:
Return:  this object
Access:  public


[ Top ]
buildFromPart  [line 744]

  string buildFromPart( )

buildFromPart builds the from part of the query and returns it


API Tags:
Return:  the query sql from part
Access:  public


[ Top ]
convertEnums  [line 192]

  array convertEnums( $params  )

convertEnums convert enum parameters to their integer equivalents

Parameters:
   $params: 

API Tags:
Return:  converted parameter array
Access:  public


Redefinition of:
Doctrine_Hydrate::convertEnums()

[ Top ]
copy  [line 1535]

  void copy( [Doctrine_Query $query = null]  )

Parameters:
Doctrine_Query   $query: 

API Tags:
Access:  public


[ Top ]
count  [line 1463]

  integer count( [array $params = array()]  )

count fetches the count of the query

This method executes the main query without all the selected fields, ORDER BY part, LIMIT part and OFFSET part.

Example: Main query: SELECT u.*, p.phonenumber FROM User u LEFT JOIN u.Phonenumber p WHERE p.phonenumber = '123 123' LIMIT 10

The modified DQL query: SELECT COUNT(DISTINCT u.id) FROM User u LEFT JOIN u.Phonenumber p WHERE p.phonenumber = '123 123'

Parameters:
array   $params:  an array of prepared statement parameters

API Tags:
Return:  the count of this query
Access:  public


Implementation of:
Countable::count

[ Top ]
free  [line 1557]

  Doctrine_Query free( )

Frees the resources used by the query object. It especially breaks a cyclic reference between the query object and it's parsers. This enables PHP's current GC to reclaim the memory.

This method can therefore be used to reduce memory usage when creating a lot of query objects during a request.


API Tags:
Return:  this object
Access:  public


[ Top ]
getAggregateAlias  [line 231]

  string getAggregateAlias( string $dqlAlias  )

getAggregateAlias

Parameters:
string   $dqlAlias:  the dql alias of an aggregate value

API Tags:
Access:  public


[ Top ]
getDql  [line 339]

  string getDql( )

getDql returns the DQL query associated with this object

the query is built from $_dqlParts


API Tags:
Return:  the DQL query
Access:  public


[ Top ]
getDqlPart  [line 323]

  string getDqlPart( string $queryPart  )

getDqlPart returns the given DQL query part

Parameters:
string   $queryPart:  the name of the query part

API Tags:
Return:  the DQL query part
Access:  public


[ Top ]
getEnumParams  [line 173]

  array getEnumParams( )

getEnumParams get all enumerated parameters


API Tags:
Return:  all enumerated parameters
Access:  public


[ Top ]
getLimitSubquery  [line 971]

  string getLimitSubquery( )

getLimitSubquery this is method is used by the record limit algorithm

when fetching one-to-many, many-to-many associated data with LIMIT clause an additional subquery is needed for limiting the number of returned records instead of limiting the number of sql result set rows


API Tags:
Return:  the limit subquery
Access:  public


[ Top ]
getParser  [line 253]

  Doctrine_Query_Part getParser( $name  )

getParser parser lazy-loader

Parameters:
   $name: 

API Tags:
Access:  public

Information Tags:
Throws:  Doctrine_Query_Exception if unknown parser name given

[ Top ]
getQuery  [line 822]

  string getQuery( [array $params = array()]  )

builds the sql query from the given parameters and applies things such as column aggregation inheritance and limit subqueries if needed

Parameters:
array   $params:  an array of prepared statement params (needed only in mysql driver when limit subquery algorithm is used)

API Tags:
Return:  the built sql query
Access:  public


[ Top ]
getQueryBase  [line 721]

  string getQueryBase( )

getQueryBase returns the base of the generated sql query On mysql driver special strategy has to be used for DELETE statements


API Tags:
Return:  the base of the generated sql query
Access:  public


[ Top ]
isLimitSubqueryUsed  [line 182]

  boolean isLimitSubqueryUsed( )

limitSubqueryUsed


API Tags:
Access:  public


Redefinition of:
Doctrine_Hydrate::isLimitSubqueryUsed()
limitSubqueryUsed whether or not limit subquery was used

[ Top ]
isSubquery  [line 216]

  Doctrine_Query|bool isSubquery( [boolean $bool = null]  )

isSubquery

if $bool parameter is set this method sets the value of Doctrine_Query::$isSubquery. If this value is set to true the query object will not load the primary key fields of the selected components.

If null is given as the first parameter this method retrieves the current value of Doctrine_Query::$isSubquery.

Parameters:
boolean   $bool:  whether or not this query acts as a subquery

API Tags:
Access:  public


[ Top ]
load  [line 1218]

  void load( $path, [ $loadFields = true]  )

Parameters:
   $path: 
   $loadFields: 

API Tags:
Access:  public


[ Top ]
loadRoot  [line 1418]

  void loadRoot( string $name, string $componentAlias  )

loadRoot

Parameters:
string   $name: 
string   $componentAlias: 

API Tags:
Access:  public


[ Top ]
parseAggregateFunction  [line 562]

  array parseAggregateFunction( string $expr, [ $nestedCall = false]  )

parseAggregateFunction parses an aggregate function and returns the parsed form

Parameters:
string   $expr:  DQL aggregate function
   $nestedCall: 

API Tags:
Return:  parsed form of given function
See:  Doctrine_Expression
Access:  public

Information Tags:
Throws:  Doctrine_Query_Exception if unknown aggregate function given

[ Top ]
parseClause  [line 473]

  string parseClause( $clause  )

parseClause parses given DQL clause

this method handles five tasks:

  1. Converts all DQL functions to their native SQL equivalents
  2. Converts all component references to their table alias equivalents
  3. Converts all column aliases to actual column names
  4. Quotes all identifiers
  5. Parses nested clauses and subqueries recursively

Parameters:
   $clause: 

API Tags:
Return:  SQL string
Access:  public


[ Top ]
parseQuery  [line 1165]

  Doctrine_Query parseQuery( string $query, [boolean $clear = true]  )

DQL PARSER

parses a DQL query first splits the query in parts and then uses individual parsers for each part

Parameters:
string   $query:  DQL query
boolean   $clear:  whether or not to clear the aliases

API Tags:
Access:  public

Information Tags:
Throws:  Doctrine_Query_Exception if some generic parsing error occurs

[ Top ]
parseQueryPart  [line 280]

  Doctrine_Query parseQueryPart( string $queryPartName, string $queryPart, [boolean $append = false]  )

parseQueryPart parses given DQL query part

Parameters:
string   $queryPartName:  the name of the query part
string   $queryPart:  query part to be parsed
boolean   $append:  whether or not to append the query part to its stack if false is given, this method will overwrite the given query part stack with $queryPart

API Tags:
Return:  this object
Access:  public


Redefinition of:
Doctrine_Query_Abstract::parseQueryPart()
parseQueryPart parses given DQL query part

[ Top ]
parseSelect  [line 400]

  void parseSelect( string $dql  )

parseSelect parses the query select part and adds selected fields to pendingFields array

Parameters:
string   $dql: 

API Tags:
Access:  public


[ Top ]
parseSubselect  [line 443]

  void parseSubselect( string $reference  )

parseSubselect

parses the subquery found in DQL SELECT part and adds the parsed form into $pendingSubqueries stack

Parameters:
string   $reference: 

API Tags:
Access:  public


[ Top ]
postQuery  [line 810]

  void postQuery( )

postQuery

Empty template method to provide Query subclasses with the possibility to hook into the query building procedure, doing any custom / specialized post query procedures (for example logging) that are neccessary.


API Tags:
Access:  public


[ Top ]
preQuery  [line 797]

  void preQuery( )

preQuery

Empty template method to provide Query subclasses with the possibility to hook into the query building procedure, doing any custom / specialized query building procedures that are neccessary.


API Tags:
Access:  public


[ Top ]
processPendingAggregates  [line 648]

  void processPendingAggregates( )

processPendingAggregates processes pending aggregate values for given component alias


API Tags:
Access:  public


[ Top ]
processPendingFields  [line 363]

  void processPendingFields( string $componentAlias  )

processPendingFields the fields in SELECT clause cannot be parsed until the components in FROM clause are parsed, hence this method is called everytime a specific component is being parsed.

Parameters:
string   $componentAlias:  the alias of the component

API Tags:
Access:  public

Information Tags:
Throws:  Doctrine_Query_Exception if unknown component alias has been given

[ Top ]
processPendingSubqueries  [line 620]

  void processPendingSubqueries( )

processPendingSubqueries processes pending subqueries

subqueries can only be processed when the query is fully constructed since some subqueries may be correlated


API Tags:
Access:  public


[ Top ]
query  [line 1528]

  mixed query( string $query, [array $params = array()]  )

query query the database with DQL (Doctrine Query Language)

Parameters:
string   $query:  DQL query
array   $params:  prepared statement parameters

API Tags:
See:  Doctrine::FETCH_* constants
Access:  public


[ Top ]
reset  [line 114]

  void reset( )


API Tags:
Access:  public


[ Top ]
setOption  [line 132]

  Doctrine_Query setOption( string $name, string $value  )

setOption

Parameters:
string   $name:  option name
string   $value:  option value

API Tags:
Return:  this object
Access:  public


[ Top ]
tokenizeQuery  [line 1114]

  array tokenizeQuery( string $query  )

tokenizeQuery

splits the given dql query into an array where keys represent different query part names and values are arrays splitted using sqlExplode method

example:

parameter: $query = "SELECT u.* FROM User u WHERE u.name LIKE ?" returns: array('select' => array('u.*'), 'from' => array('User', 'u'), 'where' => array('u.name', 'LIKE', '?'))

Parameters:
string   $query:  DQL query

API Tags:
Return:  an array containing the query string parts
Access:  public

Information Tags:
Throws:  Doctrine_Query_Exception if some generic parsing error occurs

[ Top ]
Constants
STATE_CLEAN = 1 [line 35]

[ Top ]
STATE_DIRECT = 3 [line 39]

[ Top ]
STATE_DIRTY = 2 [line 37]

[ Top ]
STATE_LOCKED = 4 [line 41]

[ Top ]