Skip to content

Commit

Permalink
Force ORDER BY usage with OFFSET-FETCH on SQL Server
Browse files Browse the repository at this point in the history
Close #3128
Close #3332
Close #3334
Close #3335
  • Loading branch information
narfbg committed Nov 18, 2014
1 parent 71f0099 commit ed3fc51
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
Expand Up @@ -304,6 +304,9 @@ protected function _limit($sql)
// As of SQL Server 2012 (11.0.*) OFFSET is supported
if (version_compare($this->version(), '11', '>='))
{
// SQL Server OFFSET-FETCH can be used only with the ORDER BY clause
empty($this->qb_orderby) && $sql .= ' ORDER BY 1';

return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY';
}

Expand Down
3 changes: 3 additions & 0 deletions system/database/drivers/sqlsrv/sqlsrv_driver.php
Expand Up @@ -494,6 +494,9 @@ protected function _limit($sql)
// As of SQL Server 2012 (11.0.*) OFFSET is supported
if (version_compare($this->version(), '11', '>='))
{
// SQL Server OFFSET-FETCH can be used only with the ORDER BY clause
empty($this->qb_orderby) && $sql .= ' ORDER BY 1';

return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY';
}

Expand Down
2 changes: 1 addition & 1 deletion system/libraries/Session/drivers/Session_cookie.php
Expand Up @@ -486,7 +486,7 @@ protected function _sess_read()
$db_cache = $this->CI->db->cache_on;
$this->CI->db->cache_off();

$query = $this->CI->db->limit(1)->get($this->sess_table_name);
$query = $this->CI->db->get($this->sess_table_name);

// Was caching in effect?
if ($db_cache)
Expand Down

0 comments on commit ed3fc51

Please sign in to comment.