Update to CodeIgniter 3.19
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -29,7 +29,7 @@
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
@@ -149,6 +149,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
*/
|
||||
protected $qb_set = array();
|
||||
|
||||
/**
|
||||
* QB data set for update_batch()
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $qb_set_ub = array();
|
||||
|
||||
/**
|
||||
* QB aliased tables list
|
||||
*
|
||||
@@ -207,6 +214,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
*/
|
||||
protected $qb_cache_join = array();
|
||||
|
||||
/**
|
||||
* QB Cache aliased tables list
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $qb_cache_aliased_tables = array();
|
||||
|
||||
/**
|
||||
* QB Cache WHERE data
|
||||
*
|
||||
@@ -666,7 +680,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
{
|
||||
if ($escape === TRUE)
|
||||
{
|
||||
$v = ' '.$this->escape($v);
|
||||
$v = $this->escape($v);
|
||||
}
|
||||
|
||||
if ( ! $this->_has_operator($k))
|
||||
@@ -679,15 +693,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
// value appears not to have been set, assign the test to IS NULL
|
||||
$k .= ' IS NULL';
|
||||
}
|
||||
elseif (preg_match('/\s*(!?=|<>|IS(?:\s+NOT)?)\s*$/i', $k, $match, PREG_OFFSET_CAPTURE))
|
||||
elseif (preg_match('/\s*(!?=|<>|\sIS(?:\s+NOT)?\s)\s*$/i', $k, $match, PREG_OFFSET_CAPTURE))
|
||||
{
|
||||
$k = substr($k, 0, $match[0][1]).($match[1][0] === '=' ? ' IS NULL' : ' IS NOT NULL');
|
||||
}
|
||||
|
||||
$this->{$qb_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape);
|
||||
${$qb_key} = array('condition' => $prefix.$k, 'value' => $v, 'escape' => $escape);
|
||||
$this->{$qb_key}[] = ${$qb_key};
|
||||
if ($this->qb_caching === TRUE)
|
||||
{
|
||||
$this->{$qb_cache_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape);
|
||||
$this->{$qb_cache_key}[] = ${$qb_key};
|
||||
$this->qb_cache_exists[] = substr($qb_key, 3);
|
||||
}
|
||||
|
||||
@@ -820,6 +835,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
|
||||
$where_in = array(
|
||||
'condition' => $prefix.$key.$not.' IN('.implode(', ', $where_in).')',
|
||||
'value' => NULL,
|
||||
'escape' => $escape
|
||||
);
|
||||
|
||||
@@ -948,33 +964,34 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
$v = $this->escape_like_str($v);
|
||||
}
|
||||
|
||||
if ($side === 'none')
|
||||
switch ($side)
|
||||
{
|
||||
$like_statement = "{$prefix} {$k} {$not} LIKE '{$v}'";
|
||||
}
|
||||
elseif ($side === 'before')
|
||||
{
|
||||
$like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}'";
|
||||
}
|
||||
elseif ($side === 'after')
|
||||
{
|
||||
$like_statement = "{$prefix} {$k} {$not} LIKE '{$v}%'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}%'";
|
||||
case 'none':
|
||||
$v = "'{$v}'";
|
||||
break;
|
||||
case 'before':
|
||||
$v = "'%{$v}'";
|
||||
break;
|
||||
case 'after':
|
||||
$v = "'{$v}%'";
|
||||
break;
|
||||
case 'both':
|
||||
default:
|
||||
$v = "'%{$v}%'";
|
||||
break;
|
||||
}
|
||||
|
||||
// some platforms require an escape sequence definition for LIKE wildcards
|
||||
if ($escape === TRUE && $this->_like_escape_str !== '')
|
||||
{
|
||||
$like_statement .= sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
$v .= sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
$this->qb_where[] = array('condition' => $like_statement, 'escape' => $escape);
|
||||
$qb_where = array('condition' => "{$prefix} {$k} {$not} LIKE {$v}", 'value' => NULL, 'escape' => $escape);
|
||||
$this->qb_where[] = $qb_where;
|
||||
if ($this->qb_caching === TRUE)
|
||||
{
|
||||
$this->qb_cache_where[] = array('condition' => $like_statement, 'escape' => $escape);
|
||||
$this->qb_cache_where[] = $qb_where;
|
||||
$this->qb_cache_exists[] = 'where';
|
||||
}
|
||||
}
|
||||
@@ -999,6 +1016,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
$prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
|
||||
$where = array(
|
||||
'condition' => $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' (',
|
||||
'value' => NULL,
|
||||
'escape' => FALSE
|
||||
);
|
||||
|
||||
@@ -1059,6 +1077,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
$this->qb_where_group_started = FALSE;
|
||||
$where = array(
|
||||
'condition' => str_repeat(' ', $this->qb_where_group_count--).')',
|
||||
'value' => NULL,
|
||||
'escape' => FALSE
|
||||
);
|
||||
|
||||
@@ -1271,7 +1290,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
return $sql.' LIMIT '.($this->qb_offset ? $this->qb_offset.', ' : '').$this->qb_limit;
|
||||
return $sql.' LIMIT '.($this->qb_offset ? $this->qb_offset.', ' : '').(int) $this->qb_limit;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@@ -1389,13 +1408,11 @@ 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_orderby;
|
||||
$qb_cache_orderby = $this->qb_cache_orderby;
|
||||
$this->qb_orderby = $this->qb_cache_orderby = array();
|
||||
|
||||
$result = ($this->qb_distinct === TRUE)
|
||||
$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")
|
||||
: $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows')));
|
||||
|
||||
@@ -1403,10 +1420,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)
|
||||
@@ -1421,7 +1438,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get_Where
|
||||
* get_where()
|
||||
*
|
||||
* Allows the where clause, limit and offset to be added directly
|
||||
*
|
||||
@@ -1498,8 +1515,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
$affected_rows = 0;
|
||||
for ($i = 0, $total = count($this->qb_set); $i < $total; $i += $batch_size)
|
||||
{
|
||||
$this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, $escape, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, $batch_size)));
|
||||
$affected_rows += $this->affected_rows();
|
||||
if ($this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, $escape, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, $batch_size))))
|
||||
{
|
||||
$affected_rows += $this->affected_rows();
|
||||
}
|
||||
}
|
||||
|
||||
$this->_reset_write();
|
||||
@@ -1544,7 +1563,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
|
||||
is_bool($escape) OR $escape = $this->_protect_identifiers;
|
||||
|
||||
$keys = array_keys($this->_object_to_array(current($key)));
|
||||
$keys = array_keys($this->_object_to_array(reset($key)));
|
||||
sort($keys);
|
||||
|
||||
foreach ($key as $row)
|
||||
@@ -1884,7 +1903,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
|
||||
if ($set === NULL)
|
||||
{
|
||||
if (empty($this->qb_set))
|
||||
if (empty($this->qb_set_ub))
|
||||
{
|
||||
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
|
||||
}
|
||||
@@ -1911,10 +1930,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
|
||||
// Batch this baby
|
||||
$affected_rows = 0;
|
||||
for ($i = 0, $total = count($this->qb_set); $i < $total; $i += $batch_size)
|
||||
for ($i = 0, $total = count($this->qb_set_ub); $i < $total; $i += $batch_size)
|
||||
{
|
||||
$this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set, $i, $batch_size), $this->protect_identifiers($index)));
|
||||
$affected_rows += $this->affected_rows();
|
||||
if ($this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set_ub, $i, $batch_size), $index)))
|
||||
{
|
||||
$affected_rows += $this->affected_rows();
|
||||
}
|
||||
|
||||
$this->qb_where = array();
|
||||
}
|
||||
|
||||
@@ -1939,13 +1961,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
$ids = array();
|
||||
foreach ($values as $key => $val)
|
||||
{
|
||||
$ids[] = $val[$index];
|
||||
$ids[] = $val[$index]['value'];
|
||||
|
||||
foreach (array_keys($val) as $field)
|
||||
{
|
||||
if ($field !== $index)
|
||||
{
|
||||
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
|
||||
$final[$val[$field]['field']][] = 'WHEN '.$val[$index]['field'].' = '.$val[$index]['value'].' THEN '.$val[$field]['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1958,7 +1980,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
.'ELSE '.$k.' END, ';
|
||||
}
|
||||
|
||||
$this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE);
|
||||
$this->where($val[$index]['field'].' IN('.implode(',', $ids).')', NULL, FALSE);
|
||||
|
||||
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
|
||||
}
|
||||
@@ -1995,7 +2017,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
$index_set = TRUE;
|
||||
}
|
||||
|
||||
$clean[$this->protect_identifiers($k2, FALSE, $escape)] = ($escape === FALSE) ? $v2 : $this->escape($v2);
|
||||
$clean[$k2] = array(
|
||||
'field' => $this->protect_identifiers($k2, FALSE, $escape),
|
||||
'value' => ($escape === FALSE ? $v2 : $this->escape($v2))
|
||||
);
|
||||
}
|
||||
|
||||
if ($index_set === FALSE)
|
||||
@@ -2003,7 +2028,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
return $this->display_error('db_batch_missing_index');
|
||||
}
|
||||
|
||||
$this->qb_set[] = $clean;
|
||||
$this->qb_set_ub[] = $clean;
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -2190,7 +2215,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
protected function _delete($table)
|
||||
{
|
||||
return 'DELETE FROM '.$table.$this->_compile_wh('qb_where')
|
||||
.($this->qb_limit ? ' LIMIT '.$this->qb_limit : '');
|
||||
.($this->qb_limit !== FALSE ? ' LIMIT '.$this->qb_limit : '');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@@ -2266,9 +2291,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
$table = trim(strrchr($table, ' '));
|
||||
|
||||
// Store the alias, if it doesn't already exist
|
||||
if ( ! in_array($table, $this->qb_aliased_tables))
|
||||
if ( ! in_array($table, $this->qb_aliased_tables, TRUE))
|
||||
{
|
||||
$this->qb_aliased_tables[] = $table;
|
||||
if ($this->qb_caching === TRUE && ! in_array($table, $this->qb_cache_aliased_tables, TRUE))
|
||||
{
|
||||
$this->qb_cache_aliased_tables[] = $table;
|
||||
$this->qb_cache_exists[] = 'aliased_tables';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2335,7 +2365,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
.$this->_compile_order_by(); // ORDER BY
|
||||
|
||||
// LIMIT
|
||||
if ($this->qb_limit)
|
||||
if ($this->qb_limit !== FALSE OR $this->qb_offset)
|
||||
{
|
||||
return $this->_limit($sql."\n");
|
||||
}
|
||||
@@ -2370,7 +2400,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
}
|
||||
elseif ($this->{$qb_key}[$i]['escape'] === FALSE)
|
||||
{
|
||||
$this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition'];
|
||||
$this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition'].(isset($this->{$qb_key}[$i]['value']) ? ' '.$this->{$qb_key}[$i]['value'] : '');
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2409,7 +2439,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
.' '.trim($matches[3]).$matches[4].$matches[5];
|
||||
}
|
||||
|
||||
$this->{$qb_key}[$i] = implode('', $conditions);
|
||||
$this->{$qb_key}[$i] = implode('', $conditions).(isset($this->{$qb_key}[$i]['value']) ? ' '.$this->{$qb_key}[$i]['value'] : '');
|
||||
}
|
||||
|
||||
return ($qb_key === 'qb_having' ? "\nHAVING " : "\nWHERE ")
|
||||
@@ -2426,7 +2456,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
*
|
||||
* Escapes identifiers in GROUP BY statements at execution time.
|
||||
*
|
||||
* Required so that aliases are tracked properly, regardless of wether
|
||||
* Required so that aliases are tracked properly, regardless of whether
|
||||
* group_by() is called prior to from(), join() and dbprefix is added
|
||||
* only if needed.
|
||||
*
|
||||
@@ -2462,7 +2492,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
*
|
||||
* Escapes identifiers in ORDER BY statements at execution time.
|
||||
*
|
||||
* Required so that aliases are tracked properly, regardless of wether
|
||||
* Required so that aliases are tracked properly, regardless of whether
|
||||
* order_by() is called prior to from(), join() and dbprefix is added
|
||||
* only if needed.
|
||||
*
|
||||
@@ -2470,26 +2500,27 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
*/
|
||||
protected function _compile_order_by()
|
||||
{
|
||||
if (is_array($this->qb_orderby) && count($this->qb_orderby) > 0)
|
||||
if (empty($this->qb_orderby))
|
||||
{
|
||||
for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++)
|
||||
{
|
||||
if ($this->qb_orderby[$i]['escape'] !== FALSE && ! $this->_is_literal($this->qb_orderby[$i]['field']))
|
||||
{
|
||||
$this->qb_orderby[$i]['field'] = $this->protect_identifiers($this->qb_orderby[$i]['field']);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction'];
|
||||
for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++)
|
||||
{
|
||||
if (is_string($this->qb_orderby[$i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return $this->qb_orderby = "\nORDER BY ".implode(', ', $this->qb_orderby);
|
||||
}
|
||||
elseif (is_string($this->qb_orderby))
|
||||
{
|
||||
return $this->qb_orderby;
|
||||
if ($this->qb_orderby[$i]['escape'] !== FALSE && ! $this->_is_literal($this->qb_orderby[$i]['field']))
|
||||
{
|
||||
$this->qb_orderby[$i]['field'] = $this->protect_identifiers($this->qb_orderby[$i]['field']);
|
||||
}
|
||||
|
||||
$this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction'];
|
||||
}
|
||||
|
||||
return '';
|
||||
return "\nORDER BY ".implode(', ', $this->qb_orderby);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@@ -2610,7 +2641,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
'qb_cache_orderby' => array(),
|
||||
'qb_cache_set' => array(),
|
||||
'qb_cache_exists' => array(),
|
||||
'qb_cache_no_escape' => array()
|
||||
'qb_cache_no_escape' => array(),
|
||||
'qb_cache_aliased_tables' => array()
|
||||
));
|
||||
|
||||
return $this;
|
||||
@@ -2661,13 +2693,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
$this->qb_no_escape = $qb_no_escape;
|
||||
}
|
||||
}
|
||||
|
||||
// If we are "protecting identifiers" we need to examine the "from"
|
||||
// portion of the query to determine if there are any aliases
|
||||
if ($this->_protect_identifiers === TRUE && count($this->qb_cache_from) > 0)
|
||||
{
|
||||
$this->_track_aliases($this->qb_from);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@@ -2770,6 +2795,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
|
||||
{
|
||||
$this->_reset_run(array(
|
||||
'qb_set' => array(),
|
||||
'qb_set_ub' => array(),
|
||||
'qb_from' => array(),
|
||||
'qb_join' => array(),
|
||||
'qb_where' => array(),
|
||||
|
Reference in New Issue
Block a user