picodb(mssql): teach picodb to use TOP for limits on MSSQL

This commit is contained in:
Joe Nahmias
2022-07-08 15:32:29 -04:00
committed by Frédéric Guillot
parent 5493c2997e
commit 37bc859df5
3 changed files with 38 additions and 2 deletions

View File

@@ -119,6 +119,14 @@ class Table
*/
private $sqlSelect = '';
/**
* SQL TOP clause
*
* @access private
* @var string
*/
private $sqlTop = '';
/**
* SQL joins
*
@@ -578,7 +586,11 @@ class Table
public function limit($value)
{
if (! is_null($value)) {
$this->sqlLimit = ' LIMIT '.(int) $value;
if ($this->db->getDriver()->useTop) {
$this->sqlTop = ' TOP ('.(int) $value.') ';
} else {
$this->sqlLimit = ' LIMIT '.(int) $value;
}
}
return $this;
@@ -693,7 +705,8 @@ class Table
$this->groupBy = $this->db->escapeIdentifierList($this->groupBy);
return trim(sprintf(
'SELECT %s FROM %s %s %s %s %s %s %s',
'SELECT %s %s FROM %s %s %s %s %s %s %s',
$this->sqlTop,
$this->sqlSelect,
$this->db->escapeIdentifier($this->name),
implode(' ', $this->joins),