Doctrine 1.2.4
Doctrine_RawSql Class Reference

Inherits Doctrine_Query_Abstract.

Public Member Functions

 __construct (Doctrine_Connection $connection=null, Doctrine_Hydrator_Abstract $hydrator=null)
 
 __toString ()
 
 addComponent ($tableAlias, $path)
 
 addFrom ($from)
 
 addGroupBy ($groupby)
 
 addHaving ($having, $params=array())
 
 addOrderBy ($orderby)
 
 addSelect ($select)
 
 addSqlQueryPart ($name, $part)
 
 addSqlTableAlias ($sqlTableAlias, $componentAlias)
 
 addWhere ($where, $params=array())
 
 andWhere ($where, $params=array())
 
 andWhereIn ($expr, $params=array(), $not=false)
 
 andWhereNotIn ($expr, $params=array())
 
 calculateQueryCacheHash ()
 
 calculateResultCacheHash ($params=array())
 
 clearResultCache ()
 
 copySubqueryInfo (Doctrine_Query_Abstract $query)
 
 count ($params=array())
 
 delete ($from=null)
 
 distinct ($flag=true)
 
 execute ($params=array(), $hydrationMode=null)
 
 expireQueryCache ($expire=true)
 
 expireResultCache ($expire=true)
 
 fixArrayParameterValues ($params=array())
 
 forUpdate ($flag=true)
 
 free ()
 
 from ($from)
 
 generateNewSqlTableAlias ($oldAlias)
 
 generateSqlTableAlias ($componentAlias, $tableName)
 
 getCachedForm ($customComponent=null)
 
 getComponentAlias ($sqlTableAlias)
 
 getConnection ()
 
 getCountQueryParams ($params=array())
 
 getCountSqlQuery ($params=array())
 
 getDql ()
 
 getFields ()
 
 getFlattenedParams ($params=array())
 
 getInheritanceCondition ($componentAlias)
 
 getInternalParams ($params=array())
 
 getParams ()
 
 getQueryCacheDriver ()
 
 getQueryCacheLifeSpan ()
 
 getQueryComponent ($componentAlias)
 
 getQueryComponents ()
 
 getResultCacheDriver ()
 
 getResultCacheHash ($params=array())
 
 getResultCacheLifeSpan ()
 
 getRoot ()
 
 getRootAlias ()
 
 getRootDeclaration ()
 
 getSqlParts ()
 
 getSqlQuery ($params=array())
 
 getSqlQueryPart ($part)
 
 getSqlTableAlias ($componentAlias, $tableName=null)
 
 getSqlTableAliasSeed ($sqlTableAlias)
 
 getTableAliasMap ()
 
 getType ()
 
 getView ()
 
 groupBy ($groupby)
 
 hasAliasDeclaration ($componentAlias)
 
 hasSqlTableAlias ($sqlTableAlias)
 
 having ($having, $params=array())
 
 innerJoin ($join, $params=array())
 
 isLimitSubqueryUsed ()
 
 leftJoin ($join, $params=array())
 
 limit ($limit)
 
 offset ($offset)
 
 orderBy ($orderby)
 
 orWhere ($where, $params=array())
 
 orWhereIn ($expr, $params=array(), $not=false)
 
 orWhereNotIn ($expr, $params=array())
 
 parseDqlQuery ($query)
 
 parseDqlQueryPart ($queryPartName, $queryPart, $append=false)
 
 preQuery ()
 
 removeDqlQueryPart ($name)
 
 removeSqlQueryPart ($name)
 
 select ($select=null)
 
 set ($key, $value=null, $params=null)
 
 setConnection (Doctrine_Connection $connection)
 
 setOption ($name, $value)
 
 setParams (array $params=array())
 
 setQueryCacheLifeSpan ($timeToLive)
 
 setResultCacheHash ($resultCacheHash)
 
 setResultCacheLifeSpan ($timeToLive)
 
 setSqlQueryPart ($name, $part)
 
 setView (Doctrine_View $view)
 
 update ($from=null)
 
 useQueryCache ($driver=true, $timeToLive=null)
 
 useResultCache ($driver=true, $timeToLive=null, $resultCacheHash=null)
 
 where ($where, $params=array())
 
 whereIn ($expr, $params=array(), $not=false)
 
 whereNotIn ($expr, $params=array())
 

Data Fields

const CREATE = 4
 
const DELETE = 1
 
const INSERT = 3
 
const SELECT = 0
 
const STATE_CLEAN = 1
 
const STATE_DIRECT = 3
 
const STATE_DIRTY = 2
 
const STATE_LOCKED = 4
 
const UPDATE = 2
 

Protected Member Functions

 _addDqlQueryPart ($queryPartName, $queryPart, $append=false)
 
 _constructQueryFromCache ($cached)
 
 _execute ($params)
 
 _getDqlCallback ()
 
 _getDqlCallbackComponents ($params=array())
 
 _getParser ($name)
 
 _hasDqlQueryPart ($queryPartName)
 
 _preQuery ($params=array())
 
 _processDqlQueryPart ($queryPartName, $queryParts)
 
 _processWhereIn ($expr, $params=array(), $not=false)
 

Detailed Description

Definition at line 39 of file RawSql.php.

Constructor & Destructor Documentation

Doctrine_RawSql::__construct ( Doctrine_Connection  $connection = null,
Doctrine_Hydrator_Abstract  $hydrator = null 
)

Constructor.

Parameters
Doctrine_ConnectionThe connection object the query will use.
Doctrine_Hydrator_AbstractThe hydrator that will be used for generating result sets.

Definition at line 52 of file RawSql.php.

{
parent::__construct($connection, $hydrator);
// Fix #1472. It's alid to disable QueryCache since there's no DQL for RawSql.
// RawSql expects to be plain SQL + syntax for SELECT part. It is used as is in query execution.
$this->useQueryCache(false);
}

Member Function Documentation

Doctrine_Query_Abstract::__toString ( )
inherited

toString magic call this method is automatically called when Doctrine_Query object is trying to be used as a string So, it it converted into its DQL correspondant

Returns
string DQL string

Definition at line 2139 of file Abstract.php.

{
return $this->getDql();
}
Doctrine_RawSql::_addDqlQueryPart (   $queryPartName,
  $queryPart,
  $append = false 
)
protected

Adds a DQL query part. Overrides Doctrine_Query_Abstract::_addDqlQueryPart(). This implementation for RawSql parses the new parts right away, generating the SQL.

Definition at line 103 of file RawSql.php.

{
return $this->parseDqlQueryPart($queryPartName, $queryPart, $append);
}
Doctrine_Query_Abstract::_constructQueryFromCache (   $cached)
protectedinherited

Constructs the query from the cached form.

Parameters
stringThe cached query, in a serialized form.
Returns
array The custom component that was cached together with the essential query data. This can be either a result set (result caching) or an SQL query string (query caching).

Definition at line 1168 of file Abstract.php.

{
$cached = unserialize($cached);
$this->_tableAliasMap = $cached[2];
$customComponent = $cached[0];
$queryComponents = array();
$cachedComponents = $cached[1];
foreach ($cachedComponents as $alias => $components) {
$e = explode('.', $components['name']);
if (count($e) === 1) {
if ( ! $this->_passedConn && $manager->hasConnectionForComponent($e[0])) {
$this->_conn = $manager->getConnectionForComponent($e[0]);
}
$queryComponents[$alias]['table'] = $this->_conn->getTable($e[0]);
} else {
$queryComponents[$alias]['parent'] = $e[0];
$queryComponents[$alias]['relation'] = $queryComponents[$e[0]]['table']->getRelation($e[1]);
$queryComponents[$alias]['table'] = $queryComponents[$alias]['relation']->getTable();
}
if (isset($components['agg'])) {
$queryComponents[$alias]['agg'] = $components['agg'];
}
if (isset($components['map'])) {
$queryComponents[$alias]['map'] = $components['map'];
}
}
$this->_queryComponents = $queryComponents;
return $customComponent;
}
Doctrine_Query_Abstract::_execute (   $params)
protectedinherited

_execute

Parameters
array$params
Returns
PDOStatement The executed PDOStatement.

Definition at line 912 of file Abstract.php.

