diff options
author | Andrey Andreev <narf@devilix.net> | 2014-11-18 10:12:35 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2014-11-18 10:12:35 +0100 |
commit | ed3fc511e4e5aa7b171fd806e73401ace2497b32 (patch) | |
tree | 7be44673224139a6bf4dba41f18fbfb7378a1dba | |
parent | 71f0099cf443eaa98e2510b3fc274da4715b3b36 (diff) |
Force ORDER BY usage with OFFSET-FETCH on SQL Server
Close #3128
Close #3332
Close #3334
Close #3335
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 3 | ||||
-rw-r--r-- | system/database/drivers/sqlsrv/sqlsrv_driver.php | 3 | ||||
-rw-r--r-- | system/libraries/Session/drivers/Session_cookie.php | 2 |
3 files changed, 7 insertions, 1 deletions
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index 78591755a..42627139b 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -304,6 +304,9 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { // 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'; } diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 6afde6153..130271115 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -494,6 +494,9 @@ class CI_DB_sqlsrv_driver extends CI_DB { // 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'; } diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 0001dc2d8..21ded899a 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -486,7 +486,7 @@ class CI_Session_cookie extends CI_Session_driver { $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) |