Prepare the simple count select

@param  Select $select
@return Select
13821
protected function prepareSelect(Select $select) {
		$select->reset(Select::COLUMNS)
		       ->reset(Select::LIMIT_OFFSET)
		       ->reset(Select::LIMIT_COUNT)
		       ->reset(Select::ORDER)
		       ->columns([self::COUNT_COLUMN => 'count(*)']);

		return $select;
	}
934988
protected function getCountQuery(): Select
    {
        if ($this->countQuery instanceof Select) {
            return $this->countQuery;
        }

        if ($this->searchTerm !== null && $this->searchFields === null) {
            $fields = $this->getFields();
            $searchFields = [];
            foreach ($fields as $field) {
                $searchFields[] = $field['name'];
            }
        } else {
            $searchFields = null;
        }

        $query = clone $this;
        $query->resetFields();
        $query->resetLimit();
        $query->resetOrderBy();
        $query->field('COUNT(*)', 'total');

        if ($this->resetGroupBy) {
            $query->resetGroupBy();
        }

        if ($searchFields !== null) {
            $query->setSearchFields($searchFields);
        }

        return $query;
    }
771441
public function selectBridge(Select $select)
    {
        if ($this->usePaginator === true) {
            return $this->initPaginator($select);
        }

        $this->result = $this->tableGateway->selectBridge($select);

        return $this->result;
    }
598407
public function selectWith(\Zend\Db\Sql\Select $select)
    {
        if ($this->usePaginator === true) {
            return $this->initPaginator($select);
        }

        $this->result = $this->tableGateway->selectWith($select);

        return $this->result;
    }
158996
public function setSelect($select)
    {
        if (is_int($select)) {
            $this->select = $select;
        } else {
            $msg = "Select must be an integer, '" . gettype($select) . "' given.";
        }
    }
647103
public static function findAndDelete($id, $select = ['*'])
    {
        $data = static::find($id, $select);

        static::$builder->delete();

        return $data;
    }
120525
public void sqlToCount(Select select, String name) {
        SelectBody selectBody = select.getSelectBody();
        // 是否能简化count查询
        List<SelectItem> COUNT_ITEM = new ArrayList<SelectItem>();
        COUNT_ITEM.add(new SelectExpressionItem(new Column("count(" + name +")")));
        if (selectBody instanceof PlainSelect && isSimpleCount((PlainSelect) selectBody)) {
            ((PlainSelect) selectBody).setSelectItems(COUNT_ITEM);
        } else {
            PlainSelect plainSelect = new PlainSelect();
            SubSelect subSelect = new SubSelect();
            subSelect.setSelectBody(selectBody);
            subSelect.setAlias(TABLE_ALIAS);
            plainSelect.setFromItem(subSelect);
            plainSelect.setSelectItems(COUNT_ITEM);
            select.setSelectBody(plainSelect);
        }
    }
302209
public function select($select = '*')
    {
        //if select is an array
        if (is_array($select)) {
            //transform into a string
            $select = implode(', ', $select);
        }
        
        $this->select = $select;
        
        return $this;
    }
1219488
private function prepareSelect(array $select)
    {
        if ($select['sql'] instanceof SelectQuery) {
            $columnsCount = count($this->columns);

            $selectColumnsCount = count($select['sql']->getColumns());

            if ($selectColumnsCount and $selectColumnsCount !== $columnsCount) {
                throw new SqlException('INSERT select columns count does not match.'
                                        . ' Expected ' . $columnsCount . ', got ' . $selectColumnsCount);
            }
            [$sql, $params] = $select['sql']->toSql();

            $select['sql'] = $sql;

            $select['params'] = $params;
        }

        return $select;
    }
468000
protected function fetchCollection(Select $select)
    {
        $collection = [];

        /** @var EntityInterface $entity */
        foreach ($this->selectWith($select) as $entity) {
            $collection[$entity->getIdentifier()] = $entity;
        }

        return $collection;
    }
249564
protected function processSelect($select, $context)
    {
        if ($select instanceof Aggregate) {
            $column = $this->processColumnOrSubQuery($select->column, $context);
            if ($column === $select->column) {
                return $select;
            } else {
                return new Aggregate($select->function, $column);
            }
        }

        return $this->processColumnOrSubQuery($select, $context);
    }
645393
protected function prepareSelect($select, $from, $where='', $group='', $having='', $order='', $limit=''){     
        $sql= "SELECT " . $select;
        $sql.= " FROM " . $from;
        if($where != '' && $where != NULL){$sql.= " WHERE " . $where;}        
        $sql.= $group;
        if($having != '' && $having != NULL){$sql.= " HAVING " . $having;}
        $sql.= $order;
        $sql.= $limit;
        //Preparo la consulta y la retorno
        return $this->connection->prepare($sql);
    }
287347
protected function selectDeletedRecords($select)
    {
        $modelClass = $this->modelClass;
        if ($modelClass::isRecoverable()) {
            if (!$this->deleted) {
                $select = clone $select;
                $select->where([
                    $modelClass::deletedAtAttribute() => $modelClass::deletedAtEmptyValue()
                ]);
            } elseif ($this->deleted === 'only') {
                $select = clone $select;
                $select->where([
                    $modelClass::deletedAtAttribute() => $modelClass::deletedAtValue()
                ]);
            }
        }
        return $select;
    }
849870
public function select($selects = array())
    {
        $this->type = self::SELECT;

        if (!empty($selects)) {
            $this->parts['select'] = array_merge($this->parts['select'], (array) $selects);
        }

        return $this;
    }
136447
public static long count(ISelect select) {
        Page<?> page = startPage(1, -1, true);
        select.doSelect();
        return page.getTotal();
    }
986015
public function select($select, $distinct = null)
    {
        if (null !== $distinct) {
            $this->distinct($distinct);
        }

        if (empty($select)) {
            return $this;
        }

        $builder = $this->getLookupBuilder();
        $parts = [];
        if (is_array($select)) {
            foreach ($select as $key => $part) {
                if (is_string($part)) {
                    $newSelect = $builder->buildJoin($this, $part);
                    if ($newSelect) {
                        list($alias, $column) = $newSelect;
                        $parts[$key] = $alias.'.'.$column;
                    } else {
                        $parts[$key] = $part;
                    }
                } else {
                    $parts[$key] = $part;
                }
            }
        } elseif (is_string($select)) {
            $newSelect = $builder->buildJoin($this, $select);
            if ($newSelect) {
                list($alias, $column) = $newSelect;
                $parts[$alias] = $column;
            } else {
                $parts[] = $select;
            }
        } else {
            $parts[] = $select;
        }

        $this->sqlParts['select'] = $parts;

        return $this;
    }
1355509
public function selectCount($as = 'count', $what = null)
    {
        if (!$what) {
            $what = '`' . $this->getTable() . '`.id';
        }
        $this->getQuery()->select([$as => 'COUNT(' . $what . ')']);

        return $this;
    }