本文整理汇总了PHP中Doctrine\DBAL\Query\QueryBuilder::setFirstResult方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::setFirstResult方法的具体用法?PHP QueryBuilder::setFirstResult怎么用?PHP QueryBuilder::setFirstResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Query\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::setFirstResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @param QueryBuilder $queryBuilder
* @param $callback
* @param int|null $limit
* @param int $maxAttempts
* @throws DBALWalkerException
* @throws DBALException
*/
public function run(QueryBuilder $queryBuilder, $callback, $limit = null, $maxAttempts = 10)
{
if (!is_callable($callback)) {
throw new DBALWalkerException('$callback is not callable');
}
if (!is_null($limit)) {
$queryBuilder->setMaxResults($limit);
} else {
$limit = $queryBuilder->getMaxResults();
}
if (is_null($limit)) {
$limit = PHP_INT_MAX;
}
$offset = 0;
do {
$rows = [];
$errors = $maxAttempts;
while (true) {
try {
$rows = $queryBuilder->setFirstResult($offset)->execute()->fetchAll();
break;
} catch (DBALException $e) {
if ($errors-- == 0) {
throw $e;
}
$queryBuilder->getConnection()->connect();
}
}
call_user_func($callback, $rows, $offset, $limit);
$offset += $limit;
} while (count($rows) >= $limit);
}
示例2: incorporateDbalQueryBuilder
/**
* @internal
*/
private function incorporateDbalQueryBuilder(QueryBuilder $qb, FilterInterface $filter)
{
$criteria = $this->getFilteringCriteria($filter);
// extraindo os rootAliases, pois o DBAL\QueryBuilder não tem
$fromPart = $qb->getQueryPart('from');
$rootAliases = array();
foreach ($fromPart as $part) {
$rootAliases[] = $part['alias'];
}
$visitor = new DbalQueryExpressionVisitor($qb->getConnection(), $rootAliases, $this->fieldMap);
if ($whereExpression = $criteria->getWhereExpression()) {
$qb->andWhere($visitor->dispatch($whereExpression));
$qb->setParameters($visitor->getParameters());
}
if ($criteria->getOrderings()) {
foreach ($criteria->getOrderings() as $sort => $order) {
$qb->addOrderBy($visitor->getFieldName($sort), $order);
}
}
if (($firstResult = $criteria->getFirstResult()) !== null) {
$qb->setFirstResult($firstResult);
}
if (($maxResults = $criteria->getMaxResults()) !== null) {
$qb->setMaxResults($maxResults);
}
}
示例3: match
/**
* @see \ComPHPPuebla\Doctrine\Query\Specification::match()
*/
public function match(QueryBuilder $qb)
{
if ($this->has('page')) {
$this->page = $this->get('page');
$this->initPageSize();
$qb->setFirstResult($this->calculateOffset())->setMaxResults($this->pageSize);
}
}
示例4: setDBALQuery
/**
* Prepare listing instance from Doctrine DBAL QueryBuilder.
*
* Total rows count for Listing instance must be set separately.
*
* @param DBALQueryBuilder
* @param boolean
* @param boolean
* @return self
*/
public function setDBALQuery(DBALQueryBuilder $query, $appendLimit = true, $appendOrder = true)
{
if ($appendLimit) {
$query->setFirstResult($this->offset())->setMaxResults($this->limit());
}
if ($appendOrder && $this->order()) {
call_user_func_array([$query, 'orderBy'], (array) $this->order());
}
$this->setItems($query->execute()->fetchAll());
return $this;
}
示例5: rewind
/**
* Rewind
*/
public function rewind()
{
//Only perform rewind if current item is not the first element
if ($this->currentKey !== 0) {
$this->batchPosition = 0;
$this->queryBuilder->setFirstResult(0);
$this->queryBuilder->setMaxResults($this->batchSize);
/* @var $stmt \Doctrine\DBAL\Statement */
$stmt = $this->queryBuilder->execute();
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
$this->currentItem = null;
$this->currentKey = -1;
$this->statement = $stmt;
$this->next();
}
}
示例6: getDataQuery
/**
* Build the data query
*
* @return QueryBuilder
*/
public function getDataQuery()
{
$this->buildFilteredQuery();
if ($this->offset !== null) {
$this->currentQueryBuilder->setFirstResult($this->offset);
}
if ($this->length !== null) {
$this->currentQueryBuilder->setMaxResults($this->length);
}
if ($this->orders !== null) {
foreach ($this->orders as $order) {
list($column, $dir) = $order;
$this->currentQueryBuilder->addOrderBy($column->sourceSort, $dir);
}
}
if (isset($this->conf->group)) {
$this->currentQueryBuilder->groupBy($this->conf->group);
}
return $this->currentQueryBuilder;
}
示例7: offset
/**
* @param int $offset
* @return $this
*/
public function offset($offset)
{
$this->queryBuilder->setFirstResult($offset);
return $this;
}
示例8: skip
public function skip($rows_count)
{
parent::setFirstResult($rows_count);
return $this;
}
示例9: next
public function next()
{
$this->offset += $this->maxresults;
$this->qb->setFirstResult($this->offset);
}
示例10: setFirstResult
/**
* Sets the position of the first result to retrieve (the "offset").
*
* @param integer $firstResult The first result to return.
*
* @return self
*/
public function setFirstResult($firstResult)
{
$this->qb->setFirstResult($firstResult);
return $this;
}
示例11: gridFiltersExt
function gridFiltersExt(\Doctrine\DBAL\Query\QueryBuilder &$dbalQuery, $params, $aColumnMapping)
{
if (is_array($aColumnMapping) && count($aColumnMapping) > 0) {
foreach ($aColumnMapping as $value) {
if ($value["ref"] == $params['sSortBy']) {
if (!$value["table"]) {
$params['sSortBy'] = $value["col"];
} else {
$params['sSortBy'] = $value["table"] . "." . $value["col"];
}
break;
}
}
}
if (is_array($params['aFilters'])) {
foreach ($params['aFilters'] as $oFilter) {
$sFieldname = $oFilter->field;
if (is_array($aColumnMapping) && count($aColumnMapping) > 0) {
foreach ($aColumnMapping as $value) {
if ($value["ref"] == $sFieldname) {
/**
* Update Catalin:
* Exista situatii cand nu am nevoie de tabel.coloana ex cand folosesc functii gen GROUP_CONCAT
*/
if (!$value["table"]) {
$sFieldname = $value["col"];
} else {
$sFieldname = $value["table"] . "." . $value["col"];
}
break;
}
}
}
$sValue = $oFilter->value;
$sCompare = isset($oFilter->comparison) ? $oFilter->comparison : NULL;
$sFilterType = $oFilter->type;
switch ($sFilterType) {
case 'string':
$dbalQuery->andWhere($sFieldname . " like '%{$sValue}%'");
break;
case 'list':
if (strstr($sValue, ',')) {
$aValues = explode(',', $sValue);
$this->db->andWhere_in($sFieldname, $aValues);
} else {
$this->db->andWhere($sFieldname, $sValue);
}
break;
case 'boolean':
$this->db->andWhere($sFieldname, $sValue);
break;
case 'combo':
$this->db->andWhere($sFieldname, $sValue);
break;
case 'numeric':
switch ($sCompare) {
case 'eq':
$dbalQuery->andWhere($sFieldname . '=' . $sValue);
break;
case 'lt':
$dbalQuery->andWhere($sFieldname . '<' . $sValue);
break;
case 'gt':
$dbalQuery->andWhere($sFieldname . '>' . $sValue);
break;
case 'gte':
$dbalQuery->andWhere($sFieldname . '>=' . $sValue);
break;
case 'lte':
$dbalQuery->andWhere($sFieldname . '<=' . $sValue);
break;
}
break;
case 'date':
switch ($sCompare) {
case 'eq':
$dbalQuery->andWhere("DATE_FORMAT({$sFieldname}, '%Y-%m-%d')='" . date('Y-m-d', strtotime($sValue)) . "'");
break;
case 'lt':
$dbalQuery->andWhere("DATE_FORMAT({$sFieldname}, '%Y-%m-%d')<='" . date('Y-m-d', strtotime($sValue)) . "'");
break;
case 'gt':
$dbalQuery->andWhere("DATE_FORMAT({$sFieldname}, '%Y-%m-%d')>='" . date('Y-m-d', strtotime($sValue)) . "'");
break;
}
break;
}
}
}
if (!$params['bIsExport']) {
$dbalQuery->orderBy($params['sSortBy'], $params['sDir']);
$dbalQuery->setFirstResult($params['sStart']);
$dbalQuery->setMaxResults($params['sLimit']);
} else {
//Limita maxima de inregistrari
$dbalQuery->setMaxResults(50000);
}
}
示例12: addPagination
/**
* Adds pagination parameters to the query.
*
* @param QueryBuilder $queryBuilder
* the query
* @param $skip
* the rows to skip
* @param $amount
* the maximum amount of rows
*/
protected function addPagination(QueryBuilder $queryBuilder, $skip, $amount)
{
$queryBuilder->setMaxResults(9999999999);
if ($amount !== null) {
$queryBuilder->setMaxResults(abs(intval($amount)));
}
if ($skip !== null) {
$queryBuilder->setFirstResult(abs(intval($skip)));
}
}
示例13: buildLimit
/**
* Build up dynamilcy the LIMIT part
* @param QueryBuilder $qb
* @param array $limit
* @return self
*/
protected function buildLimit(QueryBuilder $qb, array $limit = [])
{
switch (count($limit)) {
case 2:
$qb->setFirstResult((int) $limit[0]);
$qb->setMaxResults((int) $limit[1]);
break;
case 1:
$qb->setMaxResults((int) $limit[0]);
break;
}
return $this;
}
示例14: testSetFirstResult
public function testSetFirstResult()
{
$qb = new QueryBuilder($this->conn);
$qb->setFirstResult(10);
$this->assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
$this->assertEQuals(10, $qb->getFirstResult());
}
示例15: setFirstResultDelegatesToConcreteQueryBuilder
/**
* @test
*/
public function setFirstResultDelegatesToConcreteQueryBuilder()
{
$this->concreteQueryBuilder->setFirstResult(Argument::cetera())->shouldBeCalled()->willReturn($this->subject);
$this->subject->setFirstResult(1);
}