/**
  * @return SelectQuery
  **/
 public function makeCountQuery()
 {
     $query = $this->makeFetchQuery();
     if ($query->isDistinct()) {
         $countFunction = SQLFunction::create('count', DBField::create($this->container->getDao()->getIdName(), $this->container->getDao()->getTable()))->setAggregateDistinct();
         $query->unDistinct();
     } else {
         $countFunction = SQLFunction::create('count', DBValue::create('*'));
     }
     return $query->dropFields()->dropOrder()->dropLimit()->get($countFunction->setAlias('count'));
 }
Beispiel #2
0
 /**
  * @return SQLFunction
  **/
 protected function getFunction(Criteria $criteria, JoinCapableQuery $query)
 {
     Assert::isNotNull($this->property);
     return SQLFunction::create('count', $this->property ? $criteria->getDao()->guessAtom($this->property, $query) : $criteria->getDao()->getIdName());
 }
 /**
  * @return JoinCapableQuery
  **/
 public function process(Criteria $criteria, JoinCapableQuery $query)
 {
     Assert::isNotNull($this->property);
     return $query->get(SQLFunction::create($this->getFunctionName(), $criteria->getDao()->guessAtom($this->property, $query))->setAlias($this->alias));
 }
 /**
  * @return DialectString
  * FIXME: DBI-result, method works only for PostgreSQL.
  * Research how to generate series of values in MySQL and implement
  * this.
  **/
 private function getSeriesGenerator($start, $stop, $step = null)
 {
     if (!$step) {
         $result = SQLFunction::create('generate_series', DBValue::create($start)->castTo(DataType::create(DataType::INTEGER)->getName()), DBValue::create($stop)->castTo(DataType::create(DataType::INTEGER)->getName()));
     } else {
         $result = SQLFunction::create('generate_series', DBValue::create($start)->castTo(DataType::create(DataType::INTEGER)->getName()), DBValue::create($stop)->castTo(DataType::create(DataType::INTEGER)->getName()), DBValue::create($step)->castTo(DataType::create(DataType::INTEGER)->getName()));
     }
     return $result;
 }
 public function toDialectString(Dialect $dialect)
 {
     return '(' . $dialect->toFieldString(SQLFunction::create('lower', $this->left)) . ' = ' . $dialect->toValueString(is_string($this->right) ? mb_strtolower($this->right) : SQLFunction::create('lower', $this->right)) . ')';
 }
Beispiel #6
0
 public function getQueryResult(SelectQuery $query, $expires = Cache::DO_NOT_CACHE)
 {
     if ($expires !== Cache::DO_NOT_CACHE && ($list = $this->getCachedByQuery($query))) {
         return $list;
     } else {
         $list = $this->fetchList($query);
         $count = clone $query;
         $count = DBPool::getByDao($this->dao)->queryRow($count->dropFields()->dropOrder()->limit(null, null)->get(SQLFunction::create('COUNT', '*')->setAlias('count')));
         return $this->cacheByQuery($query, $list ? QueryResult::create()->setList($list)->setCount($count['count'])->setQuery($query) : QueryResult::create(), $expires);
     }
 }
Beispiel #7
0
 /**
  * @return SelectQuery
  **/
 public function makeTotalCountQuery()
 {
     return OSQL::select()->get(SQLFunction::create('count', DBValue::create('*')))->from($this->getTable());
 }