lib: Add sub query mode to the DbQuery

refs #9009
This commit is contained in:
Eric Lippmann 2015-06-03 14:13:15 +02:00
parent 8e88864f4a
commit ae78613443
1 changed files with 32 additions and 1 deletions

View File

@ -23,6 +23,15 @@ class DbQuery extends SimpleQuery
*/
protected $db;
/**
* Whether or not the query is a sub query
*
* Sub queries are automatically wrapped in parentheses
*
* @var bool
*/
protected $isSubQuery = false;
/**
* Select query
*
@ -71,6 +80,27 @@ class DbQuery extends SimpleQuery
parent::init();
}
/**
* Get whether or not the query is a sub query
*/
public function getIsSubQuery()
{
return $this->isSubQuery;
}
/**
* Set whether or not the query is a sub query
*
* @param bool $isSubQuery
*
* @return $this
*/
public function setIsSubQuery($isSubQuery = true)
{
$this->isSubQuery = (bool) $isSubQuery;
return $this;
}
public function setUseSubqueryCount($useSubqueryCount = true)
{
$this->useSubqueryCount = $useSubqueryCount;
@ -331,7 +361,8 @@ class DbQuery extends SimpleQuery
*/
public function __toString()
{
return (string) $this->getSelectQuery();
$select = (string) $this->getSelectQuery();
return $this->getIsSubQuery() ? ('(' . $select . ')') : $select;
}
/**