Implement the COUNT(*) query for pagination

This commit is contained in:
Kijin Sung 2020-06-29 21:32:25 +09:00
parent 7e96affa1a
commit 84a7b915b7
2 changed files with 119 additions and 14 deletions

View file

@ -19,6 +19,7 @@ class Query extends VariableBase
public $navigation = null;
public $select_distinct = false;
public $update_duplicate = false;
public $requires_pagination = false;
/**
* Attributes for subqueries in the <tables> or <columns> section.
@ -95,6 +96,16 @@ class Query extends VariableBase
return $this->_params;
}
/**
* Check if this query requires pagination.
*
* @return bool
*/
public function requiresPagination(): bool
{
return $this->requires_pagination;
}
/**
* Generate a SELECT query string.
*
@ -514,9 +525,19 @@ class Query extends VariableBase
{
list($is_expression, $offset) = $navigation->offset->getValue($this->_args);
}
// If page is available, set the offset and require pagination for this query.
if ($page > 0)
{
$offset = $list_count * ($page - 1);
if ($this->type === 'SELECT')
{
$this->requires_pagination = true;
}
}
else
{
$page = 1;
}
// Return the LIMIT/OFFSET clause.