{
// Apply boolean conversion in DQL params
$params = $this->_conn->convertBooleans($params);
foreach ($this->_params as $k => $v) {
$this->_params[$k] = $this->_conn->convertBooleans($v);
}
$dqlParams = $this->getFlattenedParams($params);
// Check if we're not using a Doctrine_View
if ( ! $this->_view) {
if ($this->_queryCache !== false && ($this->_queryCache || $this->_conn->getAttribute(Doctrine_Core::ATTR_QUERY_CACHE))) {
$queryCacheDriver = $this->getQueryCacheDriver();
$hash = $this->calculateQueryCacheHash();
$cached = $queryCacheDriver->fetch($hash);
// If we have a cached query...
if ($cached) {
// Rebuild query from cache
$query = $this->_constructQueryFromCache($cached);
// Assign building/execution specific params
$this->_params['exec'] = $params;
// Initialize prepared parameters array
$this->_execParams = $this->getFlattenedParams();
// Fix possible array parameter values in SQL params
} else {
// Generate SQL or pick already processed one
$query = $this->getSqlQuery($params);
// Check again because getSqlQuery() above could have flipped the _queryCache flag
// if this query contains the limit sub query algorithm we don't need to cache it
if ($this->_queryCache !== false && ($this->_queryCache || $this->_conn->getAttribute(Doctrine_Core::ATTR_QUERY_CACHE))) {
// Convert query into a serialized form
$serializedQuery = $this->getCachedForm($query);
// Save cached query
$queryCacheDriver->save($hash, $serializedQuery, $this->getQueryCacheLifeSpan());
}
}
} else {
$query = $this->getSqlQuery($params);
}
} else {
$query = $this->_view->getSelectSql();
}
// Get prepared SQL params for execution
$params = $this->getInternalParams();
if ($this->isLimitSubqueryUsed() &&
$this->_conn->getAttribute(Doctrine_Core::ATTR_DRIVER_NAME) !== 'mysql') {
$params = array_merge((array) $params, (array) $params);
}
if ($this->_type !== self::SELECT) {
return $this->_conn->exec($query, $params);
}
$stmt = $this->_conn->execute($query, $params);
$this->_params['exec'] = array();
return $stmt;
}
Doctrine_Query_Abstract::_getDqlCallback ( )
protectedinherited

Get the dql call back for this query

Returns
array $callback

Definition at line 1059 of file Abstract.php.

{
$callback = false;
if ( ! empty($this->_dqlParts['from'])) {
switch ($this->_type) {
case self::DELETE:
$callback = array(
'callback' => 'preDqlDelete',
'const' => Doctrine_Event::RECORD_DQL_DELETE
);
break;
case self::UPDATE:
$callback = array(
'callback' => 'preDqlUpdate',
'const' => Doctrine_Event::RECORD_DQL_UPDATE
);
break;
case self::SELECT:
$callback = array(
'callback' => 'preDqlSelect',
'const' => Doctrine_Event::RECORD_DQL_SELECT
);
break;
}
}
return $callback;
}
Doctrine_Query_Abstract::_getDqlCallbackComponents (   $params = array())
protectedinherited

Returns an array of components to execute the query callbacks for

Parameters
array$params
Returns
array $components

Definition at line 1129 of file Abstract.php.

{
$componentsBefore = array();
if ($this->isSubquery()) {
$componentsBefore = $this->getQueryComponents();
}
$copy = $this->copy();
$copy->getSqlQuery($params, false);
$componentsAfter = $copy->getQueryComponents();
$this->_rootAlias = $copy->getRootAlias();
$copy->free();
if ($componentsBefore !== $componentsAfter) {
return array_diff($componentsAfter, $componentsBefore);
} else {
return $componentsAfter;
}
}
Doctrine_Query_Abstract::_getParser (   $name)
protectedinherited

_getParser parser lazy-loader

Exceptions
Doctrine_Query_Exceptionif unknown parser name given
Returns
Doctrine_Query_Part
Todo:
Doc/Description: What is the parameter for? Which parsers are available?

Definition at line 2097 of file Abstract.php.

{
if ( ! isset($this->_parsers[$name])) {
$class = 'Doctrine_Query_' . ucwords(strtolower($name));
if ( ! class_exists($class)) {
throw new Doctrine_Query_Exception('Unknown parser ' . $name);
}
$this->_parsers[$name] = new $class($this, $this->_tokenizer);
}
return $this->_parsers[$name];
}
Doctrine_Query_Abstract::_hasDqlQueryPart (   $queryPartName)
protectedinherited

Checks if there's at least one DQL part defined to the internal parts collection.

Parameters
string$queryPartNameThe name of the query part.
Returns
boolean

Definition at line 2024 of file Abstract.php.

{
return count($this->_dqlParts[$queryPartName]) > 0;
}
Doctrine_Query_Abstract::_preQuery (   $params = array())
protectedinherited

Pre query method which invokes the pre*Query() methods on the model instance or any attached record listeners

Returns
void

Definition at line 1094 of file Abstract.php.

{
if ( ! $this->_preQueried && $this->getConnection()->getAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS)) {
$this->_preQueried = true;
$callback = $this->_getDqlCallback();
// if there is no callback for the query type, then we can return early
if ( ! $callback) {
return;
}
foreach ($this->_getDqlCallbackComponents($params) as $alias => $component) {
$table = $component['table'];
$record = $table->getRecordInstance();
// Trigger preDql*() callback event
$params = array('component' => $component, 'alias' => $alias);
$event = new Doctrine_Event($record, $callback['const'], $this, $params);
$record->$callback['callback']($event);
$table->getRecordListener()->$callback['callback']($event);
}
}
// Invoke preQuery() hook on Doctrine_Query for child classes which implement this hook
$this->preQuery();
}
Doctrine_Query_Abstract::_processDqlQueryPart (   $queryPartName,
  $queryParts 
)
protectedinherited

_processDqlQueryPart parses given query part

Parameters
string$queryPartNamethe name of the query part
array$queryPartsan array containing the query part data
Returns
Doctrine_Query this object
Todo:
Better description. "parses given query part" ??? Then wheres the difference between process/parseQueryPart? I suppose this does something different.

Definition at line 2070 of file Abstract.php.

{
$this->removeSqlQueryPart($queryPartName);
if (is_array($queryParts) && ! empty($queryParts)) {
foreach ($queryParts as $queryPart) {
$parser = $this->_getParser($queryPartName);
$sql = $parser->parse($queryPart);
if (isset($sql)) {
if ($queryPartName == 'limit' || $queryPartName == 'offset') {
$this->setSqlQueryPart($queryPartName, $sql);
} else {
$this->addSqlQueryPart($queryPartName, $sql);
}
}
}
}
}
Doctrine_Query_Abstract::_processWhereIn (   $expr,
  $params = array(),
  $not = false 
)
protectedinherited

Definition at line 1404 of file Abstract.php.

{
$params = (array) $params;
// if there's no params, return (else we'll get a WHERE IN (), invalid SQL)
if (count($params) == 0) {
throw new Doctrine_Query_Exception('You must pass at least one parameter when using an IN() condition.');
}
$a = array();
foreach ($params as $k => $value) {
if ($value instanceof Doctrine_Expression) {
$value = $value->getSql();
unset($params[$k]);
} else {
$value = '?';
}
$a[] = $value;
}
$this->_params['where'] = array_merge($this->_params['where'], $params);
return $expr . ($not === true ? ' NOT' : '') . ' IN (' . implode(', ', $a) . ')';
}
Doctrine_RawSql::addComponent (   $tableAlias,
  $path 
)

addComponent

Parameters
string$tableAlias
string$componentName
Returns
Doctrine_RawSql

Definition at line 383 of file RawSql.php.

{
$tmp = explode(' ', $path);
$originalAlias = (count($tmp) > 1) ? end($tmp) : null;
$e = explode('.', $tmp[0]);
$fullPath = $tmp[0];
$fullLength = strlen($fullPath);
$table = null;
$currPath = '';
if (isset($this->_queryComponents[$e[0]])) {
$table = $this->_queryComponents[$e[0]]['table'];
$currPath = $parent = array_shift($e);
}
foreach ($e as $k => $component) {
// get length of the previous path
$length = strlen($currPath);
// build the current component path
$currPath = ($currPath) ? $currPath . '.' . $component : $component;
$delimeter = substr($fullPath, $length, 1);
// if an alias is not given use the current path as an alias identifier
if (strlen($currPath) === $fullLength && isset($originalAlias)) {
$componentAlias = $originalAlias;
} else {
$componentAlias = $currPath;
}
if ( ! isset($table)) {
->getConnectionForComponent($component);
$table = $conn->getTable($component);
$this->_queryComponents[$componentAlias] = array('table' => $table);
} else {
$relation = $table->getRelation($component);
$this->_queryComponents[$componentAlias] = array('table' => $relation->getTable(),
'parent' => $parent,
'relation' => $relation);
}
$this->addSqlTableAlias($tableAlias, $componentAlias);
$parent = $currPath;
}
return $this;
}
Doctrine_Query_Abstract::addFrom (   $from)
inherited

addFrom adds fields to the FROM part of the query

Parameters
string$fromQuery FROM part
Returns
Doctrine_Query

Definition at line 1272 of file Abstract.php.

{
return $this->_addDqlQueryPart('from', $from, true);
}
Doctrine_Query_Abstract::addGroupBy (   $groupby)
inherited

