Example #1
0
File: Query.php Project: titon/db
 /**
  * Instantiate a new query object that will be used for sub-queries.
  *
  * @return \Titon\Db\Query\SubQuery
  */
 public function subQuery()
 {
     $query = new SubQuery(Query::SELECT, $this->getRepository());
     $query->fields(func_get_args());
     return $query;
 }
Example #2
0
 /**
  * Format a sub-query.
  *
  * @param \Titon\Db\Query\SubQuery $query
  * @return string
  * @throws \Titon\Db\Exception\UnsupportedQueryStatementException
  */
 public function formatSubQuery(SubQuery $query)
 {
     // Reset the alias since statement would have double aliasing
     $alias = $query->getAlias();
     $query->asAlias(null);
     // @codeCoverageIgnoreStart
     if (method_exists($this, 'buildSelect')) {
         $output = sprintf($this->getClause(self::SUB_QUERY), trim($this->buildSelect($query), ';'));
     } else {
         throw new UnsupportedQueryStatementException('Sub-query building requires a buildSelect() method');
     }
     // @codeCoverageIgnoreEnd
     if ($alias) {
         $output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
     }
     if ($filter = $query->getFilter()) {
         $output = $this->getKeyword($filter) . ' ' . $output;
     }
     return $output;
 }