Helper method to handle the execution of "SELECT COUNT(...) ..." SQL
statements. To be invoked inside a {@link #doSelect(Callable)} or
{@link #doSelectStatic(Callable)} method.

@param aQuery
The SELECT COUNT query
@return a non-negative row count
163547
@Nonnull
  public static final Number getSelectCountResultObj (@Nonnull final Query aQuery)
  {
    final Number ret = (Number) aQuery.getSingleResult ();
    return ret != null ? ret : Integer.valueOf (0);
  }
592192
private boolean isCountQuery()
    {
        if (getKunderaQuery().getSelectStatement() != null)
        {
            final Expression selectClause = getKunderaQuery().getSelectStatement().getSelectClause();

            if (selectClause instanceof SelectClause)
            {
                final Expression expression = ((SelectClause) selectClause).getSelectExpression();

                return expression instanceof CountFunction;
            }
        }

        return false;
    }
1053483
def count(self):
        
        if self._batch:
            raise CQLEngineException("Only inserts, updates, and deletes are available in batch mode")

        if self._count is None:
            query = self._select_query()
            query.count = True
            result = self._execute(query)
            count_row = result.one().popitem()
            self._count = count_row[1]
        return self._count
244215
public String selectCountByExample(MappedStatement ms) {
        Class<?> entityClass = getEntityClass(ms);
        StringBuilder sql = new StringBuilder("SELECT ");
        if (isCheckExampleEntityClass()) {
            sql.append(SqlHelper.exampleCheck(entityClass));
        }
        sql.append(SqlHelper.exampleCountColumn(entityClass));
        sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
        sql.append(SqlHelper.exampleWhereClause());
        sql.append(SqlHelper.exampleForUpdate());
        return sql.toString();
    }
250370
@Override
	public long dynamicQueryCount(DynamicQuery dynamicQuery,
		Projection projection) {
		return cpDefinitionOptionRelPersistence.countWithDynamicQuery(dynamicQuery,
			projection);
	}
275710
public function countAll($executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('p')
            ->select('COUNT(p)');

        return $executeQuery ? $queryBuilder->getQuery()->getSingleScalarResult() : $queryBuilder;
    }
43914
@Override
	public int countByG_A_P(long groupId, boolean active, boolean primary) {
		FinderPath finderPath = FINDER_PATH_COUNT_BY_G_A_P;

		Object[] finderArgs = new Object[] { groupId, active, primary };

		Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(4);

			query.append(_SQL_COUNT_COMMERCEWAREHOUSE_WHERE);

			query.append(_FINDER_COLUMN_G_A_P_GROUPID_2);

			query.append(_FINDER_COLUMN_G_A_P_ACTIVE_2);

			query.append(_FINDER_COLUMN_G_A_P_PRIMARY_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(groupId);

				qPos.add(active);

				qPos.add(primary);

				count = (Long)q.uniqueResult();

				finderCache.putResult(finderPath, finderArgs, count);
			}
			catch (Exception e) {
				finderCache.removeResult(finderPath, finderArgs);

				throw processException(e);
			}
			finally {
				closeSession(session);
			}
		}

		return count.intValue();
	}
112408
final public function count($table = '', $resetselect = true)
    {

        if (!empty($table)) {
            $this->traceTableAlias($table);
            $this->fromTable($table);
        }
        $sql = $this->compile($this->_countString . $this->identifiers('totalcount'), true);
        $statement = $this->DBO->prepare($sql);

        $results = $statement->execute();

        if ($resetselect) $this->resetSelect();
        if ($results->rowCount() == 0) return '0';

        $row = $results->fetchObject();

        return $row->totalcount;
    }
591601
private String setSelectQuery(List<String> columns) {
        if (columns != null && !columns.isEmpty()) {
            return CQLTranslator.SELECT_QUERY;
        }
        if (kunderaQuery.isAggregated()) {
            Expression selectExpression =
                ((SelectClause) kunderaQuery.getSelectStatement().getSelectClause()).getSelectExpression();
            // create query depending on function
            if (selectExpression instanceof CountFunction) {
                return CQLTranslator.SELECT_COUNT_QUERY;
            }
        }
        return CQLTranslator.SELECTALL_QUERY;
    }
542906
public static FutureRowCount fetchRowCount(MultivaluedMap<String, String> queryParams, Query query) {
        String reqTotalCount = getSingleParam(queryParams.get(REQ_TOTAL_COUNT_PARAM_NAME));
        if (reqTotalCount != null && !"false".equalsIgnoreCase(reqTotalCount) && !"0".equals(reqTotalCount)) {
            return query.findFutureCount();
        }
        return null;
    }
1239815
public static int getRowCount(Connection connection, String tableReference) throws SQLException {
        Statement st = connection.createStatement();
        int rowCount = 0;
        try {
            ResultSet rs = st.executeQuery(String.format("select count(*) rowcount from %s", TableLocation.parse(tableReference)));
            try {
                if(rs.next()) {
                    rowCount = rs.getInt(1);
                }
            } finally {
                rs.close();
            }
        }finally {
            st.close();
        }
        return rowCount;
    }
475384
@Override
	public long count(final String col) {
		final String expr = col != null
				? tableMetadata.getColumn(CaseFormat.CAMEL_CASE.convert(col)).getColumnIdentifier()
				: "*";
		StringBuilder sql = new StringBuilder("select count(").append(expr).append(") from (")
				.append(System.lineSeparator())
				.append(aggregationSourceSql())
				.append(System.lineSeparator())
				.append(") t_");
		context().setSql(sql.toString());
		try (ResultSet rs = agent().query(context())) {
			rs.next();
			return rs.getLong(1);
		} catch (final SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.SELECT, e);
		}
	}