Adds fields to the GROUP BY part of the query. $q->groupBy('u.id');

Parameters
string$groupbyQuery GROUP BY part
Returns
Doctrine_Query

Definition at line 1479 of file Abstract.php.

{
return $this->_addDqlQueryPart('groupby', $groupby, true);
}
Doctrine_Query_Abstract::addHaving (   $having,
  $params = array() 
)
inherited

Adds conditions to the HAVING part of the query.

This methods add HAVING clauses. These clauses are used to narrow the results by operating on aggregated values. $q->having('num_phonenumbers > ?', 1);

Parameters
string$havingQuery HAVING part
mixed$paramsan array of parameters or a simple scalar
Returns
Doctrine_Query

Definition at line 1497 of file Abstract.php.

{
if (is_array($params)) {
$this->_params['having'] = array_merge($this->_params['having'], $params);
} else {
$this->_params['having'][] = $params;
}
return $this->_addDqlQueryPart('having', $having, true);
}
Doctrine_Query_Abstract::addOrderBy (   $orderby)
inherited

addOrderBy adds fields to the ORDER BY part of the query

Parameters
string$orderbyQuery ORDER BY part
Returns
Doctrine_Query

Definition at line 1514 of file Abstract.php.

{
return $this->_addDqlQueryPart('orderby', $orderby, true);
}
Doctrine_Query_Abstract::addSelect (   $select)
inherited

Adds fields or aliased functions.

This method adds fields or dbms functions to the SELECT query part. $query->addSelect('COUNT(p.id) as num_phonenumbers');

Parameters
string$selectQuery SELECT part
Returns
Doctrine_Query

Definition at line 1246 of file Abstract.php.

{
return $this->_addDqlQueryPart('select', $select, true);
}
Doctrine_Query_Abstract::addSqlQueryPart (   $name,
  $part 
)
inherited

addSqlQueryPart adds an SQL query part to the SQL query part array

Parameters
string$namethe name of the query part to be added
string$partquery part string
Exceptions
Doctrine_Query_Exceptionif trying to add unknown query part
Returns
Doctrine_Query this object

Definition at line 426 of file Abstract.php.

{
if ( ! isset($this->_sqlParts[$name])) {
throw new Doctrine_Query_Exception('Unknown query part ' . $name);
}
if (is_array($part)) {
$this->_sqlParts[$name] = array_merge($this->_sqlParts[$name], $part);
} else {
$this->_sqlParts[$name][] = $part;
}
return $this;
}
Doctrine_Query_Abstract::addSqlTableAlias (   $sqlTableAlias,
  $componentAlias 
)
inherited

addSqlTableAlias adds an SQL table alias and associates it a component alias

Parameters
string$componentAliasthe alias for the query component associated with given tableAlias
string$tableAliasthe table alias to be added
Returns
Doctrine_Query_Abstract

Definition at line 1259 of file Abstract.php.

{
$this->_tableAliasMap[$sqlTableAlias] = $componentAlias;
return $this;
}
Doctrine_Query_Abstract::addWhere (   $where,
  $params = array() 
)
inherited

Alias for

See Also
andWhere().
Returns
Doctrine_Query this object

Definition at line 1281 of file Abstract.php.

{
return $this->andWhere($where, $params);
}
Doctrine_Query_Abstract::andWhere (   $where,
  $params = array() 
)
inherited

Adds conditions to the WHERE part of the query. $q->andWhere('u.birthDate > ?', '1975-01-01');

Parameters
string$whereQuery WHERE part
mixed$paramsAn array of parameters or a simple scalar
Returns
Doctrine_Query

Definition at line 1296 of file Abstract.php.

{
if (is_array($params)) {
$this->_params['where'] = array_merge($this->_params['where'], $params);
} else {
$this->_params['where'][] = $params;
}
if ($this->_hasDqlQueryPart('where')) {
$this->_addDqlQueryPart('where', 'AND', true);
}
return $this->_addDqlQueryPart('where', $where, true);
}
Doctrine_Query_Abstract::andWhereIn (   $expr,
  $params = array(),
  $not = false 
)
inherited

Adds IN condition to the query WHERE part $q->whereIn('u.id', array(10, 23, 44));

Parameters
string$exprThe operand of the IN
mixed$paramsAn array of parameters or a simple scalar
boolean$notWhether or not to use NOT in front of IN. Defaults to false (simple IN clause)
Returns
Doctrine_Query this object.

Definition at line 1360 of file Abstract.php.

{
// if there's no params, return (else we'll get a WHERE IN (), invalid SQL)
if (isset($params) and (count($params) == 0)) {
return $this;
}
if ($this->_hasDqlQueryPart('where')) {
$this->_addDqlQueryPart('where', 'AND', true);
}
return $this->_addDqlQueryPart('where', $this->_processWhereIn($expr, $params, $not), true);
}
Doctrine_Query_Abstract::andWhereNotIn (   $expr,
  $params = array() 
)
inherited

Adds NOT IN condition to the query WHERE part Alias for

See Also
whereNotIn().
Parameters
string$exprThe operand of the NOT IN
mixed$paramsAn array of parameters or a simple scalar
Returns
Doctrine_Query

Definition at line 1453 of file Abstract.php.

{
return $this->andWhereIn($expr, $params, true);
}
Doctrine_Query_Abstract::calculateQueryCacheHash ( )
inherited

calculateQueryCacheHash calculate hash key for query cache

Returns
string the hash

Definition at line 867 of file Abstract.php.

{
$dql = $this->getDql();
$hash = md5($dql . var_export($this->_pendingJoinConditions, true) . 'DOCTRINE_QUERY_CACHE_SALT');
return $hash;
}
Doctrine_RawSql::calculateResultCacheHash (   $params = array())

calculateResultCacheHash calculate hash key for result cache

Parameters
array$params
Returns
string the hash

Definition at line 446 of file RawSql.php.

{
$sql = $this->getSqlQuery();
$conn = $this->getConnection();
$params = $this->getFlattenedParams($params);
$hash = md5($this->_hydrator->getHydrationMode() . $conn->getName() . $conn->getOption('dsn') . $sql . var_export($params, true));
return $hash;
}
Doctrine_Query_Abstract::clearResultCache ( )
inherited

Clear the result cache entry for this query

Returns
void

Definition at line 1873 of file Abstract.php.

{
->delete($this->getResultCacheHash());
return $this;
}
Doctrine_Query_Abstract::copySubqueryInfo ( Doctrine_Query_Abstract  $query)
inherited

copySubqueryInfo copy aliases from another Hydrate object

this method is needed by DQL subqueries which need the aliases of the parent query

Parameters
Doctrine_Hydrate$querythe query object from which the aliases are copied from
Returns
Doctrine_Query this object

Definition at line 760 of file Abstract.php.

