Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function buildSelectFoundRowsQuery(ISelectBuilder $query)
 {
     if ($query->getExecuted() && $query->getUseCalcFoundRows()) {
         return 'SELECT FOUND_ROWS()';
     }
     $distinctSql = $query->getDistinct() ? ' DISTINCT' : '';
     return 'SELECT count(*) FROM (SELECT' . $distinctSql . ' ' . $this->buildSelectQueryBody($query) . ') AS `mainQuery`';
 }
 /**
  * Строит sql-запрос на выборку данных без LIMIT и ORDER BY
  * @param ISelectBuilder $query запрос
  * @throws IException если не удалось построить запрос
  * @return string
  */
 protected function buildSelectQueryBody($query)
 {
     $distinctSql = $query->getDistinct() ? ' DISTINCT' : '';
     $whatSql = $this->buildSelectWhatPart($query);
     $fromSql = $this->buildSelectFromPart($query);
     $whereSql = $this->buildWherePart($query);
     $groupBySql = $this->buildSelectGroupByPart($query);
     $havingSql = $this->buildSelectHavingPart($query);
     $joinSql = $this->buildSelectJoinPart($query);
     $result = 'SELECT' . $distinctSql . ' ' . $whatSql . $fromSql . $joinSql . $whereSql . $groupBySql . $havingSql;
     return $result;
 }