summaryrefslogtreecommitdiffstats
path: root/system/database/DB_active_rec.php
diff options
context:
space:
mode:
authorRonald Beilsma <beilsma@gmail.com>2012-01-10 15:45:31 +0100
committerRonald Beilsma <beilsma@gmail.com>2012-01-10 15:45:31 +0100
commit25dcb93d05bd098e89188ea0691adf72228bd131 (patch)
tree37d3d769f2e64bebb48a98378c7aee3ab4c17efe /system/database/DB_active_rec.php
parentdb66eb38cfc4a2ab6c8816b8f7663211232d4f4e (diff)
parente9a5a862a1252548b463aa738e50e8d9bfd01379 (diff)
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into develop
Diffstat (limited to 'system/database/DB_active_rec.php')
-rw-r--r--system/database/DB_active_rec.php409
1 files changed, 128 insertions, 281 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index b7f43945c..424735157 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
@@ -18,7 +18,7 @@
*
* @package CodeIgniter
* @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
@@ -43,23 +43,23 @@ class CI_DB_active_record extends CI_DB_driver {
protected $return_delete_sql = FALSE;
protected $reset_delete_data = FALSE;
- protected $ar_select = array();
- protected $ar_distinct = FALSE;
- protected $ar_from = array();
- protected $ar_join = array();
- protected $ar_where = array();
- protected $ar_like = array();
- protected $ar_groupby = array();
- protected $ar_having = array();
- protected $ar_keys = array();
- protected $ar_limit = FALSE;
- protected $ar_offset = FALSE;
- protected $ar_order = FALSE;
- protected $ar_orderby = array();
- protected $ar_set = array();
- protected $ar_wherein = array();
+ protected $ar_select = array();
+ protected $ar_distinct = FALSE;
+ protected $ar_from = array();
+ protected $ar_join = array();
+ protected $ar_where = array();
+ protected $ar_like = array();
+ protected $ar_groupby = array();
+ protected $ar_having = array();
+ protected $ar_keys = array();
+ protected $ar_limit = FALSE;
+ protected $ar_offset = FALSE;
+ protected $ar_order = FALSE;
+ protected $ar_orderby = array();
+ protected $ar_set = array();
+ protected $ar_wherein = array();
protected $ar_aliased_tables = array();
- protected $ar_store_array = array();
+ protected $ar_store_array = array();
protected $ar_where_group_started = FALSE;
protected $ar_where_group_count = 0;
@@ -77,9 +77,7 @@ class CI_DB_active_record extends CI_DB_driver {
protected $ar_cache_set = array();
protected $ar_no_escape = array();
- protected $ar_cache_no_escape = array();
-
- // --------------------------------------------------------------------
+ protected $ar_cache_no_escape = array();
/**
* Select
@@ -113,6 +111,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
}
+
return $this;
}
@@ -188,7 +187,7 @@ class CI_DB_active_record extends CI_DB_driver {
* select_max()
* select_min()
* select_avg()
- * select_sum()
+ * select_sum()
*
* @param string the field
* @param string an alias
@@ -214,7 +213,6 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_protect_identifiers($type.'('.trim($select).')').' AS '.$this->_protect_identifiers(trim($alias));
-
$this->ar_select[] = $sql;
if ($this->ar_caching === TRUE)
@@ -280,30 +278,27 @@ class CI_DB_active_record extends CI_DB_driver {
{
$v = trim($v);
$this->_track_aliases($v);
-
- $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE);
+ $v = $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_from[] = $v;
$this->ar_cache_exists[] = 'from';
}
}
-
}
else
{
$val = trim($val);
- // Extract any aliases that might exist. We use this information
+ // 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);
+ $this->ar_from[] = $val = $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_from[] = $val;
$this->ar_cache_exists[] = 'from';
}
}
@@ -340,23 +335,19 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
- // Extract any aliases that might exist. We use this information
+ // 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($table);
// Strip apart the condition and protect the identifiers
if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match))
{
- $match[1] = $this->_protect_identifiers($match[1]);
- $match[3] = $this->_protect_identifiers($match[3]);
-
- $cond = $match[1].$match[2].$match[3];
+ $cond = $this->_protect_identifiers($match[1]).$match[2].$this->_protect_identifiers($match[3]);
}
// Assemble the JOIN statement
- $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
+ $this->ar_join[] = $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond;
- $this->ar_join[] = $join;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_join[] = $join;
@@ -429,7 +420,7 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($key as $k => $v)
{
- $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_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))
{
@@ -442,7 +433,6 @@ class CI_DB_active_record extends CI_DB_driver {
if ($escape === TRUE)
{
$k = $this->_protect_identifiers($k, FALSE, $escape);
-
$v = ' '.$this->escape($v);
}
@@ -457,7 +447,6 @@ class CI_DB_active_record extends CI_DB_driver {
}
$this->ar_where[] = $prefix.$k.$v;
-
if ($this->ar_caching === TRUE)
{
$this->ar_cache_where[] = $prefix.$k.$v;
@@ -571,11 +560,9 @@ class CI_DB_active_record extends CI_DB_driver {
$this->ar_wherein[] = $this->escape($value);
}
- $prefix = (count($this->ar_where) == 0) ? '' : $type;
-
- $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
+ $prefix = (count($this->ar_where) === 0) ? '' : $type;
+ $this->ar_where[] = $where_in = $prefix.$this->_protect_identifiers($key).$not.' IN ('.implode(', ', $this->ar_wherein).') ';
- $this->ar_where[] = $where_in;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_where[] = $where_in;
@@ -679,20 +666,18 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($field as $k => $v)
{
$k = $this->_protect_identifiers($k);
-
- $prefix = (count($this->ar_like) == 0) ? '' : $type;
-
+ $prefix = (count($this->ar_like) === 0) ? '' : $type;
$v = $this->escape_like_str($v);
- if ($side == 'none')
+ if ($side === 'none')
{
$like_statement = $prefix." $k $not LIKE '{$v}'";
}
- elseif ($side == 'before')
+ elseif ($side === 'before')
{
$like_statement = $prefix." $k $not LIKE '%{$v}'";
}
- elseif ($side == 'after')
+ elseif ($side === 'after')
{
$like_statement = $prefix." $k $not LIKE '{$v}%'";
}
@@ -715,6 +700,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
+
return $this;
}
@@ -730,13 +716,10 @@ class CI_DB_active_record extends CI_DB_driver {
public function group_start($not = '', $type = 'AND ')
{
$type = $this->_group_get_type($type);
-
$this->ar_where_group_started = TRUE;
+ $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
+ $this->ar_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->ar_where_group_count).' (';
- $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type;
- $value = $prefix . $not . str_repeat(' ', ++$this->ar_where_group_count) . ' (';
-
- $this->ar_where[] = $value;
if ($this->ar_caching)
{
$this->ar_cache_where[] = $value;
@@ -790,16 +773,14 @@ class CI_DB_active_record extends CI_DB_driver {
*/
public function group_end()
{
- $value = str_repeat(' ', $this->ar_where_group_count--) . ')';
+ $this->ar_where_group_started = FALSE;
+ $this->ar_where[] = $value = str_repeat(' ', $this->ar_where_group_count--) . ')';
- $this->ar_where[] = $value;
if ($this->ar_caching)
{
$this->ar_cache_where[] = $value;
}
- $this->ar_where_group_started = FALSE;
-
return $this;
}
@@ -845,15 +826,16 @@ class CI_DB_active_record extends CI_DB_driver {
if ($val != '')
{
- $this->ar_groupby[] = $this->_protect_identifiers($val);
+ $this->ar_groupby[] = $val = $this->_protect_identifiers($val);
if ($this->ar_caching === TRUE)
{
- $this->ar_cache_groupby[] = $this->_protect_identifiers($val);
+ $this->ar_cache_groupby[] = $val;
$this->ar_cache_exists[] = 'groupby';
}
}
}
+
return $this;
}
@@ -909,7 +891,7 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($key as $k => $v)
{
- $prefix = (count($this->ar_having) == 0) ? '' : $type;
+ $prefix = (count($this->ar_having) === 0) ? '' : $type;
if ($escape === TRUE)
{
@@ -949,7 +931,7 @@ class CI_DB_active_record extends CI_DB_driver {
*/
public function order_by($orderby, $direction = '', $escape = TRUE)
{
- if (strtolower($direction) == 'random')
+ if (strtolower($direction) === 'random')
{
$orderby = ''; // Random results want or don't need a field name
$direction = $this->_random_keyword;
@@ -960,7 +942,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
- if ((strpos($orderby, ',') !== FALSE) && ($escape === TRUE))
+ if ((strpos($orderby, ',') !== FALSE) && $escape === TRUE)
{
$temp = array();
foreach (explode(',', $orderby) as $part)
@@ -976,7 +958,7 @@ class CI_DB_active_record extends CI_DB_driver {
$orderby = implode(', ', $temp);
}
- else if ($direction != $this->_random_keyword)
+ elseif ($direction != $this->_random_keyword)
{
if ($escape === TRUE)
{
@@ -984,9 +966,8 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
- $orderby_statement = $orderby.$direction;
+ $this->ar_orderby[] = $orderby_statement = $orderby.$direction;
- $this->ar_orderby[] = $orderby_statement;
if ($this->ar_caching === TRUE)
{
$this->ar_cache_orderby[] = $orderby_statement;
@@ -1121,9 +1102,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit, $offset);
}
- $sql = $this->_compile_select();
-
- $result = $this->query($sql);
+ $result = $this->query($this->_compile_select());
$this->_reset_select();
return $result;
}
@@ -1145,20 +1124,17 @@ class CI_DB_active_record extends CI_DB_driver {
$this->from($table);
}
- $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
-
- $query = $this->query($sql);
+ $result = $this->query($this->_compile_select($this->_count_string.$this->_protect_identifiers('numrows')));
$this->_reset_select();
- if ($query->num_rows() == 0)
+ if ($result->num_rows() === 0)
{
return 0;
}
- $row = $query->row();
+ $row = $result->row();
return (int) $row->numrows;
}
-
// --------------------------------------------------------------------
/**
@@ -1188,9 +1164,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit, $offset);
}
- $sql = $this->_compile_select();
-
- $result = $this->query($sql);
+ $result = $this->query($this->_compile_select());
$this->_reset_select();
return $result;
}
@@ -1213,11 +1187,11 @@ class CI_DB_active_record extends CI_DB_driver {
$this->set_insert_batch($set);
}
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
if ($this->db_debug)
{
- //No valid data array. Folds in cases where keys and values did not match up
+ // No valid data array. Folds in cases where keys and values did not match up
return $this->display_error('db_must_use_set');
}
return FALSE;
@@ -1227,30 +1201,19 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
}
// Batch this baby
- for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
+ for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
{
-
- $sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100));
-
- //echo $sql;
-
- $this->query($sql);
+ $this->query($this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)));
}
$this->_reset_write();
-
-
return TRUE;
}
@@ -1294,7 +1257,6 @@ class CI_DB_active_record extends CI_DB_driver {
else
{
$clean = array();
-
foreach ($row as $value)
{
$clean[] = $this->escape($value);
@@ -1398,24 +1360,16 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _validate_insert($table = '')
{
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
}
else
@@ -1444,31 +1398,22 @@ class CI_DB_active_record extends CI_DB_driver {
$this->set($set);
}
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
}
$sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));
-
$this->_reset_write();
return $this->query($sql);
}
@@ -1543,7 +1488,6 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit, $this->ar_like);
-
$this->_reset_write();
return $this->query($sql);
}
@@ -1559,34 +1503,28 @@ class CI_DB_active_record extends CI_DB_driver {
*
* @access public
* @param string the table to update data on
- * @return string
+ * @return bool
*/
protected function _validate_update($table = '')
{
if (count($this->ar_set) == 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
}
else
{
$this->ar_from[0] = $table;
}
+
+ return TRUE;
}
// --------------------------------------------------------------------
@@ -1599,7 +1537,7 @@ class CI_DB_active_record extends CI_DB_driver {
* @param string the table to retrieve the results from
* @param array an associative array of update values
* @param string the where key
- * @return object
+ * @return bool
*/
public function update_batch($table = '', $set = NULL, $index = NULL)
{
@@ -1608,12 +1546,7 @@ class CI_DB_active_record extends CI_DB_driver {
if (is_null($index))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_index');
- }
-
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE;
}
if ( ! is_null($set))
@@ -1621,39 +1554,29 @@ class CI_DB_active_record extends CI_DB_driver {
$this->set_update_batch($set, $index);
}
- if (count($this->ar_set) == 0)
+ if (count($this->ar_set) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_use_set');
- }
-
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
if ($table == '')
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
}
// Batch this baby
- for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
+ for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100)
{
- $sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where);
-
- $this->query($sql);
+ $this->query($this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where));
}
$this->_reset_write();
+ return TRUE;
}
// --------------------------------------------------------------------
@@ -1679,7 +1602,6 @@ class CI_DB_active_record extends CI_DB_driver {
{
$index_set = FALSE;
$clean = array();
-
foreach ($v as $k2 => $v2)
{
if ($k2 == $index)
@@ -1691,14 +1613,7 @@ class CI_DB_active_record extends CI_DB_driver {
$not[] = $k.'-'.$v;
}
- if ($escape === FALSE)
- {
- $clean[$this->_protect_identifiers($k2)] = $v2;
- }
- else
- {
- $clean[$this->_protect_identifiers($k2)] = $this->escape($v2);
- }
+ $clean[$this->_protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
}
if ($index_set == FALSE)
@@ -1728,11 +1643,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
@@ -1743,9 +1654,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_delete($table);
-
$this->_reset_write();
-
return $this->query($sql);
}
@@ -1767,11 +1676,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
@@ -1782,9 +1687,7 @@ class CI_DB_active_record extends CI_DB_driver {
}
$sql = $this->_truncate($table);
-
$this->_reset_write();
-
return $this->query($sql);
}
@@ -1830,11 +1733,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ( ! isset($this->ar_from[0]))
{
- if ($this->db_debug)
- {
- return $this->display_error('db_must_set_table');
- }
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->ar_from[0];
@@ -1864,29 +1763,18 @@ class CI_DB_active_record extends CI_DB_driver {
$this->limit($limit);
}
- if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like) == 0)
+ if (count($this->ar_where) === 0 && count($this->ar_wherein) === 0 && count($this->ar_like) === 0)
{
- if ($this->db_debug)
- {
- return $this->display_error('db_del_must_use_where');
- }
-
- return FALSE;
+ return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE;
}
$sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit);
-
if ($reset_data)
{
$this->_reset_write();
}
- if ($this->return_delete_sql === true)
- {
- return $sql;
- }
-
- return $this->query($sql);
+ return ($this->return_delete_sql === TRUE) ? $sql : $this->query($sql);
}
// --------------------------------------------------------------------
@@ -1953,13 +1841,13 @@ class CI_DB_active_record extends CI_DB_driver {
}
// if a table alias is used we can recognize it by a space
- if (strpos($table, " ") !== FALSE)
+ if (strpos($table, ' ') !== FALSE)
{
// if the alias is written with the AS keyword, remove it
$table = preg_replace('/ AS /i', ' ', $table);
// Grab the alias
- $table = trim(strrchr($table, " "));
+ $table = trim(strrchr($table, ' '));
// Store the alias, if it doesn't already exist
if ( ! in_array($table, $this->ar_aliased_tables))
@@ -1984,10 +1872,7 @@ class CI_DB_active_record extends CI_DB_driver {
// Combine any cached components with the current statements
$this->_merge_cache();
- // ----------------------------------------------------------------
-
// Write the "select" portion of the query
-
if ($select_override !== FALSE)
{
$sql = $select_override;
@@ -1996,7 +1881,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
$sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
- if (count($this->ar_select) == 0)
+ if (count($this->ar_select) === 0)
{
$sql .= '*';
}
@@ -2015,32 +1900,19 @@ class CI_DB_active_record extends CI_DB_driver {
}
}
- // ----------------------------------------------------------------
-
// Write the "FROM" portion of the query
-
if (count($this->ar_from) > 0)
{
- $sql .= "\nFROM ";
-
- $sql .= $this->_from_tables($this->ar_from);
+ $sql .= "\nFROM ".$this->_from_tables($this->ar_from);
}
- // ----------------------------------------------------------------
-
// Write the "JOIN" portion of the query
-
if (count($this->ar_join) > 0)
{
- $sql .= "\n";
-
- $sql .= implode("\n", $this->ar_join);
+ $sql .= "\n".implode("\n", $this->ar_join);
}
- // ----------------------------------------------------------------
-
// Write the "WHERE" portion of the query
-
if (count($this->ar_where) > 0 OR count($this->ar_like) > 0)
{
$sql .= "\nWHERE ";
@@ -2048,10 +1920,7 @@ class CI_DB_active_record extends CI_DB_driver {
$sql .= implode("\n", $this->ar_where);
- // ----------------------------------------------------------------
-
// Write the "LIKE" portion of the query
-
if (count($this->ar_like) > 0)
{
if (count($this->ar_where) > 0)
@@ -2062,50 +1931,32 @@ class CI_DB_active_record extends CI_DB_driver {
$sql .= implode("\n", $this->ar_like);
}
- // ----------------------------------------------------------------
-
// Write the "GROUP BY" portion of the query
-
if (count($this->ar_groupby) > 0)
{
- $sql .= "\nGROUP BY ";
-
- $sql .= implode(', ', $this->ar_groupby);
+ $sql .= "\nGROUP BY ".implode(', ', $this->ar_groupby);
}
- // ----------------------------------------------------------------
-
// Write the "HAVING" portion of the query
-
if (count($this->ar_having) > 0)
{
- $sql .= "\nHAVING ";
- $sql .= implode("\n", $this->ar_having);
+ $sql .= "\nHAVING ".implode("\n", $this->ar_having);
}
- // ----------------------------------------------------------------
-
// Write the "ORDER BY" portion of the query
-
if (count($this->ar_orderby) > 0)
{
- $sql .= "\nORDER BY ";
- $sql .= implode(', ', $this->ar_orderby);
-
+ $sql .= "\nORDER BY ".implode(', ', $this->ar_orderby);
if ($this->ar_order !== FALSE)
{
$sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
}
}
- // ----------------------------------------------------------------
-
// Write the "LIMIT" portion of the query
-
if (is_numeric($this->ar_limit))
{
- $sql .= "\n";
- $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset);
+ return $this->_limit($sql."\n", $this->ar_limit, $this->ar_offset);
}
return $sql;
@@ -2165,14 +2016,12 @@ class CI_DB_active_record extends CI_DB_driver {
foreach ($fields as $val)
{
// There are some built in keys we need to ignore for this conversion
- if ($val != '_parent_name')
+ if ($val !== '_parent_name')
{
-
$i = 0;
foreach ($out[$val] as $data)
{
- $array[$i][$val] = $data;
- $i++;
+ $array[$i++][$val] = $data;
}
}
}
@@ -2247,7 +2096,7 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _merge_cache()
{
- if (count($this->ar_cache_exists) == 0)
+ if (count($this->ar_cache_exists) === 0)
{
return;
}
@@ -2257,7 +2106,7 @@ class CI_DB_active_record extends CI_DB_driver {
$ar_variable = 'ar_'.$val;
$ar_cache_var = 'ar_cache_'.$val;
- if (count($this->$ar_cache_var) == 0)
+ if (count($this->$ar_cache_var) === 0)
{
continue;
}
@@ -2282,7 +2131,6 @@ class CI_DB_active_record extends CI_DB_driver {
*
* Publicly-visible method to reset the AR values.
*
- * @access public
* @return void
*/
public function reset_query()
@@ -2319,25 +2167,24 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _reset_select()
{
- $ar_reset_items = array(
- 'ar_select' => array(),
- 'ar_from' => array(),
- 'ar_join' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_groupby' => array(),
- 'ar_having' => array(),
- 'ar_orderby' => array(),
- 'ar_wherein' => array(),
- 'ar_aliased_tables' => array(),
- 'ar_no_escape' => array(),
- 'ar_distinct' => FALSE,
- 'ar_limit' => FALSE,
- 'ar_offset' => FALSE,
- 'ar_order' => FALSE,
- );
-
- $this->_reset_run($ar_reset_items);
+ $this->_reset_run(array(
+ 'ar_select' => array(),
+ 'ar_from' => array(),
+ 'ar_join' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_groupby' => array(),
+ 'ar_having' => array(),
+ 'ar_orderby' => array(),
+ 'ar_wherein' => array(),
+ 'ar_aliased_tables' => array(),
+ 'ar_no_escape' => array(),
+ 'ar_distinct' => FALSE,
+ 'ar_limit' => FALSE,
+ 'ar_offset' => FALSE,
+ 'ar_order' => FALSE
+ )
+ );
}
// --------------------------------------------------------------------
@@ -2351,19 +2198,19 @@ class CI_DB_active_record extends CI_DB_driver {
*/
protected function _reset_write()
{
- $ar_reset_items = array(
- 'ar_set' => array(),
- 'ar_from' => array(),
- 'ar_where' => array(),
- 'ar_like' => array(),
- 'ar_orderby' => array(),
- 'ar_keys' => array(),
- 'ar_limit' => FALSE,
- 'ar_order' => FALSE
- );
-
- $this->_reset_run($ar_reset_items);
+ $this->_reset_run(array(
+ 'ar_set' => array(),
+ 'ar_from' => array(),
+ 'ar_where' => array(),
+ 'ar_like' => array(),
+ 'ar_orderby' => array(),
+ 'ar_keys' => array(),
+ 'ar_limit' => FALSE,
+ 'ar_order' => FALSE
+ )
+ );
}
+
}
/* End of file DB_active_rec.php */