summaryrefslogtreecommitdiffstats
path: root/system/database/DB_active_rec.php
diff options
context:
space:
mode:
authorRick Ellis <rick.ellis@ellislab.com>2008-10-27 00:55:00 +0100
committerRick Ellis <rick.ellis@ellislab.com>2008-10-27 00:55:00 +0100
commit0efc4d331fa1e8212c0aa01bf9c220810d14f61c (patch)
treefcb1331b0bf7bf0ac0df0da791793258782de5ea /system/database/DB_active_rec.php
parent1152b6eda7c2a12796ffe395c5107c923c743195 (diff)
Fixed order_by bug #5704
Diffstat (limited to 'system/database/DB_active_rec.php')
-rw-r--r--system/database/DB_active_rec.php64
1 files changed, 54 insertions, 10 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index e3798254c..b270b6fc1 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -267,16 +267,38 @@ class CI_DB_active_record extends CI_DB_driver {
{
foreach ((array)$from as $val)
{
- // Extract any aliases that might exist. We use this information
- // in the _protect_identifiers to know whether to add a table prefix
- $this->_track_aliases($val);
+ if (strpos($val, ',') !== FALSE)
+ {
+ foreach (explode(',', $val) as $v)
+ {
+ $v = trim($v);
+ $this->_track_aliases($v);
- $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
-
- if ($this->ar_caching === TRUE)
+ $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+
+ if ($this->ar_caching === TRUE)
+ {
+ $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+ $this->ar_cache_exists[] = 'from';
+ }
+ }
+
+ }
+ else
{
- $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
- $this->ar_cache_exists[] = 'from';
+ $val = trim($val);
+
+ // Extract any aliases that might exist. We use this information
+ // in the _protect_identifiers to know whether to add a table prefix
+ $this->_track_aliases($val);
+
+ $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+
+ if ($this->ar_caching === TRUE)
+ {
+ $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE);
+ $this->ar_cache_exists[] = 'from';
+ }
}
}
@@ -873,8 +895,30 @@ class CI_DB_active_record extends CI_DB_driver {
{
$direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC';
}
-
- $orderby_statement = $this->_protect_identifiers($orderby).$direction;
+
+
+ if (strpos($orderby, ',') !== FALSE)
+ {
+ $temp = array();
+ foreach (explode(',', $orderby) as $part)
+ {
+ $part = trim($part);
+ if ( ! in_array($part, $this->ar_aliased_tables))
+ {
+ $part = $this->_protect_identifiers(trim($part));
+ }
+
+ $temp[] = $part;
+ }
+
+ $orderby = implode(', ', $temp);
+ }
+ else
+ {
+ $orderby = $this->_protect_identifiers($orderby);
+ }
+
+ $orderby_statement = $orderby.$direction;
$this->ar_orderby[] = $orderby_statement;
if ($this->ar_caching === TRUE)