summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-06-08 15:23:01 +0200
committerAndrey Andreev <narf@bofh.bg>2012-06-08 15:23:01 +0200
commitd25c589dc3bbfc83fb59bbeb1a3046b99bf694f8 (patch)
tree648b94fd7e326250b2beaf951f0e6b49aded8628
parent1be495483749c661f785cdef574ac84b2176d43a (diff)
Add OFFSET support for SQL Server 2012
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php6
-rw-r--r--user_guide_src/source/changelog.rst1
2 files changed, 7 insertions, 0 deletions
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index d2b73aee4..e3e97f14b 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -462,6 +462,12 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
protected function _limit($sql, $limit, $offset)
{
+ // As of SQL Server 2012 (11.0.*) OFFSET is supported
+ if ($offset != 0 && version_compare($this->version(), '11', '>='))
+ {
+ return $sql .= ' OFFSET '. (int) $offset .' ROW FETCH NEXT '. (int) $limit .' ROW ONLY';
+ }
+
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.($limit + $offset).' ', $sql);
}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 0880247fc..25b42b2e0 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -98,6 +98,7 @@ Release Date: Not Released
- Added support for optimize_table() in :doc:`Database Utility <database/utilities>`.
- Added escaping with QUOTE_IDENTIFIER setting detection.
- Added port handling support for UNIX-based systems (MSSQL driver).
+ - Added OFFSET support for SQL Server 2012 and above.
- Improved support of the Oracle (OCI8) driver, including:
- Added DSN string support (Easy Connect and TNS).
- Added support for dropping tables to :doc:`Database Forge <database/forge>`.