summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2017-07-03 13:13:08 +0200
committerAndrey Andreev <narf@devilix.net>2017-07-03 13:13:08 +0200
commit59bae57503865f6dcea91fc20fd2729b2e79bb74 (patch)
tree63a57feba1c9741f812db33d80bbfebdea73e7e1
parent7af882026c476f2a64376512b33ff890d2792a8d (diff)
[ci skip] Fix #5168
-rw-r--r--system/database/DB_query_builder.php14
-rw-r--r--user_guide_src/source/changelog.rst1
2 files changed, 7 insertions, 8 deletions
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 9216651aa..7677f5b40 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -1403,11 +1403,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
// ORDER BY usage is often problematic here (most notably
// on Microsoft SQL Server) and ultimately unnecessary
// for selecting COUNT(*) ...
- if ( ! empty($this->qb_orderby))
- {
- $orderby = $this->qb_orderby;
- $this->qb_orderby = NULL;
- }
+ $qb_orderby = $this->qb_order_by;
+ $qb_cache_orderby = $this->qb_cache_orderby;
+ $this->qb_orderby = $this->qb_cache_orderby = NULL;
$result = ($this->qb_distinct === TRUE OR ! empty($this->qb_groupby) OR ! empty($this->qb_cache_groupby) OR $this->qb_limit OR $this->qb_offset)
? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results")
@@ -1417,10 +1415,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
$this->_reset_select();
}
- // If we've previously reset the qb_orderby values, get them back
- elseif ( ! isset($this->qb_orderby))
+ else
{
- $this->qb_orderby = $orderby;
+ $this->qb_orderby = $qb_orderby;
+ $this->qb_cache_orderby = $qb_cache_orderby;
}
if ($result->num_rows() === 0)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index fd7485f64..77648a937 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -12,6 +12,7 @@ Bug fixes for 3.1.6
-------------------
- Fixed a bug (#5164) - :doc:`Loader Library <libraries/loader>` method ``library()`` ignored requests to load libraries previously assigned to super-object properties named differently than the library name.
+- Fixed a bug (#5168) - :doc:`Query Builder <database/query_builder>` method ``count_all_results()`` produced erroneous queries on Microsoft SQL Server when ``ORDER BY`` clauses are cached.
Version 3.1.5
=============