705830
public long countQuery(SearchRequestBuilder countRequestBuilder,
            long timeoutMillis) {
        countRequestBuilder.setSize(0);
        return searchQuery("countQuery", countRequestBuilder, timeoutMillis)
                .getHits().getTotalHits();
    }
440333
def count(self) -> "CountQuery":
        
        return CountQuery(
            db=self._db,
            model=self.model,
            q_objects=self._q_objects,
            annotations=self._annotations,
            custom_filters=self._custom_filters,
        )
1270251
protected int[] getRowCounts(Vector inTable,
                                 Vector inSchema) throws Exception {

        if (!displayRowCounts) {
            return (null);
        }

        String rowCountSelect = "SELECT COUNT(*) FROM ";
        int[]  counts;
        String name;

        counts = new int[inTable.size()];

        try {
            Statement select = rowConn.createStatement();

            for (int i = 0; i < inTable.size(); i++) {
                try {
                    String schemaPart = (String) inSchema.elementAt(i);

                    schemaPart = schemaPart == null ? ""
                                                    : (schemaPart + '.');
                    name       = schemaPart + (String) inTable.elementAt(i);

                    ResultSet resultSet = select.executeQuery(rowCountSelect
                        + name);

                    while (resultSet.next()) {
                        counts[i] = resultSet.getInt(1);
                    }
                } catch (Exception e) {
                    System.err.println("Unable to get row count for table "
                                       + inSchema.elementAt(i) + '.'
                                       + inTable.elementAt(i)
                                       + ".  Using value '0': " + e);
                }
            }
        } catch (Exception e) {
            CommonSwing.errorMessage(e);
        }

        return (counts);
    }
1266271
@Override
    public int rowCount() {
        int result = 0;
        if (!columnList.isEmpty()) {
            // all the columns have the same number of elements, so we can check any of them
            result = columnList.get(0).size();
        }
        return result;
    }
877842
private SQLQuery query(Class<?>... entity) {
		SQLQuery q = session.createSQLQuery(sql);
		if (entity.length == 1) {
			q.addEntity(entity[0]);
		}
		for (Map.Entry<String, Type> scalar : scalars.entrySet()) {
			q.addScalar(scalar.getKey(), scalar.getValue());
		}
		for (int i = 0; i < positionedParameters.length; i++) {
			q.setParameter(i, positionedParameters[i]);
		}
		for (Map.Entry<String, Object> entry : namedParameters.entrySet()) {
			Object value = entry.getValue();
			if (Types.isArray(value)) {
				Object[] parameter = (Object[]) value;
				if (parameter.length == 0) {
					throw new HibernateException(String.format("Invalid named parameter |%s|. Empty array.", entry.getKey()));
				}
				q.setParameterList(entry.getKey(), parameter);
			} else if (Types.isCollection(value)) {
				Collection<?> parameter = (Collection<?>) value;
				if (parameter.isEmpty()) {
					throw new HibernateException(String.format("Invalid named parameter |%s|. Empty list.", entry.getKey()));
				}
				q.setParameterList(entry.getKey(), parameter);
			} else {
				q.setParameter(entry.getKey(), value);
			}
		}
		if (offset > 0) {
			q.setFirstResult(offset);
		}
		if (rowsCount > 0) {
			q.setMaxResults(rowsCount);
		}
		return q;
	}