Returns true if this Query uses aggregate functions in either a GROUP BY clause or in the
select columns
@return bool
17859
protected function hasAggregates() {
		if ($this->groups) {
			return true;
		}
		foreach ($this->columns as $column) {
			if (strpos($column, '(') !== false) {
				return true;
			}
		}
		return false;
	}
833193
public function isQuery()
    {
        if (false === $this->hasFilter(self::FILTER_QUERY)) {
            return false;
        }
        $query = $this->getFilter(self::FILTER_QUERY);
        return isset($query[self::FILTER_QUERY_CRITERIA]);
    }
1275448
function count()
    {
        if ( $this->count !== null )
            return $this->count;

        if ( $this->query === null )
        {
            $this->query = $this->generateSQL();
        }
        if ( $this->query === false )
            return 0;
        $query = "SELECT count(*) AS count {$this->query}";
        $db = eZDB::instance();
        $rows = $db->arrayQuery( $query );
        if ( count( $rows ) == 0 )
            $this->count = 0;
        else
            $this->count = $rows[0]['count'];
        return $this->count;
    }
1152643
public function toSql()
    {
        return implode(' ', array_filter(array(
            $this->_clause(($this->_distinct
                ? 'SELECT DISTINCT' : 'SELECT'), $this->_select),
            $this->_clause('FROM', $this->_from),
            implode(' ', $this->_joins),
            $this->_clause('WHERE', $this->_where),
            $this->_clause('GROUP BY', $this->_group),
            $this->_clause('HAVING', $this->_having),
            $this->_clause('ORDER BY', $this->_order),
            $this->_limit,
            $this->_lock
            )));
    }
4211
public function count($columns = '*')
    {
        if (! is_array($columns)) {
            $columns = [$columns];
        }

        return (int) $this->aggregate(__FUNCTION__, $columns);
    }
1149348
public function group()
    {
        $columns = func_get_args();
        $group = '';
        $i = 0;
        //
        if ($columns) {
            foreach ($columns as $value) {
                if (!$i) {
                    $order .= ' group by '.$value;
                } else {
                    $order .= ','.$value;
                }
                $i = 1;
            }
        }
        //
        $this->group = $group;
        //
        return $this;
    }
1239375
private function hasLayouts(): bool
    {
        $queryBuilder = $this->connection->createQueryBuilder();
        $queryBuilder->select('COUNT(id) as count')
            ->from('ngbm_layout');

        $result = $queryBuilder->execute()->fetchAll(PDO::FETCH_ASSOC);

        return (int) $result[0]['count'] > 0;
    }
939193
public function count() {
        $sql    = $this->getSQL();
        $values = $this->values;
        if ($sql) {
            try {
                $statement = $this->dialect->prepare($sql);
                foreach ($values as $value) {
                    list ($name, $val, $type) = $value;
                    if (!$statement->bindValue($name, $val, $type)) {
                        $this->errorSQL    = $sql;
                        $this->errorValues = $values->__toString();
                        $this->error       = 'can not bind the value ' . $val . '[' . $type . '] to the argument:' . $name;

                        return false;
                    }
                }
                $rst = $statement->execute();
                $cnt = false;
                if ($rst) {
                    $cnt = $statement->rowCount();
                } else {
                    $this->dumpSQL($statement);
                }
                if ($statement) {
                    $statement->closeCursor();
                    $statement = null;
                }
                QueryBuilder::addSqlCount();

                return $cnt;
            } catch (\PDOException $e) {
                $this->exception   = $e;
                $this->error       = $e->getMessage();
                $this->errorSQL    = $sql;
                $this->errorValues = $values->__toString();

                return false;
            }
        } else {
            $this->error       = 'Can not generate the delete SQL';
            $this->errorSQL    = '';
            $this->errorValues = $values->__toString();
        }

        return false;
    }
