You are currently viewing the 1.2 version of the API documentation. Switch to 2.0 or 1.0 or 1.1.

Doctrine Query

Doctrine_Query A Doctrine_Query object represents a DQL query. It is used to query databases for data in an object-oriented fashion. A DQL query understands relations and inheritance and is dbms independant.

Inheritence

Doctrine_Query > Doctrine_Query_Abstract > Doctrine_Hydrate

Method Summary

Returns Name Description
addPendingJoinCondition
adjustProcessedParam Adjust the processed param index for "foo.bar IN ?" support
buildAssociativeRelationSql
buildIndexBy
string buildInheritanceJoinSql
buildSimpleRelationSql
string buildSqlQuery Build the SQL query from the DQL
clear Clears all the sql parts.
boolean contains Method to check if a arbitrary piece of dql exists
copy Copies a Doctrine_Query object.
integer 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 = '12
create create returns a new Doctrine_Query object
Doctrine_Hydrate createSubquery createSubquery creates a subquery
array fetchArray fetchArray Convenience method to execute using array fetching as hydration mode.
mixed fetchOne fetchOne Convenience method to execute the query and return the first item of the collection.
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.
string getCountSqlQuery Get count sql query for this Doctrine_Query instance. This method is used in Doctrine_Query::count() for returning an integer for the number of records which will be returned when executed.
array getDqlPart Retrieves a specific DQL query part.
string getExpressionOwner getExpressionOwner returns the component alias for owner of given expression
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
string getSqlAggregateAlias
string getSqlQuery builds the sql query from the given parameters and applies things such as column aggregation inheritance and limit subqueries if needed
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 retr
load
loadRoot
string parseClause parseClause parses given DQL clause this method handles five tasks:
  • Converts all DQL functions to their native SQL equivalents

  • Converts all component references to their table alias equivalents

  • Converts all field names to actual column

  • parseDqlQuery DQL PARSER parses a DQL query first splits the query in parts and then uses individual parsers for each part
    parseFunctionExpression
    parseIdentifierReference
    parseSelect parseSelect parses the query select part and adds selected fields to pendingFields array
    string parseSelectField Parses a nested field
    parseSelectField('u.Phonenumber.value');]]>
    parseSubquery
    processPendingAggregates processPendingAggregates processes pending aggregate values for given component alias
    string 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. For instance, the wildcard '*' is expanded in the list of columns.
    processPendingSubqueries processPendingSubqueries processes pending subqueries subqueries can only be processed when the query is fully constructed since some subqueries may be correlated
    mixed query Queries the database with DQL (Doctrine Query Language). This methods parses a Dql query and builds the query parts.
    reset Resets the query to the state just after it has been instantiated.
    string _buildSqlFromPart _buildSqlFromPart builds the from part of the query and returns it
    string _buildSqlQueryBase returns the base of the generated sql query On mysql driver special strategy has to be used for DELETE statements (where is this special strategy??)
    _killReference Kill the reference for the passed class property. This method simply copies the value to a temporary variable and then unsets the reference and re-assigns the old value but not by reference
    Processed _processPendingJoinConditions Processes the pending join conditions, used for dynamically add conditions to root component/joined components without interfering in the main dql handling.
    __clone Magic method called after cloning process.

    Method Details

    • $componentAlias component alias
      $joinCondition dql join condition

      addPendingJoinCondition($componentAlias, $joinCondition)

      returns this object


    • adjustProcessedParam($index)

      Adjust the processed param index for "foo.bar IN ?" support


    • buildAssociativeRelationSql($relation, $assocAlias, $foreignAlias, $localAlias)


    • buildIndexBy($componentAlias, $mapWith = null)


    • $name component class name
      $componentAlias alias of the component in the dql

      (string) buildInheritanceJoinSql($name, $componentAlias)

      returns query part


    • buildSimpleRelationSql($relation, $foreignAlias, $localAlias, $overrideJoin, $join)


    • (string) buildSqlQuery()

      Build the SQL query from the DQL

      returns The generated SQL string


    • clear()

      Clears all the sql parts.


    • $dql Arbitrary piece of dql to check for

      (boolean) contains($dql)

      Method to check if a arbitrary piece of dql exists


    • copy($query = null)

      Copies a Doctrine_Query object.

      returns Copy of the Doctrine_Query instance.


    • $params an array of prepared statement parameters

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

      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 = '12

      returns the count of this query


    • $conn optional connection parameter
      $class Query class to instantiate

      create((Doctrine_Connection) $conn = null, $class = null)

      create returns a new Doctrine_Query object


    • (Doctrine_Hydrate) createSubquery()

      createSubquery creates a subquery


    • (array) fetchArray($params = array())

      fetchArray Convenience method to execute using array fetching as hydration mode.


    • $params Query parameters
      $hydrationMode Hydration mode: see Doctrine_Core::HYDRATE_* constants

      (mixed) fetchOne($params = array(), $hydrationMode = null)

      fetchOne Convenience method to execute the query and return the first item of the collection.

      returns Array or Doctrine_Collection, depending on hydration mode. False if no result.


    • 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.

      returns this object


    • (string) getCountSqlQuery()

      Get count sql query for this Doctrine_Query instance.

      This method is used in Doctrine_Query::count() for returning an integer for the number of records which will be returned when executed.


    • $queryPart the name of the query part; can be: array from, containing strings; array select, containg string; boolean forUpdate; array set; array join; array where; array groupby; array having; array orderby, containing s

      (array) getDqlPart($queryPart)

      Retrieves a specific DQL query part.


    • $expr expression from which to get to owner from

      (string) getExpressionOwner($expr)

      getExpressionOwner returns the component alias for owner of given expression

      returns the component alias


    • (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

      returns the limit subquery


    • $dqlAlias the dql alias of an aggregate value

      (string) getSqlAggregateAlias($dqlAlias)


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

      (string) getSqlQuery($params = array())

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

      returns the built sql query


    • $bool whether or not this query acts as a subquery

      isSubquery($bool = null)

      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 retr


    • $path component alias

      load($path, $loadFields = true)


    • loadRoot($name, $componentAlias)


    • (string) parseClause($clause)

      parseClause parses given DQL clause

      this method handles five tasks:

    • Converts all DQL functions to their native SQL equivalents

    • Converts all component references to their table alias equivalents

    • Converts all field names to actual column

      returns SQL string


  • $query DQL query
    $clear whether or not to clear the aliases

    parseDqlQuery($query, $clear = true)

    DQL PARSER

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

    throws Doctrine_Query_Exception if some generic parsing error occurs


  • parseFunctionExpression($expr)


  • parseIdentifierReference($expr)


  • parseSelect($dql)

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


  • (string) parseSelectField($field)

    Parses a nested field

    parseSelectField('u.Phonenumber.value');]]>

    returns SQL fragment

    throws Doctrine_Query_Exception if unknown component alias has been given


  • parseSubquery($subquery)


  • processPendingAggregates()

    processPendingAggregates processes pending aggregate values for given component alias


  • $componentAlias the alias of the component

    (string) processPendingFields($componentAlias)

    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. For instance, the wildcard '*' is expanded in the list of columns.

    returns SQL code

    throws Doctrine_Query_Exception if unknown component alias has been given


  • processPendingSubqueries()

    processPendingSubqueries processes pending subqueries

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


  • $query Dql query
    $params prepared statement parameters
    $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD

    (mixed) query($query, $params = array(), $hydrationMode = null)

    Queries the database with DQL (Doctrine Query Language).

    This methods parses a Dql query and builds the query parts.


  • reset()

    Resets the query to the state just after it has been instantiated.


  • (string) _buildSqlFromPart($ignorePending = false)

    _buildSqlFromPart builds the from part of the query and returns it

    returns the query sql from part


  • (string) _buildSqlQueryBase()

    returns the base of the generated sql query On mysql driver special strategy has to be used for DELETE statements (where is this special strategy??)

    returns the base of the generated sql query


  • _killReference($key)

    Kill the reference for the passed class property.

    This method simply copies the value to a temporary variable and then unsets the reference and re-assigns the old value but not by reference


  • $alias Component Alias

    (Processed) _processPendingJoinConditions($alias)

    Processes the pending join conditions, used for dynamically add conditions to root component/joined components without interfering in the main dql handling.

    returns pending conditions


  • __clone()

    Magic method called after cloning process.