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 /system/database/drivers | |
parent | 71f0099cf443eaa98e2510b3fc274da4715b3b36 (diff) |
Force ORDER BY usage with OFFSET-FETCH on SQL Server
Close #3128
Close #3332
Close #3334
Close #3335
Diffstat (limited to 'system/database/drivers')
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 3 | ||||
-rw-r--r-- | system/database/drivers/sqlsrv/sqlsrv_driver.php | 3 |
2 files changed, 6 insertions, 0 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'; } |