From 000f89d16ca48e5dd6a858911fd91484d7f1251f Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 23:26:15 +0000 Subject: --- system/database/DB_active_rec.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index f4c13cc42..47933ed78 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -412,7 +412,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { - $prefix = (count($this->ar_where) == 0) ? '' : $type; + $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type; if (is_null($v) && ! $this->_has_operator($k)) { @@ -1675,13 +1675,20 @@ class CI_DB_active_record extends CI_DB_driver { return; } - $ar_items = array('select', 'from', 'join', 'where', 'like', 'groupby', 'having', 'orderby', 'set'); - - foreach ($ar_items as $ar_item) + foreach (array('select', 'from', 'join', 'where', 'like', 'groupby', 'having', 'orderby', 'set') as $val) { - $ar_cache_item = 'ar_cache_'.$ar_item; - $ar_item = 'ar_'.$ar_item; - $this->$ar_item = array_unique(array_merge($this->$ar_item, $this->$ar_cache_item)); + $ar_variable = 'ar_'.$val; + $ar_cache_var = 'ar_cache_'.$val; + + if (count($this->$ar_cache_var) == 0) + { + continue; + } + + // This doesn't seem to work right, per bug report #4995 + // $this->$ar_variable = array_unique(array_merge($this->$ar_variable, $this->$ar_cache_var)); + + $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable)); } // If we are "protecting identifiers" we need to examine the "from" -- cgit v1.2.3-24-g4f1b