{
$this->_params =& $query->_params;
$this->_tableAliasMap =& $query->_tableAliasMap;
$this->_queryComponents =& $query->_queryComponents;
$this->_tableAliasSeeds = $query->_tableAliasSeeds;
return $this;
}
Doctrine_RawSql::count (   $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.

This is an exact copy of the Dql Version

See Also
Doctrine_Query::count()
Parameters
array$paramsan array of prepared statement parameters
Returns
integer the count of this query

Definition at line 345 of file RawSql.php.

{
$sql = $this->getCountSqlQuery();
$params = $this->getCountQueryParams($params);
$results = $this->getConnection()->fetchAll($sql, $params);
if (count($results) > 1) {
$count = count($results);
} else {
if (isset($results[0])) {
$results[0] = array_change_key_case($results[0], CASE_LOWER);
$count = $results[0]['num_results'];
} else {
$count = 0;
}
}
return (int) $count;
}
Doctrine_Query_Abstract::delete (   $from = null)
inherited

delete sets the query type to DELETE

Returns
Doctrine_Query

Definition at line 1571 of file Abstract.php.

{
$this->_type = self::DELETE;
if ($from != null) {
return $this->_addDqlQueryPart('from', $from);
}
return $this;
}
Doctrine_Query_Abstract::distinct (   $flag = true)
inherited

distinct Makes the query SELECT DISTINCT. $q->distinct();

Parameters
bool$flagWhether or not the SELECT is DISTINCT (default true).
Returns
Doctrine_Query

Definition at line 1546 of file Abstract.php.

{
$this->_sqlParts['distinct'] = (bool) $flag;
return $this;
}
Doctrine_Query_Abstract::execute (   $params = array(),
  $hydrationMode = null 
)
inherited

execute executes the query and populates the data set

Parameters
array$params
Returns
Doctrine_Collection the root collection

Definition at line 990 of file Abstract.php.

{
// Clean any possible processed params
$this->_execParams = array();
if (empty($this->_dqlParts['from']) && empty($this->_sqlParts['from'])) {
throw new Doctrine_Query_Exception('You must have at least one component specified in your from.');
}
$dqlParams = $this->getFlattenedParams($params);
$this->_preQuery($dqlParams);
if ($hydrationMode !== null) {
$this->_hydrator->setHydrationMode($hydrationMode);
}
$hydrationMode = $this->_hydrator->getHydrationMode();
if ($this->_resultCache && $this->_type == self::SELECT) {
$cacheDriver = $this->getResultCacheDriver();
$hash = $this->getResultCacheHash($params);
$cached = ($this->_expireResultCache) ? false : $cacheDriver->fetch($hash);
if ($cached === false) {
// cache miss
$stmt = $this->_execute($params);
$this->_hydrator->setQueryComponents($this->_queryComponents);
$result = $this->_hydrator->hydrateResultSet($stmt, $this->_tableAliasMap);
$cached = $this->getCachedForm($result);
$cacheDriver->save($hash, $cached, $this->getResultCacheLifeSpan());
} else {
$result = $this->_constructQueryFromCache($cached);
}
} else {
$stmt = $this->_execute($params);
if (is_integer($stmt)) {
$result = $stmt;
} else {
$this->_hydrator->setQueryComponents($this->_queryComponents);
if ($this->_type == self::SELECT && $hydrationMode == Doctrine_Core::HYDRATE_ON_DEMAND) {
$hydrationDriver = $this->_hydrator->getHydratorDriver($hydrationMode, $this->_tableAliasMap);
$result = new Doctrine_Collection_OnDemand($stmt, $hydrationDriver, $this->_tableAliasMap);
} else {
$result = $this->_hydrator->hydrateResultSet($stmt, $this->_tableAliasMap);
}
}
}
if ($this->getConnection()->getAttribute(Doctrine_Core::ATTR_AUTO_FREE_QUERY_OBJECTS)) {
$this->free();
}
return $result;
}
Doctrine_Query_Abstract::expireQueryCache (   $expire = true)
inherited

expireQueryCache

Parameters
boolean$expirewhether or not to force cache expiration
Returns
Doctrine_Query this object

Definition at line 1920 of file Abstract.php.

{
$this->_expireQueryCache = $expire;
return $this;
}
Doctrine_Query_Abstract::expireResultCache (   $expire = true)
inherited

expireCache

Parameters
boolean$expirewhether or not to force cache expiration
Returns
Doctrine_Query this object

Definition at line 1908 of file Abstract.php.

{
$this->_expireResultCache = $expire;
return $this;
}
Doctrine_Query_Abstract::fixArrayParameterValues (   $params = array())
inherited

Definition at line 555 of file Abstract.php.

{
$i = 0;
foreach ($params as $param) {
if (is_array($param)) {
$c = count($param);
array_splice($params, $i, 1, $param);
$i += $c;
} else {
$i++;
}
}
$this->_execParams = $params;
}
Doctrine_Query_Abstract::forUpdate (   $flag = true)
inherited

forUpdate Makes the query SELECT FOR UPDATE.

Parameters
bool$flagWhether or not the SELECT is FOR UPDATE (default true).
Returns
Doctrine_Query

Definition at line 1559 of file Abstract.php.

{
$this->_sqlParts['forUpdate'] = (bool) $flag;
return $this;
}
Doctrine_Query_Abstract::free ( )
inherited

Blank template method free(). Override to be used to free query object memory

Definition at line 1050 of file Abstract.php.

{
}
Doctrine_Query_Abstract::from (   $from)
inherited

from sets the FROM part of the query $q->from('User u');

Parameters
string$fromQuery FROM part
Returns
Doctrine_Query

Definition at line 1633 of file Abstract.php.

{
return $this->_addDqlQueryPart('from', $from);
}
Doctrine_Query_Abstract::generateNewSqlTableAlias (   $oldAlias)
inherited

generateNewSqlTableAlias generates a new alias from given table alias

Parameters
string$tableAliastable alias from which to generate the new alias from
Returns
string the created table alias

Definition at line 686 of file Abstract.php.

{
if (isset($this->_tableAliasMap[$oldAlias])) {
// generate a new alias
$name = substr($oldAlias, 0, 1);
$i = ((int) substr($oldAlias, 1));
// Fix #1530: It was reaching unexistent seeds index
if ( ! isset($this->_tableAliasSeeds[$name])) {
$this->_tableAliasSeeds[$name] = 1;
}
$newIndex = ($this->_tableAliasSeeds[$name] + (($i == 0) ? 1 : $i));
return $name . $newIndex;
}
return $oldAlias;
}
Doctrine_Query_Abstract::generateSqlTableAlias (   $componentAlias,
  $tableName 
)
inherited

generateSqlTableAlias generates a table alias from given table name and associates it with given component alias

Parameters
string$componentAliasthe component alias to be associated with generated table alias
string$tableNamethe table name from which to generate the table alias
Returns
string the generated table alias

Definition at line 822 of file Abstract.php.

{
preg_match('/([^_|\d])/', $tableName, $matches);
$char = strtolower($matches[0]);
$alias = $char;
if ( ! isset($this->_tableAliasSeeds[$alias])) {
$this->_tableAliasSeeds[$alias] = 1;
}
while (isset($this->_tableAliasMap[$alias])) {
if ( ! isset($this->_tableAliasSeeds[$alias])) {
$this->_tableAliasSeeds[$alias] = 1;
}
$alias = $char . ++$this->_tableAliasSeeds[$alias];
}
$this->_tableAliasMap[$alias] = $componentAlias;
return $alias;
}
Doctrine_Query_Abstract::getCachedForm (   $customComponent = null)
inherited

getCachedForm returns the cached form of this query for given resultSet

Parameters
array$resultSet
Returns
string serialized string representation of this query

Definition at line 1208 of file Abstract.php.

{
$componentInfo = array();
foreach ($this->getQueryComponents() as $alias => $components) {
if ( ! isset($components['parent'])) {
$componentInfo[$alias]['name'] = $components['table']->getComponentName();
} else {
$componentInfo[$alias]['name'] = $components['parent'] . '.' . $components['relation']->getAlias();
}
if (isset($components['agg'])) {
$componentInfo[$alias]['agg'] = $components['agg'];
}
if (isset($components['map'])) {
$componentInfo[$alias]['map'] = $components['map'];
}
}
if ($customComponent instanceof Doctrine_Collection) {
foreach ($customComponent as $record) {
$record->serializeReferences(true);
}
}
return serialize(array($customComponent, $componentInfo, $this->getTableAliasMap()));
}
Doctrine_Query_Abstract::getComponentAlias (   $sqlTableAlias)
inherited

getComponentAlias get component alias associated with given table alias

Parameters
string$sqlTableAliasthe SQL table alias that identifies the component alias
Returns
string component alias

Definition at line 852 of file Abstract.php.

{
$sqlTableAlias = trim($sqlTableAlias, '[]`"');
if ( ! isset($this->_tableAliasMap[$sqlTableAlias])) {
throw new Doctrine_Query_Exception('Unknown table alias ' . $sqlTableAlias);
}
return $this->_tableAliasMap[$sqlTableAlias];
}
Doctrine_Query_Abstract::getConnection ( )
inherited

getConnection

Returns
Doctrine_Connection

Definition at line 2013 of file Abstract.php.

{
return $this->_conn;
}
Doctrine_Query_Abstract::getCountQueryParams (   $params = array())
inherited

getCountQueryParams Retrieves the parameters for count query

Returns
array Parameters array

Definition at line 537 of file Abstract.php.

{
if ( ! is_array($params)) {
$params = array($params);
}
$this->_params['exec'] = $params;
$params = array_merge($this->_params['join'], $this->_params['where'], $this->_params['having'], $this->_params['exec']);
$this->fixArrayParameterValues($params);
return $this->_execParams;
}
Doctrine_RawSql::getCountSqlQuery (   $params = array())

getCountQuery builds the count query.

Returns
string the built sql query

Definition at line 295 of file RawSql.php.

{
//Doing COUNT( DISTINCT rootComponent.id )
//This is not correct, if the result is not hydrated by doctrine, but it mimics the behaviour of Doctrine_Query::getCountQuery
reset($this->_queryComponents);
$componentAlias = key($this->_queryComponents);
$this->_rootAlias = $componentAlias;
$tableAlias = $this->getSqlTableAlias($componentAlias);
$fields = array();
foreach ((array) $this->_queryComponents[$componentAlias]['table']->getIdentifierColumnNames() as $key) {
$fields[] = $tableAlias . '.' . $key;
}
$q = 'SELECT COUNT(*) as num_results FROM (SELECT DISTINCT '.implode(', ',$fields);
$string = $this->getInheritanceCondition($this->getRootAlias());
if ( ! empty($string)) {
$this->_sqlParts['where'][] = $string;
}
$q .= ( ! empty($this->_sqlParts['from']))? ' FROM ' . implode(' ', $this->_sqlParts['from']) : '';
$q .= ( ! empty($this->_sqlParts['where']))? ' WHERE ' . implode(' AND ', $this->_sqlParts['where']) : '';
$q .= ( ! empty($this->_sqlParts['groupby']))? ' GROUP BY ' . implode(', ', $this->_sqlParts['groupby']) : '';
$q .= ( ! empty($this->_sqlParts['having']))? ' HAVING ' . implode(' AND ', $this->_sqlParts['having']) : '';
$q .= ') as results';
if ( ! empty($string)) {
array_pop($this->_sqlParts['where']);
}
return $q;
}
Doctrine_Query_Abstract::getDql ( )
inherited

getDql returns the DQL query that is represented by this query object.

the query is built from $_dqlParts

Returns
string the DQL query

Definition at line 348 of file Abstract.php.

{
$q = '';
if ($this->_type == self::SELECT) {
$q .= ( ! empty($this->_dqlParts['select'])) ? 'SELECT ' . implode(', ', $this->_dqlParts['select']) : '';
$q .= ( ! empty($this->_dqlParts['from'])) ? ' FROM ' . implode(' ', $this->_dqlParts['from']) : '';
} else if ($this->_type == self::DELETE) {
$q .= 'DELETE';
$q .= ( ! empty($this->_dqlParts['from'])) ? ' FROM ' . implode(' ', $this->_dqlParts['from']) : '';
} else if ($this->_type == self::UPDATE) {
$q .= 'UPDATE ';
$q .= ( ! empty($this->_dqlParts['from'])) ? implode(' ', $this->_dqlParts['from']) : '';
$q .= ( ! empty($this->_dqlParts['set'])) ? ' SET ' . implode(' ', $this->_dqlParts['set']) : '';
}
$q .= ( ! empty($this->_dqlParts['where'])) ? ' WHERE ' . implode(' ', $this->_dqlParts['where']) : '';
$q .= ( ! empty($this->_dqlParts['groupby'])) ? ' GROUP BY ' . implode(', ', $this->_dqlParts['groupby']) : '';
$q .= ( ! empty($this->_dqlParts['having'])) ? ' HAVING ' . implode(' AND ', $this->_dqlParts['having']) : '';
$q .= ( ! empty($this->_dqlParts['orderby'])) ? ' ORDER BY ' . implode(', ', $this->_dqlParts['orderby']) : '';
$q .= ( ! empty($this->_dqlParts['limit'])) ? ' LIMIT ' . implode(' ', $this->_dqlParts['limit']) : '';
$q .= ( ! empty($this->_dqlParts['offset'])) ? ' OFFSET ' . implode(' ', $this->_dqlParts['offset']) : '';
return $q;
}
Doctrine_RawSql::getFields ( )

getFields returns the fields associated with this parser

Returns
array all the fields associated with this parser

Definition at line 371 of file RawSql.php.

{
return $this->fields;
}
Doctrine_Query_Abstract::getFlattenedParams (   $params = array())
inherited

Get flattened array of parameters for query. Used internally and used to pass flat array of params to the database.

Parameters
array$params
Returns
void

Definition at line 502 of file Abstract.php.

{
return array_merge(
(array) $params, (array) $this->_params['exec'],
$this->_params['join'], $this->_params['set'],
$this->_params['where'], $this->_params['having']
);
}
Doctrine_Query_Abstract::getInheritanceCondition (   $componentAlias)
inherited

Returns the inheritance condition for the passed componentAlias If no component alias is specified it defaults to the root component

This function is used to append a SQL condition to models which have inheritance mapping The condition is applied to the FROM component in the WHERE, but the condition is applied to JOINS in the ON condition and not the WHERE

Returns
string $str SQL condition string

Definition at line 618 of file Abstract.php.

{
$map = $this->_queryComponents[$componentAlias]['table']->inheritanceMap;
// No inheritance map so lets just return
if (empty($map)) {
return;
}
$tableAlias = $this->getSqlTableAlias($componentAlias);
if ($this->_type !== Doctrine_Query::SELECT) {
$tableAlias = '';
} else {
$tableAlias .= '.';
}
// Fix for 2015: loop through whole inheritanceMap to add all
// keyFields for inheritance (and not only the first)
$retVal = "";
$count = 0;
foreach ($map as $field => $value) {
if ($count++ > 0) {
$retVal .= ' AND ';
}
$identifier = $this->_conn->quoteIdentifier($tableAlias . $field);
$retVal .= $identifier . ' = ' . $this->_conn->quote($value);
}
return $retVal;
}
Doctrine_Query_Abstract::getInternalParams (   $params = array())
inherited

getInternalParams

Returns
array

Definition at line 516 of file Abstract.php.

{
return array_merge($params, $this->_execParams);
}
Doctrine_Query_Abstract::getParams ( )
inherited

Get raw array of parameters for query and all parts.

Returns
array $params

Definition at line 490 of file Abstract.php.

{
return $this->_params;
}
Doctrine_Query_Abstract::getQueryCacheDriver ( )
inherited

getQueryCacheDriver returns the cache driver used for caching queries

Returns
Doctrine_Cache_Interface|boolean|null cache driver

Definition at line 1999 of file Abstract.php.

{
if ($this->_queryCache instanceof Doctrine_Cache_Interface) {
return $this->_queryCache;
} else {
return $this->_conn->getQueryCacheDriver();
}
}
Doctrine_Query_Abstract::getQueryCacheLifeSpan ( )
inherited

Gets the life span of the query cache the Query object is using.

Returns
integer The life span in seconds.

Definition at line 1973 of file Abstract.php.

{
return $this->_queryCacheTTL;
}
Doctrine_Query_Abstract::getQueryComponent (   $componentAlias)
inherited

getQueryComponent get the declaration for given component alias

Parameters
string$componentAliasthe component alias the retrieve the declaration from
Returns
array the alias declaration

Definition at line 740 of file Abstract.php.

{
if ( ! isset($this->_queryComponents[$componentAlias])) {
throw new Doctrine_Query_Exception('Unknown component alias ' . $componentAlias);
}
return $this->_queryComponents[$componentAlias];
}
Doctrine_Query_Abstract::getQueryComponents ( )
inherited

Gets the components of this query.

Definition at line 1798 of file Abstract.php.

{
return $this->_queryComponents;
}
Doctrine_Query_Abstract::getResultCacheDriver ( )
inherited

getResultCacheDriver returns the cache driver used for caching result sets

Returns
Doctrine_Cache_Interface|boolean|null cache driver

Definition at line 1984 of file Abstract.php.

{
if ($this->_resultCache instanceof Doctrine_Cache_Interface) {
return $this->_resultCache;
} else {
return $this->_conn->getResultCacheDriver();
}
}
Doctrine_Query_Abstract::getResultCacheHash (   $params = array())
inherited

Get the result cache hash/key. Returns key set with useResultCache() or generates a unique key from the query automatically.

Parameters
array$params
Returns
string $hash

Definition at line 897 of file Abstract.php.

{
if ($this->_resultCacheHash) {
return $this->_resultCacheHash;
} else {
return $this->calculateResultCacheHash($params);
}
}
Doctrine_Query_Abstract::getResultCacheLifeSpan ( )
inherited

Gets the life span of the result cache in seconds.

Returns
integer

Definition at line 1947 of file Abstract.php.

{
return $this->_resultCacheTTL;
}
Doctrine_Query_Abstract::getRoot ( )
inherited

getRoot returns the root component for this object

Returns
Doctrine_Table root components table

Definition at line 802 of file Abstract.php.

{
$map = $this->_queryComponents[$this->_rootAlias];
if ( ! isset($map['table'])) {
throw new Doctrine_Query_Exception('Root component not initialized.');
}
return $map['table'];
}
Doctrine_Query_Abstract::getRootAlias ( )
inherited

getRootAlias returns the alias of the root component

Returns
array

Definition at line 775 of file Abstract.php.

{
if ( ! $this->_queryComponents) {
$this->getSqlQuery(array(), false);
}
return $this->_rootAlias;
}
Doctrine_Query_Abstract::getRootDeclaration ( )
inherited

getRootDeclaration returns the root declaration

Returns
array

Definition at line 790 of file Abstract.php.

{
$map = $this->_queryComponents[$this->_rootAlias];
return $map;
}
Doctrine_Query_Abstract::getSqlParts ( )
inherited

Return the SQL parts.

Returns
array The parts

Definition at line 1808 of file Abstract.php.

{
return $this->_sqlParts;
}
Doctrine_RawSql::getSqlQuery (   $params = array())

getSqlQuery builds the sql query.

Returns
string the built sql query

Definition at line 190 of file RawSql.php.

{
// Assign building/execution specific params
$this->_params['exec'] = $params;
// Initialize prepared parameters array
$this->_execParams = $this->getFlattenedParams();
// Initialize prepared parameters array
$this->fixArrayParameterValues($this->_execParams);
$select = array();
$formatter = $this->getConnection()->formatter;
foreach ($this->fields as $field) {
$e = explode('.', $field);
if ( ! isset($e[1])) {
throw new Doctrine_RawSql_Exception('All selected fields in Sql query must be in format tableAlias.fieldName');
}
// try to auto-add component
if ( ! $this->hasSqlTableAlias($e[0])) {
try {
$this->addComponent($e[0], ucwords($e[0]));
} catch (Doctrine_Exception $exception) {
throw new Doctrine_RawSql_Exception('The associated component for table alias ' . $e[0] . ' couldn\'t be found.');
}
}
$componentAlias = $this->getComponentAlias($e[0]);
if ($e[1] == '*') {
foreach ($this->_queryComponents[$componentAlias]['table']->getColumnNames() as $name) {
$field = $formatter->quoteIdentifier($e[0]) . '.' . $formatter->quoteIdentifier($name);
$select[$componentAlias][$field] = $field . ' AS ' . $formatter->quoteIdentifier($e[0] . '__' . $name);
}
} else {
$field = $formatter->quoteIdentifier($e[0]) . '.' . $formatter->quoteIdentifier($e[1]);
$select[$componentAlias][$field] = $field . ' AS ' . $formatter->quoteIdentifier($e[0] . '__' . $e[1]);
}
}
// force-add all primary key fields
if ( ! isset($this->_sqlParts['distinct']) || $this->_sqlParts['distinct'] != true) {
foreach ($this->getTableAliasMap() as $tableAlias => $componentAlias) {
$map = $this->_queryComponents[$componentAlias];
foreach ((array) $map['table']->getIdentifierColumnNames() as $key) {
$field = $formatter->quoteIdentifier($tableAlias) . '.' . $formatter->quoteIdentifier($key);
if ( ! isset($this->_sqlParts['select'][$field])) {
$select[$componentAlias][$field] = $field . ' AS ' . $formatter->quoteIdentifier($tableAlias . '__' . $key);
}
}
}
}
$q = 'SELECT ';
if (isset($this->_sqlParts['distinct']) && $this->_sqlParts['distinct'] == true) {
$q .= 'DISTINCT ';
}
// first add the fields of the root component
reset($this->_queryComponents);
$componentAlias = key($this->_queryComponents);
$this->_rootAlias = $componentAlias;
$q .= implode(', ', $select[$componentAlias]);
unset($select[$componentAlias]);
foreach ($select as $component => $fields) {
if ( ! empty($fields)) {
$q .= ', ' . implode(', ', $fields);
}
}
$string = $this->getInheritanceCondition($this->getRootAlias());
if ( ! empty($string)) {
$this->_sqlParts['where'][] = $string;
}
$q .= ( ! empty($this->_sqlParts['from']))? ' FROM ' . implode(' ', $this->_sqlParts['from']) : '';
$q .= ( ! empty($this->_sqlParts['where']))? ' WHERE ' . implode(' AND ', $this->_sqlParts['where']) : '';
$q .= ( ! empty($this->_sqlParts['groupby']))? ' GROUP BY ' . implode(', ', $this->_sqlParts['groupby']) : '';
$q .= ( ! empty($this->_sqlParts['having']))? ' HAVING ' . implode(' AND ', $this->_sqlParts['having']) : '';
$q .= ( ! empty($this->_sqlParts['orderby']))? ' ORDER BY ' . implode(', ', $this->_sqlParts['orderby']) : '';
$q .= ( ! empty($this->_sqlParts['limit']))? ' LIMIT ' . implode(' ', $this->_sqlParts['limit']) : '';
$q .= ( ! empty($this->_sqlParts['offset']))? ' OFFSET ' . implode(' ', $this->_sqlParts['offset']) : '';
if ( ! empty($string)) {
array_pop($this->_sqlParts['where']);
}
return $q;
}
Doctrine_Query_Abstract::getSqlQueryPart (   $part)
inherited

getSqlQueryPart gets an SQL query part from the SQL query part array

Parameters
string$namethe name of the query part to be set
string$partquery part string
Exceptions
Doctrine_Query_Exceptionif trying to set unknown query part
Returns
mixed this object

Definition at line 381 of file Abstract.php.

{
if ( ! isset($this->_sqlParts[$part])) {
throw new Doctrine_Query_Exception('Unknown SQL query part ' . $part);
}
return $this->_sqlParts[$part];
}
Doctrine_Query_Abstract::getSqlTableAlias (   $componentAlias,
  $tableName = null 
)
inherited

getSqlTableAlias some database such as Oracle need the identifier lengths to be < ~30 chars hence Doctrine creates as short identifier aliases as possible

this method is used for the creation of short table aliases, its also smart enough to check if an alias already exists for given component (componentAlias)

Parameters
string$componentAliasthe alias for the query component to search table alias for
string$tableNamethe table name from which the table alias is being created
Returns
string the generated / fetched short alias

Definition at line 664 of file Abstract.php.

{
$alias = array_search($componentAlias, $this->_tableAliasMap);
if ($alias !== false) {
return $alias;
}
if ($tableName === null) {
throw new Doctrine_Query_Exception("Couldn't get short alias for " . $componentAlias);
}
return $this->generateSqlTableAlias($componentAlias, $tableName);
}
Doctrine_Query_Abstract::getSqlTableAliasSeed (   $sqlTableAlias)
inherited

getSqlTableAliasSeed returns the alias seed for given table alias

Parameters
string$tableAliastable alias that identifies the alias seed
Returns
integer table alias seed

Definition at line 713 of file Abstract.php.

{
if ( ! isset($this->_tableAliasSeeds[$sqlTableAlias])) {
return 0;
}
return $this->_tableAliasSeeds[$sqlTableAlias];
}
Doctrine_Query_Abstract::getTableAliasMap ( )
inherited

getTableAliasMap returns all table aliases

Returns
array table aliases as an array

Definition at line 335 of file Abstract.php.

{
return $this->_tableAliasMap;
}
Doctrine_Query_Abstract::getType ( )
inherited

getType

returns the type of this query object by default the type is Doctrine_Query_Abstract::SELECT but if update() or delete() are being called the type is Doctrine_Query_Abstract::UPDATE and Doctrine_Query_Abstract::DELETE, respectively

See Also
Doctrine_Query_Abstract::SELECT
Doctrine_Query_Abstract::UPDATE
Doctrine_Query_Abstract::DELETE
Returns
integer return the query type

Definition at line 1827 of file Abstract.php.

{
return $this->_type;
}
Doctrine_Query_Abstract::getView ( )
inherited

getView returns the view associated with this query object (if any)

Returns
Doctrine_View the view associated with this query object

Definition at line 593 of file Abstract.php.

{
return $this->_view;
}
Doctrine_Query_Abstract::groupBy (   $groupby)
inherited

groupBy sets the GROUP BY part of the query

Parameters
string$groupbyQuery GROUP BY part
Returns
Doctrine_Query

Definition at line 1681 of file Abstract.php.

{
return $this->_addDqlQueryPart('groupby', $groupby);
}
Doctrine_Query_Abstract::hasAliasDeclaration (   $componentAlias)
inherited

hasAliasDeclaration whether or not this object has a declaration for given component alias

Parameters
string$componentAliasthe component alias the retrieve the declaration from
Returns
boolean

Definition at line 728 of file Abstract.php.

{
return isset($this->_queryComponents[$componentAlias]);
}
Doctrine_Query_Abstract::hasSqlTableAlias (   $sqlTableAlias)
inherited

hasSqlTableAlias whether or not this object has given tableAlias

Parameters
string$tableAliasthe table alias to be checked
Returns
boolean true if this object has given alias, otherwise false

Definition at line 324 of file Abstract.php.

{
return (isset($this->_tableAliasMap[$sqlTableAlias]));
}
Doctrine_Query_Abstract::having (   $having,
  $params = array() 
)
inherited

having sets the HAVING part of the query

Parameters
string$havingQuery HAVING part
mixed$paramsan array of parameters or a simple scalar
Returns
Doctrine_Query

Definition at line 1715 of file Abstract.php.

{
$this->_params['having'] = array();
if (is_array($params)) {
$this->_params['having'] = $params;
} else {
$this->_params['having'][] = $params;
}
return $this->_addDqlQueryPart('having', $having);
}
Doctrine_Query_Abstract::innerJoin (   $join,
  $params = array() 
)
inherited

innerJoin appends an INNER JOIN to the FROM part of the query

Parameters
string$joinQuery INNER JOIN
Returns
Doctrine_Query

Definition at line 1645 of file Abstract.php.

{
if (is_array($params)) {
$this->_params['join'] = array_merge($this->_params['join'], $params);
} else {
$this->_params['join'][] = $params;
}
return $this->_addDqlQueryPart('from', 'INNER JOIN ' . $join, true);
}
Doctrine_Query_Abstract::isLimitSubqueryUsed ( )
inherited

limitSubqueryUsed

Returns
boolean

Definition at line 603 of file Abstract.php.

{
return $this->_isLimitSubqueryUsed;
}
Doctrine_Query_Abstract::leftJoin (   $join,
  $params = array() 
)
inherited

leftJoin appends a LEFT JOIN to the FROM part of the query

Parameters
string$joinQuery LEFT JOIN
Returns
Doctrine_Query

Definition at line 1663 of file Abstract.php.

{
if (is_array($params)) {
$this->_params['join'] = array_merge($this->_params['join'], $params);
} else {
$this->_params['join'][] = $params;
}
return $this->_addDqlQueryPart('from', 'LEFT JOIN ' . $join, true);
}
Doctrine_Query_Abstract::limit (   $limit)
inherited

limit sets the Query query limit

Parameters
integer$limitlimit to be used for limiting the query results
Returns
Doctrine_Query

Definition at line 1749 of file Abstract.php.

{
return $this->_addDqlQueryPart('limit', $limit);
}
Doctrine_Query_Abstract::offset (   $offset)
inherited

offset sets the Query query offset

Parameters
integer$offsetoffset to be used for paginating the query
Returns
Doctrine_Query

Definition at line 1761 of file Abstract.php.

{
return $this->_addDqlQueryPart('offset', $offset);
}
Doctrine_Query_Abstract::orderBy (   $orderby)
inherited

Sets the ORDER BY part of the query. $q->orderBy('u.name'); $query->orderBy('u.birthDate DESC');

Parameters
string$orderbyQuery ORDER BY part
Returns
Doctrine_Query

Definition at line 1737 of file Abstract.php.

{
return $this->_addDqlQueryPart('orderby', $orderby);
}
Doctrine_Query_Abstract::orWhere (   $where,
  $params = array() 
)
inherited

Adds conditions to the WHERE part of the query $q->orWhere('u.role = ?', 'admin');

Parameters
string$whereQuery WHERE part
mixed$paramsAn array of parameters or a simple scalar
Returns
Doctrine_Query

Definition at line 1321 of file Abstract.php.

{
if (is_array($params)) {
$this->_params['where'] = array_merge($this->_params['where'], $params);
} else {
$this->_params['where'][] = $params;
}
if ($this->_hasDqlQueryPart('where')) {
$this->_addDqlQueryPart('where', 'OR', true);
}
return $this->_addDqlQueryPart('where', $where, true);
}
Doctrine_Query_Abstract::orWhereIn (   $expr,
  $params = array(),
  $not = false 
)
inherited

Adds IN condition to the query WHERE part, appending it with an OR operator. $q->orWhereIn('u.id', array(10, 23)) ->orWhereIn('u.id', 44); // will select all record with id equal to 10, 23 or 44

Parameters
string$exprThe operand of the IN
mixed$paramsAn array of parameters or a simple scalar
boolean$notWhether or not to use NOT in front of IN
Returns
Doctrine_Query

Definition at line 1387 of file Abstract.php.

{
// if there's no params, return (else we'll get a WHERE IN (), invalid SQL)
if (isset($params) and (count($params) == 0)) {
return $this;
}
if ($this->_hasDqlQueryPart('where')) {
$this->_addDqlQueryPart('where', 'OR', true);
}
return $this->_addDqlQueryPart('where', $this->_processWhereIn($expr, $params, $not), true);
}
Doctrine_Query_Abstract::orWhereNotIn (   $expr,
  $params = array() 
)
inherited

Adds NOT IN condition to the query WHERE part

Parameters
string$exprThe operand of the NOT IN
mixed$paramsAn array of parameters or a simple scalar
Returns
Doctrine_Query

Definition at line 1465 of file Abstract.php.

{
return $this->orWhereIn($expr, $params, true);
}
Doctrine_RawSql::parseDqlQuery (   $query)

parseDqlQuery parses an sql query and adds the parts to internal array. Overrides Doctrine_Query_Abstract::parseDqlQuery(). This implementation simply tokenizes the provided query string and uses them as SQL parts right away.

Parameters
string$queryquery to be parsed
Returns
Doctrine_RawSql this object

Definition at line 130 of file RawSql.php.

{
$this->_parseSelectFields($query);
$this->clear();
$tokens = $this->_tokenizer->sqlExplode($query, ' ');
$parts = array();
foreach ($tokens as $key => $part) {
$partLowerCase = strtolower($part);
switch ($partLowerCase) {
case 'select':
case 'from':
case 'where':
case 'limit':
case 'offset':
case 'having':
$type = $partLowerCase;
if ( ! isset($parts[$partLowerCase])) {
$parts[$partLowerCase] = array();
}
break;
case 'order':
case 'group':
$i = $key + 1;
if (isset($tokens[$i]) && strtolower($tokens[$i]) === 'by') {
$type = $partLowerCase . 'by';
$parts[$type] = array();
} else {
//not a keyword so we add it to the previous type
$parts[$type][] = $part;
}
break;
case 'by':
continue;
default:
//not a keyword so we add it to the previous type.
if ( ! isset($parts[$type][0])) {
$parts[$type][0] = $part;
} else {
// why does this add to index 0 and not append to the
// array. If it had done that one could have used
// parseQueryPart.
$parts[$type][0] .= ' '.$part;
}
}
}
$this->_sqlParts = $parts;
$this->_sqlParts['select'] = array();
return $this;
}
Doctrine_RawSql::parseDqlQueryPart (   $queryPartName,
  $queryPart,
  $append = false 
)

parseDqlQueryPart parses given DQL query part. Overrides Doctrine_Query_Abstract::parseDqlQueryPart(). This implementation does no parsing at all, except of the SELECT portion of the query which is special in RawSql queries. The entire remaining parts are used "as is", so the user of the RawSql query is responsible for writing SQL that is portable between different DBMS.

Parameters
string$queryPartNamethe name of the query part
string$queryPartquery part to be parsed
boolean$appendwhether 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
Returns
Doctrine_Query this object

Definition at line 81 of file RawSql.php.

{
if ($queryPartName == 'select') {
$this->_parseSelectFields($queryPart);
return $this;
}
if ( ! isset($this->_sqlParts[$queryPartName])) {
$this->_sqlParts[$queryPartName] = array();
}
if ( ! $append) {
$this->_sqlParts[$queryPartName] = array($queryPart);
} else {
$this->_sqlParts[$queryPartName][] = $queryPart;
}
return $this;
}
Doctrine_Query_Abstract::preQuery ( )
inherited

Blank hook methods which can be implemented in Doctrine_Query child classes

Returns
void

Definition at line 1156 of file Abstract.php.

{
}
Doctrine_Query_Abstract::removeDqlQueryPart (   $name)
inherited

removeDqlQueryPart removes a dql query part from the dql query part array

Parameters
string$namethe name of the query part to be removed
Exceptions
Doctrine_Query_Exceptionif trying to remove unknown query part
Returns
Doctrine_Query this object

Definition at line 470 of file Abstract.php.

{
if ( ! isset($this->_dqlParts[$name])) {
throw new Doctrine_Query_Exception('Unknown query part ' . $name);
}
if ($name == 'limit' || $name == 'offset') {
$this->_dqlParts[$name] = false;
} else {
$this->_dqlParts[$name] = array();
}
return $this;
}
Doctrine_Query_Abstract::removeSqlQueryPart (   $name)
inherited

removeSqlQueryPart removes a query part from the query part array

Parameters
string$namethe name of the query part to be removed
Exceptions
Doctrine_Query_Exceptionif trying to remove unknown query part
Returns
Doctrine_Query this object

Definition at line 447 of file Abstract.php.

{
if ( ! isset($this->_sqlParts[$name])) {
throw new Doctrine_Query_Exception('Unknown query part ' . $name);
}
if ($name == 'limit' || $name == 'offset' || $name == 'forUpdate') {
$this->_sqlParts[$name] = false;
} else {
$this->_sqlParts[$name] = array();
}
return $this;
}
Doctrine_Query_Abstract::select (   $select = null)
inherited

select sets the SELECT part of the query

Parameters
string$selectQuery SELECT part
Returns
Doctrine_Query

Definition at line 1526 of file Abstract.php.

{
$this->_type = self::SELECT;
if ($select) {
return $this->_addDqlQueryPart('select', $select);
} else {
return $this;
}
}
Doctrine_Query_Abstract::set (   $key,
  $value = null,
  $params = null 
)
inherited

set sets the SET part of the query

Parameters
string$updateQuery UPDATE part
Returns
Doctrine_Query

Definition at line 1603 of file Abstract.php.

{
if (is_array($key)) {
foreach ($key as $k => $v) {
$this->set($k, '?', array($v));
}
return $this;
} else {
if ($params !== null) {
if (is_array($params)) {
$this->_params['set'] = array_merge($this->_params['set'], $params);
} else {
$this->_params['set'][] = $params;
}
}
return $this->_addDqlQueryPart('set', $key . ' = ' . $value, true);
}
}
Doctrine_Query_Abstract::setConnection ( Doctrine_Connection  $connection)
inherited

Set the connection this query object should use

Parameters
Doctrine_Connection$connection
Returns
void

Definition at line 296 of file Abstract.php.

{
$this->_passedConn = true;
$this->_conn = $connection;
}
Doctrine_Query_Abstract::setOption (   $name,
  $value 
)
inherited

setOption

Parameters
string$nameoption name
string$valueoption value
Returns
Doctrine_Query this object

Definition at line 309 of file Abstract.php.

{
if ( ! isset($this->_options[$name])) {
throw new Doctrine_Query_Exception('Unknown option ' . $name);
}
$this->_options[$name] = $value;
}
Doctrine_Query_Abstract::setParams ( array  $params = array())
inherited

setParams

Parameters
array$params

Definition at line 526 of file Abstract.php.

{
$this->_params = $params;
}
Doctrine_Query_Abstract::setQueryCacheLifeSpan (   $timeToLive)
inherited

setQueryCacheLifeSpan

Parameters
integer$timeToLivehow long the cache entry is valid
Returns
Doctrine_Query this object

Definition at line 1958 of file Abstract.php.

{
if ($timeToLive !== null) {
$timeToLive = (int) $timeToLive;
}
$this->_queryCacheTTL = $timeToLive;
return $this;
}
Doctrine_Query_Abstract::setResultCacheHash (   $resultCacheHash)
inherited

Set the result cache hash to be used for storing the results in the cache driver

Parameters
string$resultCacheHash
Returns
void

Definition at line 1861 of file Abstract.php.

{
$this->_resultCacheHash = $resultCacheHash;
return $this;
}
Doctrine_Query_Abstract::setResultCacheLifeSpan (   $timeToLive)
inherited

setResultCacheLifeSpan

Parameters
integer$timeToLivehow long the cache entry is valid (in seconds)
Returns
Doctrine_Query this object

Definition at line 1932 of file Abstract.php.

{
if ($timeToLive !== null) {
$timeToLive = (int) $timeToLive;
}
$this->_resultCacheTTL = $timeToLive;
return $this;
}
Doctrine_Query_Abstract::setSqlQueryPart (   $name,
  $part 
)
inherited

setSqlQueryPart sets an SQL query part in the SQL query part array

Parameters
string$namethe name of the query part to be set
string$partquery part string
Exceptions
Doctrine_Query_Exceptionif trying to set unknown query part
Returns
Doctrine_Query this object

Definition at line 398 of file Abstract.php.

{
if ( ! isset($this->_sqlParts[$name])) {
throw new Doctrine_Query_Exception('Unknown query part ' . $name);
}
if ($name !== 'limit' && $name !== 'offset') {
if (is_array($part)) {
$this->_sqlParts[$name] = $part;
} else {
$this->_sqlParts[$name] = array($part);
}
} else {
$this->_sqlParts[$name] = $part;
}
return $this;
}
Doctrine_Query_Abstract::setView ( Doctrine_View  $view)
inherited

setView sets a database view this query object uses this method should only be called internally by doctrine

Parameters
Doctrine_View$viewdatabase view
Returns
void

Definition at line 582 of file Abstract.php.

{
$this->_view = $view;
}
Doctrine_Query_Abstract::update (   $from = null)
inherited

update sets the UPDATE part of the query

Parameters
string$updateQuery UPDATE part
Returns
Doctrine_Query

Definition at line 1587 of file Abstract.php.

{
$this->_type = self::UPDATE;
if ($from != null) {
return $this->_addDqlQueryPart('from', $from);
}
return $this;
}
Doctrine_Query_Abstract::useQueryCache (   $driver = true,
  $timeToLive = null 
)
inherited

useQueryCache

Parameters
Doctrine_Cache_Interface | bool$drivercache driver
integer$timeToLivehow long the cache entry is valid
Returns
Doctrine_Query this object

Definition at line 1888 of file Abstract.php.

{
if ($driver !== null && $driver !== true && $driver !== false && ! ($driver instanceOf Doctrine_Cache_Interface)) {
$msg = 'First argument should be instance of Doctrine_Cache_Interface or null.';
throw new Doctrine_Query_Exception($msg);
}
$this->_queryCache = $driver;
if ($timeToLive !== null) {
$this->setQueryCacheLifeSpan($timeToLive);
}
return $this;
}
Doctrine_Query_Abstract::useResultCache (   $driver = true,
  $timeToLive = null,
  $resultCacheHash = null 
)
inherited

useResultCache

Parameters
Doctrine_Cache_Interface | bool$drivercache driver
integer$timeToLivehow long the cache entry is valid
string$resultCacheHashThe key to use for storing the queries result cache entry
Returns
Doctrine_Query this object

Definition at line 1840 of file Abstract.php.

{
if ($driver !== null && $driver !== true && ! ($driver instanceOf Doctrine_Cache_Interface)) {
$msg = 'First argument should be instance of Doctrine_Cache_Interface or null.';
throw new Doctrine_Query_Exception($msg);
}
$this->_resultCache = $driver;
$this->_resultCacheHash = $resultCacheHash;
if ($timeToLive !== null) {
$this->setResultCacheLifeSpan($timeToLive);
}
return $this;
}
Doctrine_Query_Abstract::where (   $where,
  $params = array() 
)
inherited

where sets the WHERE part of the query

Parameters
string$joinQuery WHERE part
mixed$paramsan array of parameters or a simple scalar
Returns
Doctrine_Query

Definition at line 1694 of file Abstract.php.

{
$this->_params['where'] = array();
if (is_array($params)) {
$this->_params['where'] = $params;
} else {
$this->_params['where'][] = $params;
}
return $this->_addDqlQueryPart('where', $where);
}
Doctrine_Query_Abstract::whereIn (   $expr,
  $params = array(),
  $not = false 
)
inherited

Adds IN condition to the query WHERE part. Alias to

See Also
andWhereIn().
Parameters
string$exprthe operand of the IN
mixed$paramsan array of parameters or a simple scalar
boolean$notwhether or not to use NOT in front of IN
Returns
Doctrine_Query

Definition at line 1344 of file Abstract.php.

{
return $this->andWhereIn($expr, $params, $not);
}
Doctrine_Query_Abstract::whereNotIn (   $expr,
  $params = array() 
)
inherited

Adds NOT IN condition to the query WHERE part. $q->whereNotIn('u.id', array(10, 20)); // will exclude users with id 10 and 20 from the select

Parameters
string$exprthe operand of the NOT IN
mixed$paramsan array of parameters or a simple scalar
Returns
Doctrine_Query this object

Definition at line 1440 of file Abstract.php.

{
return $this->whereIn($expr, $params, true);
}

Field Documentation

const Doctrine_Query_Abstract::CREATE = 4
inherited

constant for CREATE queries

Definition at line 63 of file Abstract.php.

const Doctrine_Query_Abstract::DELETE = 1
inherited

constant for DELETE queries

Definition at line 48 of file Abstract.php.

const Doctrine_Query_Abstract::INSERT = 3
inherited

constant for INSERT queries

Definition at line 58 of file Abstract.php.

const Doctrine_Query_Abstract::SELECT = 0
inherited

QUERY TYPE CONSTANTS constant for SELECT queries

Definition at line 43 of file Abstract.php.

const Doctrine_Query_Abstract::STATE_CLEAN = 1
inherited
Todo:
document the query states (and the transitions between them).

A query object is in CLEAN state when it has NO unparsed/unprocessed DQL parts.

Definition at line 69 of file Abstract.php.

const Doctrine_Query_Abstract::STATE_DIRECT = 3
inherited

A query is in DIRECT state when ... ?

Definition at line 80 of file Abstract.php.

const Doctrine_Query_Abstract::STATE_DIRTY = 2
inherited

A query object is in state DIRTY when it has DQL parts that have not yet been parsed/processed.

Definition at line 75 of file Abstract.php.

const Doctrine_Query_Abstract::STATE_LOCKED = 4
inherited

A query object is on LOCKED state when ... ?

Definition at line 85 of file Abstract.php.

const Doctrine_Query_Abstract::UPDATE = 2
inherited

constant for UPDATE queries

Definition at line 53 of file Abstract.php.


The documentation for this class was generated from the following file: