Archived
1
0

Update to CodeIgniter 3.19

This commit is contained in:
Marcel 2018-12-29 16:16:49 +01:00
parent b036b4d36e
commit d09ee2788d
159 changed files with 2508 additions and 1910 deletions

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -55,7 +55,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
* @var string * @var string
* *
*/ */
define('CI_VERSION', '3.0.6'); const CI_VERSION = '3.1.9';
/* /*
* ------------------------------------------------------ * ------------------------------------------------------
@ -67,7 +67,10 @@ defined('BASEPATH') OR exit('No direct script access allowed');
require_once(APPPATH.'config/'.ENVIRONMENT.'/constants.php'); require_once(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
} }
if (file_exists(APPPATH.'config/constants.php'))
{
require_once(APPPATH.'config/constants.php'); require_once(APPPATH.'config/constants.php');
}
/* /*
* ------------------------------------------------------ * ------------------------------------------------------
@ -416,14 +419,29 @@ if ( ! is_php('5.4'))
$params = array($method, array_slice($URI->rsegments, 2)); $params = array($method, array_slice($URI->rsegments, 2));
$method = '_remap'; $method = '_remap';
} }
// WARNING: It appears that there are issues with is_callable() even in PHP 5.2! elseif ( ! method_exists($class, $method))
// Furthermore, there are bug reports and feature/change requests related to it
// that make it unreliable to use in this context. Please, DO NOT change this
// work-around until a better alternative is available.
elseif ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($class)), TRUE))
{ {
$e404 = TRUE; $e404 = TRUE;
} }
/**
* DO NOT CHANGE THIS, NOTHING ELSE WORKS!
*
* - method_exists() returns true for non-public methods, which passes the previous elseif
* - is_callable() returns false for PHP 4-style constructors, even if there's a __construct()
* - method_exists($class, '__construct') won't work because CI_Controller::__construct() is inherited
* - People will only complain if this doesn't work, even though it is documented that it shouldn't.
*
* ReflectionMethod::isConstructor() is the ONLY reliable check,
* knowing which method will be executed as a constructor.
*/
elseif ( ! is_callable(array($class, $method)))
{
$reflection = new ReflectionMethod($class, $method);
if ( ! $reflection->isPublic() OR $reflection->isConstructor())
{
$e404 = TRUE;
}
}
} }
if ($e404) if ($e404)

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -135,7 +135,7 @@ if ( ! function_exists('load_class'))
* *
* @param string the class name being requested * @param string the class name being requested
* @param string the directory where the class should be found * @param string the directory where the class should be found
* @param string an optional argument to pass to the class constructor * @param mixed an optional argument to pass to the class constructor
* @return object * @return object
*/ */
function &load_class($class, $directory = 'libraries', $param = NULL) function &load_class($class, $directory = 'libraries', $param = NULL)
@ -319,17 +319,13 @@ if ( ! function_exists('get_mimes'))
if (empty($_mimes)) if (empty($_mimes))
{ {
$_mimes = file_exists(APPPATH.'config/mimes.php')
? include(APPPATH.'config/mimes.php')
: array();
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
{ {
$_mimes = include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); $_mimes = array_merge($_mimes, include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'));
}
elseif (file_exists(APPPATH.'config/mimes.php'))
{
$_mimes = include(APPPATH.'config/mimes.php');
}
else
{
$_mimes = array();
} }
} }
@ -355,7 +351,7 @@ if ( ! function_exists('is_https'))
{ {
return TRUE; return TRUE;
} }
elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https')
{ {
return TRUE; return TRUE;
} }
@ -410,11 +406,6 @@ if ( ! function_exists('show_error'))
if ($status_code < 100) if ($status_code < 100)
{ {
$exit_status = $status_code + 9; // 9 is EXIT__AUTO_MIN $exit_status = $status_code + 9; // 9 is EXIT__AUTO_MIN
if ($exit_status > 125) // 125 is EXIT__AUTO_MAX
{
$exit_status = 1; // EXIT_ERROR
}
$status_code = 500; $status_code = 500;
} }
else else
@ -544,13 +535,18 @@ if ( ! function_exists('set_status_header'))
416 => 'Requested Range Not Satisfiable', 416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed', 417 => 'Expectation Failed',
422 => 'Unprocessable Entity', 422 => 'Unprocessable Entity',
426 => 'Upgrade Required',
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
500 => 'Internal Server Error', 500 => 'Internal Server Error',
501 => 'Not Implemented', 501 => 'Not Implemented',
502 => 'Bad Gateway', 502 => 'Bad Gateway',
503 => 'Service Unavailable', 503 => 'Service Unavailable',
504 => 'Gateway Timeout', 504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported' 505 => 'HTTP Version Not Supported',
511 => 'Network Authentication Required',
); );
if (isset($stati[$code])) if (isset($stati[$code]))
@ -566,14 +562,14 @@ if ( ! function_exists('set_status_header'))
if (strpos(PHP_SAPI, 'cgi') === 0) if (strpos(PHP_SAPI, 'cgi') === 0)
{ {
header('Status: '.$code.' '.$text, TRUE); header('Status: '.$code.' '.$text, TRUE);
return;
} }
else
{ $server_protocol = (isset($_SERVER['SERVER_PROTOCOL']) && in_array($_SERVER['SERVER_PROTOCOL'], array('HTTP/1.0', 'HTTP/1.1', 'HTTP/2'), TRUE))
$server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
header($server_protocol.' '.$code.' '.$text, TRUE, $code); header($server_protocol.' '.$code.' '.$text, TRUE, $code);
} }
} }
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -598,7 +594,7 @@ if ( ! function_exists('_error_handler'))
*/ */
function _error_handler($severity, $message, $filepath, $line) function _error_handler($severity, $message, $filepath, $line)
{ {
$is_error = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $severity) === $severity); $is_error = (((E_ERROR | E_PARSE | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $severity) === $severity);
// When an error occurred, set the status header to '500 Internal Server Error' // When an error occurred, set the status header to '500 Internal Server Error'
// to indicate to the client something went wrong. // to indicate to the client something went wrong.
@ -656,6 +652,7 @@ if ( ! function_exists('_exception_handler'))
$_error =& load_class('Exceptions', 'core'); $_error =& load_class('Exceptions', 'core');
$_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine()); $_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine());
is_cli() OR set_status_header(500);
// Should we display the error? // Should we display the error?
if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors')))
{ {
@ -716,8 +713,9 @@ if ( ! function_exists('remove_invisible_characters'))
// carriage return (dec 13) and horizontal tab (dec 09) // carriage return (dec 13) and horizontal tab (dec 09)
if ($url_encoded) if ($url_encoded)
{ {
$non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 $non_displayables[] = '/%0[0-8bcef]/i'; // url encoded 00-08, 11, 12, 14, 15
$non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 $non_displayables[] = '/%1[0-9a-f]/i'; // url encoded 16-31
$non_displayables[] = '/%7f/i'; // url encoded 127
} }
$non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
@ -821,7 +819,7 @@ if ( ! function_exists('function_usable'))
* terminate script execution if a disabled function is executed. * terminate script execution if a disabled function is executed.
* *
* The above described behavior turned out to be a bug in Suhosin, * The above described behavior turned out to be a bug in Suhosin,
* but even though a fix was commited for 0.9.34 on 2012-02-12, * but even though a fix was committed for 0.9.34 on 2012-02-12,
* that version is yet to be released. This function will therefore * that version is yet to be released. This function will therefore
* be just temporary, but would probably be kept for a few years. * be just temporary, but would probably be kept for a few years.
* *

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -319,7 +319,7 @@ class CI_Config {
} }
} }
return $base_url.ltrim($this->_uri_string($uri), '/'); return $base_url.$this->_uri_string($uri);
} }
// ------------------------------------------------------------- // -------------------------------------------------------------
@ -337,11 +337,8 @@ class CI_Config {
{ {
if ($this->item('enable_query_strings') === FALSE) if ($this->item('enable_query_strings') === FALSE)
{ {
if (is_array($uri)) is_array($uri) && $uri = implode('/', $uri);
{ return ltrim($uri, '/');
$uri = implode('/', $uri);
}
return trim($uri, '/');
} }
elseif (is_array($uri)) elseif (is_array($uri))
{ {

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -207,7 +207,6 @@ class CI_Exceptions {
} }
else else
{ {
set_status_header(500);
$templates_path .= 'html'.DIRECTORY_SEPARATOR; $templates_path .= 'html'.DIRECTORY_SEPARATOR;
} }
@ -232,7 +231,7 @@ class CI_Exceptions {
* @param string $message Error message * @param string $message Error message
* @param string $filepath File path * @param string $filepath File path
* @param int $line Line number * @param int $line Line number
* @return string Error page output * @return void
*/ */
public function show_php_error($severity, $message, $filepath, $line) public function show_php_error($severity, $message, $filepath, $line)
{ {

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -137,7 +137,7 @@ class CI_Input {
*/ */
public function __construct() public function __construct()
{ {
$this->_allow_get_array = (config_item('allow_get_array') === TRUE); $this->_allow_get_array = (config_item('allow_get_array') !== FALSE);
$this->_enable_xss = (config_item('global_xss_filtering') === TRUE); $this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
$this->_enable_csrf = (config_item('csrf_protection') === TRUE); $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
$this->_standardize_newlines = (bool) config_item('standardize_newlines'); $this->_standardize_newlines = (bool) config_item('standardize_newlines');
@ -359,7 +359,7 @@ class CI_Input {
* @param bool $httponly Whether to only makes the cookie accessible via HTTP (no javascript) * @param bool $httponly Whether to only makes the cookie accessible via HTTP (no javascript)
* @return void * @return void
*/ */
public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE) public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL)
{ {
if (is_array($name)) if (is_array($name))
{ {
@ -388,15 +388,13 @@ class CI_Input {
$path = config_item('cookie_path'); $path = config_item('cookie_path');
} }
if ($secure === FALSE && config_item('cookie_secure') === TRUE) $secure = ($secure === NULL && config_item('cookie_secure') !== NULL)
{ ? (bool) config_item('cookie_secure')
$secure = config_item('cookie_secure'); : (bool) $secure;
}
if ($httponly === FALSE && config_item('cookie_httponly') !== FALSE) $httponly = ($httponly === NULL && config_item('cookie_httponly') !== NULL)
{ ? (bool) config_item('cookie_httponly')
$httponly = config_item('cookie_httponly'); : (bool) $httponly;
}
if ( ! is_numeric($expire)) if ( ! is_numeric($expire))
{ {
@ -519,9 +517,9 @@ class CI_Input {
if ($separator === ':') if ($separator === ':')
{ {
$netaddr = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr)); $netaddr = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr));
for ($i = 0; $i < 8; $i++) for ($j = 0; $j < 8; $j++)
{ {
$netaddr[$i] = intval($netaddr[$i], 16); $netaddr[$j] = intval($netaddr[$j], 16);
} }
} }
else else
@ -760,16 +758,17 @@ class CI_Input {
// If header is already defined, return it immediately // If header is already defined, return it immediately
if ( ! empty($this->headers)) if ( ! empty($this->headers))
{ {
return $this->headers; return $this->_fetch_from_array($this->headers, NULL, $xss_clean);
} }
// In Apache, you can simply call apache_request_headers() // In Apache, you can simply call apache_request_headers()
if (function_exists('apache_request_headers')) if (function_exists('apache_request_headers'))
{ {
return $this->headers = apache_request_headers(); $this->headers = apache_request_headers();
} }
else
$this->headers['Content-Type'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE'); {
isset($_SERVER['CONTENT_TYPE']) && $this->headers['Content-Type'] = $_SERVER['CONTENT_TYPE'];
foreach ($_SERVER as $key => $val) foreach ($_SERVER as $key => $val)
{ {
@ -779,11 +778,12 @@ class CI_Input {
$header = str_replace('_', ' ', strtolower($header)); $header = str_replace('_', ' ', strtolower($header));
$header = str_replace(' ', '-', ucwords($header)); $header = str_replace(' ', '-', ucwords($header));
$this->headers[$header] = $this->_fetch_from_array($_SERVER, $key, $xss_clean); $this->headers[$header] = $_SERVER[$key];
}
} }
} }
return $this->headers; return $this->_fetch_from_array($this->headers, NULL, $xss_clean);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -78,7 +78,7 @@ class CI_Lang {
* Load a language file * Load a language file
* *
* @param mixed $langfile Language file name * @param mixed $langfile Language file name
* @param string $idiom Language name (en, etc.) * @param string $idiom Language name (english, etc.)
* @param bool $return Whether to return the loaded array of translations * @param bool $return Whether to return the loaded array of translations
* @param bool $add_suffix Whether to add suffix to $langfile * @param bool $add_suffix Whether to add suffix to $langfile
* @param string $alt_path Alternative path to look for the language file * @param string $alt_path Alternative path to look for the language file
@ -109,7 +109,7 @@ class CI_Lang {
if (empty($idiom) OR ! preg_match('/^[a-z_-]+$/i', $idiom)) if (empty($idiom) OR ! preg_match('/^[a-z_-]+$/i', $idiom))
{ {
$config =& get_config(); $config =& get_config();
$idiom = empty($config['language']) ? 'en' : $config['language']; $idiom = empty($config['language']) ? 'english' : $config['language'];
} }
if ($return === FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom) if ($return === FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom)

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -182,7 +182,7 @@ class CI_Loader {
* Loads and instantiates libraries. * Loads and instantiates libraries.
* Designed to be called from application controllers. * Designed to be called from application controllers.
* *
* @param string $library Library name * @param mixed $library Library name
* @param array $params Optional parameters to pass to the library class constructor * @param array $params Optional parameters to pass to the library class constructor
* @param string $object_name An optional object name to assign to * @param string $object_name An optional object name to assign to
* @return object * @return object
@ -226,7 +226,7 @@ class CI_Loader {
* *
* Loads and instantiates models. * Loads and instantiates models.
* *
* @param string $model Model name * @param mixed $model Model name
* @param string $name An optional object name to assign to * @param string $name An optional object name to assign to
* @param bool $db_conn An optional database connection configuration to initialize * @param bool $db_conn An optional database connection configuration to initialize
* @return object * @return object
@ -303,6 +303,8 @@ class CI_Loader {
{ {
throw new RuntimeException($app_path."Model.php exists, but doesn't declare class CI_Model"); throw new RuntimeException($app_path."Model.php exists, but doesn't declare class CI_Model");
} }
log_message('info', 'CI_Model class loaded');
} }
elseif ( ! class_exists('CI_Model', FALSE)) elseif ( ! class_exists('CI_Model', FALSE))
{ {
@ -317,6 +319,8 @@ class CI_Loader {
{ {
throw new RuntimeException($app_path.$class.".php exists, but doesn't declare class ".$class); throw new RuntimeException($app_path.$class.".php exists, but doesn't declare class ".$class);
} }
log_message('info', config_item('subclass_prefix').'Model class loaded');
} }
} }
@ -350,7 +354,9 @@ class CI_Loader {
} }
$this->_ci_models[] = $name; $this->_ci_models[] = $name;
$CI->$name = new $model(); $model = new $model();
$CI->$name = $model;
log_message('info', 'Model "'.get_class($model).'" initialized');
return $this; return $this;
} }
@ -486,7 +492,7 @@ class CI_Loader {
*/ */
public function view($view, $vars = array(), $return = FALSE) public function view($view, $vars = array(), $return = FALSE)
{ {
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -519,20 +525,14 @@ class CI_Loader {
*/ */
public function vars($vars, $val = '') public function vars($vars, $val = '')
{ {
if (is_string($vars)) $vars = is_string($vars)
{ ? array($vars => $val)
$vars = array($vars => $val); : $this->_ci_prepare_view_vars($vars);
}
$vars = $this->_ci_object_to_array($vars);
if (is_array($vars) && count($vars) > 0)
{
foreach ($vars as $key => $val) foreach ($vars as $key => $val)
{ {
$this->_ci_cached_vars[$key] = $val; $this->_ci_cached_vars[$key] = $val;
} }
}
return $this; return $this;
} }
@ -591,15 +591,21 @@ class CI_Loader {
*/ */
public function helper($helpers = array()) public function helper($helpers = array())
{ {
foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper) is_array($helpers) OR $helpers = array($helpers);
foreach ($helpers as &$helper)
{ {
$filename = basename($helper);
$filepath = ($filename === $helper) ? '' : substr($helper, 0, strlen($helper) - strlen($filename));
$filename = strtolower(preg_replace('#(_helper)?(\.php)?$#i', '', $filename)).'_helper';
$helper = $filepath.$filename;
if (isset($this->_ci_helpers[$helper])) if (isset($this->_ci_helpers[$helper]))
{ {
continue; continue;
} }
// Is this a helper extension request? // Is this a helper extension request?
$ext_helper = config_item('subclass_prefix').$helper; $ext_helper = config_item('subclass_prefix').$filename;
$ext_loaded = FALSE; $ext_loaded = FALSE;
foreach ($this->_ci_helper_paths as $path) foreach ($this->_ci_helper_paths as $path)
{ {
@ -934,18 +940,7 @@ class CI_Loader {
* the two types and cache them so that views that are embedded within * the two types and cache them so that views that are embedded within
* other views can have access to these variables. * other views can have access to these variables.
*/ */
if (is_array($_ci_vars)) empty($_ci_vars) OR $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
{
foreach (array_keys($_ci_vars) as $key)
{
if (strncmp($key, '_ci_', 4) === 0)
{
unset($_ci_vars[$key]);
}
}
$this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
}
extract($this->_ci_cached_vars); extract($this->_ci_cached_vars);
/* /*
@ -1048,6 +1043,26 @@ class CI_Loader {
return $this->_ci_load_stock_library($class, $subdir, $params, $object_name); return $this->_ci_load_stock_library($class, $subdir, $params, $object_name);
} }
// Safety: Was the class already loaded by a previous call?
if (class_exists($class, FALSE))
{
$property = $object_name;
if (empty($property))
{
$property = strtolower($class);
isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
}
$CI =& get_instance();
if (isset($CI->$property))
{
log_message('debug', $class.' class already loaded. Second attempt ignored.');
return;
}
return $this->_ci_init_library($class, '', $params, $object_name);
}
// Let's search for the requested library file and load it. // Let's search for the requested library file and load it.
foreach ($this->_ci_library_paths as $path) foreach ($this->_ci_library_paths as $path)
{ {
@ -1058,27 +1073,8 @@ class CI_Loader {
} }
$filepath = $path.'libraries/'.$subdir.$class.'.php'; $filepath = $path.'libraries/'.$subdir.$class.'.php';
// Safety: Was the class already loaded by a previous call?
if (class_exists($class, FALSE))
{
// Before we deem this to be a duplicate request, let's see
// if a custom object name is being supplied. If so, we'll
// return a new instance of the object
if ($object_name !== NULL)
{
$CI =& get_instance();
if ( ! isset($CI->$object_name))
{
return $this->_ci_init_library($class, '', $params, $object_name);
}
}
log_message('debug', $class.' class already loaded. Second attempt ignored.');
return;
}
// Does the file exist? No? Bummer... // Does the file exist? No? Bummer...
elseif ( ! file_exists($filepath)) if ( ! file_exists($filepath))
{ {
continue; continue;
} }
@ -1106,7 +1102,7 @@ class CI_Loader {
* @used-by CI_Loader::_ci_load_library() * @used-by CI_Loader::_ci_load_library()
* @uses CI_Loader::_ci_init_library() * @uses CI_Loader::_ci_init_library()
* *
* @param string $library Library name to load * @param string $library_name Library name to load
* @param string $file_path Path to the library filename, relative to libraries/ * @param string $file_path Path to the library filename, relative to libraries/
* @param mixed $params Optional parameters to pass to the class constructor * @param mixed $params Optional parameters to pass to the class constructor
* @param string $object_name Optional object name to assign to * @param string $object_name Optional object name to assign to
@ -1123,17 +1119,18 @@ class CI_Loader {
$prefix = config_item('subclass_prefix'); $prefix = config_item('subclass_prefix');
} }
// Before we deem this to be a duplicate request, let's see $property = $object_name;
// if a custom object name is being supplied. If so, we'll if (empty($property))
// return a new instance of the object
if ($object_name !== NULL)
{ {
$property = strtolower($library_name);
isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
}
$CI =& get_instance(); $CI =& get_instance();
if ( ! isset($CI->$object_name)) if ( ! isset($CI->$property))
{ {
return $this->_ci_init_library($library_name, $prefix, $params, $object_name); return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
} }
}
log_message('debug', $library_name.' class already loaded. Second attempt ignored.'); log_message('debug', $library_name.' class already loaded. Second attempt ignored.');
return; return;
@ -1154,12 +1151,10 @@ class CI_Loader {
{ {
return $this->_ci_init_library($library_name, $prefix, $params, $object_name); return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
} }
else
{
log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name); log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name);
} }
} }
}
include_once(BASEPATH.'libraries/'.$file_path.$library_name.'.php'); include_once(BASEPATH.'libraries/'.$file_path.$library_name.'.php');
@ -1175,12 +1170,10 @@ class CI_Loader {
$prefix = config_item('subclass_prefix'); $prefix = config_item('subclass_prefix');
break; break;
} }
else
{
log_message('debug', $path.' exists, but does not declare '.$subclass); log_message('debug', $path.' exists, but does not declare '.$subclass);
} }
} }
}
return $this->_ci_init_library($library_name, $prefix, $params, $object_name); return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
} }
@ -1376,17 +1369,32 @@ class CI_Loader {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* CI Object to Array translator * Prepare variables for _ci_vars, to be later extract()-ed inside views
* *
* Takes an object as input and converts the class variables to * Converts objects to associative arrays and filters-out internal
* an associative array with key/value pairs. * variable names (i.e. keys prefixed with '_ci_').
* *
* @param object $object Object data to translate * @param mixed $vars
* @return array * @return array
*/ */
protected function _ci_object_to_array($object) protected function _ci_prepare_view_vars($vars)
{ {
return is_object($object) ? get_object_vars($object) : $object; if ( ! is_array($vars))
{
$vars = is_object($vars)
? get_object_vars($vars)
: array();
}
foreach (array_keys($vars) as $key)
{
if (strncmp($key, '_ci_', 4) === 0)
{
unset($vars[$key]);
}
}
return $vars;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -1404,34 +1412,4 @@ class CI_Loader {
$CI =& get_instance(); $CI =& get_instance();
return $CI->$component; return $CI->$component;
} }
// --------------------------------------------------------------------
/**
* Prep filename
*
* This function prepares filenames of various items to
* make their loading more reliable.
*
* @param string|string[] $filename Filename(s)
* @param string $extension Filename extension
* @return array
*/
protected function _ci_prep_filename($filename, $extension)
{
if ( ! is_array($filename))
{
return array(strtolower(str_replace(array($extension, '.php'), '', $filename).$extension));
}
else
{
foreach ($filename as $key => $val)
{
$filename[$key] = strtolower(str_replace(array($extension, '.php'), '', $val).$extension);
}
return $filename;
}
}
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -104,6 +104,13 @@ class CI_Log {
*/ */
protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4);
/**
* mbstring.func_overload flag
*
* @var bool
*/
protected static $func_overload;
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
@ -115,6 +122,8 @@ class CI_Log {
{ {
$config =& get_config(); $config =& get_config();
isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));
$this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/';
$this->_file_ext = (isset($config['log_file_extension']) && $config['log_file_extension'] !== '') $this->_file_ext = (isset($config['log_file_extension']) && $config['log_file_extension'] !== '')
? ltrim($config['log_file_extension'], '.') : 'php'; ? ltrim($config['log_file_extension'], '.') : 'php';
@ -208,9 +217,9 @@ class CI_Log {
$message .= $this->_format_line($level, $date, $msg); $message .= $this->_format_line($level, $date, $msg);
for ($written = 0, $length = strlen($message); $written < $length; $written += $result) for ($written = 0, $length = self::strlen($message); $written < $length; $written += $result)
{ {
if (($result = fwrite($fp, substr($message, $written))) === FALSE) if (($result = fwrite($fp, self::substr($message, $written))) === FALSE)
{ {
break; break;
} }
@ -237,11 +246,51 @@ class CI_Log {
* *
* @param string $level The error level * @param string $level The error level
* @param string $date Formatted date string * @param string $date Formatted date string
* @param string $msg The log message * @param string $message The log message
* @return string Formatted log line with a new line character '\n' at the end * @return string Formatted log line with a new line character '\n' at the end
*/ */
protected function _format_line($level, $date, $message) protected function _format_line($level, $date, $message)
{ {
return $level.' - '.$date.' --> '.$message."\n"; return $level.' - '.$date.' --> '.$message."\n";
} }
// --------------------------------------------------------------------
/**
* Byte-safe strlen()
*
* @param string $str
* @return int
*/
protected static function strlen($str)
{
return (self::$func_overload)
? mb_strlen($str, '8bit')
: strlen($str);
}
// --------------------------------------------------------------------
/**
* Byte-safe substr()
*
* @param string $str
* @param int $start
* @param int $length
* @return string
*/
protected static function substr($str, $start, $length = NULL)
{
if (self::$func_overload)
{
// mb_substr($str, $start, null, '8bit') returns an empty
// string on PHP 5.3
isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start);
return mb_substr($str, $start, $length, '8bit');
}
return isset($length)
? substr($str, $start, $length)
: substr($str, $start);
}
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -51,14 +51,10 @@ class CI_Model {
/** /**
* Class constructor * Class constructor
* *
* @link https://github.com/bcit-ci/CodeIgniter/issues/5332
* @return void * @return void
*/ */
public function __construct() public function __construct() {}
{
log_message('info', 'Model Class Initialized');
}
// --------------------------------------------------------------------
/** /**
* __get magic * __get magic

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -122,6 +122,13 @@ class CI_Output {
*/ */
public $parse_exec_vars = TRUE; public $parse_exec_vars = TRUE;
/**
* mbstring.func_overload flag
*
* @var bool
*/
protected static $func_overload;
/** /**
* Class constructor * Class constructor
* *
@ -138,6 +145,8 @@ class CI_Output {
&& extension_loaded('zlib') && extension_loaded('zlib')
); );
isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));
// Get mime types for later // Get mime types for later
$this->mimes =& get_mimes(); $this->mimes =& get_mimes();
@ -285,7 +294,7 @@ class CI_Output {
/** /**
* Get Header * Get Header
* *
* @param string $header_name * @param string $header
* @return string * @return string
*/ */
public function get_header($header) public function get_header($header)
@ -302,11 +311,12 @@ class CI_Output {
return NULL; return NULL;
} }
for ($i = 0, $c = count($headers); $i < $c; $i++) // Count backwards, in order to get the last matching header
for ($c = count($headers) - 1; $c > -1; $c--)
{ {
if (strncasecmp($header, $headers[$i], $l = strlen($header)) === 0) if (strncasecmp($header, $headers[$c], $l = self::strlen($header)) === 0)
{ {
return trim(substr($headers[$i], $l+1)); return trim(self::substr($headers[$c], $l+1));
} }
} }
@ -480,13 +490,13 @@ class CI_Output {
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
{ {
header('Content-Encoding: gzip'); header('Content-Encoding: gzip');
header('Content-Length: '.strlen($output)); header('Content-Length: '.self::strlen($output));
} }
else else
{ {
// User agent doesn't support gzip compression, // User agent doesn't support gzip compression,
// so we'll have to decompress our cache // so we'll have to decompress our cache
$output = gzinflate(substr($output, 10, -8)); $output = gzinflate(self::substr($output, 10, -8));
} }
} }
@ -576,8 +586,13 @@ class CI_Output {
return; return;
} }
if (flock($fp, LOCK_EX)) if ( ! flock($fp, LOCK_EX))
{ {
log_message('error', 'Unable to secure a file lock for file at: '.$cache_path);
fclose($fp);
return;
}
// If output compression is enabled, compress the cache // If output compression is enabled, compress the cache
// itself, so that we don't have to do that each time // itself, so that we don't have to do that each time
// we're serving it // we're serving it
@ -601,38 +616,30 @@ class CI_Output {
$output = $cache_info.'ENDCI--->'.$output; $output = $cache_info.'ENDCI--->'.$output;
for ($written = 0, $length = strlen($output); $written < $length; $written += $result) for ($written = 0, $length = self::strlen($output); $written < $length; $written += $result)
{ {
if (($result = fwrite($fp, substr($output, $written))) === FALSE) if (($result = fwrite($fp, self::substr($output, $written))) === FALSE)
{ {
break; break;
} }
} }
flock($fp, LOCK_UN); flock($fp, LOCK_UN);
} fclose($fp);
else
if ( ! is_int($result))
{ {
log_message('error', 'Unable to secure a file lock for file at: '.$cache_path); @unlink($cache_path);
log_message('error', 'Unable to write the complete cache content at: '.$cache_path);
return; return;
} }
fclose($fp);
if (is_int($result))
{
chmod($cache_path, 0640); chmod($cache_path, 0640);
log_message('debug', 'Cache file written: '.$cache_path); log_message('debug', 'Cache file written: '.$cache_path);
// Send HTTP cache-control headers to browser to match file cache settings. // Send HTTP cache-control headers to browser to match file cache settings.
$this->set_cache_header($_SERVER['REQUEST_TIME'], $expire); $this->set_cache_header($_SERVER['REQUEST_TIME'], $expire);
} }
else
{
@unlink($cache_path);
log_message('error', 'Unable to write the complete cache content at: '.$cache_path);
}
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -698,11 +705,9 @@ class CI_Output {
log_message('debug', 'Cache file has expired. File deleted.'); log_message('debug', 'Cache file has expired. File deleted.');
return FALSE; return FALSE;
} }
else
{ // Send the HTTP cache control headers
// Or else send the HTTP cache control headers.
$this->set_cache_header($last_modified, $expire); $this->set_cache_header($last_modified, $expire);
}
// Add headers from cache file. // Add headers from cache file.
foreach ($cache_info['headers'] as $header) foreach ($cache_info['headers'] as $header)
@ -711,7 +716,7 @@ class CI_Output {
} }
// Display the cache // Display the cache
$this->_display(substr($cache, strlen($match[0]))); $this->_display(self::substr($cache, self::strlen($match[0])));
log_message('debug', 'Cache file is current. Sending it to browser.'); log_message('debug', 'Cache file is current. Sending it to browser.');
return TRUE; return TRUE;
} }
@ -788,13 +793,50 @@ class CI_Output {
$this->set_status_header(304); $this->set_status_header(304);
exit; exit;
} }
else
{
header('Pragma: public'); header('Pragma: public');
header('Cache-Control: max-age='.$max_age.', public'); header('Cache-Control: max-age='.$max_age.', public');
header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT'); header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT');
header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT'); header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT');
} }
// --------------------------------------------------------------------
/**
* Byte-safe strlen()
*
* @param string $str
* @return int
*/
protected static function strlen($str)
{
return (self::$func_overload)
? mb_strlen($str, '8bit')
: strlen($str);
} }
// --------------------------------------------------------------------
/**
* Byte-safe substr()
*
* @param string $str
* @param int $start
* @param int $length
* @return string
*/
protected static function substr($str, $start, $length = NULL)
{
if (self::$func_overload)
{
// mb_substr($str, $start, null, '8bit') returns an empty
// string on PHP 5.3
isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start);
return mb_substr($str, $start, $length, '8bit');
}
return isset($length)
? substr($str, $start, $length)
: substr($str, $start);
}
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -134,14 +134,17 @@ class CI_Security {
*/ */
protected $_never_allowed_str = array( protected $_never_allowed_str = array(
'document.cookie' => '[removed]', 'document.cookie' => '[removed]',
'(document).cookie' => '[removed]',
'document.write' => '[removed]', 'document.write' => '[removed]',
'(document).write' => '[removed]',
'.parentNode' => '[removed]', '.parentNode' => '[removed]',
'.innerHTML' => '[removed]', '.innerHTML' => '[removed]',
'-moz-binding' => '[removed]', '-moz-binding' => '[removed]',
'<!--' => '&lt;!--', '<!--' => '&lt;!--',
'-->' => '--&gt;', '-->' => '--&gt;',
'<![CDATA[' => '&lt;![CDATA[', '<![CDATA[' => '&lt;![CDATA[',
'<comment>' => '&lt;comment&gt;' '<comment>' => '&lt;comment&gt;',
'<%' => '&lt;&#37;'
); );
/** /**
@ -151,7 +154,7 @@ class CI_Security {
*/ */
protected $_never_allowed_regex = array( protected $_never_allowed_regex = array(
'javascript\s*:', 'javascript\s*:',
'(document|(document\.)?window)\.(location|on\w*)', '(\(?document\)?|\(?window\)?(\.document)?)\.(location|on\w*)',
'expression\s*(\(|&\#40;)', // CSS and IE 'expression\s*(\(|&\#40;)', // CSS and IE
'vbscript\s*:', // IE, surprise! 'vbscript\s*:', // IE, surprise!
'wscript\s*:', // IE 'wscript\s*:', // IE
@ -223,14 +226,11 @@ class CI_Security {
} }
} }
// Do the tokens exist in both the _POST and _COOKIE arrays? // Check CSRF token validity, but don't error on mismatch just yet - we'll want to regenerate
if ( ! isset($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name]) $valid = isset($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name])
OR $_POST[$this->_csrf_token_name] !== $_COOKIE[$this->_csrf_cookie_name]) // Do the tokens match? && hash_equals($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name]);
{
$this->csrf_show_error();
}
// We kill this since we're done and we don't want to polute the _POST array // We kill this since we're done and we don't want to pollute the _POST array
unset($_POST[$this->_csrf_token_name]); unset($_POST[$this->_csrf_token_name]);
// Regenerate on every submission? // Regenerate on every submission?
@ -244,6 +244,11 @@ class CI_Security {
$this->_csrf_set_hash(); $this->_csrf_set_hash();
$this->csrf_set_cookie(); $this->csrf_set_cookie();
if ($valid !== TRUE)
{
$this->csrf_show_error();
}
log_message('info', 'CSRF token verified'); log_message('info', 'CSRF token verified');
return $this; return $this;
} }
@ -351,9 +356,9 @@ class CI_Security {
// Is the string an array? // Is the string an array?
if (is_array($str)) if (is_array($str))
{ {
while (list($key) = each($str)) foreach ($str as $key => &$value)
{ {
$str[$key] = $this->xss_clean($str[$key]); $str[$key] = $this->xss_clean($value);
} }
return $str; return $str;
@ -371,11 +376,17 @@ class CI_Security {
* *
* Note: Use rawurldecode() so it does not remove plus signs * Note: Use rawurldecode() so it does not remove plus signs
*/ */
if (stripos($str, '%') !== false)
{
do do
{ {
$oldstr = $str;
$str = rawurldecode($str); $str = rawurldecode($str);
$str = preg_replace_callback('#%(?:\s*[0-9a-f]){2,}#i', array($this, '_urldecodespaces'), $str);
}
while ($oldstr !== $str);
unset($oldstr);
} }
while (preg_match('/%[0-9a-f]{2,}/i', $str));
/* /*
* Convert character entities to ASCII * Convert character entities to ASCII
@ -466,7 +477,7 @@ class CI_Security {
if (preg_match('/<a/i', $str)) if (preg_match('/<a/i', $str))
{ {
$str = preg_replace_callback('#<a[^a-z0-9>]+([^>]*?)(?:>|$)#si', array($this, '_js_link_removal'), $str); $str = preg_replace_callback('#<a(?:rea)?[^a-z0-9>]+([^>]*?)(?:>|$)#si', array($this, '_js_link_removal'), $str);
} }
if (preg_match('/<img/i', $str)) if (preg_match('/<img/i', $str))
@ -492,7 +503,7 @@ class CI_Security {
* Becomes: &lt;blink&gt; * Becomes: &lt;blink&gt;
*/ */
$pattern = '#' $pattern = '#'
.'<((?<slash>/*\s*)(?<tagName>[a-z0-9]+)(?=[^a-z0-9]|$)' // tag start and name, followed by a non-tag character .'<((?<slash>/*\s*)((?<tagName>[a-z0-9]+)(?=[^a-z0-9]|$)|.+)' // tag start and name, followed by a non-tag character
.'[^\s\042\047a-z0-9>/=]*' // a valid attribute character immediately after the tag would count as a separator .'[^\s\042\047a-z0-9>/=]*' // a valid attribute character immediately after the tag would count as a separator
// optional attributes // optional attributes
.'(?<attributes>(?:[\s\042\047/=]*' // non-attribute characters, excluding > (tag close) for obvious reasons .'(?<attributes>(?:[\s\042\047/=]*' // non-attribute characters, excluding > (tag close) for obvious reasons
@ -533,6 +544,14 @@ class CI_Security {
$str $str
); );
// Same thing, but for "tag functions" (e.g. eval`some code`)
// See https://github.com/bcit-ci/CodeIgniter/issues/5420
$str = preg_replace(
'#(alert|prompt|confirm|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)`(.*?)`#si',
'\\1\\2&#96;\\3&#96;',
$str
);
// Final clean up // Final clean up
// This adds a bit of extra precaution in case // This adds a bit of extra precaution in case
// something got through the above filters // something got through the above filters
@ -669,21 +688,9 @@ class CI_Security {
? ENT_COMPAT | ENT_HTML5 ? ENT_COMPAT | ENT_HTML5
: ENT_COMPAT; : ENT_COMPAT;
do
{
$str_compare = $str;
// Decode standard entities, avoiding false positives
if (preg_match_all('/&[a-z]{2,}(?![a-z;])/i', $str, $matches))
{
if ( ! isset($_entities)) if ( ! isset($_entities))
{ {
$_entities = array_map( $_entities = array_map('strtolower', get_html_translation_table(HTML_ENTITIES, $flag, $charset));
'strtolower',
is_php('5.3.4')
? get_html_translation_table(HTML_ENTITIES, $flag, $charset)
: get_html_translation_table(HTML_ENTITIES, $flag)
);
// If we're not on PHP 5.4+, add the possibly dangerous HTML 5 // If we're not on PHP 5.4+, add the possibly dangerous HTML 5
// entities to the array manually // entities to the array manually
@ -692,11 +699,18 @@ class CI_Security {
$_entities[':'] = '&colon;'; $_entities[':'] = '&colon;';
$_entities['('] = '&lpar;'; $_entities['('] = '&lpar;';
$_entities[')'] = '&rpar;'; $_entities[')'] = '&rpar;';
$_entities["\n"] = '&newline;'; $_entities["\n"] = '&NewLine;';
$_entities["\t"] = '&tab;'; $_entities["\t"] = '&Tab;';
} }
} }
do
{
$str_compare = $str;
// Decode standard entities, avoiding false positives
if (preg_match_all('/&[a-z]{2,}(?![a-z;])/i', $str, $matches))
{
$replace = array(); $replace = array();
$matches = array_unique(array_map('strtolower', $matches[0])); $matches = array_unique(array_map('strtolower', $matches[0]));
foreach ($matches as &$match) foreach ($matches as &$match)
@ -707,7 +721,7 @@ class CI_Security {
} }
} }
$str = str_ireplace(array_keys($replace), array_values($replace), $str); $str = str_replace(array_keys($replace), array_values($replace), $str);
} }
// Decode numeric & UTF16 two byte entities // Decode numeric & UTF16 two byte entities
@ -716,6 +730,11 @@ class CI_Security {
$flag, $flag,
$charset $charset
); );
if ($flag === ENT_COMPAT)
{
$str = str_replace(array_values($_entities), array_keys($_entities), $str);
}
} }
while ($str_compare !== $str); while ($str_compare !== $str);
return $str; return $str;
@ -774,6 +793,24 @@ class CI_Security {
// ---------------------------------------------------------------- // ----------------------------------------------------------------
/**
* URL-decode taking spaces into account
*
* @see https://github.com/bcit-ci/CodeIgniter/issues/4877
* @param array $matches
* @return string
*/
protected function _urldecodespaces($matches)
{
$input = $matches[0];
$nospaces = preg_replace('#\s+#', '', $input);
return ($nospaces === $input)
? $input
: rawurldecode($nospaces);
}
// ----------------------------------------------------------------
/** /**
* Compact Exploded Words * Compact Exploded Words
* *
@ -803,7 +840,7 @@ class CI_Security {
protected function _sanitize_naughty_html($matches) protected function _sanitize_naughty_html($matches)
{ {
static $naughty_tags = array( static $naughty_tags = array(
'alert', 'prompt', 'confirm', 'applet', 'audio', 'basefont', 'base', 'behavior', 'bgsound', 'alert', 'area', 'prompt', 'confirm', 'applet', 'audio', 'basefont', 'base', 'behavior', 'bgsound',
'blink', 'body', 'embed', 'expression', 'form', 'frameset', 'frame', 'head', 'html', 'ilayer', 'blink', 'body', 'embed', 'expression', 'form', 'frameset', 'frame', 'head', 'html', 'ilayer',
'iframe', 'input', 'button', 'select', 'isindex', 'layer', 'link', 'meta', 'keygen', 'object', 'iframe', 'input', 'button', 'select', 'isindex', 'layer', 'link', 'meta', 'keygen', 'object',
'plaintext', 'style', 'script', 'textarea', 'title', 'math', 'video', 'svg', 'xml', 'xss' 'plaintext', 'style', 'script', 'textarea', 'title', 'math', 'video', 'svg', 'xml', 'xss'
@ -826,7 +863,7 @@ class CI_Security {
// For other tags, see if their attributes are "evil" and strip those // For other tags, see if their attributes are "evil" and strip those
elseif (isset($matches['attributes'])) elseif (isset($matches['attributes']))
{ {
// We'll store the already fitlered attributes here // We'll store the already filtered attributes here
$attributes = array(); $attributes = array();
// Attribute-catching pattern // Attribute-catching pattern
@ -842,7 +879,7 @@ class CI_Security {
// Each iteration filters a single attribute // Each iteration filters a single attribute
do do
{ {
// Strip any non-alpha characters that may preceed an attribute. // Strip any non-alpha characters that may precede an attribute.
// Browsers often parse these incorrectly and that has been a // Browsers often parse these incorrectly and that has been a
// of numerous XSS issues we've had. // of numerous XSS issues we've had.
$matches['attributes'] = preg_replace('#^[^a-z]+#i', '', $matches['attributes']); $matches['attributes'] = preg_replace('#^[^a-z]+#i', '', $matches['attributes']);
@ -900,7 +937,7 @@ class CI_Security {
return str_replace( return str_replace(
$match[1], $match[1],
preg_replace( preg_replace(
'#href=.*?(?:(?:alert|prompt|confirm)(?:\(|&\#40;)|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|data\s*:)#si', '#href=.*?(?:(?:alert|prompt|confirm)(?:\(|&\#40;|`|&\#96;)|javascript:|livescript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|<script|<xss|d\s*a\s*t\s*a\s*:)#si',
'', '',
$this->_filter_attributes($match[1]) $this->_filter_attributes($match[1])
), ),
@ -928,7 +965,7 @@ class CI_Security {
return str_replace( return str_replace(
$match[1], $match[1],
preg_replace( preg_replace(
'#src=.*?(?:(?:alert|prompt|confirm|eval)(?:\(|&\#40;)|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si', '#src=.*?(?:(?:alert|prompt|confirm|eval)(?:\(|&\#40;|`|&\#96;)|javascript:|livescript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|<script|<xss|base64\s*,)#si',
'', '',
$this->_filter_attributes($match[1]) $this->_filter_attributes($match[1])
), ),

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.0.0 * @since Version 2.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -119,7 +119,7 @@ if ( ! function_exists('hash_pbkdf2'))
*/ */
function hash_pbkdf2($algo, $password, $salt, $iterations, $length = 0, $raw_output = FALSE) function hash_pbkdf2($algo, $password, $salt, $iterations, $length = 0, $raw_output = FALSE)
{ {
if ( ! in_array($algo, hash_algos(), TRUE)) if ( ! in_array(strtolower($algo), hash_algos(), TRUE))
{ {
trigger_error('hash_pbkdf2(): Unknown hashing algorithm: '.$algo, E_USER_WARNING); trigger_error('hash_pbkdf2(): Unknown hashing algorithm: '.$algo, E_USER_WARNING);
return FALSE; return FALSE;
@ -173,7 +173,9 @@ if ( ! function_exists('hash_pbkdf2'))
return FALSE; return FALSE;
} }
$hash_length = strlen(hash($algo, NULL, TRUE)); $hash_length = defined('MB_OVERLOAD_STRING')
? mb_strlen(hash($algo, NULL, TRUE), '8bit')
: strlen(hash($algo, NULL, TRUE));
empty($length) && $length = $hash_length; empty($length) && $length = $hash_length;
// Pre-hash password inputs longer than the algorithm's block size // Pre-hash password inputs longer than the algorithm's block size
@ -221,14 +223,14 @@ if ( ! function_exists('hash_pbkdf2'))
'whirlpool' => 64 'whirlpool' => 64
); );
if (isset($block_sizes[$algo]) && strlen($password) > $block_sizes[$algo]) if (isset($block_sizes[$algo], $password[$block_sizes[$algo]]))
{ {
$password = hash($algo, $password, TRUE); $password = hash($algo, $password, TRUE);
} }
$hash = ''; $hash = '';
// Note: Blocks are NOT 0-indexed // Note: Blocks are NOT 0-indexed
for ($bc = ceil($length / $hash_length), $bi = 1; $bi <= $bc; $bi++) for ($bc = (int) ceil($length / $hash_length), $bi = 1; $bi <= $bc; $bi++)
{ {
$key = $derived_key = hash_hmac($algo, $salt.pack('N', $bi), $password, TRUE); $key = $derived_key = hash_hmac($algo, $salt.pack('N', $bi), $password, TRUE);
for ($i = 1; $i < $iterations; $i++) for ($i = 1; $i < $iterations; $i++)
@ -240,6 +242,13 @@ if ( ! function_exists('hash_pbkdf2'))
} }
// This is not RFC-compatible, but we're aiming for natural PHP compatibility // This is not RFC-compatible, but we're aiming for natural PHP compatibility
return substr($raw_output ? $hash : bin2hex($hash), 0, $length); if ( ! $raw_output)
{
$hash = bin2hex($hash);
}
return defined('MB_OVERLOAD_STRING')
? mb_substr($hash, 0, $length, '8bit')
: substr($hash, 0, $length);
} }
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -68,7 +68,7 @@ if ( ! function_exists('mb_strlen'))
* @link http://php.net/mb_strlen * @link http://php.net/mb_strlen
* @param string $str * @param string $str
* @param string $encoding * @param string $encoding
* @return string * @return int
*/ */
function mb_strlen($str, $encoding = NULL) function mb_strlen($str, $encoding = NULL)
{ {

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -50,7 +50,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
if (is_php('5.5') OR ! is_php('5.3.7') OR ! defined('CRYPT_BLOWFISH') OR CRYPT_BLOWFISH !== 1 OR defined('HHVM_VERSION')) if (is_php('5.5') OR ! defined('CRYPT_BLOWFISH') OR CRYPT_BLOWFISH !== 1 OR defined('HHVM_VERSION'))
{ {
return; return;
} }
@ -94,8 +94,8 @@ if ( ! function_exists('password_hash'))
*/ */
function password_hash($password, $algo, array $options = array()) function password_hash($password, $algo, array $options = array())
{ {
static $func_override; static $func_overload;
isset($func_override) OR $func_override = (extension_loaded('mbstring') && ini_get('mbstring.func_override')); isset($func_overload) OR $func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));
if ($algo !== 1) if ($algo !== 1)
{ {
@ -109,21 +109,29 @@ if ( ! function_exists('password_hash'))
return NULL; return NULL;
} }
if (isset($options['salt']) && ($saltlen = ($func_override ? mb_strlen($options['salt'], '8bit') : strlen($options['salt']))) < 22) if (isset($options['salt']) && ($saltlen = ($func_overload ? mb_strlen($options['salt'], '8bit') : strlen($options['salt']))) < 22)
{ {
trigger_error('password_hash(): Provided salt is too short: '.$saltlen.' expecting 22', E_USER_WARNING); trigger_error('password_hash(): Provided salt is too short: '.$saltlen.' expecting 22', E_USER_WARNING);
return NULL; return NULL;
} }
elseif ( ! isset($options['salt'])) elseif ( ! isset($options['salt']))
{ {
if (defined('MCRYPT_DEV_URANDOM')) if (function_exists('random_bytes'))
{
try
{
$options['salt'] = random_bytes(16);
}
catch (Exception $e)
{
log_message('error', 'compat/password: Error while trying to use random_bytes(): '.$e->getMessage());
return FALSE;
}
}
elseif (defined('MCRYPT_DEV_URANDOM'))
{ {
$options['salt'] = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM); $options['salt'] = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM);
} }
elseif (function_exists('openssl_random_pseudo_bytes'))
{
$options['salt'] = openssl_random_pseudo_bytes(16);
}
elseif (DIRECTORY_SEPARATOR === '/' && (is_readable($dev = '/dev/arandom') OR is_readable($dev = '/dev/urandom'))) elseif (DIRECTORY_SEPARATOR === '/' && (is_readable($dev = '/dev/arandom') OR is_readable($dev = '/dev/urandom')))
{ {
if (($fp = fopen($dev, 'rb')) === FALSE) if (($fp = fopen($dev, 'rb')) === FALSE)
@ -136,7 +144,7 @@ if ( ! function_exists('password_hash'))
is_php('5.4') && stream_set_chunk_size($fp, 16); is_php('5.4') && stream_set_chunk_size($fp, 16);
$options['salt'] = ''; $options['salt'] = '';
for ($read = 0; $read < 16; $read = ($func_override) ? mb_strlen($options['salt'], '8bit') : strlen($options['salt'])) for ($read = 0; $read < 16; $read = ($func_overload) ? mb_strlen($options['salt'], '8bit') : strlen($options['salt']))
{ {
if (($read = fread($fp, 16 - $read)) === FALSE) if (($read = fread($fp, 16 - $read)) === FALSE)
{ {
@ -148,6 +156,16 @@ if ( ! function_exists('password_hash'))
fclose($fp); fclose($fp);
} }
elseif (function_exists('openssl_random_pseudo_bytes'))
{
$is_secure = NULL;
$options['salt'] = openssl_random_pseudo_bytes(16, $is_secure);
if ($is_secure !== TRUE)
{
log_message('error', 'compat/password: openssl_random_pseudo_bytes() set the $cryto_strong flag to FALSE');
return FALSE;
}
}
else else
{ {
log_message('error', 'compat/password: No CSPRNG available.'); log_message('error', 'compat/password: No CSPRNG available.');

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -62,7 +62,7 @@ if ( ! function_exists('array_column'))
* array_column() * array_column()
* *
* @link http://php.net/array_column * @link http://php.net/array_column
* @param string $array * @param array $array
* @param mixed $column_key * @param mixed $column_key
* @param mixed $index_key * @param mixed $index_key
* @return array * @return array
@ -153,7 +153,7 @@ if ( ! function_exists('hex2bin'))
*/ */
function hex2bin($data) function hex2bin($data)
{ {
if (in_array($type = gettype($data), array('array', 'double', 'object'), TRUE)) if (in_array($type = gettype($data), array('array', 'double', 'object', 'resource'), TRUE))
{ {
if ($type === 'object' && method_exists($data, '__toString')) if ($type === 'object' && method_exists($data, '__toString'))
{ {
@ -180,210 +180,3 @@ if ( ! function_exists('hex2bin'))
return pack('H*', $data); return pack('H*', $data);
} }
} }
// ------------------------------------------------------------------------
if (is_php('5.3'))
{
return;
}
// ------------------------------------------------------------------------
if ( ! function_exists('array_replace'))
{
/**
* array_replace()
*
* @link http://php.net/array_replace
* @return array
*/
function array_replace()
{
$arrays = func_get_args();
if (($c = count($arrays)) === 0)
{
trigger_error('array_replace() expects at least 1 parameter, 0 given', E_USER_WARNING);
return NULL;
}
elseif ($c === 1)
{
if ( ! is_array($arrays[0]))
{
trigger_error('array_replace(): Argument #1 is not an array', E_USER_WARNING);
return NULL;
}
return $arrays[0];
}
$array = array_shift($arrays);
$c--;
for ($i = 0; $i < $c; $i++)
{
if ( ! is_array($arrays[$i]))
{
trigger_error('array_replace(): Argument #'.($i + 2).' is not an array', E_USER_WARNING);
return NULL;
}
elseif (empty($arrays[$i]))
{
continue;
}
foreach (array_keys($arrays[$i]) as $key)
{
$array[$key] = $arrays[$i][$key];
}
}
return $array;
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('array_replace_recursive'))
{
/**
* array_replace_recursive()
*
* @link http://php.net/array_replace_recursive
* @return array
*/
function array_replace_recursive()
{
$arrays = func_get_args();
if (($c = count($arrays)) === 0)
{
trigger_error('array_replace_recursive() expects at least 1 parameter, 0 given', E_USER_WARNING);
return NULL;
}
elseif ($c === 1)
{
if ( ! is_array($arrays[0]))
{
trigger_error('array_replace_recursive(): Argument #1 is not an array', E_USER_WARNING);
return NULL;
}
return $arrays[0];
}
$array = array_shift($arrays);
$c--;
for ($i = 0; $i < $c; $i++)
{
if ( ! is_array($arrays[$i]))
{
trigger_error('array_replace_recursive(): Argument #'.($i + 2).' is not an array', E_USER_WARNING);
return NULL;
}
elseif (empty($arrays[$i]))
{
continue;
}
foreach (array_keys($arrays[$i]) as $key)
{
$array[$key] = (is_array($arrays[$i][$key]) && isset($array[$key]) && is_array($array[$key]))
? array_replace_recursive($array[$key], $arrays[$i][$key])
: $arrays[$i][$key];
}
}
return $array;
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('quoted_printable_encode'))
{
/**
* quoted_printable_encode()
*
* @link http://php.net/quoted_printable_encode
* @param string $str
* @return string
*/
function quoted_printable_encode($str)
{
if (strlen($str) === 0)
{
return '';
}
elseif (in_array($type = gettype($str), array('array', 'object'), TRUE))
{
if ($type === 'object' && method_exists($str, '__toString'))
{
$str = (string) $str;
}
else
{
trigger_error('quoted_printable_encode() expects parameter 1 to be string, '.$type.' given', E_USER_WARNING);
return NULL;
}
}
if (function_exists('imap_8bit'))
{
return imap_8bit($str);
}
$i = $lp = 0;
$output = '';
$hex = '0123456789ABCDEF';
$length = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'))
? mb_strlen($str, '8bit')
: strlen($str);
while ($length--)
{
if ((($c = $str[$i++]) === "\015") && isset($str[$i]) && ($str[$i] === "\012") && $length > 0)
{
$output .= "\015".$str[$i++];
$length--;
$lp = 0;
continue;
}
if (
ctype_cntrl($c)
OR (ord($c) === 0x7f)
OR (ord($c) & 0x80)
OR ($c === '=')
OR ($c === ' ' && isset($str[$i]) && $str[$i] === "\015")
)
{
if (
(($lp += 3) > 75 && ord($c) <= 0x7f)
OR (ord($c) > 0x7f && ord($c) <= 0xdf && ($lp + 3) > 75)
OR (ord($c) > 0xdf && ord($c) <= 0xef && ($lp + 6) > 75)
OR (ord($c) > 0xef && ord($c) <= 0xf4 && ($lp + 9) > 75)
)
{
$output .= "=\015\012";
$lp = 3;
}
$output .= '='.$hex[ord($c) >> 4].$hex[ord($c) & 0xf];
continue;
}
if ((++$lp) > 75)
{
$output .= "=\015\012";
$lp = 1;
}
$output .= $c;
}
return $output;
}
}

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -143,7 +143,7 @@ class CI_DB_Cache {
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
$filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql);
if (FALSE === ($cachedata = @file_get_contents($filepath))) if ( ! is_file($filepath) OR FALSE === ($cachedata = file_get_contents($filepath)))
{ {
return FALSE; return FALSE;
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -916,6 +916,7 @@ abstract class CI_DB_driver {
if ($this->_trans_begin()) if ($this->_trans_begin())
{ {
$this->_trans_status = TRUE;
$this->_trans_depth++; $this->_trans_depth++;
return TRUE; return TRUE;
} }
@ -980,7 +981,7 @@ abstract class CI_DB_driver {
*/ */
public function compile_binds($sql, $binds) public function compile_binds($sql, $binds)
{ {
if (empty($binds) OR empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE) if (empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE)
{ {
return $sql; return $sql;
} }
@ -1000,7 +1001,7 @@ abstract class CI_DB_driver {
$ml = strlen($this->bind_marker); $ml = strlen($this->bind_marker);
// Make sure not to replace a chunk inside a string that happens to match the bind marker // Make sure not to replace a chunk inside a string that happens to match the bind marker
if ($c = preg_match_all("/'[^']*'/i", $sql, $matches)) if ($c = preg_match_all("/'[^']*'|\"[^\"]*\"/i", $sql, $matches))
{ {
$c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', $c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i',
str_replace($matches[0], str_replace($matches[0],
@ -1044,7 +1045,7 @@ abstract class CI_DB_driver {
*/ */
public function is_write_type($sql) public function is_write_type($sql)
{ {
return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s/i', $sql); return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX|MERGE)\s/i', $sql);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -1173,14 +1174,14 @@ abstract class CI_DB_driver {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Platform-dependant string escape * Platform-dependent string escape
* *
* @param string * @param string
* @return string * @return string
*/ */
protected function _escape_str($str) protected function _escape_str($str)
{ {
return str_replace("'", "''", remove_invisible_characters($str)); return str_replace("'", "''", remove_invisible_characters($str, FALSE));
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -1527,7 +1528,7 @@ abstract class CI_DB_driver {
return 'UPDATE '.$table.' SET '.implode(', ', $valstr) return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
.$this->_compile_wh('qb_where') .$this->_compile_wh('qb_where')
.$this->_compile_order_by() .$this->_compile_order_by()
.($this->qb_limit ? ' LIMIT '.$this->qb_limit : ''); .($this->qb_limit !== FALSE ? ' LIMIT '.$this->qb_limit : '');
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -1925,15 +1926,19 @@ abstract class CI_DB_driver {
$i++; $i++;
} }
// dbprefix may've already been applied, with or without the identifier escaped
$ec = '(?<ec>'.preg_quote(is_array($this->_escape_char) ? $this->_escape_char[0] : $this->_escape_char).')?';
isset($ec[0]) && $ec .= '?'; // Just in case someone has disabled escaping by forcing an empty escape character
// Verify table prefix and replace if necessary // Verify table prefix and replace if necessary
if ($this->swap_pre !== '' && strpos($parts[$i], $this->swap_pre) === 0) if ($this->swap_pre !== '' && preg_match('#^'.$ec.preg_quote($this->swap_pre).'#', $parts[$i]))
{ {
$parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]); $parts[$i] = preg_replace('#^'.$ec.preg_quote($this->swap_pre).'(\S+?)#', '\\1'.$this->dbprefix.'\\2', $parts[$i]);
} }
// We only add the table prefix if it does not already exist // We only add the table prefix if it does not already exist
elseif (strpos($parts[$i], $this->dbprefix) !== 0) else
{ {
$parts[$i] = $this->dbprefix.$parts[$i]; preg_match('#^'.$ec.preg_quote($this->dbprefix).'#', $parts[$i]) OR $parts[$i] = $this->dbprefix.$parts[$i];
} }
// Put the parts back together // Put the parts back together

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -184,7 +184,7 @@ abstract class CI_DB_forge {
{ {
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
} }
elseif ( ! $this->db->query(sprintf($this->_create_database, $db_name, $this->db->char_set, $this->db->dbcollat))) elseif ( ! $this->db->query(sprintf($this->_create_database, $this->db->escape_identifiers($db_name), $this->db->char_set, $this->db->dbcollat)))
{ {
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
} }
@ -211,7 +211,7 @@ abstract class CI_DB_forge {
{ {
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
} }
elseif ( ! $this->db->query(sprintf($this->_drop_database, $db_name))) elseif ( ! $this->db->query(sprintf($this->_drop_database, $this->db->escape_identifiers($db_name))))
{ {
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
} }
@ -348,7 +348,7 @@ abstract class CI_DB_forge {
if (($result = $this->db->query($sql)) !== FALSE) if (($result = $this->db->query($sql)) !== FALSE)
{ {
empty($this->db->data_cache['table_names']) OR $this->db->data_cache['table_names'][] = $table; isset($this->db->data_cache['table_names']) && $this->db->data_cache['table_names'][] = $table;
// Most databases don't support creating indexes from within the CREATE TABLE statement // Most databases don't support creating indexes from within the CREATE TABLE statement
if ( ! empty($this->keys)) if ( ! empty($this->keys))
@ -382,11 +382,9 @@ abstract class CI_DB_forge {
{ {
return TRUE; return TRUE;
} }
else
{
$if_not_exists = FALSE; $if_not_exists = FALSE;
} }
}
$sql = ($if_not_exists) $sql = ($if_not_exists)
? sprintf($this->_create_table_if, $this->db->escape_identifiers($table)) ? sprintf($this->_create_table_if, $this->db->escape_identifiers($table))
@ -488,7 +486,7 @@ abstract class CI_DB_forge {
* *
* @param string $table Table name * @param string $table Table name
* @param bool $if_exists Whether to add an IF EXISTS condition * @param bool $if_exists Whether to add an IF EXISTS condition
* @return string * @return mixed (Returns a platform-specific DROP table string, or TRUE to indicate there's nothing to do)
*/ */
protected function _drop_table($table, $if_exists) protected function _drop_table($table, $if_exists)
{ {
@ -979,8 +977,8 @@ abstract class CI_DB_forge {
/** /**
* Process indexes * Process indexes
* *
* @param string $table * @param string $table Table name
* @return string * @return string[] list of SQL statements
*/ */
protected function _process_indexes($table) protected function _process_indexes($table)
{ {

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -149,6 +149,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/ */
protected $qb_set = array(); protected $qb_set = array();
/**
* QB data set for update_batch()
*
* @var array
*/
protected $qb_set_ub = array();
/** /**
* QB aliased tables list * QB aliased tables list
* *
@ -207,6 +214,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/ */
protected $qb_cache_join = array(); protected $qb_cache_join = array();
/**
* QB Cache aliased tables list
*
* @var array
*/
protected $qb_cache_aliased_tables = array();
/** /**
* QB Cache WHERE data * QB Cache WHERE data
* *
@ -666,7 +680,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{ {
if ($escape === TRUE) if ($escape === TRUE)
{ {
$v = ' '.$this->escape($v); $v = $this->escape($v);
} }
if ( ! $this->_has_operator($k)) 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 // value appears not to have been set, assign the test to IS NULL
$k .= ' 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'); $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) 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); $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( $where_in = array(
'condition' => $prefix.$key.$not.' IN('.implode(', ', $where_in).')', 'condition' => $prefix.$key.$not.' IN('.implode(', ', $where_in).')',
'value' => NULL,
'escape' => $escape 'escape' => $escape
); );
@ -948,33 +964,34 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$v = $this->escape_like_str($v); $v = $this->escape_like_str($v);
} }
if ($side === 'none') switch ($side)
{ {
$like_statement = "{$prefix} {$k} {$not} LIKE '{$v}'"; case 'none':
} $v = "'{$v}'";
elseif ($side === 'before') break;
{ case 'before':
$like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}'"; $v = "'%{$v}'";
} break;
elseif ($side === 'after') case 'after':
{ $v = "'{$v}%'";
$like_statement = "{$prefix} {$k} {$not} LIKE '{$v}%'"; break;
} case 'both':
else default:
{ $v = "'%{$v}%'";
$like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}%'"; break;
} }
// some platforms require an escape sequence definition for LIKE wildcards // some platforms require an escape sequence definition for LIKE wildcards
if ($escape === TRUE && $this->_like_escape_str !== '') 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) 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'; $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; $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
$where = array( $where = array(
'condition' => $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' (', 'condition' => $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' (',
'value' => NULL,
'escape' => FALSE 'escape' => FALSE
); );
@ -1059,6 +1077,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->qb_where_group_started = FALSE; $this->qb_where_group_started = FALSE;
$where = array( $where = array(
'condition' => str_repeat(' ', $this->qb_where_group_count--).')', 'condition' => str_repeat(' ', $this->qb_where_group_count--).')',
'value' => NULL,
'escape' => FALSE 'escape' => FALSE
); );
@ -1271,7 +1290,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/ */
protected function _limit($sql) 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 // ORDER BY usage is often problematic here (most notably
// on Microsoft SQL Server) and ultimately unnecessary // on Microsoft SQL Server) and ultimately unnecessary
// for selecting COUNT(*) ... // for selecting COUNT(*) ...
if ( ! empty($this->qb_orderby)) $qb_orderby = $this->qb_orderby;
{ $qb_cache_orderby = $this->qb_cache_orderby;
$orderby = $this->qb_orderby; $this->qb_orderby = $this->qb_cache_orderby = array();
$this->qb_orderby = NULL;
}
$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->_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'))); : $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(); $this->_reset_select();
} }
// If we've previously reset the qb_orderby values, get them back else
elseif ( ! isset($this->qb_orderby))
{ {
$this->qb_orderby = $orderby; $this->qb_orderby = $qb_orderby;
$this->qb_cache_orderby = $qb_cache_orderby;
} }
if ($result->num_rows() === 0) 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 * Allows the where clause, limit and offset to be added directly
* *
@ -1498,9 +1515,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$affected_rows = 0; $affected_rows = 0;
for ($i = 0, $total = count($this->qb_set); $i < $total; $i += $batch_size) 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))); 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(); $affected_rows += $this->affected_rows();
} }
}
$this->_reset_write(); $this->_reset_write();
return $affected_rows; return $affected_rows;
@ -1544,7 +1563,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
is_bool($escape) OR $escape = $this->_protect_identifiers; 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); sort($keys);
foreach ($key as $row) foreach ($key as $row)
@ -1884,7 +1903,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
if ($set === NULL) 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; 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 // Batch this baby
$affected_rows = 0; $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)
{
if ($this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set_ub, $i, $batch_size), $index)))
{ {
$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(); $affected_rows += $this->affected_rows();
}
$this->qb_where = array(); $this->qb_where = array();
} }
@ -1939,13 +1961,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$ids = array(); $ids = array();
foreach ($values as $key => $val) foreach ($values as $key => $val)
{ {
$ids[] = $val[$index]; $ids[] = $val[$index]['value'];
foreach (array_keys($val) as $field) foreach (array_keys($val) as $field)
{ {
if ($field !== $index) 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, '; .'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'); 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; $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) 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'); return $this->display_error('db_batch_missing_index');
} }
$this->qb_set[] = $clean; $this->qb_set_ub[] = $clean;
} }
return $this; return $this;
@ -2190,7 +2215,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
protected function _delete($table) protected function _delete($table)
{ {
return 'DELETE FROM '.$table.$this->_compile_wh('qb_where') 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, ' ')); $table = trim(strrchr($table, ' '));
// Store the alias, if it doesn't already exist // 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; $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 .$this->_compile_order_by(); // ORDER BY
// LIMIT // LIMIT
if ($this->qb_limit) if ($this->qb_limit !== FALSE OR $this->qb_offset)
{ {
return $this->_limit($sql."\n"); 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) 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; continue;
} }
@ -2409,7 +2439,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
.' '.trim($matches[3]).$matches[4].$matches[5]; .' '.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 ") 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. * 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 * group_by() is called prior to from(), join() and dbprefix is added
* only if needed. * 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. * 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 * order_by() is called prior to from(), join() and dbprefix is added
* only if needed. * only if needed.
* *
@ -2470,10 +2500,18 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
*/ */
protected function _compile_order_by() protected function _compile_order_by()
{ {
if (is_array($this->qb_orderby) && count($this->qb_orderby) > 0) if (empty($this->qb_orderby))
{ {
return '';
}
for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++) for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++)
{ {
if (is_string($this->qb_orderby[$i]))
{
continue;
}
if ($this->qb_orderby[$i]['escape'] !== FALSE && ! $this->_is_literal($this->qb_orderby[$i]['field'])) 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]['field'] = $this->protect_identifiers($this->qb_orderby[$i]['field']);
@ -2482,14 +2520,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction']; $this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction'];
} }
return $this->qb_orderby = "\nORDER BY ".implode(', ', $this->qb_orderby); return "\nORDER BY ".implode(', ', $this->qb_orderby);
}
elseif (is_string($this->qb_orderby))
{
return $this->qb_orderby;
}
return '';
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -2610,7 +2641,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
'qb_cache_orderby' => array(), 'qb_cache_orderby' => array(),
'qb_cache_set' => array(), 'qb_cache_set' => array(),
'qb_cache_exists' => array(), 'qb_cache_exists' => array(),
'qb_cache_no_escape' => array() 'qb_cache_no_escape' => array(),
'qb_cache_aliased_tables' => array()
)); ));
return $this; return $this;
@ -2661,13 +2693,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->qb_no_escape = $qb_no_escape; $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( $this->_reset_run(array(
'qb_set' => array(), 'qb_set' => array(),
'qb_set_ub' => array(),
'qb_from' => array(), 'qb_from' => array(),
'qb_join' => array(), 'qb_join' => array(),
'qb_where' => array(), 'qb_where' => array(),

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -163,11 +163,9 @@ class CI_DB_result {
{ {
return $this->result_object(); return $this->result_object();
} }
else
{
return $this->custom_result_object($type); return $this->custom_result_object($type);
} }
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -336,7 +334,8 @@ class CI_DB_result {
if ($type === 'object') return $this->row_object($n); if ($type === 'object') return $this->row_object($n);
elseif ($type === 'array') return $this->row_array($n); elseif ($type === 'array') return $this->row_array($n);
else return $this->custom_row_object($n, $type);
return $this->custom_row_object($n, $type);
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -660,7 +659,7 @@ class CI_DB_result {
*/ */
protected function _fetch_object($class_name = 'stdClass') protected function _fetch_object($class_name = 'stdClass')
{ {
return array(); return new $class_name();
} }
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.1.0 * @since Version 2.1.0
@ -250,7 +250,7 @@ class CI_DB_cubrid_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Platform-dependant string escape * Platform-dependent string escape
* *
* @param string * @param string
* @return string * @return string
@ -361,7 +361,7 @@ class CI_DB_cubrid_driver extends CI_DB {
* Error * Error
* *
* Returns an array containing code and message of the last * Returns an array containing code and message of the last
* database error that has occured. * database error that has occurred.
* *
* @return array * @return array
*/ */

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.1.0 * @since Version 2.1.0
@ -178,6 +178,9 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
$attributes['TYPE'] = 'INTEGER'; $attributes['TYPE'] = 'INTEGER';
$attributes['UNSIGNED'] = FALSE; $attributes['UNSIGNED'] = FALSE;
return; return;
case 'LONGTEXT':
$attributes['TYPE'] = 'STRING';
return;
default: return; default: return;
} }
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.1.0 * @since Version 2.1.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.1.0 * @since Version 2.1.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -294,7 +294,7 @@ class CI_DB_ibase_driver extends CI_DB {
* Error * Error
* *
* Returns an array containing code and message of the last * Returns an array containing code and message of the last
* database error that has occured. * database error that has occurred.
* *
* @return array * @return array
*/ */
@ -383,6 +383,23 @@ class CI_DB_ibase_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Insert batch statement
*
* Generates a platform-specific insert string from the supplied data.
*
* @param string $table Table name
* @param array $keys INSERT keys
* @param array $values INSERT values
* @return string|bool
*/
protected function _insert_batch($table, $keys, $values)
{
return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
}
// --------------------------------------------------------------------
/** /**
* Close DB Connection * Close DB Connection
* *

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -91,7 +91,7 @@ class CI_DB_ibase_forge extends CI_DB_forge {
* Create database * Create database
* *
* @param string $db_name * @param string $db_name
* @return string * @return bool
*/ */
public function create_database($db_name) public function create_database($db_name)
{ {
@ -111,7 +111,7 @@ class CI_DB_ibase_forge extends CI_DB_forge {
* @param string $db_name (ignored) * @param string $db_name (ignored)
* @return bool * @return bool
*/ */
public function drop_database($db_name = '') public function drop_database($db_name)
{ {
if ( ! ibase_drop_db($this->conn_id)) if ( ! ibase_drop_db($this->conn_id))
{ {

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0
@ -158,6 +158,7 @@ class CI_DB_mssql_driver extends CI_DB {
if (mssql_select_db('['.$database.']', $this->conn_id)) if (mssql_select_db('['.$database.']', $this->conn_id))
{ {
$this->database = $database; $this->database = $database;
$this->data_cache = array();
return TRUE; return TRUE;
} }
@ -351,7 +352,7 @@ class CI_DB_mssql_driver extends CI_DB {
* Error * Error
* *
* Returns an array containing code and message of the last * Returns an array containing code and message of the last
* database error that has occured. * database error that has occurred.
* *
* @return array * @return array
*/ */
@ -452,7 +453,7 @@ class CI_DB_mssql_driver extends CI_DB {
$sql = trim(substr($sql, 0, strrpos($sql, $orderby))); $sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
// Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results
if (count($this->qb_select) === 0) if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
{ {
$select = '*'; // Inevitable $select = '*'; // Inevitable
} }
@ -499,7 +500,7 @@ class CI_DB_mssql_driver extends CI_DB {
return parent::_insert_batch($table, $keys, $values); return parent::_insert_batch($table, $keys, $values);
} }
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0
@ -113,6 +113,11 @@ class CI_DB_mssql_forge extends CI_DB_forge {
*/ */
protected function _attr_type(&$attributes) protected function _attr_type(&$attributes)
{ {
if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE)
{
unset($attributes['CONSTRAINT']);
}
switch (strtoupper($attributes['TYPE'])) switch (strtoupper($attributes['TYPE']))
{ {
case 'MEDIUMINT': case 'MEDIUMINT':

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0
@ -208,6 +208,7 @@ class CI_DB_mysql_driver extends CI_DB {
if (mysql_select_db($database, $this->conn_id)) if (mysql_select_db($database, $this->conn_id))
{ {
$this->database = $database; $this->database = $database;
$this->data_cache = array();
return TRUE; return TRUE;
} }
@ -336,7 +337,7 @@ class CI_DB_mysql_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Platform-dependant string escape * Platform-dependent string escape
* *
* @param string * @param string
* @return string * @return string
@ -447,7 +448,7 @@ class CI_DB_mysql_driver extends CI_DB {
* Error * Error
* *
* Returns an array containing code and message of the last * Returns an array containing code and message of the last
* database error that has occured. * database error that has occurred.
* *
* @return array * @return array
*/ */

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.0.0 * @since Version 1.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0
@ -125,8 +125,7 @@ class CI_DB_mysqli_driver extends CI_DB {
} }
else else
{ {
// Persistent connection support was added in PHP 5.3.0 $hostname = ($persistent === TRUE)
$hostname = ($persistent === TRUE && is_php('5.3'))
? 'p:'.$this->hostname : $this->hostname; ? 'p:'.$this->hostname : $this->hostname;
$port = empty($this->port) ? NULL : $this->port; $port = empty($this->port) ? NULL : $this->port;
$socket = NULL; $socket = NULL;
@ -184,7 +183,7 @@ class CI_DB_mysqli_driver extends CI_DB {
// https://bugs.php.net/bug.php?id=68344 // https://bugs.php.net/bug.php?id=68344
elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT')) elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT'))
{ {
$this->_mysqli->options(MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT, TRUE); $client_flags |= MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
} }
} }
@ -211,7 +210,7 @@ class CI_DB_mysqli_driver extends CI_DB {
$this->_mysqli->close(); $this->_mysqli->close();
$message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!'; $message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!';
log_message('error', $message); log_message('error', $message);
return ($this->db->db_debug) ? $this->db->display_error($message, '', TRUE) : FALSE; return ($this->db_debug) ? $this->display_error($message, '', TRUE) : FALSE;
} }
return $this->_mysqli; return $this->_mysqli;
@ -256,6 +255,7 @@ class CI_DB_mysqli_driver extends CI_DB {
if ($this->conn_id->select_db($database)) if ($this->conn_id->select_db($database))
{ {
$this->database = $database; $this->database = $database;
$this->data_cache = array();
return TRUE; return TRUE;
} }
@ -381,7 +381,7 @@ class CI_DB_mysqli_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Platform-dependant string escape * Platform-dependent string escape
* *
* @param string * @param string
* @return string * @return string
@ -502,7 +502,7 @@ class CI_DB_mysqli_driver extends CI_DB {
{ {
return array( return array(
'code' => $this->_mysqli->connect_errno, 'code' => $this->_mysqli->connect_errno,
'message' => is_php('5.2.9') ? $this->_mysqli->connect_error : mysqli_connect_error() 'message' => $this->_mysqli->connect_error
); );
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0
@ -112,9 +112,9 @@ class CI_DB_mysqli_result extends CI_DB_result {
{ {
$retval[$i] = new stdClass(); $retval[$i] = new stdClass();
$retval[$i]->name = $field_data[$i]->name; $retval[$i]->name = $field_data[$i]->name;
$retval[$i]->type = $field_data[$i]->type; $retval[$i]->type = static::_get_field_type($field_data[$i]->type);
$retval[$i]->max_length = $field_data[$i]->max_length; $retval[$i]->max_length = $field_data[$i]->max_length;
$retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2); $retval[$i]->primary_key = (int) ($field_data[$i]->flags & MYSQLI_PRI_KEY_FLAG);
$retval[$i]->default = $field_data[$i]->def; $retval[$i]->default = $field_data[$i]->def;
} }
@ -123,6 +123,52 @@ class CI_DB_mysqli_result extends CI_DB_result {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Get field type
*
* Extracts field type info from the bitflags returned by
* mysqli_result::fetch_fields()
*
* @used-by CI_DB_mysqli_result::field_data()
* @param int $type
* @return string
*/
private static function _get_field_type($type)
{
static $map;
isset($map) OR $map = array(
MYSQLI_TYPE_DECIMAL => 'decimal',
MYSQLI_TYPE_BIT => 'bit',
MYSQLI_TYPE_TINY => 'tinyint',
MYSQLI_TYPE_SHORT => 'smallint',
MYSQLI_TYPE_INT24 => 'mediumint',
MYSQLI_TYPE_LONG => 'int',
MYSQLI_TYPE_LONGLONG => 'bigint',
MYSQLI_TYPE_FLOAT => 'float',
MYSQLI_TYPE_DOUBLE => 'double',
MYSQLI_TYPE_TIMESTAMP => 'timestamp',
MYSQLI_TYPE_DATE => 'date',
MYSQLI_TYPE_TIME => 'time',
MYSQLI_TYPE_DATETIME => 'datetime',
MYSQLI_TYPE_YEAR => 'year',
MYSQLI_TYPE_NEWDATE => 'date',
MYSQLI_TYPE_INTERVAL => 'interval',
MYSQLI_TYPE_ENUM => 'enum',
MYSQLI_TYPE_SET => 'set',
MYSQLI_TYPE_TINY_BLOB => 'tinyblob',
MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob',
MYSQLI_TYPE_BLOB => 'blob',
MYSQLI_TYPE_LONG_BLOB => 'longblob',
MYSQLI_TYPE_STRING => 'char',
MYSQLI_TYPE_VAR_STRING => 'varchar',
MYSQLI_TYPE_GEOMETRY => 'geometry'
);
return isset($map[$type]) ? $map[$type] : $type;
}
// --------------------------------------------------------------------
/** /**
* Free the result * Free the result
* *

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0
@ -155,9 +155,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility {
while ($field = $query->result_id->fetch_field()) while ($field = $query->result_id->fetch_field())
{ {
// Most versions of MySQL store timestamp as a string // Most versions of MySQL store timestamp as a string
$is_int[$i] = in_array(strtolower($field->type), $is_int[$i] = in_array($field->type, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_INT24, MYSQLI_TYPE_LONG), TRUE);
array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
TRUE);
// Create a string of field names // Create a string of field names
$field_str .= $this->db->escape_identifiers($field->name).', '; $field_str .= $this->db->escape_identifiers($field->name).', ';

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.4.1 * @since Version 1.4.1
@ -97,7 +97,7 @@ class CI_DB_oci8_driver extends CI_DB {
* *
* @var bool * @var bool
*/ */
public $limit_used; public $limit_used = FALSE;
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -386,7 +386,7 @@ class CI_DB_oci8_driver extends CI_DB {
*/ */
protected function _trans_begin() protected function _trans_begin()
{ {
$this->commit_mode = is_php('5.3.2') ? OCI_NO_AUTO_COMMIT : OCI_DEFAULT; $this->commit_mode = OCI_NO_AUTO_COMMIT;
return TRUE; return TRUE;
} }
@ -553,29 +553,35 @@ class CI_DB_oci8_driver extends CI_DB {
* Error * Error
* *
* Returns an array containing code and message of the last * Returns an array containing code and message of the last
* database error that has occured. * database error that has occurred.
* *
* @return array * @return array
*/ */
public function error() public function error()
{ {
/* oci_error() returns an array that already contains the // oci_error() returns an array that already contains
* 'code' and 'message' keys, so we can just return it. // 'code' and 'message' keys, but it can return false
*/ // if there was no error ....
if (is_resource($this->curs_id)) if (is_resource($this->curs_id))
{ {
return oci_error($this->curs_id); $error = oci_error($this->curs_id);
} }
elseif (is_resource($this->stmt_id)) elseif (is_resource($this->stmt_id))
{ {
return oci_error($this->stmt_id); $error = oci_error($this->stmt_id);
} }
elseif (is_resource($this->conn_id)) elseif (is_resource($this->conn_id))
{ {
return oci_error($this->conn_id); $error = oci_error($this->conn_id);
}
else
{
$error = oci_error();
} }
return oci_error(); return is_array($error)
? $error
: array('code' => '', 'message' => '');
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -679,4 +685,17 @@ class CI_DB_oci8_driver extends CI_DB {
oci_close($this->conn_id); oci_close($this->conn_id);
} }
// --------------------------------------------------------------------
/**
* We need to reset our $limit_used hack flag, so it doesn't propagate
* to subsequent queries.
*
* @return void
*/
protected function _reset_select()
{
$this->limit_used = FALSE;
parent::_reset_select();
}
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.4.1 * @since Version 1.4.1
@ -53,6 +53,13 @@ class CI_DB_oci8_forge extends CI_DB_forge {
*/ */
protected $_create_database = FALSE; protected $_create_database = FALSE;
/**
* CREATE TABLE IF statement
*
* @var string
*/
protected $_create_table_if = FALSE;
/** /**
* DROP DATABASE statement * DROP DATABASE statement
* *
@ -117,8 +124,10 @@ class CI_DB_oci8_forge extends CI_DB_forge {
if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name'])) if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
{ {
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
.' '.$this->db->escape_identifiers($field[$i]['new_name']); .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
} }
$field[$i] = "\n\t".$field[$i]['_literal'];
} }
} }
@ -129,7 +138,7 @@ class CI_DB_oci8_forge extends CI_DB_forge {
// RENAME COLUMN must be executed after MODIFY // RENAME COLUMN must be executed after MODIFY
array_unshift($sqls, $sql); array_unshift($sqls, $sql);
return $sql; return $sqls;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -146,4 +155,33 @@ class CI_DB_oci8_forge extends CI_DB_forge {
// Not supported - sequences and triggers must be used instead // Not supported - sequences and triggers must be used instead
} }
// --------------------------------------------------------------------
/**
* Field attribute TYPE
*
* Performs a data type mapping between different databases.
*
* @param array &$attributes
* @return void
*/
protected function _attr_type(&$attributes)
{
switch (strtoupper($attributes['TYPE']))
{
case 'TINYINT':
$attributes['TYPE'] = 'NUMBER';
return;
case 'MEDIUMINT':
$attributes['TYPE'] = 'NUMBER';
return;
case 'INT':
$attributes['TYPE'] = 'NUMBER';
return;
case 'BIGINT':
$attributes['TYPE'] = 'NUMBER';
return;
default: return;
}
}
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.4.1 * @since Version 1.4.1

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.4.1 * @since Version 1.4.1

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0
@ -50,7 +50,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/database/ * @link https://codeigniter.com/user_guide/database/
*/ */
class CI_DB_odbc_driver extends CI_DB { class CI_DB_odbc_driver extends CI_DB_driver {
/** /**
* Database driver * Database driver
@ -93,6 +93,22 @@ class CI_DB_odbc_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* ODBC result ID resource returned from odbc_prepare()
*
* @var resource
*/
private $odbc_result;
/**
* Values to use with odbc_execute() for prepared statements
*
* @var array
*/
private $binds = array();
// --------------------------------------------------------------------
/** /**
* Class constructor * Class constructor
* *
@ -127,6 +143,74 @@ class CI_DB_odbc_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Compile Bindings
*
* @param string $sql SQL statement
* @param array $binds An array of values to bind
* @return string
*/
public function compile_binds($sql, $binds)
{
if (empty($binds) OR empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE)
{
return $sql;
}
elseif ( ! is_array($binds))
{
$binds = array($binds);
$bind_count = 1;
}
else
{
// Make sure we're using numeric keys
$binds = array_values($binds);
$bind_count = count($binds);
}
// We'll need the marker length later
$ml = strlen($this->bind_marker);
// Make sure not to replace a chunk inside a string that happens to match the bind marker
if ($c = preg_match_all("/'[^']*'|\"[^\"]*\"/i", $sql, $matches))
{
$c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i',
str_replace($matches[0],
str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]),
$sql, $c),
$matches, PREG_OFFSET_CAPTURE);
// Bind values' count must match the count of markers in the query
if ($bind_count !== $c)
{
return $sql;
}
}
elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count)
{
return $sql;
}
if ($this->bind_marker !== '?')
{
do
{
$c--;
$sql = substr_replace($sql, '?', $matches[0][$c][1], $ml);
}
while ($c !== 0);
}
if (FALSE !== ($this->odbc_result = odbc_prepare($this->conn_id, $sql)))
{
$this->binds = array_values($binds);
}
return $sql;
}
// --------------------------------------------------------------------
/** /**
* Execute the query * Execute the query
* *
@ -134,9 +218,27 @@ class CI_DB_odbc_driver extends CI_DB {
* @return resource * @return resource
*/ */
protected function _execute($sql) protected function _execute($sql)
{
if ( ! isset($this->odbc_result))
{ {
return odbc_exec($this->conn_id, $sql); return odbc_exec($this->conn_id, $sql);
} }
elseif ($this->odbc_result === FALSE)
{
return FALSE;
}
if (TRUE === ($success = odbc_execute($this->odbc_result, $this->binds)))
{
// For queries that return result sets, return the result_id resource on success
$this->is_write_type($sql) OR $success = $this->odbc_result;
}
$this->odbc_result = NULL;
$this->binds = array();
return $success;
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -196,7 +298,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/ */
public function is_write_type($sql) public function is_write_type($sql)
{ {
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql)) if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql))
{ {
return FALSE; return FALSE;
} }
@ -207,14 +309,14 @@ class CI_DB_odbc_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Platform-dependant string escape * Platform-dependent string escape
* *
* @param string * @param string
* @return string * @return string
*/ */
protected function _escape_str($str) protected function _escape_str($str)
{ {
return remove_invisible_characters($str); $this->display_error('db_unsupported_feature');
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -238,7 +340,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/ */
public function insert_id() public function insert_id()
{ {
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -300,7 +402,7 @@ class CI_DB_odbc_driver extends CI_DB {
* Error * Error
* *
* Returns an array containing code and message of the last * Returns an array containing code and message of the last
* database error that has occured. * database error that has occurred.
* *
* @return array * @return array
*/ */
@ -311,58 +413,6 @@ class CI_DB_odbc_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Update statement
*
* Generates a platform-specific update string from the supplied data
*
* @param string $table
* @param array $values
* @return string
*/
protected function _update($table, $values)
{
$this->qb_limit = FALSE;
$this->qb_orderby = array();
return parent::_update($table, $values);
}
// --------------------------------------------------------------------
/**
* Truncate statement
*
* Generates a platform-specific truncate string from the supplied data
*
* If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
* @param string $table
* @return string
*/
protected function _truncate($table)
{
return 'DELETE FROM '.$table;
}
// --------------------------------------------------------------------
/**
* Delete statement
*
* Generates a platform-specific delete string from the supplied data
*
* @param string $table
* @return string
*/
protected function _delete($table)
{
$this->qb_limit = FALSE;
return parent::_delete($table);
}
// --------------------------------------------------------------------
/** /**
* Close DB Connection * Close DB Connection
* *
@ -372,5 +422,4 @@ class CI_DB_odbc_driver extends CI_DB {
{ {
odbc_close($this->conn_id); odbc_close($this->conn_id);
} }
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.1.0 * @since Version 2.1.0
@ -126,7 +126,10 @@ class CI_DB_pdo_driver extends CI_DB {
*/ */
public function db_connect($persistent = FALSE) public function db_connect($persistent = FALSE)
{ {
$this->options[PDO::ATTR_PERSISTENT] = $persistent; if ($persistent === TRUE)
{
$this->options[PDO::ATTR_PERSISTENT] = TRUE;
}
try try
{ {
@ -220,7 +223,7 @@ class CI_DB_pdo_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Platform-dependant string escape * Platform-dependent string escape
* *
* @param string * @param string
* @return string * @return string
@ -282,7 +285,7 @@ class CI_DB_pdo_driver extends CI_DB {
* Error * Error
* *
* Returns an array containing code and message of the last * Returns an array containing code and message of the last
* database error that has occured. * database error that has occurred.
* *
* @return array * @return array
*/ */
@ -307,52 +310,6 @@ class CI_DB_pdo_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Update_Batch statement
*
* Generates a platform-specific batch update string from the supplied data
*
* @param string $table Table name
* @param array $values Update data
* @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
{
$ids = array();
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
foreach (array_keys($val) as $field)
{
if ($field !== $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
}
}
$cases = '';
foreach ($final as $k => $v)
{
$cases .= $k.' = CASE '."\n";
foreach ($v as $row)
{
$cases .= $row."\n";
}
$cases .= 'ELSE '.$k.' END, ';
}
$this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE);
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
}
// --------------------------------------------------------------------
/** /**
* Truncate statement * Truncate statement
* *

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.1.0 * @since Version 2.1.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.1.0 * @since Version 2.1.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.1.0 * @since Version 2.1.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -170,47 +170,6 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Update_Batch statement
*
* Generates a platform-specific batch update string from the supplied data
*
* @param string $table Table name
* @param array $values Update data
* @param string $index WHERE key
* @return string
*/
protected function _update_batch($table, $values, $index)
{
$ids = array();
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
foreach (array_keys($val) as $field)
{
if ($field !== $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
}
}
$cases = '';
foreach ($final as $k => $v)
{
$cases .= $k." = CASE \n"
.implode("\n", $v)."\n"
.'ELSE '.$k.' END), ';
}
$this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE);
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
}
// --------------------------------------------------------------------
/** /**
* Truncate statement * Truncate statement
* *

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -178,6 +178,9 @@ class CI_DB_pdo_cubrid_forge extends CI_DB_pdo_forge {
$attributes['TYPE'] = 'INTEGER'; $attributes['TYPE'] = 'INTEGER';
$attributes['UNSIGNED'] = FALSE; $attributes['UNSIGNED'] = FALSE;
return; return;
case 'LONGTEXT':
$attributes['TYPE'] = 'STRING';
return;
default: return; default: return;
} }
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -126,7 +126,12 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
*/ */
public function db_connect($persistent = FALSE) public function db_connect($persistent = FALSE)
{ {
$this->conn_id = parent::db_connect($persistent); if ($persistent === TRUE)
{
log_message('debug', "dblib driver doesn't support persistent connections");
}
$this->conn_id = parent::db_connect(FALSE);
if ( ! is_object($this->conn_id)) if ( ! is_object($this->conn_id))
{ {
@ -279,7 +284,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
$sql = trim(substr($sql, 0, strrpos($sql, $orderby))); $sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
// Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results
if (count($this->qb_select) === 0) if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
{ {
$select = '*'; // Inevitable $select = '*'; // Inevitable
} }
@ -326,7 +331,23 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
return parent::_insert_batch($table, $keys, $values); return parent::_insert_batch($table, $keys, $values);
} }
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
} }
// --------------------------------------------------------------------
/**
* Database version number
*
* @return string
*/
public function version()
{
if (isset($this->data_cache['version']))
{
return $this->data_cache['version'];
}
return $this->data_cache['version'] = $this->conn_id->query("SELECT SERVERPROPERTY('ProductVersion') AS ver")->fetchColumn(0);
}
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -111,6 +111,11 @@ class CI_DB_pdo_dblib_forge extends CI_DB_pdo_forge {
*/ */
protected function _attr_type(&$attributes) protected function _attr_type(&$attributes)
{ {
if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE)
{
unset($attributes['CONSTRAINT']);
}
switch (strtoupper($attributes['TYPE'])) switch (strtoupper($attributes['TYPE']))
{ {
case 'MEDIUMINT': case 'MEDIUMINT':

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -260,4 +260,20 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
return preg_replace('`SELECT`i', 'SELECT '.$select, $sql); return preg_replace('`SELECT`i', 'SELECT '.$select, $sql);
} }
// --------------------------------------------------------------------
/**
* Insert batch statement
*
* Generates a platform-specific insert string from the supplied data.
*
* @param string $table Table name
* @param array $keys INSERT keys
* @param array $values INSERT values
* @return string|bool
*/
protected function _insert_batch($table, $keys, $values)
{
return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
}
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -97,7 +97,7 @@ class CI_DB_pdo_firebird_forge extends CI_DB_pdo_forge {
* @param string $db_name (ignored) * @param string $db_name (ignored)
* @return bool * @return bool
*/ */
public function drop_database($db_name = '') public function drop_database($db_name)
{ {
if ( ! ibase_drop_db($this->conn_id)) if ( ! ibase_drop_db($this->conn_id))
{ {

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -106,7 +106,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
empty($this->database) OR $this->dsn .= ';dbname='.$this->database; empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set; empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
} }
elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE && is_php('5.3.6')) elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE)
{ {
$this->dsn .= ';charset='.$this->char_set; $this->dsn .= ';charset='.$this->char_set;
} }
@ -122,17 +122,6 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*/ */
public function db_connect($persistent = FALSE) public function db_connect($persistent = FALSE)
{ {
/* Prior to PHP 5.3.6, even if the charset was supplied in the DSN
* on connect - it was ignored. This is a work-around for the issue.
*
* Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php
*/
if ( ! is_php('5.3.6') && ! empty($this->char_set))
{
$this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES '.$this->char_set
.(empty($this->dbcollat) ? '' : ' COLLATE '.$this->dbcollat);
}
if (isset($this->stricton)) if (isset($this->stricton))
{ {
if ($this->stricton) if ($this->stricton)
@ -169,8 +158,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
$this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE; $this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE;
} }
// SSL support was added to PDO_MYSQL in PHP 5.3.7 if (is_array($this->encrypt))
if (is_array($this->encrypt) && is_php('5.3.7'))
{ {
$ssl = array(); $ssl = array();
empty($this->encrypt['ssl_key']) OR $ssl[PDO::MYSQL_ATTR_SSL_KEY] = $this->encrypt['ssl_key']; empty($this->encrypt['ssl_key']) OR $ssl[PDO::MYSQL_ATTR_SSL_KEY] = $this->encrypt['ssl_key'];
@ -194,7 +182,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
{ {
$message = 'PDO_MYSQL was configured for an SSL connection, but got an unencrypted connection instead!'; $message = 'PDO_MYSQL was configured for an SSL connection, but got an unencrypted connection instead!';
log_message('error', $message); log_message('error', $message);
return ($this->db->db_debug) ? $this->db->display_error($message, '', TRUE) : FALSE; return ($this->db_debug) ? $this->display_error($message, '', TRUE) : FALSE;
} }
return $pdo; return $pdo;
@ -218,6 +206,56 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
if (FALSE !== $this->simple_query('USE '.$this->escape_identifiers($database))) if (FALSE !== $this->simple_query('USE '.$this->escape_identifiers($database)))
{ {
$this->database = $database; $this->database = $database;
$this->data_cache = array();
return TRUE;
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* Begin Transaction
*
* @return bool
*/
protected function _trans_begin()
{
$this->conn_id->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE);
return $this->conn_id->beginTransaction();
}
// --------------------------------------------------------------------
/**
* Commit Transaction
*
* @return bool
*/
protected function _trans_commit()
{
if ($this->conn_id->commit())
{
$this->conn_id->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE);
return TRUE;
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* Rollback Transaction
*
* @return bool
*/
protected function _trans_rollback()
{
if ($this->conn_id->rollBack())
{
$this->conn_id->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE);
return TRUE; return TRUE;
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -53,6 +53,13 @@ class CI_DB_pdo_oci_forge extends CI_DB_pdo_forge {
*/ */
protected $_create_database = FALSE; protected $_create_database = FALSE;
/**
* CREATE TABLE IF statement
*
* @var string
*/
protected $_create_table_if = FALSE;
/** /**
* DROP DATABASE statement * DROP DATABASE statement
* *
@ -60,13 +67,6 @@ class CI_DB_pdo_oci_forge extends CI_DB_pdo_forge {
*/ */
protected $_drop_database = FALSE; protected $_drop_database = FALSE;
/**
* CREATE TABLE IF statement
*
* @var string
*/
protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
/** /**
* UNSIGNED support * UNSIGNED support
* *
@ -117,7 +117,7 @@ class CI_DB_pdo_oci_forge extends CI_DB_pdo_forge {
if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name'])) if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
{ {
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
.' '.$this->db->escape_identifiers($field[$i]['new_name']); .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
} }
} }
} }
@ -146,4 +146,31 @@ class CI_DB_pdo_oci_forge extends CI_DB_pdo_forge {
// Not supported - sequences and triggers must be used instead // Not supported - sequences and triggers must be used instead
} }
/**
* Field attribute TYPE
*
* Performs a data type mapping between different databases.
*
* @param array &$attributes
* @return void
*/
protected function _attr_type(&$attributes)
{
switch (strtoupper($attributes['TYPE']))
{
case 'TINYINT':
$attributes['TYPE'] = 'NUMBER';
return;
case 'MEDIUMINT':
$attributes['TYPE'] = 'NUMBER';
return;
case 'INT':
$attributes['TYPE'] = 'NUMBER';
return;
case 'BIGINT':
$attributes['TYPE'] = 'NUMBER';
return;
default: return;
}
}
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -160,6 +160,19 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/**
* Platform-dependent string escape
*
* @param string
* @return string
*/
protected function _escape_str($str)
{
$this->display_error('db_unsupported_feature');
}
// --------------------------------------------------------------------
/** /**
* Determines if a query is a "write" type. * Determines if a query is a "write" type.
* *
@ -168,7 +181,7 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
*/ */
public function is_write_type($sql) public function is_write_type($sql)
{ {
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql)) if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql))
{ {
return FALSE; return FALSE;
} }
@ -213,72 +226,4 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
{ {
return 'SELECT column_name FROM information_schema.columns WHERE table_name = '.$this->escape($table); return 'SELECT column_name FROM information_schema.columns WHERE table_name = '.$this->escape($table);
} }
// --------------------------------------------------------------------
/**
* Update statement
*
* Generates a platform-specific update string from the supplied data
*
* @param string $table
* @param array $values
* @return string
*/
protected function _update($table, $values)
{
$this->qb_limit = FALSE;
$this->qb_orderby = array();
return parent::_update($table, $values);
}
// --------------------------------------------------------------------
/**
* Truncate statement
*
* Generates a platform-specific truncate string from the supplied data
*
* If the database does not support the TRUNCATE statement,
* then this method maps to 'DELETE FROM table'
*
* @param string $table
* @return string
*/
protected function _truncate($table)
{
return 'DELETE FROM '.$table;
}
// --------------------------------------------------------------------
/**
* Delete statement
*
* Generates a platform-specific delete string from the supplied data
*
* @param string the table name
* @return string
*/
protected function _delete($table)
{
$this->qb_limit = FALSE;
return parent::_delete($table);
}
// --------------------------------------------------------------------
/**
* LIMIT
*
* Generates a platform-specific LIMIT clause
*
* @param string $sql SQL Query
* @return string
*/
protected function _limit($sql)
{
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$this->qb_limit.' ', $sql);
}
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -154,7 +154,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
*/ */
public function is_write_type($sql) public function is_write_type($sql)
{ {
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql)) if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql))
{ {
return FALSE; return FALSE;
} }
@ -326,13 +326,13 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
$ids = array(); $ids = array();
foreach ($values as $key => $val) foreach ($values as $key => $val)
{ {
$ids[] = $val[$index]; $ids[] = $val[$index]['value'];
foreach (array_keys($val) as $field) foreach (array_keys($val) as $field)
{ {
if ($field !== $index) if ($field !== $index)
{ {
$final[$field][] = 'WHEN '.$val[$index].' THEN '.$val[$field]; $final[$val[$field]['field']][] = 'WHEN '.$val[$index]['value'].' THEN '.$val[$field]['value'];
} }
} }
} }
@ -340,12 +340,12 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
$cases = ''; $cases = '';
foreach ($final as $k => $v) foreach ($final as $k => $v)
{ {
$cases .= $k.' = (CASE '.$index."\n" $cases .= $k.' = (CASE '.$val[$index]['field']."\n"
.implode("\n", $v)."\n" .implode("\n", $v)."\n"
.'ELSE '.$k.' END), '; .'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'); return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -168,7 +168,7 @@ class CI_DB_pdo_pgsql_forge extends CI_DB_pdo_forge {
*/ */
protected function _attr_type(&$attributes) protected function _attr_type(&$attributes)
{ {
// Reset field lenghts for data types that don't support it // Reset field lengths for data types that don't support it
if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE) if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
{ {
$attributes['CONSTRAINT'] = NULL; $attributes['CONSTRAINT'] = NULL;

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -66,7 +66,7 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
* *
* @var array * @var array
*/ */
protected $_random_keyword = ' RANDOM()'; protected $_random_keyword = array('RANDOM()', 'RANDOM()');
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -101,7 +101,7 @@ class CI_DB_pdo_sqlite_forge extends CI_DB_pdo_forge {
* @param string $db_name (ignored) * @param string $db_name (ignored)
* @return bool * @return bool
*/ */
public function create_database($db_name = '') public function create_database($db_name)
{ {
// In SQLite, a database is created when you connect to the database. // In SQLite, a database is created when you connect to the database.
// We'll return TRUE so that an error isn't generated // We'll return TRUE so that an error isn't generated
@ -116,7 +116,7 @@ class CI_DB_pdo_sqlite_forge extends CI_DB_pdo_forge {
* @param string $db_name (ignored) * @param string $db_name (ignored)
* @return bool * @return bool
*/ */
public function drop_database($db_name = '') public function drop_database($db_name)
{ {
// In SQLite, a database is dropped when we delete a file // In SQLite, a database is dropped when we delete a file
if (file_exists($this->db->database)) if (file_exists($this->db->database))

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -316,7 +316,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
$sql = trim(substr($sql, 0, strrpos($sql, $orderby))); $sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
// Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results
if (count($this->qb_select) === 0) if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
{ {
$select = '*'; // Inevitable $select = '*'; // Inevitable
} }
@ -363,7 +363,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
return parent::_insert_batch($table, $keys, $values); return parent::_insert_batch($table, $keys, $values);
} }
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
} }
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -111,6 +111,11 @@ class CI_DB_pdo_sqlsrv_forge extends CI_DB_pdo_forge {
*/ */
protected function _attr_type(&$attributes) protected function _attr_type(&$attributes)
{ {
if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE)
{
unset($attributes['CONSTRAINT']);
}
switch (strtoupper($attributes['TYPE'])) switch (strtoupper($attributes['TYPE']))
{ {
case 'MEDIUMINT': case 'MEDIUMINT':

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0
@ -130,9 +130,9 @@ class CI_DB_postgre_driver extends CI_DB {
*/ */
foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key) foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key)
{ {
if (isset($this->$key) && is_string($this->key) && $this->key !== '') if (isset($this->$key) && is_string($this->$key) && $this->$key !== '')
{ {
$this->dsn .= $key."='".$this->key."' "; $this->dsn .= $key."='".$this->$key."' ";
} }
} }
@ -224,8 +224,8 @@ class CI_DB_postgre_driver extends CI_DB {
* and so we'll have to fall back to running a query in * and so we'll have to fall back to running a query in
* order to get it. * order to get it.
*/ */
return isset($pg_version['server']) return (isset($pg_version['server']) && preg_match('#^(\d+\.\d+)#', $pg_version['server'], $match))
? $this->data_cache['version'] = $pg_version['server'] ? $this->data_cache['version'] = $match[1]
: parent::version(); : parent::version();
} }
@ -288,7 +288,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/ */
public function is_write_type($sql) public function is_write_type($sql)
{ {
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql)) if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql))
{ {
return FALSE; return FALSE;
} }
@ -299,7 +299,7 @@ class CI_DB_postgre_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Platform-dependant string escape * Platform-dependent string escape
* *
* @param string * @param string
* @return string * @return string
@ -354,8 +354,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/ */
public function insert_id() public function insert_id()
{ {
$v = pg_version($this->conn_id); $v = $this->version();
$v = isset($v['server']) ? $v['server'] : 0; // 'server' key is only available since PosgreSQL 7.4
$table = (func_num_args() > 0) ? func_get_arg(0) : NULL; $table = (func_num_args() > 0) ? func_get_arg(0) : NULL;
$column = (func_num_args() > 1) ? func_get_arg(1) : NULL; $column = (func_num_args() > 1) ? func_get_arg(1) : NULL;
@ -471,7 +470,7 @@ class CI_DB_postgre_driver extends CI_DB {
* Error * Error
* *
* Returns an array containing code and message of the last * Returns an array containing code and message of the last
* database error that has occured. * database error that has occurred.
* *
* @return array * @return array
*/ */
@ -550,13 +549,13 @@ class CI_DB_postgre_driver extends CI_DB {
$ids = array(); $ids = array();
foreach ($values as $key => $val) foreach ($values as $key => $val)
{ {
$ids[] = $val[$index]; $ids[] = $val[$index]['value'];
foreach (array_keys($val) as $field) foreach (array_keys($val) as $field)
{ {
if ($field !== $index) if ($field !== $index)
{ {
$final[$field][] = 'WHEN '.$val[$index].' THEN '.$val[$field]; $final[$val[$field]['field']][] = 'WHEN '.$val[$index]['value'].' THEN '.$val[$field]['value'];
} }
} }
} }
@ -564,12 +563,12 @@ class CI_DB_postgre_driver extends CI_DB {
$cases = ''; $cases = '';
foreach ($final as $k => $v) foreach ($final as $k => $v)
{ {
$cases .= $k.' = (CASE '.$index."\n" $cases .= $k.' = (CASE '.$val[$index]['field']."\n"
.implode("\n", $v)."\n" .implode("\n", $v)."\n"
.'ELSE '.$k.' END), '; .'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'); return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
} }

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0
@ -163,7 +163,7 @@ class CI_DB_postgre_forge extends CI_DB_forge {
*/ */
protected function _attr_type(&$attributes) protected function _attr_type(&$attributes)
{ {
// Reset field lenghts for data types that don't support it // Reset field lengths for data types that don't support it
if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE) if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
{ {
$attributes['CONSTRAINT'] = NULL; $attributes['CONSTRAINT'] = NULL;

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0
@ -75,7 +75,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
* @param string $db_name (ignored) * @param string $db_name (ignored)
* @return bool * @return bool
*/ */
public function create_database($db_name = '') public function create_database($db_name)
{ {
// In SQLite, a database is created when you connect to the database. // In SQLite, a database is created when you connect to the database.
// We'll return TRUE so that an error isn't generated // We'll return TRUE so that an error isn't generated
@ -90,7 +90,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge {
* @param string $db_name (ignored) * @param string $db_name (ignored)
* @return bool * @return bool
*/ */
public function drop_database($db_name = '') public function drop_database($db_name)
{ {
if ( ! file_exists($this->db->database) OR ! @unlink($this->db->database)) if ( ! file_exists($this->db->database) OR ! @unlink($this->db->database))
{ {

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 1.3.0 * @since Version 1.3.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -168,7 +168,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/** /**
* Platform-dependant string escape * Platform-dependent string escape
* *
* @param string * @param string
* @return string * @return string
@ -291,7 +291,7 @@ class CI_DB_sqlite3_driver extends CI_DB {
* Error * Error
* *
* Returns an array containing code and message of the last * Returns an array containing code and message of the last
* database error that has occured. * database error that has occurred.
* *
* @return array * @return array
*/ */

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0
@ -87,7 +87,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
* @param string $db_name * @param string $db_name
* @return bool * @return bool
*/ */
public function create_database($db_name = '') public function create_database($db_name)
{ {
// In SQLite, a database is created when you connect to the database. // In SQLite, a database is created when you connect to the database.
// We'll return TRUE so that an error isn't generated // We'll return TRUE so that an error isn't generated
@ -102,7 +102,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge {
* @param string $db_name (ignored) * @param string $db_name (ignored)
* @return bool * @return bool
*/ */
public function drop_database($db_name = '') public function drop_database($db_name)
{ {
// In SQLite, a database is dropped when we delete a file // In SQLite, a database is dropped when we delete a file
if (file_exists($this->db->database)) if (file_exists($this->db->database))

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 3.0.0 * @since Version 3.0.0

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.0.3 * @since Version 2.0.3
@ -171,6 +171,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
if ($this->_execute('USE '.$this->escape_identifiers($database))) if ($this->_execute('USE '.$this->escape_identifiers($database)))
{ {
$this->database = $database; $this->database = $database;
$this->data_cache = array();
return TRUE; return TRUE;
} }
@ -357,7 +358,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
* Error * Error
* *
* Returns an array containing code and message of the last * Returns an array containing code and message of the last
* database error that has occured. * database error that has occurred.
* *
* @return array * @return array
*/ */
@ -477,7 +478,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
$sql = trim(substr($sql, 0, strrpos($sql, $orderby))); $sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
// Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results
if (count($this->qb_select) === 0) if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
{ {
$select = '*'; // Inevitable $select = '*'; // Inevitable
} }
@ -524,7 +525,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
return parent::_insert_batch($table, $keys, $values); return parent::_insert_batch($table, $keys, $values);
} }
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.0.3 * @since Version 2.0.3
@ -111,6 +111,11 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge {
*/ */
protected function _attr_type(&$attributes) protected function _attr_type(&$attributes)
{ {
if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE)
{
unset($attributes['CONSTRAINT']);
}
switch (strtoupper($attributes['TYPE'])) switch (strtoupper($attributes['TYPE']))
{ {
case 'MEDIUMINT': case 'MEDIUMINT':

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.0.3 * @since Version 2.0.3

View File

@ -6,7 +6,7 @@
* *
* This content is released under the MIT License (MIT) * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,7 +29,7 @@
* @package CodeIgniter * @package CodeIgniter
* @author EllisLab Dev Team * @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @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 * @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com * @link https://codeigniter.com
* @since Version 2.0.3 * @since Version 2.0.3

Some files were not shown because too many files have changed in this diff Show More