/**
  * @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'));
 }
Example #2
0
 /**
  * @return BinaryExpression
  **/
 public static function eqId($field, Identifiable $object)
 {
     return self::eq($field, DBValue::create($object->getId()));
 }
 /**
  * @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;
 }
Example #4
0
 /**
  * @return SelectQuery
  **/
 public function makeTotalCountQuery()
 {
     return OSQL::select()->get(SQLFunction::create('count', DBValue::create('*')))->from($this->getTable());
 }