792227
public function count()
    {
        $query   = $this->query();
        $myQuery = $query instanceof EloquentBuilder ? clone $this->query() : $query;
        if ($query instanceof Collection) {
            return $query->count();
        }

        $finalQuery = $this->applyScopes($myQuery);
        $this->applyGlobalGroupScope($finalQuery);


        // if its a normal query ( no union, having and distinct word )
        // replace the select with static text to improve performance
        $connection = $finalQuery->getQuery()->getConnection();

        if (!Str::contains(Str::lower($finalQuery->toSql()), ['union', 'having', 'distinct', 'order by', 'group by'])) {

            $row_count = $connection->getQueryGrammar()->wrap('row_count');
            return $connection->table($connection->raw('(' . $finalQuery->toSql() . ') count_row_table'))->select($connection->raw("'1' as {$row_count}"))->setBindings($finalQuery->getBindings())->count();
        }

        return $connection->table($connection->raw('(' . $finalQuery->toSql() . ') count_row_table'))
                        ->setBindings($finalQuery->getBindings())->count();
    }
933226
public function isSupported()
    {
        $sql = 'SHOW TABLES LIKE :table';

        $stat = $this->pdo->prepare($sql);
        $stat->bindValue(':table', $this->table);
        $stat->execute();

        return (bool) $stat->fetch(\PDO::FETCH_ASSOC);
    }
1064185
public function count()
    {
        if (isset($this->_resultset)) {
            return $this->_resultset->count();
        } elseif (isset($this->_limit) || isset($this->_group)) {
            return $this->execute()->count();
        } else {
            $query = clone $this;

            return (int)$query->select("count(*) count")->execute()->scalar();
        }
    }
933587
public function query()
    {
        $stmt = call_user_func_array([$this, 'executeSql'], func_get_args());
        if (ActiveRecord::lastError())
            return false;
        return $stmt->fetchAll();
    }
549575
public function deleteOutdated(): bool
    {
        $sql =  'DELETE FROM `' . $this->table . '`'
                . ' WHERE `' . $this->savetimeField . '`<'
                . '(' . time() . '-`' . $this->timestampField . '`)';
        return $this->db->query($sql);
    }
667280
public function getSelectQuery()
    {
        $sql = 'SELECT ' . $this->getSelect();
        $sql .= "\nFROM " . $this->getFrom();
        if ($this->where) {
            $sql .= "\nWHERE " . $this->getWhere();
        }
        if ($this->groupBy) {
            $sql .= "\nGROUP BY " . $this->getGroupBy();
        }
        if ($this->having) {
            $sql .= "\nHAVING " . $this->getHaving();
        }
        if ($this->orderBy) {
            $sql .= "\nORDER BY " . $this->getOrderBy();
        }
        if ($this->limit) {
            $sql .= "\nLIMIT " . $this->getLimit();
        }

        return $sql;
    }
661776
private function aggregate(Aggregation $q)
    {
        $sql = $this->buildAggregateSql($q);
        $statement = $this->getConnection()->query($sql);
        $value = $statement->fetch();
        if (is_array($value)) {
            $value = end($value);
        }

        return false !== strpos((string) $value, '.') ? floatval($value) : intval($value);
    }
708361
function hasRangeData()
    {
        $db = eZDB::instance();
        $tableList = $db->eZTableList();
        if ( array_key_exists( 'ezisbn_group', $tableList ) and
             array_key_exists( 'ezisbn_group_range', $tableList ) and
             array_key_exists( 'ezisbn_registrant_range', $tableList ) )
        {
            $query = "SELECT count( ezisbn_group.id ) AS count
                      FROM ezisbn_group, ezisbn_group_range, ezisbn_registrant_range
                      WHERE ezisbn_group.group_number >= ezisbn_group_range.from_number AND
                            ezisbn_group.group_number <= ezisbn_group_range.to_number AND
                            ezisbn_group.id=ezisbn_registrant_range.isbn_group_id";
            $countArray = $db->arrayQuery( $query );
            return ( $countArray[0]['count'] > 0 );
        }
        else
            return false;
    }
1031168
public function count_by()
    {
        if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
        {
            $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
        }

        $where = func_get_args();
        $this->_set_where($where);

        return $this->_database->count_all_results($this->_table);
    }