added files
This commit is contained in:
BIN
system/.DS_Store
vendored
Normal file
BIN
system/.DS_Store
vendored
Normal file
Binary file not shown.
6
system/.htaccess
Normal file
6
system/.htaccess
Normal file
@ -0,0 +1,6 @@
|
||||
<IfModule authz_core_module>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
<IfModule !authz_core_module>
|
||||
Deny from all
|
||||
</IfModule>
|
||||
133
system/core/Benchmark.php
Normal file
133
system/core/Benchmark.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Benchmark Class
|
||||
*
|
||||
* This class enables you to mark points and calculate the time difference
|
||||
* between them. Memory consumption can also be displayed.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/libraries/benchmark.html
|
||||
*/
|
||||
class CI_Benchmark {
|
||||
|
||||
/**
|
||||
* List of all benchmark markers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $marker = array();
|
||||
|
||||
/**
|
||||
* Set a benchmark marker
|
||||
*
|
||||
* Multiple calls to this function can be made so that several
|
||||
* execution points can be timed.
|
||||
*
|
||||
* @param string $name Marker name
|
||||
* @return void
|
||||
*/
|
||||
public function mark($name)
|
||||
{
|
||||
$this->marker[$name] = microtime(TRUE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Elapsed time
|
||||
*
|
||||
* Calculates the time difference between two marked points.
|
||||
*
|
||||
* If the first parameter is empty this function instead returns the
|
||||
* {elapsed_time} pseudo-variable. This permits the full system
|
||||
* execution time to be shown in a template. The output class will
|
||||
* swap the real value for this variable.
|
||||
*
|
||||
* @param string $point1 A particular marked point
|
||||
* @param string $point2 A particular marked point
|
||||
* @param int $decimals Number of decimal places
|
||||
*
|
||||
* @return string Calculated elapsed time on success,
|
||||
* an '{elapsed_string}' if $point1 is empty
|
||||
* or an empty string if $point1 is not found.
|
||||
*/
|
||||
public function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
|
||||
{
|
||||
if ($point1 === '')
|
||||
{
|
||||
return '{elapsed_time}';
|
||||
}
|
||||
|
||||
if ( ! isset($this->marker[$point1]))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( ! isset($this->marker[$point2]))
|
||||
{
|
||||
$this->marker[$point2] = microtime(TRUE);
|
||||
}
|
||||
|
||||
return number_format($this->marker[$point2] - $this->marker[$point1], $decimals);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Memory Usage
|
||||
*
|
||||
* Simply returns the {memory_usage} marker.
|
||||
*
|
||||
* This permits it to be put it anywhere in a template
|
||||
* without the memory being calculated until the end.
|
||||
* The output class will swap the real value for this variable.
|
||||
*
|
||||
* @return string '{memory_usage}'
|
||||
*/
|
||||
public function memory_usage()
|
||||
{
|
||||
return '{memory_usage}';
|
||||
}
|
||||
|
||||
}
|
||||
559
system/core/CodeIgniter.php
Normal file
559
system/core/CodeIgniter.php
Normal file
@ -0,0 +1,559 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* System Initialization File
|
||||
*
|
||||
* Loads the base classes and executes the request.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage CodeIgniter
|
||||
* @category Front-controller
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter Version
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
const CI_VERSION = '3.1.9';
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Load the framework constants
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
if (file_exists(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');
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Load the global functions
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
require_once(BASEPATH.'core/Common.php');
|
||||
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Security procedures
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
|
||||
if ( ! is_php('5.4'))
|
||||
{
|
||||
ini_set('magic_quotes_runtime', 0);
|
||||
|
||||
if ((bool) ini_get('register_globals'))
|
||||
{
|
||||
$_protected = array(
|
||||
'_SERVER',
|
||||
'_GET',
|
||||
'_POST',
|
||||
'_FILES',
|
||||
'_REQUEST',
|
||||
'_SESSION',
|
||||
'_ENV',
|
||||
'_COOKIE',
|
||||
'GLOBALS',
|
||||
'HTTP_RAW_POST_DATA',
|
||||
'system_path',
|
||||
'application_folder',
|
||||
'view_folder',
|
||||
'_protected',
|
||||
'_registered'
|
||||
);
|
||||
|
||||
$_registered = ini_get('variables_order');
|
||||
foreach (array('E' => '_ENV', 'G' => '_GET', 'P' => '_POST', 'C' => '_COOKIE', 'S' => '_SERVER') as $key => $superglobal)
|
||||
{
|
||||
if (strpos($_registered, $key) === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (array_keys($$superglobal) as $var)
|
||||
{
|
||||
if (isset($GLOBALS[$var]) && ! in_array($var, $_protected, TRUE))
|
||||
{
|
||||
$GLOBALS[$var] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Define a custom error handler so we can log PHP errors
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
set_error_handler('_error_handler');
|
||||
set_exception_handler('_exception_handler');
|
||||
register_shutdown_function('_shutdown_handler');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Set the subclass_prefix
|
||||
* ------------------------------------------------------
|
||||
*
|
||||
* Normally the "subclass_prefix" is set in the config file.
|
||||
* The subclass prefix allows CI to know if a core class is
|
||||
* being extended via a library in the local application
|
||||
* "libraries" folder. Since CI allows config items to be
|
||||
* overridden via data set in the main index.php file,
|
||||
* before proceeding we need to know if a subclass_prefix
|
||||
* override exists. If so, we will set this value now,
|
||||
* before any classes are loaded
|
||||
* Note: Since the config file data is cached it doesn't
|
||||
* hurt to load it here.
|
||||
*/
|
||||
if ( ! empty($assign_to_config['subclass_prefix']))
|
||||
{
|
||||
get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Should we use a Composer autoloader?
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
if ($composer_autoload = config_item('composer_autoload'))
|
||||
{
|
||||
if ($composer_autoload === TRUE)
|
||||
{
|
||||
file_exists(APPPATH.'vendor/autoload.php')
|
||||
? require_once(APPPATH.'vendor/autoload.php')
|
||||
: log_message('error', '$config[\'composer_autoload\'] is set to TRUE but '.APPPATH.'vendor/autoload.php was not found.');
|
||||
}
|
||||
elseif (file_exists($composer_autoload))
|
||||
{
|
||||
require_once($composer_autoload);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_message('error', 'Could not find the specified $config[\'composer_autoload\'] path: '.$composer_autoload);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Start the timer... tick tock tick tock...
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$BM =& load_class('Benchmark', 'core');
|
||||
$BM->mark('total_execution_time_start');
|
||||
$BM->mark('loading_time:_base_classes_start');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Instantiate the hooks class
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$EXT =& load_class('Hooks', 'core');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Is there a "pre_system" hook?
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$EXT->call_hook('pre_system');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Instantiate the config class
|
||||
* ------------------------------------------------------
|
||||
*
|
||||
* Note: It is important that Config is loaded first as
|
||||
* most other classes depend on it either directly or by
|
||||
* depending on another class that uses it.
|
||||
*
|
||||
*/
|
||||
$CFG =& load_class('Config', 'core');
|
||||
|
||||
// Do we have any manually set config items in the index.php file?
|
||||
if (isset($assign_to_config) && is_array($assign_to_config))
|
||||
{
|
||||
foreach ($assign_to_config as $key => $value)
|
||||
{
|
||||
$CFG->set_item($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Important charset-related stuff
|
||||
* ------------------------------------------------------
|
||||
*
|
||||
* Configure mbstring and/or iconv if they are enabled
|
||||
* and set MB_ENABLED and ICONV_ENABLED constants, so
|
||||
* that we don't repeatedly do extension_loaded() or
|
||||
* function_exists() calls.
|
||||
*
|
||||
* Note: UTF-8 class depends on this. It used to be done
|
||||
* in it's constructor, but it's _not_ class-specific.
|
||||
*
|
||||
*/
|
||||
$charset = strtoupper(config_item('charset'));
|
||||
ini_set('default_charset', $charset);
|
||||
|
||||
if (extension_loaded('mbstring'))
|
||||
{
|
||||
define('MB_ENABLED', TRUE);
|
||||
// mbstring.internal_encoding is deprecated starting with PHP 5.6
|
||||
// and it's usage triggers E_DEPRECATED messages.
|
||||
@ini_set('mbstring.internal_encoding', $charset);
|
||||
// This is required for mb_convert_encoding() to strip invalid characters.
|
||||
// That's utilized by CI_Utf8, but it's also done for consistency with iconv.
|
||||
mb_substitute_character('none');
|
||||
}
|
||||
else
|
||||
{
|
||||
define('MB_ENABLED', FALSE);
|
||||
}
|
||||
|
||||
// There's an ICONV_IMPL constant, but the PHP manual says that using
|
||||
// iconv's predefined constants is "strongly discouraged".
|
||||
if (extension_loaded('iconv'))
|
||||
{
|
||||
define('ICONV_ENABLED', TRUE);
|
||||
// iconv.internal_encoding is deprecated starting with PHP 5.6
|
||||
// and it's usage triggers E_DEPRECATED messages.
|
||||
@ini_set('iconv.internal_encoding', $charset);
|
||||
}
|
||||
else
|
||||
{
|
||||
define('ICONV_ENABLED', FALSE);
|
||||
}
|
||||
|
||||
if (is_php('5.6'))
|
||||
{
|
||||
ini_set('php.internal_encoding', $charset);
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Load compatibility features
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once(BASEPATH.'core/compat/mbstring.php');
|
||||
require_once(BASEPATH.'core/compat/hash.php');
|
||||
require_once(BASEPATH.'core/compat/password.php');
|
||||
require_once(BASEPATH.'core/compat/standard.php');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Instantiate the UTF-8 class
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$UNI =& load_class('Utf8', 'core');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Instantiate the URI class
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$URI =& load_class('URI', 'core');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Instantiate the routing class and set the routing
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL);
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Instantiate the output class
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$OUT =& load_class('Output', 'core');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Is there a valid cache file? If so, we're done...
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE)
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* -----------------------------------------------------
|
||||
* Load the security class for xss and csrf support
|
||||
* -----------------------------------------------------
|
||||
*/
|
||||
$SEC =& load_class('Security', 'core');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Load the Input class and sanitize globals
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$IN =& load_class('Input', 'core');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Load the Language class
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$LANG =& load_class('Lang', 'core');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Load the app controller and local controller
|
||||
* ------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
// Load the base controller class
|
||||
require_once BASEPATH.'core/Controller.php';
|
||||
|
||||
/**
|
||||
* Reference to the CI_Controller method.
|
||||
*
|
||||
* Returns current CI instance object
|
||||
*
|
||||
* @return CI_Controller
|
||||
*/
|
||||
function &get_instance()
|
||||
{
|
||||
return CI_Controller::get_instance();
|
||||
}
|
||||
|
||||
if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
|
||||
{
|
||||
require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
|
||||
}
|
||||
|
||||
// Set a mark point for benchmarking
|
||||
$BM->mark('loading_time:_base_classes_end');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Sanity checks
|
||||
* ------------------------------------------------------
|
||||
*
|
||||
* The Router class has already validated the request,
|
||||
* leaving us with 3 options here:
|
||||
*
|
||||
* 1) an empty class name, if we reached the default
|
||||
* controller, but it didn't exist;
|
||||
* 2) a query string which doesn't go through a
|
||||
* file_exists() check
|
||||
* 3) a regular request for a non-existing page
|
||||
*
|
||||
* We handle all of these as a 404 error.
|
||||
*
|
||||
* Furthermore, none of the methods in the app controller
|
||||
* or the loader class can be called via the URI, nor can
|
||||
* controller methods that begin with an underscore.
|
||||
*/
|
||||
|
||||
$e404 = FALSE;
|
||||
$class = ucfirst($RTR->class);
|
||||
$method = $RTR->method;
|
||||
|
||||
if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php'))
|
||||
{
|
||||
$e404 = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
require_once(APPPATH.'controllers/'.$RTR->directory.$class.'.php');
|
||||
|
||||
if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
|
||||
{
|
||||
$e404 = TRUE;
|
||||
}
|
||||
elseif (method_exists($class, '_remap'))
|
||||
{
|
||||
$params = array($method, array_slice($URI->rsegments, 2));
|
||||
$method = '_remap';
|
||||
}
|
||||
elseif ( ! method_exists($class, $method))
|
||||
{
|
||||
$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 ( ! empty($RTR->routes['404_override']))
|
||||
{
|
||||
if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $error_class, $error_method) !== 2)
|
||||
{
|
||||
$error_method = 'index';
|
||||
}
|
||||
|
||||
$error_class = ucfirst($error_class);
|
||||
|
||||
if ( ! class_exists($error_class, FALSE))
|
||||
{
|
||||
if (file_exists(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php'))
|
||||
{
|
||||
require_once(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php');
|
||||
$e404 = ! class_exists($error_class, FALSE);
|
||||
}
|
||||
// Were we in a directory? If so, check for a global override
|
||||
elseif ( ! empty($RTR->directory) && file_exists(APPPATH.'controllers/'.$error_class.'.php'))
|
||||
{
|
||||
require_once(APPPATH.'controllers/'.$error_class.'.php');
|
||||
if (($e404 = ! class_exists($error_class, FALSE)) === FALSE)
|
||||
{
|
||||
$RTR->directory = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$e404 = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Did we reset the $e404 flag? If so, set the rsegments, starting from index 1
|
||||
if ( ! $e404)
|
||||
{
|
||||
$class = $error_class;
|
||||
$method = $error_method;
|
||||
|
||||
$URI->rsegments = array(
|
||||
1 => $class,
|
||||
2 => $method
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
show_404($RTR->directory.$class.'/'.$method);
|
||||
}
|
||||
}
|
||||
|
||||
if ($method !== '_remap')
|
||||
{
|
||||
$params = array_slice($URI->rsegments, 2);
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Is there a "pre_controller" hook?
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$EXT->call_hook('pre_controller');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Instantiate the requested controller
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
// Mark a start point so we can benchmark the controller
|
||||
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
|
||||
|
||||
$CI = new $class();
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Is there a "post_controller_constructor" hook?
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$EXT->call_hook('post_controller_constructor');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Call the requested method
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
call_user_func_array(array(&$CI, $method), $params);
|
||||
|
||||
// Mark a benchmark end point
|
||||
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Is there a "post_controller" hook?
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$EXT->call_hook('post_controller');
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Send the final rendered output to the browser
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
if ($EXT->call_hook('display_override') === FALSE)
|
||||
{
|
||||
$OUT->_display();
|
||||
}
|
||||
|
||||
/*
|
||||
* ------------------------------------------------------
|
||||
* Is there a "post_system" hook?
|
||||
* ------------------------------------------------------
|
||||
*/
|
||||
$EXT->call_hook('post_system');
|
||||
849
system/core/Common.php
Normal file
849
system/core/Common.php
Normal file
@ -0,0 +1,849 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Common Functions
|
||||
*
|
||||
* Loads the base classes and executes the request.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage CodeIgniter
|
||||
* @category Common Functions
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('is_php'))
|
||||
{
|
||||
/**
|
||||
* Determines if the current version of PHP is equal to or greater than the supplied value
|
||||
*
|
||||
* @param string
|
||||
* @return bool TRUE if the current version is $version or higher
|
||||
*/
|
||||
function is_php($version)
|
||||
{
|
||||
static $_is_php;
|
||||
$version = (string) $version;
|
||||
|
||||
if ( ! isset($_is_php[$version]))
|
||||
{
|
||||
$_is_php[$version] = version_compare(PHP_VERSION, $version, '>=');
|
||||
}
|
||||
|
||||
return $_is_php[$version];
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('is_really_writable'))
|
||||
{
|
||||
/**
|
||||
* Tests for file writability
|
||||
*
|
||||
* is_writable() returns TRUE on Windows servers when you really can't write to
|
||||
* the file, based on the read-only attribute. is_writable() is also unreliable
|
||||
* on Unix servers if safe_mode is on.
|
||||
*
|
||||
* @link https://bugs.php.net/bug.php?id=54709
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function is_really_writable($file)
|
||||
{
|
||||
// If we're on a Unix server with safe_mode off we call is_writable
|
||||
if (DIRECTORY_SEPARATOR === '/' && (is_php('5.4') OR ! ini_get('safe_mode')))
|
||||
{
|
||||
return is_writable($file);
|
||||
}
|
||||
|
||||
/* For Windows servers and safe_mode "on" installations we'll actually
|
||||
* write a file then read it. Bah...
|
||||
*/
|
||||
if (is_dir($file))
|
||||
{
|
||||
$file = rtrim($file, '/').'/'.md5(mt_rand());
|
||||
if (($fp = @fopen($file, 'ab')) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
@chmod($file, 0777);
|
||||
@unlink($file);
|
||||
return TRUE;
|
||||
}
|
||||
elseif ( ! is_file($file) OR ($fp = @fopen($file, 'ab')) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('load_class'))
|
||||
{
|
||||
/**
|
||||
* Class registry
|
||||
*
|
||||
* This function acts as a singleton. If the requested class does not
|
||||
* exist it is instantiated and set to a static variable. If it has
|
||||
* previously been instantiated the variable is returned.
|
||||
*
|
||||
* @param string the class name being requested
|
||||
* @param string the directory where the class should be found
|
||||
* @param mixed an optional argument to pass to the class constructor
|
||||
* @return object
|
||||
*/
|
||||
function &load_class($class, $directory = 'libraries', $param = NULL)
|
||||
{
|
||||
static $_classes = array();
|
||||
|
||||
// Does the class exist? If so, we're done...
|
||||
if (isset($_classes[$class]))
|
||||
{
|
||||
return $_classes[$class];
|
||||
}
|
||||
|
||||
$name = FALSE;
|
||||
|
||||
// Look for the class first in the local application/libraries folder
|
||||
// then in the native system/libraries folder
|
||||
foreach (array(APPPATH, BASEPATH) as $path)
|
||||
{
|
||||
if (file_exists($path.$directory.'/'.$class.'.php'))
|
||||
{
|
||||
$name = 'CI_'.$class;
|
||||
|
||||
if (class_exists($name, FALSE) === FALSE)
|
||||
{
|
||||
require_once($path.$directory.'/'.$class.'.php');
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Is the request a class extension? If so we load it too
|
||||
if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
|
||||
{
|
||||
$name = config_item('subclass_prefix').$class;
|
||||
|
||||
if (class_exists($name, FALSE) === FALSE)
|
||||
{
|
||||
require_once(APPPATH.$directory.'/'.$name.'.php');
|
||||
}
|
||||
}
|
||||
|
||||
// Did we find the class?
|
||||
if ($name === FALSE)
|
||||
{
|
||||
// Note: We use exit() rather than show_error() in order to avoid a
|
||||
// self-referencing loop with the Exceptions class
|
||||
set_status_header(503);
|
||||
echo 'Unable to locate the specified class: '.$class.'.php';
|
||||
exit(5); // EXIT_UNK_CLASS
|
||||
}
|
||||
|
||||
// Keep track of what we just loaded
|
||||
is_loaded($class);
|
||||
|
||||
$_classes[$class] = isset($param)
|
||||
? new $name($param)
|
||||
: new $name();
|
||||
return $_classes[$class];
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('is_loaded'))
|
||||
{
|
||||
/**
|
||||
* Keeps track of which libraries have been loaded. This function is
|
||||
* called by the load_class() function above
|
||||
*
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
function &is_loaded($class = '')
|
||||
{
|
||||
static $_is_loaded = array();
|
||||
|
||||
if ($class !== '')
|
||||
{
|
||||
$_is_loaded[strtolower($class)] = $class;
|
||||
}
|
||||
|
||||
return $_is_loaded;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('get_config'))
|
||||
{
|
||||
/**
|
||||
* Loads the main config.php file
|
||||
*
|
||||
* This function lets us grab the config file even if the Config class
|
||||
* hasn't been instantiated yet
|
||||
*
|
||||
* @param array
|
||||
* @return array
|
||||
*/
|
||||
function &get_config(Array $replace = array())
|
||||
{
|
||||
static $config;
|
||||
|
||||
if (empty($config))
|
||||
{
|
||||
$file_path = APPPATH.'config/config.php';
|
||||
$found = FALSE;
|
||||
if (file_exists($file_path))
|
||||
{
|
||||
$found = TRUE;
|
||||
require($file_path);
|
||||
}
|
||||
|
||||
// Is the config file in the environment folder?
|
||||
if (file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
|
||||
{
|
||||
require($file_path);
|
||||
}
|
||||
elseif ( ! $found)
|
||||
{
|
||||
set_status_header(503);
|
||||
echo 'The configuration file does not exist.';
|
||||
exit(3); // EXIT_CONFIG
|
||||
}
|
||||
|
||||
// Does the $config array exist in the file?
|
||||
if ( ! isset($config) OR ! is_array($config))
|
||||
{
|
||||
set_status_header(503);
|
||||
echo 'Your config file does not appear to be formatted correctly.';
|
||||
exit(3); // EXIT_CONFIG
|
||||
}
|
||||
}
|
||||
|
||||
// Are any values being dynamically added or replaced?
|
||||
foreach ($replace as $key => $val)
|
||||
{
|
||||
$config[$key] = $val;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('config_item'))
|
||||
{
|
||||
/**
|
||||
* Returns the specified config item
|
||||
*
|
||||
* @param string
|
||||
* @return mixed
|
||||
*/
|
||||
function config_item($item)
|
||||
{
|
||||
static $_config;
|
||||
|
||||
if (empty($_config))
|
||||
{
|
||||
// references cannot be directly assigned to static variables, so we use an array
|
||||
$_config[0] =& get_config();
|
||||
}
|
||||
|
||||
return isset($_config[0][$item]) ? $_config[0][$item] : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('get_mimes'))
|
||||
{
|
||||
/**
|
||||
* Returns the MIME types array from config/mimes.php
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function &get_mimes()
|
||||
{
|
||||
static $_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'))
|
||||
{
|
||||
$_mimes = array_merge($_mimes, include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'));
|
||||
}
|
||||
}
|
||||
|
||||
return $_mimes;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('is_https'))
|
||||
{
|
||||
/**
|
||||
* Is HTTPS?
|
||||
*
|
||||
* Determines if the application is accessed via an encrypted
|
||||
* (HTTPS) connection.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function is_https()
|
||||
{
|
||||
if ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off')
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https')
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
elseif ( ! empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off')
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('is_cli'))
|
||||
{
|
||||
|
||||
/**
|
||||
* Is CLI?
|
||||
*
|
||||
* Test to see if a request was made from the command line.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function is_cli()
|
||||
{
|
||||
return (PHP_SAPI === 'cli' OR defined('STDIN'));
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('show_error'))
|
||||
{
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* This function lets us invoke the exception class and
|
||||
* display errors using the standard error template located
|
||||
* in application/views/errors/error_general.php
|
||||
* This function will send the error page directly to the
|
||||
* browser and exit.
|
||||
*
|
||||
* @param string
|
||||
* @param int
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
|
||||
{
|
||||
$status_code = abs($status_code);
|
||||
if ($status_code < 100)
|
||||
{
|
||||
$exit_status = $status_code + 9; // 9 is EXIT__AUTO_MIN
|
||||
$status_code = 500;
|
||||
}
|
||||
else
|
||||
{
|
||||
$exit_status = 1; // EXIT_ERROR
|
||||
}
|
||||
|
||||
$_error =& load_class('Exceptions', 'core');
|
||||
echo $_error->show_error($heading, $message, 'error_general', $status_code);
|
||||
exit($exit_status);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('show_404'))
|
||||
{
|
||||
/**
|
||||
* 404 Page Handler
|
||||
*
|
||||
* This function is similar to the show_error() function above
|
||||
* However, instead of the standard error template it displays
|
||||
* 404 errors.
|
||||
*
|
||||
* @param string
|
||||
* @param bool
|
||||
* @return void
|
||||
*/
|
||||
function show_404($page = '', $log_error = TRUE)
|
||||
{
|
||||
$_error =& load_class('Exceptions', 'core');
|
||||
$_error->show_404($page, $log_error);
|
||||
exit(4); // EXIT_UNKNOWN_FILE
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('log_message'))
|
||||
{
|
||||
/**
|
||||
* Error Logging Interface
|
||||
*
|
||||
* We use this as a simple mechanism to access the logging
|
||||
* class and send messages to be logged.
|
||||
*
|
||||
* @param string the error level: 'error', 'debug' or 'info'
|
||||
* @param string the error message
|
||||
* @return void
|
||||
*/
|
||||
function log_message($level, $message)
|
||||
{
|
||||
static $_log;
|
||||
|
||||
if ($_log === NULL)
|
||||
{
|
||||
// references cannot be directly assigned to static variables, so we use an array
|
||||
$_log[0] =& load_class('Log', 'core');
|
||||
}
|
||||
|
||||
$_log[0]->write_log($level, $message);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('set_status_header'))
|
||||
{
|
||||
/**
|
||||
* Set HTTP Status Header
|
||||
*
|
||||
* @param int the status code
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function set_status_header($code = 200, $text = '')
|
||||
{
|
||||
if (is_cli())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($code) OR ! is_numeric($code))
|
||||
{
|
||||
show_error('Status codes must be numeric', 500);
|
||||
}
|
||||
|
||||
if (empty($text))
|
||||
{
|
||||
is_int($code) OR $code = (int) $code;
|
||||
$stati = array(
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
|
||||
200 => 'OK',
|
||||
201 => 'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found',
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
307 => 'Temporary Redirect',
|
||||
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
422 => 'Unprocessable Entity',
|
||||
426 => 'Upgrade Required',
|
||||
428 => 'Precondition Required',
|
||||
429 => 'Too Many Requests',
|
||||
431 => 'Request Header Fields Too Large',
|
||||
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported',
|
||||
511 => 'Network Authentication Required',
|
||||
);
|
||||
|
||||
if (isset($stati[$code]))
|
||||
{
|
||||
$text = $stati[$code];
|
||||
}
|
||||
else
|
||||
{
|
||||
show_error('No status text available. Please check your status code number or supply your own message text.', 500);
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos(PHP_SAPI, 'cgi') === 0)
|
||||
{
|
||||
header('Status: '.$code.' '.$text, TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
$server_protocol = (isset($_SERVER['SERVER_PROTOCOL']) && in_array($_SERVER['SERVER_PROTOCOL'], array('HTTP/1.0', 'HTTP/1.1', 'HTTP/2'), TRUE))
|
||||
? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
|
||||
header($server_protocol.' '.$code.' '.$text, TRUE, $code);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('_error_handler'))
|
||||
{
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* This is the custom error handler that is declared at the (relative)
|
||||
* top of CodeIgniter.php. The main reason we use this is to permit
|
||||
* PHP errors to be logged in our own log files since the user may
|
||||
* not have access to server logs. Since this function effectively
|
||||
* intercepts PHP errors, however, we also need to display errors
|
||||
* based on the current error_reporting level.
|
||||
* We do that with the use of a PHP error template.
|
||||
*
|
||||
* @param int $severity
|
||||
* @param string $message
|
||||
* @param string $filepath
|
||||
* @param int $line
|
||||
* @return void
|
||||
*/
|
||||
function _error_handler($severity, $message, $filepath, $line)
|
||||
{
|
||||
$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'
|
||||
// to indicate to the client something went wrong.
|
||||
// This can't be done within the $_error->show_php_error method because
|
||||
// it is only called when the display_errors flag is set (which isn't usually
|
||||
// the case in a production environment) or when errors are ignored because
|
||||
// they are above the error_reporting threshold.
|
||||
if ($is_error)
|
||||
{
|
||||
set_status_header(500);
|
||||
}
|
||||
|
||||
// Should we ignore the error? We'll get the current error_reporting
|
||||
// level and add its bits with the severity bits to find out.
|
||||
if (($severity & error_reporting()) !== $severity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$_error =& load_class('Exceptions', 'core');
|
||||
$_error->log_exception($severity, $message, $filepath, $line);
|
||||
|
||||
// Should we display the error?
|
||||
if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors')))
|
||||
{
|
||||
$_error->show_php_error($severity, $message, $filepath, $line);
|
||||
}
|
||||
|
||||
// If the error is fatal, the execution of the script should be stopped because
|
||||
// errors can't be recovered from. Halting the script conforms with PHP's
|
||||
// default error handling. See http://www.php.net/manual/en/errorfunc.constants.php
|
||||
if ($is_error)
|
||||
{
|
||||
exit(1); // EXIT_ERROR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('_exception_handler'))
|
||||
{
|
||||
/**
|
||||
* Exception Handler
|
||||
*
|
||||
* Sends uncaught exceptions to the logger and displays them
|
||||
* only if display_errors is On so that they don't show up in
|
||||
* production environments.
|
||||
*
|
||||
* @param Exception $exception
|
||||
* @return void
|
||||
*/
|
||||
function _exception_handler($exception)
|
||||
{
|
||||
$_error =& load_class('Exceptions', 'core');
|
||||
$_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine());
|
||||
|
||||
is_cli() OR set_status_header(500);
|
||||
// Should we display the error?
|
||||
if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors')))
|
||||
{
|
||||
$_error->show_exception($exception);
|
||||
}
|
||||
|
||||
exit(1); // EXIT_ERROR
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('_shutdown_handler'))
|
||||
{
|
||||
/**
|
||||
* Shutdown Handler
|
||||
*
|
||||
* This is the shutdown handler that is declared at the top
|
||||
* of CodeIgniter.php. The main reason we use this is to simulate
|
||||
* a complete custom exception handler.
|
||||
*
|
||||
* E_STRICT is purposively neglected because such events may have
|
||||
* been caught. Duplication or none? None is preferred for now.
|
||||
*
|
||||
* @link http://insomanic.me.uk/post/229851073/php-trick-catching-fatal-errors-e-error-with-a
|
||||
* @return void
|
||||
*/
|
||||
function _shutdown_handler()
|
||||
{
|
||||
$last_error = error_get_last();
|
||||
if (isset($last_error) &&
|
||||
($last_error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING)))
|
||||
{
|
||||
_error_handler($last_error['type'], $last_error['message'], $last_error['file'], $last_error['line']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('remove_invisible_characters'))
|
||||
{
|
||||
/**
|
||||
* Remove Invisible Characters
|
||||
*
|
||||
* This prevents sandwiching null characters
|
||||
* between ascii characters, like Java\0script.
|
||||
*
|
||||
* @param string
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
function remove_invisible_characters($str, $url_encoded = TRUE)
|
||||
{
|
||||
$non_displayables = array();
|
||||
|
||||
// every control character except newline (dec 10),
|
||||
// carriage return (dec 13) and horizontal tab (dec 09)
|
||||
if ($url_encoded)
|
||||
{
|
||||
$non_displayables[] = '/%0[0-8bcef]/i'; // url encoded 00-08, 11, 12, 14, 15
|
||||
$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
|
||||
|
||||
do
|
||||
{
|
||||
$str = preg_replace($non_displayables, '', $str, -1, $count);
|
||||
}
|
||||
while ($count);
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('html_escape'))
|
||||
{
|
||||
/**
|
||||
* Returns HTML escaped variable.
|
||||
*
|
||||
* @param mixed $var The input string or array of strings to be escaped.
|
||||
* @param bool $double_encode $double_encode set to FALSE prevents escaping twice.
|
||||
* @return mixed The escaped string or array of strings as a result.
|
||||
*/
|
||||
function html_escape($var, $double_encode = TRUE)
|
||||
{
|
||||
if (empty($var))
|
||||
{
|
||||
return $var;
|
||||
}
|
||||
|
||||
if (is_array($var))
|
||||
{
|
||||
foreach (array_keys($var) as $key)
|
||||
{
|
||||
$var[$key] = html_escape($var[$key], $double_encode);
|
||||
}
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
return htmlspecialchars($var, ENT_QUOTES, config_item('charset'), $double_encode);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('_stringify_attributes'))
|
||||
{
|
||||
/**
|
||||
* Stringify attributes for use in HTML tags.
|
||||
*
|
||||
* Helper function used to convert a string, array, or object
|
||||
* of attributes to a string.
|
||||
*
|
||||
* @param mixed string, array, object
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
function _stringify_attributes($attributes, $js = FALSE)
|
||||
{
|
||||
$atts = NULL;
|
||||
|
||||
if (empty($attributes))
|
||||
{
|
||||
return $atts;
|
||||
}
|
||||
|
||||
if (is_string($attributes))
|
||||
{
|
||||
return ' '.$attributes;
|
||||
}
|
||||
|
||||
$attributes = (array) $attributes;
|
||||
|
||||
foreach ($attributes as $key => $val)
|
||||
{
|
||||
$atts .= ($js) ? $key.'='.$val.',' : ' '.$key.'="'.$val.'"';
|
||||
}
|
||||
|
||||
return rtrim($atts, ',');
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('function_usable'))
|
||||
{
|
||||
/**
|
||||
* Function usable
|
||||
*
|
||||
* Executes a function_exists() check, and if the Suhosin PHP
|
||||
* extension is loaded - checks whether the function that is
|
||||
* checked might be disabled in there as well.
|
||||
*
|
||||
* This is useful as function_exists() will return FALSE for
|
||||
* functions disabled via the *disable_functions* php.ini
|
||||
* setting, but not for *suhosin.executor.func.blacklist* and
|
||||
* *suhosin.executor.disable_eval*. These settings will just
|
||||
* terminate script execution if a disabled function is executed.
|
||||
*
|
||||
* The above described behavior turned out to be a bug in Suhosin,
|
||||
* 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
|
||||
* be just temporary, but would probably be kept for a few years.
|
||||
*
|
||||
* @link http://www.hardened-php.net/suhosin/
|
||||
* @param string $function_name Function to check for
|
||||
* @return bool TRUE if the function exists and is safe to call,
|
||||
* FALSE otherwise.
|
||||
*/
|
||||
function function_usable($function_name)
|
||||
{
|
||||
static $_suhosin_func_blacklist;
|
||||
|
||||
if (function_exists($function_name))
|
||||
{
|
||||
if ( ! isset($_suhosin_func_blacklist))
|
||||
{
|
||||
$_suhosin_func_blacklist = extension_loaded('suhosin')
|
||||
? explode(',', trim(ini_get('suhosin.executor.func.blacklist')))
|
||||
: array();
|
||||
}
|
||||
|
||||
return ! in_array($function_name, $_suhosin_func_blacklist, TRUE);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
379
system/core/Config.php
Normal file
379
system/core/Config.php
Normal file
@ -0,0 +1,379 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Config Class
|
||||
*
|
||||
* This class contains functions that enable config files to be managed
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/libraries/config.html
|
||||
*/
|
||||
class CI_Config {
|
||||
|
||||
/**
|
||||
* List of all loaded config values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $config = array();
|
||||
|
||||
/**
|
||||
* List of all loaded config files
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $is_loaded = array();
|
||||
|
||||
/**
|
||||
* List of paths to search when trying to load a config file.
|
||||
*
|
||||
* @used-by CI_Loader
|
||||
* @var array
|
||||
*/
|
||||
public $_config_paths = array(APPPATH);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Sets the $config data from the primary config.php file as a class variable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->config =& get_config();
|
||||
|
||||
// Set the base_url automatically if none was provided
|
||||
if (empty($this->config['base_url']))
|
||||
{
|
||||
if (isset($_SERVER['SERVER_ADDR']))
|
||||
{
|
||||
if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE)
|
||||
{
|
||||
$server_addr = '['.$_SERVER['SERVER_ADDR'].']';
|
||||
}
|
||||
else
|
||||
{
|
||||
$server_addr = $_SERVER['SERVER_ADDR'];
|
||||
}
|
||||
|
||||
$base_url = (is_https() ? 'https' : 'http').'://'.$server_addr
|
||||
.substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
|
||||
}
|
||||
else
|
||||
{
|
||||
$base_url = 'http://localhost/';
|
||||
}
|
||||
|
||||
$this->set_item('base_url', $base_url);
|
||||
}
|
||||
|
||||
log_message('info', 'Config Class Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Load Config File
|
||||
*
|
||||
* @param string $file Configuration file name
|
||||
* @param bool $use_sections Whether configuration values should be loaded into their own section
|
||||
* @param bool $fail_gracefully Whether to just return FALSE or display an error message
|
||||
* @return bool TRUE if the file was loaded correctly or FALSE on failure
|
||||
*/
|
||||
public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
|
||||
{
|
||||
$file = ($file === '') ? 'config' : str_replace('.php', '', $file);
|
||||
$loaded = FALSE;
|
||||
|
||||
foreach ($this->_config_paths as $path)
|
||||
{
|
||||
foreach (array($file, ENVIRONMENT.DIRECTORY_SEPARATOR.$file) as $location)
|
||||
{
|
||||
$file_path = $path.'config/'.$location.'.php';
|
||||
if (in_array($file_path, $this->is_loaded, TRUE))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ( ! file_exists($file_path))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
include($file_path);
|
||||
|
||||
if ( ! isset($config) OR ! is_array($config))
|
||||
{
|
||||
if ($fail_gracefully === TRUE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.');
|
||||
}
|
||||
|
||||
if ($use_sections === TRUE)
|
||||
{
|
||||
$this->config[$file] = isset($this->config[$file])
|
||||
? array_merge($this->config[$file], $config)
|
||||
: $config;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->config = array_merge($this->config, $config);
|
||||
}
|
||||
|
||||
$this->is_loaded[] = $file_path;
|
||||
$config = NULL;
|
||||
$loaded = TRUE;
|
||||
log_message('debug', 'Config file loaded: '.$file_path);
|
||||
}
|
||||
}
|
||||
|
||||
if ($loaded === TRUE)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
elseif ($fail_gracefully === TRUE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
show_error('The configuration file '.$file.'.php does not exist.');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch a config file item
|
||||
*
|
||||
* @param string $item Config item name
|
||||
* @param string $index Index name
|
||||
* @return string|null The configuration item or NULL if the item doesn't exist
|
||||
*/
|
||||
public function item($item, $index = '')
|
||||
{
|
||||
if ($index == '')
|
||||
{
|
||||
return isset($this->config[$item]) ? $this->config[$item] : NULL;
|
||||
}
|
||||
|
||||
return isset($this->config[$index], $this->config[$index][$item]) ? $this->config[$index][$item] : NULL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch a config file item with slash appended (if not empty)
|
||||
*
|
||||
* @param string $item Config item name
|
||||
* @return string|null The configuration item or NULL if the item doesn't exist
|
||||
*/
|
||||
public function slash_item($item)
|
||||
{
|
||||
if ( ! isset($this->config[$item]))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
elseif (trim($this->config[$item]) === '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
return rtrim($this->config[$item], '/').'/';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Site URL
|
||||
*
|
||||
* Returns base_url . index_page [. uri_string]
|
||||
*
|
||||
* @uses CI_Config::_uri_string()
|
||||
*
|
||||
* @param string|string[] $uri URI string or an array of segments
|
||||
* @param string $protocol
|
||||
* @return string
|
||||
*/
|
||||
public function site_url($uri = '', $protocol = NULL)
|
||||
{
|
||||
$base_url = $this->slash_item('base_url');
|
||||
|
||||
if (isset($protocol))
|
||||
{
|
||||
// For protocol-relative links
|
||||
if ($protocol === '')
|
||||
{
|
||||
$base_url = substr($base_url, strpos($base_url, '//'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$base_url = $protocol.substr($base_url, strpos($base_url, '://'));
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($uri))
|
||||
{
|
||||
return $base_url.$this->item('index_page');
|
||||
}
|
||||
|
||||
$uri = $this->_uri_string($uri);
|
||||
|
||||
if ($this->item('enable_query_strings') === FALSE)
|
||||
{
|
||||
$suffix = isset($this->config['url_suffix']) ? $this->config['url_suffix'] : '';
|
||||
|
||||
if ($suffix !== '')
|
||||
{
|
||||
if (($offset = strpos($uri, '?')) !== FALSE)
|
||||
{
|
||||
$uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
$uri .= $suffix;
|
||||
}
|
||||
}
|
||||
|
||||
return $base_url.$this->slash_item('index_page').$uri;
|
||||
}
|
||||
elseif (strpos($uri, '?') === FALSE)
|
||||
{
|
||||
$uri = '?'.$uri;
|
||||
}
|
||||
|
||||
return $base_url.$this->item('index_page').$uri;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* Returns base_url [. uri_string]
|
||||
*
|
||||
* @uses CI_Config::_uri_string()
|
||||
*
|
||||
* @param string|string[] $uri URI string or an array of segments
|
||||
* @param string $protocol
|
||||
* @return string
|
||||
*/
|
||||
public function base_url($uri = '', $protocol = NULL)
|
||||
{
|
||||
$base_url = $this->slash_item('base_url');
|
||||
|
||||
if (isset($protocol))
|
||||
{
|
||||
// For protocol-relative links
|
||||
if ($protocol === '')
|
||||
{
|
||||
$base_url = substr($base_url, strpos($base_url, '//'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$base_url = $protocol.substr($base_url, strpos($base_url, '://'));
|
||||
}
|
||||
}
|
||||
|
||||
return $base_url.$this->_uri_string($uri);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Build URI string
|
||||
*
|
||||
* @used-by CI_Config::site_url()
|
||||
* @used-by CI_Config::base_url()
|
||||
*
|
||||
* @param string|string[] $uri URI string or an array of segments
|
||||
* @return string
|
||||
*/
|
||||
protected function _uri_string($uri)
|
||||
{
|
||||
if ($this->item('enable_query_strings') === FALSE)
|
||||
{
|
||||
is_array($uri) && $uri = implode('/', $uri);
|
||||
return ltrim($uri, '/');
|
||||
}
|
||||
elseif (is_array($uri))
|
||||
{
|
||||
return http_build_query($uri);
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* System URL
|
||||
*
|
||||
* @deprecated 3.0.0 Encourages insecure practices
|
||||
* @return string
|
||||
*/
|
||||
public function system_url()
|
||||
{
|
||||
$x = explode('/', preg_replace('|/*(.+?)/*$|', '\\1', BASEPATH));
|
||||
return $this->slash_item('base_url').end($x).'/';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set a config file item
|
||||
*
|
||||
* @param string $item Config item key
|
||||
* @param string $value Config item value
|
||||
* @return void
|
||||
*/
|
||||
public function set_item($item, $value)
|
||||
{
|
||||
$this->config[$item] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
96
system/core/Controller.php
Normal file
96
system/core/Controller.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Application Controller Class
|
||||
*
|
||||
* This class object is the super class that every library in
|
||||
* CodeIgniter will be assigned to.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/general/controllers.html
|
||||
*/
|
||||
class CI_Controller {
|
||||
|
||||
/**
|
||||
* Reference to the CI singleton
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
self::$instance =& $this;
|
||||
|
||||
// Assign all the class objects that were instantiated by the
|
||||
// bootstrap file (CodeIgniter.php) to local class variables
|
||||
// so that CI can run as one big super object.
|
||||
foreach (is_loaded() as $var => $class)
|
||||
{
|
||||
$this->$var =& load_class($class);
|
||||
}
|
||||
|
||||
$this->load =& load_class('Loader', 'core');
|
||||
$this->load->initialize();
|
||||
log_message('info', 'Controller Class Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the CI singleton
|
||||
*
|
||||
* @static
|
||||
* @return object
|
||||
*/
|
||||
public static function &get_instance()
|
||||
{
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
}
|
||||
274
system/core/Exceptions.php
Normal file
274
system/core/Exceptions.php
Normal file
@ -0,0 +1,274 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Exceptions Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Exceptions
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/libraries/exceptions.html
|
||||
*/
|
||||
class CI_Exceptions {
|
||||
|
||||
/**
|
||||
* Nesting level of the output buffering mechanism
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $ob_level;
|
||||
|
||||
/**
|
||||
* List of available error levels
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $levels = array(
|
||||
E_ERROR => 'Error',
|
||||
E_WARNING => 'Warning',
|
||||
E_PARSE => 'Parsing Error',
|
||||
E_NOTICE => 'Notice',
|
||||
E_CORE_ERROR => 'Core Error',
|
||||
E_CORE_WARNING => 'Core Warning',
|
||||
E_COMPILE_ERROR => 'Compile Error',
|
||||
E_COMPILE_WARNING => 'Compile Warning',
|
||||
E_USER_ERROR => 'User Error',
|
||||
E_USER_WARNING => 'User Warning',
|
||||
E_USER_NOTICE => 'User Notice',
|
||||
E_STRICT => 'Runtime Notice'
|
||||
);
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->ob_level = ob_get_level();
|
||||
// Note: Do not log messages from this constructor.
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Exception Logger
|
||||
*
|
||||
* Logs PHP generated error messages
|
||||
*
|
||||
* @param int $severity Log level
|
||||
* @param string $message Error message
|
||||
* @param string $filepath File path
|
||||
* @param int $line Line number
|
||||
* @return void
|
||||
*/
|
||||
public function log_exception($severity, $message, $filepath, $line)
|
||||
{
|
||||
$severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity;
|
||||
log_message('error', 'Severity: '.$severity.' --> '.$message.' '.$filepath.' '.$line);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 404 Error Handler
|
||||
*
|
||||
* @uses CI_Exceptions::show_error()
|
||||
*
|
||||
* @param string $page Page URI
|
||||
* @param bool $log_error Whether to log the error
|
||||
* @return void
|
||||
*/
|
||||
public function show_404($page = '', $log_error = TRUE)
|
||||
{
|
||||
if (is_cli())
|
||||
{
|
||||
$heading = 'Not Found';
|
||||
$message = 'The controller/method pair you requested was not found.';
|
||||
}
|
||||
else
|
||||
{
|
||||
$heading = '404 Page Not Found';
|
||||
$message = 'The page you requested was not found.';
|
||||
}
|
||||
|
||||
// By default we log this, but allow a dev to skip it
|
||||
if ($log_error)
|
||||
{
|
||||
log_message('error', $heading.': '.$page);
|
||||
}
|
||||
|
||||
echo $this->show_error($heading, $message, 'error_404', 404);
|
||||
exit(4); // EXIT_UNKNOWN_FILE
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* General Error Page
|
||||
*
|
||||
* Takes an error message as input (either as a string or an array)
|
||||
* and displays it using the specified template.
|
||||
*
|
||||
* @param string $heading Page heading
|
||||
* @param string|string[] $message Error message
|
||||
* @param string $template Template name
|
||||
* @param int $status_code (default: 500)
|
||||
*
|
||||
* @return string Error page output
|
||||
*/
|
||||
public function show_error($heading, $message, $template = 'error_general', $status_code = 500)
|
||||
{
|
||||
$templates_path = config_item('error_views_path');
|
||||
if (empty($templates_path))
|
||||
{
|
||||
$templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
if (is_cli())
|
||||
{
|
||||
$message = "\t".(is_array($message) ? implode("\n\t", $message) : $message);
|
||||
$template = 'cli'.DIRECTORY_SEPARATOR.$template;
|
||||
}
|
||||
else
|
||||
{
|
||||
set_status_header($status_code);
|
||||
$message = '<p>'.(is_array($message) ? implode('</p><p>', $message) : $message).'</p>';
|
||||
$template = 'html'.DIRECTORY_SEPARATOR.$template;
|
||||
}
|
||||
|
||||
if (ob_get_level() > $this->ob_level + 1)
|
||||
{
|
||||
ob_end_flush();
|
||||
}
|
||||
ob_start();
|
||||
include($templates_path.$template.'.php');
|
||||
$buffer = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
public function show_exception($exception)
|
||||
{
|
||||
$templates_path = config_item('error_views_path');
|
||||
if (empty($templates_path))
|
||||
{
|
||||
$templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$message = $exception->getMessage();
|
||||
if (empty($message))
|
||||
{
|
||||
$message = '(null)';
|
||||
}
|
||||
|
||||
if (is_cli())
|
||||
{
|
||||
$templates_path .= 'cli'.DIRECTORY_SEPARATOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
$templates_path .= 'html'.DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
if (ob_get_level() > $this->ob_level + 1)
|
||||
{
|
||||
ob_end_flush();
|
||||
}
|
||||
|
||||
ob_start();
|
||||
include($templates_path.'error_exception.php');
|
||||
$buffer = ob_get_contents();
|
||||
ob_end_clean();
|
||||
echo $buffer;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Native PHP error handler
|
||||
*
|
||||
* @param int $severity Error level
|
||||
* @param string $message Error message
|
||||
* @param string $filepath File path
|
||||
* @param int $line Line number
|
||||
* @return void
|
||||
*/
|
||||
public function show_php_error($severity, $message, $filepath, $line)
|
||||
{
|
||||
$templates_path = config_item('error_views_path');
|
||||
if (empty($templates_path))
|
||||
{
|
||||
$templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity;
|
||||
|
||||
// For safety reasons we don't show the full file path in non-CLI requests
|
||||
if ( ! is_cli())
|
||||
{
|
||||
$filepath = str_replace('\\', '/', $filepath);
|
||||
if (FALSE !== strpos($filepath, '/'))
|
||||
{
|
||||
$x = explode('/', $filepath);
|
||||
$filepath = $x[count($x)-2].'/'.end($x);
|
||||
}
|
||||
|
||||
$template = 'html'.DIRECTORY_SEPARATOR.'error_php';
|
||||
}
|
||||
else
|
||||
{
|
||||
$template = 'cli'.DIRECTORY_SEPARATOR.'error_php';
|
||||
}
|
||||
|
||||
if (ob_get_level() > $this->ob_level + 1)
|
||||
{
|
||||
ob_end_flush();
|
||||
}
|
||||
ob_start();
|
||||
include($templates_path.$template.'.php');
|
||||
$buffer = ob_get_contents();
|
||||
ob_end_clean();
|
||||
echo $buffer;
|
||||
}
|
||||
|
||||
}
|
||||
266
system/core/Hooks.php
Normal file
266
system/core/Hooks.php
Normal file
@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Hooks Class
|
||||
*
|
||||
* Provides a mechanism to extend the base system without hacking.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/general/hooks.html
|
||||
*/
|
||||
class CI_Hooks {
|
||||
|
||||
/**
|
||||
* Determines whether hooks are enabled
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $enabled = FALSE;
|
||||
|
||||
/**
|
||||
* List of all hooks set in config/hooks.php
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $hooks = array();
|
||||
|
||||
/**
|
||||
* Array with class objects to use hooks methods
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_objects = array();
|
||||
|
||||
/**
|
||||
* In progress flag
|
||||
*
|
||||
* Determines whether hook is in progress, used to prevent infinte loops
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_in_progress = FALSE;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$CFG =& load_class('Config', 'core');
|
||||
log_message('info', 'Hooks Class Initialized');
|
||||
|
||||
// If hooks are not enabled in the config file
|
||||
// there is nothing else to do
|
||||
if ($CFG->item('enable_hooks') === FALSE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Grab the "hooks" definition file.
|
||||
if (file_exists(APPPATH.'config/hooks.php'))
|
||||
{
|
||||
include(APPPATH.'config/hooks.php');
|
||||
}
|
||||
|
||||
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'))
|
||||
{
|
||||
include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php');
|
||||
}
|
||||
|
||||
// If there are no hooks, we're done.
|
||||
if ( ! isset($hook) OR ! is_array($hook))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->hooks =& $hook;
|
||||
$this->enabled = TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Call Hook
|
||||
*
|
||||
* Calls a particular hook. Called by CodeIgniter.php.
|
||||
*
|
||||
* @uses CI_Hooks::_run_hook()
|
||||
*
|
||||
* @param string $which Hook name
|
||||
* @return bool TRUE on success or FALSE on failure
|
||||
*/
|
||||
public function call_hook($which = '')
|
||||
{
|
||||
if ( ! $this->enabled OR ! isset($this->hooks[$which]))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (is_array($this->hooks[$which]) && ! isset($this->hooks[$which]['function']))
|
||||
{
|
||||
foreach ($this->hooks[$which] as $val)
|
||||
{
|
||||
$this->_run_hook($val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_run_hook($this->hooks[$which]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Run Hook
|
||||
*
|
||||
* Runs a particular hook
|
||||
*
|
||||
* @param array $data Hook details
|
||||
* @return bool TRUE on success or FALSE on failure
|
||||
*/
|
||||
protected function _run_hook($data)
|
||||
{
|
||||
// Closures/lambda functions and array($object, 'method') callables
|
||||
if (is_callable($data))
|
||||
{
|
||||
is_array($data)
|
||||
? $data[0]->{$data[1]}()
|
||||
: $data();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
elseif ( ! is_array($data))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
// Safety - Prevents run-away loops
|
||||
// -----------------------------------
|
||||
|
||||
// If the script being called happens to have the same
|
||||
// hook call within it a loop can happen
|
||||
if ($this->_in_progress === TRUE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
// Set file path
|
||||
// -----------------------------------
|
||||
|
||||
if ( ! isset($data['filepath'], $data['filename']))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$filepath = APPPATH.$data['filepath'].'/'.$data['filename'];
|
||||
|
||||
if ( ! file_exists($filepath))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Determine and class and/or function names
|
||||
$class = empty($data['class']) ? FALSE : $data['class'];
|
||||
$function = empty($data['function']) ? FALSE : $data['function'];
|
||||
$params = isset($data['params']) ? $data['params'] : '';
|
||||
|
||||
if (empty($function))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Set the _in_progress flag
|
||||
$this->_in_progress = TRUE;
|
||||
|
||||
// Call the requested class and/or function
|
||||
if ($class !== FALSE)
|
||||
{
|
||||
// The object is stored?
|
||||
if (isset($this->_objects[$class]))
|
||||
{
|
||||
if (method_exists($this->_objects[$class], $function))
|
||||
{
|
||||
$this->_objects[$class]->$function($params);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->_in_progress = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
class_exists($class, FALSE) OR require_once($filepath);
|
||||
|
||||
if ( ! class_exists($class, FALSE) OR ! method_exists($class, $function))
|
||||
{
|
||||
return $this->_in_progress = FALSE;
|
||||
}
|
||||
|
||||
// Store the object and execute the method
|
||||
$this->_objects[$class] = new $class();
|
||||
$this->_objects[$class]->$function($params);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
function_exists($function) OR require_once($filepath);
|
||||
|
||||
if ( ! function_exists($function))
|
||||
{
|
||||
return $this->_in_progress = FALSE;
|
||||
}
|
||||
|
||||
$function($params);
|
||||
}
|
||||
|
||||
$this->_in_progress = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
895
system/core/Input.php
Normal file
895
system/core/Input.php
Normal file
@ -0,0 +1,895 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Input Class
|
||||
*
|
||||
* Pre-processes global input data for security
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Input
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/libraries/input.html
|
||||
*/
|
||||
class CI_Input {
|
||||
|
||||
/**
|
||||
* IP address of the current user
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $ip_address = FALSE;
|
||||
|
||||
/**
|
||||
* Allow GET array flag
|
||||
*
|
||||
* If set to FALSE, then $_GET will be set to an empty array.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_allow_get_array = TRUE;
|
||||
|
||||
/**
|
||||
* Standardize new lines flag
|
||||
*
|
||||
* If set to TRUE, then newlines are standardized.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_standardize_newlines;
|
||||
|
||||
/**
|
||||
* Enable XSS flag
|
||||
*
|
||||
* Determines whether the XSS filter is always active when
|
||||
* GET, POST or COOKIE data is encountered.
|
||||
* Set automatically based on config setting.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_enable_xss = FALSE;
|
||||
|
||||
/**
|
||||
* Enable CSRF flag
|
||||
*
|
||||
* Enables a CSRF cookie token to be set.
|
||||
* Set automatically based on config setting.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_enable_csrf = FALSE;
|
||||
|
||||
/**
|
||||
* List of all HTTP request headers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* Raw input stream data
|
||||
*
|
||||
* Holds a cache of php://input contents
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_raw_input_stream;
|
||||
|
||||
/**
|
||||
* Parsed input stream data
|
||||
*
|
||||
* Parsed from php://input at runtime
|
||||
*
|
||||
* @see CI_Input::input_stream()
|
||||
* @var array
|
||||
*/
|
||||
protected $_input_stream;
|
||||
|
||||
protected $security;
|
||||
protected $uni;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Determines whether to globally enable the XSS processing
|
||||
* and whether to allow the $_GET array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_allow_get_array = (config_item('allow_get_array') !== FALSE);
|
||||
$this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
|
||||
$this->_enable_csrf = (config_item('csrf_protection') === TRUE);
|
||||
$this->_standardize_newlines = (bool) config_item('standardize_newlines');
|
||||
|
||||
$this->security =& load_class('Security', 'core');
|
||||
|
||||
// Do we need the UTF-8 class?
|
||||
if (UTF8_ENABLED === TRUE)
|
||||
{
|
||||
$this->uni =& load_class('Utf8', 'core');
|
||||
}
|
||||
|
||||
// Sanitize global arrays
|
||||
$this->_sanitize_globals();
|
||||
|
||||
// CSRF Protection check
|
||||
if ($this->_enable_csrf === TRUE && ! is_cli())
|
||||
{
|
||||
$this->security->csrf_verify();
|
||||
}
|
||||
|
||||
log_message('info', 'Input Class Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch from array
|
||||
*
|
||||
* Internal method used to retrieve values from global arrays.
|
||||
*
|
||||
* @param array &$array $_GET, $_POST, $_COOKIE, $_SERVER, etc.
|
||||
* @param mixed $index Index for item to be fetched from $array
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _fetch_from_array(&$array, $index = NULL, $xss_clean = NULL)
|
||||
{
|
||||
is_bool($xss_clean) OR $xss_clean = $this->_enable_xss;
|
||||
|
||||
// If $index is NULL, it means that the whole $array is requested
|
||||
isset($index) OR $index = array_keys($array);
|
||||
|
||||
// allow fetching multiple keys at once
|
||||
if (is_array($index))
|
||||
{
|
||||
$output = array();
|
||||
foreach ($index as $key)
|
||||
{
|
||||
$output[$key] = $this->_fetch_from_array($array, $key, $xss_clean);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
if (isset($array[$index]))
|
||||
{
|
||||
$value = $array[$index];
|
||||
}
|
||||
elseif (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) // Does the index contain array notation
|
||||
{
|
||||
$value = $array;
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
{
|
||||
$key = trim($matches[0][$i], '[]');
|
||||
if ($key === '') // Empty notation will return the value as array
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($value[$key]))
|
||||
{
|
||||
$value = $value[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ($xss_clean === TRUE)
|
||||
? $this->security->xss_clean($value)
|
||||
: $value;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch an item from the GET array
|
||||
*
|
||||
* @param mixed $index Index for item to be fetched from $_GET
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($index = NULL, $xss_clean = NULL)
|
||||
{
|
||||
return $this->_fetch_from_array($_GET, $index, $xss_clean);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch an item from the POST array
|
||||
*
|
||||
* @param mixed $index Index for item to be fetched from $_POST
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return mixed
|
||||
*/
|
||||
public function post($index = NULL, $xss_clean = NULL)
|
||||
{
|
||||
return $this->_fetch_from_array($_POST, $index, $xss_clean);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch an item from POST data with fallback to GET
|
||||
*
|
||||
* @param string $index Index for item to be fetched from $_POST or $_GET
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return mixed
|
||||
*/
|
||||
public function post_get($index, $xss_clean = NULL)
|
||||
{
|
||||
return isset($_POST[$index])
|
||||
? $this->post($index, $xss_clean)
|
||||
: $this->get($index, $xss_clean);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch an item from GET data with fallback to POST
|
||||
*
|
||||
* @param string $index Index for item to be fetched from $_GET or $_POST
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_post($index, $xss_clean = NULL)
|
||||
{
|
||||
return isset($_GET[$index])
|
||||
? $this->get($index, $xss_clean)
|
||||
: $this->post($index, $xss_clean);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch an item from the COOKIE array
|
||||
*
|
||||
* @param mixed $index Index for item to be fetched from $_COOKIE
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return mixed
|
||||
*/
|
||||
public function cookie($index = NULL, $xss_clean = NULL)
|
||||
{
|
||||
return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch an item from the SERVER array
|
||||
*
|
||||
* @param mixed $index Index for item to be fetched from $_SERVER
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return mixed
|
||||
*/
|
||||
public function server($index, $xss_clean = NULL)
|
||||
{
|
||||
return $this->_fetch_from_array($_SERVER, $index, $xss_clean);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch an item from the php://input stream
|
||||
*
|
||||
* Useful when you need to access PUT, DELETE or PATCH request data.
|
||||
*
|
||||
* @param string $index Index for item to be fetched
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return mixed
|
||||
*/
|
||||
public function input_stream($index = NULL, $xss_clean = NULL)
|
||||
{
|
||||
// Prior to PHP 5.6, the input stream can only be read once,
|
||||
// so we'll need to check if we have already done that first.
|
||||
if ( ! is_array($this->_input_stream))
|
||||
{
|
||||
// $this->raw_input_stream will trigger __get().
|
||||
parse_str($this->raw_input_stream, $this->_input_stream);
|
||||
is_array($this->_input_stream) OR $this->_input_stream = array();
|
||||
}
|
||||
|
||||
return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set cookie
|
||||
*
|
||||
* Accepts an arbitrary number of parameters (up to 7) or an associative
|
||||
* array in the first parameter containing all the values.
|
||||
*
|
||||
* @param string|mixed[] $name Cookie name or an array containing parameters
|
||||
* @param string $value Cookie value
|
||||
* @param int $expire Cookie expiration time in seconds
|
||||
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
|
||||
* @param string $path Cookie path (default: '/')
|
||||
* @param string $prefix Cookie name prefix
|
||||
* @param bool $secure Whether to only transfer cookies via SSL
|
||||
* @param bool $httponly Whether to only makes the cookie accessible via HTTP (no javascript)
|
||||
* @return void
|
||||
*/
|
||||
public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL)
|
||||
{
|
||||
if (is_array($name))
|
||||
{
|
||||
// always leave 'name' in last place, as the loop will break otherwise, due to $$item
|
||||
foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name') as $item)
|
||||
{
|
||||
if (isset($name[$item]))
|
||||
{
|
||||
$$item = $name[$item];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($prefix === '' && config_item('cookie_prefix') !== '')
|
||||
{
|
||||
$prefix = config_item('cookie_prefix');
|
||||
}
|
||||
|
||||
if ($domain == '' && config_item('cookie_domain') != '')
|
||||
{
|
||||
$domain = config_item('cookie_domain');
|
||||
}
|
||||
|
||||
if ($path === '/' && config_item('cookie_path') !== '/')
|
||||
{
|
||||
$path = config_item('cookie_path');
|
||||
}
|
||||
|
||||
$secure = ($secure === NULL && config_item('cookie_secure') !== NULL)
|
||||
? (bool) config_item('cookie_secure')
|
||||
: (bool) $secure;
|
||||
|
||||
$httponly = ($httponly === NULL && config_item('cookie_httponly') !== NULL)
|
||||
? (bool) config_item('cookie_httponly')
|
||||
: (bool) $httponly;
|
||||
|
||||
if ( ! is_numeric($expire))
|
||||
{
|
||||
$expire = time() - 86500;
|
||||
}
|
||||
else
|
||||
{
|
||||
$expire = ($expire > 0) ? time() + $expire : 0;
|
||||
}
|
||||
|
||||
setcookie($prefix.$name, $value, $expire, $path, $domain, $secure, $httponly);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch the IP Address
|
||||
*
|
||||
* Determines and validates the visitor's IP address.
|
||||
*
|
||||
* @return string IP address
|
||||
*/
|
||||
public function ip_address()
|
||||
{
|
||||
if ($this->ip_address !== FALSE)
|
||||
{
|
||||
return $this->ip_address;
|
||||
}
|
||||
|
||||
$proxy_ips = config_item('proxy_ips');
|
||||
if ( ! empty($proxy_ips) && ! is_array($proxy_ips))
|
||||
{
|
||||
$proxy_ips = explode(',', str_replace(' ', '', $proxy_ips));
|
||||
}
|
||||
|
||||
$this->ip_address = $this->server('REMOTE_ADDR');
|
||||
|
||||
if ($proxy_ips)
|
||||
{
|
||||
foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header)
|
||||
{
|
||||
if (($spoof = $this->server($header)) !== NULL)
|
||||
{
|
||||
// Some proxies typically list the whole chain of IP
|
||||
// addresses through which the client has reached us.
|
||||
// e.g. client_ip, proxy_ip1, proxy_ip2, etc.
|
||||
sscanf($spoof, '%[^,]', $spoof);
|
||||
|
||||
if ( ! $this->valid_ip($spoof))
|
||||
{
|
||||
$spoof = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($spoof)
|
||||
{
|
||||
for ($i = 0, $c = count($proxy_ips); $i < $c; $i++)
|
||||
{
|
||||
// Check if we have an IP address or a subnet
|
||||
if (strpos($proxy_ips[$i], '/') === FALSE)
|
||||
{
|
||||
// An IP address (and not a subnet) is specified.
|
||||
// We can compare right away.
|
||||
if ($proxy_ips[$i] === $this->ip_address)
|
||||
{
|
||||
$this->ip_address = $spoof;
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// We have a subnet ... now the heavy lifting begins
|
||||
isset($separator) OR $separator = $this->valid_ip($this->ip_address, 'ipv6') ? ':' : '.';
|
||||
|
||||
// If the proxy entry doesn't match the IP protocol - skip it
|
||||
if (strpos($proxy_ips[$i], $separator) === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Convert the REMOTE_ADDR IP address to binary, if needed
|
||||
if ( ! isset($ip, $sprintf))
|
||||
{
|
||||
if ($separator === ':')
|
||||
{
|
||||
// Make sure we're have the "full" IPv6 format
|
||||
$ip = explode(':',
|
||||
str_replace('::',
|
||||
str_repeat(':', 9 - substr_count($this->ip_address, ':')),
|
||||
$this->ip_address
|
||||
)
|
||||
);
|
||||
|
||||
for ($j = 0; $j < 8; $j++)
|
||||
{
|
||||
$ip[$j] = intval($ip[$j], 16);
|
||||
}
|
||||
|
||||
$sprintf = '%016b%016b%016b%016b%016b%016b%016b%016b';
|
||||
}
|
||||
else
|
||||
{
|
||||
$ip = explode('.', $this->ip_address);
|
||||
$sprintf = '%08b%08b%08b%08b';
|
||||
}
|
||||
|
||||
$ip = vsprintf($sprintf, $ip);
|
||||
}
|
||||
|
||||
// Split the netmask length off the network address
|
||||
sscanf($proxy_ips[$i], '%[^/]/%d', $netaddr, $masklen);
|
||||
|
||||
// Again, an IPv6 address is most likely in a compressed form
|
||||
if ($separator === ':')
|
||||
{
|
||||
$netaddr = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr));
|
||||
for ($j = 0; $j < 8; $j++)
|
||||
{
|
||||
$netaddr[$j] = intval($netaddr[$j], 16);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$netaddr = explode('.', $netaddr);
|
||||
}
|
||||
|
||||
// Convert to binary and finally compare
|
||||
if (strncmp($ip, vsprintf($sprintf, $netaddr), $masklen) === 0)
|
||||
{
|
||||
$this->ip_address = $spoof;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->valid_ip($this->ip_address))
|
||||
{
|
||||
return $this->ip_address = '0.0.0.0';
|
||||
}
|
||||
|
||||
return $this->ip_address;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Validate IP Address
|
||||
*
|
||||
* @param string $ip IP address
|
||||
* @param string $which IP protocol: 'ipv4' or 'ipv6'
|
||||
* @return bool
|
||||
*/
|
||||
public function valid_ip($ip, $which = '')
|
||||
{
|
||||
switch (strtolower($which))
|
||||
{
|
||||
case 'ipv4':
|
||||
$which = FILTER_FLAG_IPV4;
|
||||
break;
|
||||
case 'ipv6':
|
||||
$which = FILTER_FLAG_IPV6;
|
||||
break;
|
||||
default:
|
||||
$which = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
return (bool) filter_var($ip, FILTER_VALIDATE_IP, $which);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch User Agent string
|
||||
*
|
||||
* @return string|null User Agent string or NULL if it doesn't exist
|
||||
*/
|
||||
public function user_agent($xss_clean = NULL)
|
||||
{
|
||||
return $this->_fetch_from_array($_SERVER, 'HTTP_USER_AGENT', $xss_clean);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sanitize Globals
|
||||
*
|
||||
* Internal method serving for the following purposes:
|
||||
*
|
||||
* - Unsets $_GET data, if query strings are not enabled
|
||||
* - Cleans POST, COOKIE and SERVER data
|
||||
* - Standardizes newline characters to PHP_EOL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _sanitize_globals()
|
||||
{
|
||||
// Is $_GET data allowed? If not we'll set the $_GET to an empty array
|
||||
if ($this->_allow_get_array === FALSE)
|
||||
{
|
||||
$_GET = array();
|
||||
}
|
||||
elseif (is_array($_GET))
|
||||
{
|
||||
foreach ($_GET as $key => $val)
|
||||
{
|
||||
$_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean $_POST Data
|
||||
if (is_array($_POST))
|
||||
{
|
||||
foreach ($_POST as $key => $val)
|
||||
{
|
||||
$_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean $_COOKIE Data
|
||||
if (is_array($_COOKIE))
|
||||
{
|
||||
// Also get rid of specially treated cookies that might be set by a server
|
||||
// or silly application, that are of no use to a CI application anyway
|
||||
// but that when present will trip our 'Disallowed Key Characters' alarm
|
||||
// http://www.ietf.org/rfc/rfc2109.txt
|
||||
// note that the key names below are single quoted strings, and are not PHP variables
|
||||
unset(
|
||||
$_COOKIE['$Version'],
|
||||
$_COOKIE['$Path'],
|
||||
$_COOKIE['$Domain']
|
||||
);
|
||||
|
||||
foreach ($_COOKIE as $key => $val)
|
||||
{
|
||||
if (($cookie_key = $this->_clean_input_keys($key)) !== FALSE)
|
||||
{
|
||||
$_COOKIE[$cookie_key] = $this->_clean_input_data($val);
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($_COOKIE[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sanitize PHP_SELF
|
||||
$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
|
||||
|
||||
log_message('debug', 'Global POST, GET and COOKIE data sanitized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clean Input Data
|
||||
*
|
||||
* Internal method that aids in escaping data and
|
||||
* standardizing newline characters to PHP_EOL.
|
||||
*
|
||||
* @param string|string[] $str Input string(s)
|
||||
* @return string
|
||||
*/
|
||||
protected function _clean_input_data($str)
|
||||
{
|
||||
if (is_array($str))
|
||||
{
|
||||
$new_array = array();
|
||||
foreach (array_keys($str) as $key)
|
||||
{
|
||||
$new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($str[$key]);
|
||||
}
|
||||
return $new_array;
|
||||
}
|
||||
|
||||
/* We strip slashes if magic quotes is on to keep things consistent
|
||||
|
||||
NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
|
||||
it will probably not exist in future versions at all.
|
||||
*/
|
||||
if ( ! is_php('5.4') && get_magic_quotes_gpc())
|
||||
{
|
||||
$str = stripslashes($str);
|
||||
}
|
||||
|
||||
// Clean UTF-8 if supported
|
||||
if (UTF8_ENABLED === TRUE)
|
||||
{
|
||||
$str = $this->uni->clean_string($str);
|
||||
}
|
||||
|
||||
// Remove control characters
|
||||
$str = remove_invisible_characters($str, FALSE);
|
||||
|
||||
// Standardize newlines if needed
|
||||
if ($this->_standardize_newlines === TRUE)
|
||||
{
|
||||
return preg_replace('/(?:\r\n|[\r\n])/', PHP_EOL, $str);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clean Keys
|
||||
*
|
||||
* Internal method that helps to prevent malicious users
|
||||
* from trying to exploit keys we make sure that keys are
|
||||
* only named with alpha-numeric text and a few other items.
|
||||
*
|
||||
* @param string $str Input string
|
||||
* @param bool $fatal Whether to terminate script exection
|
||||
* or to return FALSE if an invalid
|
||||
* key is encountered
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function _clean_input_keys($str, $fatal = TRUE)
|
||||
{
|
||||
if ( ! preg_match('/^[a-z0-9:_\/|-]+$/i', $str))
|
||||
{
|
||||
if ($fatal === TRUE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
set_status_header(503);
|
||||
echo 'Disallowed Key Characters.';
|
||||
exit(7); // EXIT_USER_INPUT
|
||||
}
|
||||
}
|
||||
|
||||
// Clean UTF-8 if supported
|
||||
if (UTF8_ENABLED === TRUE)
|
||||
{
|
||||
return $this->uni->clean_string($str);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Request Headers
|
||||
*
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return array
|
||||
*/
|
||||
public function request_headers($xss_clean = FALSE)
|
||||
{
|
||||
// If header is already defined, return it immediately
|
||||
if ( ! empty($this->headers))
|
||||
{
|
||||
return $this->_fetch_from_array($this->headers, NULL, $xss_clean);
|
||||
}
|
||||
|
||||
// In Apache, you can simply call apache_request_headers()
|
||||
if (function_exists('apache_request_headers'))
|
||||
{
|
||||
$this->headers = apache_request_headers();
|
||||
}
|
||||
else
|
||||
{
|
||||
isset($_SERVER['CONTENT_TYPE']) && $this->headers['Content-Type'] = $_SERVER['CONTENT_TYPE'];
|
||||
|
||||
foreach ($_SERVER as $key => $val)
|
||||
{
|
||||
if (sscanf($key, 'HTTP_%s', $header) === 1)
|
||||
{
|
||||
// take SOME_HEADER and turn it into Some-Header
|
||||
$header = str_replace('_', ' ', strtolower($header));
|
||||
$header = str_replace(' ', '-', ucwords($header));
|
||||
|
||||
$this->headers[$header] = $_SERVER[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_fetch_from_array($this->headers, NULL, $xss_clean);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Request Header
|
||||
*
|
||||
* Returns the value of a single member of the headers class member
|
||||
*
|
||||
* @param string $index Header name
|
||||
* @param bool $xss_clean Whether to apply XSS filtering
|
||||
* @return string|null The requested header on success or NULL on failure
|
||||
*/
|
||||
public function get_request_header($index, $xss_clean = FALSE)
|
||||
{
|
||||
static $headers;
|
||||
|
||||
if ( ! isset($headers))
|
||||
{
|
||||
empty($this->headers) && $this->request_headers();
|
||||
foreach ($this->headers as $key => $value)
|
||||
{
|
||||
$headers[strtolower($key)] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$index = strtolower($index);
|
||||
|
||||
if ( ! isset($headers[$index]))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ($xss_clean === TRUE)
|
||||
? $this->security->xss_clean($headers[$index])
|
||||
: $headers[$index];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is AJAX request?
|
||||
*
|
||||
* Test to see if a request contains the HTTP_X_REQUESTED_WITH header.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_ajax_request()
|
||||
{
|
||||
return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is CLI request?
|
||||
*
|
||||
* Test to see if a request was made from the command line.
|
||||
*
|
||||
* @deprecated 3.0.0 Use is_cli() instead
|
||||
* @return bool
|
||||
*/
|
||||
public function is_cli_request()
|
||||
{
|
||||
return is_cli();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Request Method
|
||||
*
|
||||
* Return the request method
|
||||
*
|
||||
* @param bool $upper Whether to return in upper or lower case
|
||||
* (default: FALSE)
|
||||
* @return string
|
||||
*/
|
||||
public function method($upper = FALSE)
|
||||
{
|
||||
return ($upper)
|
||||
? strtoupper($this->server('REQUEST_METHOD'))
|
||||
: strtolower($this->server('REQUEST_METHOD'));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Magic __get()
|
||||
*
|
||||
* Allows read access to protected properties
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if ($name === 'raw_input_stream')
|
||||
{
|
||||
isset($this->_raw_input_stream) OR $this->_raw_input_stream = file_get_contents('php://input');
|
||||
return $this->_raw_input_stream;
|
||||
}
|
||||
elseif ($name === 'ip_address')
|
||||
{
|
||||
return $this->ip_address;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
203
system/core/Lang.php
Normal file
203
system/core/Lang.php
Normal file
@ -0,0 +1,203 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Language Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Language
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/libraries/language.html
|
||||
*/
|
||||
class CI_Lang {
|
||||
|
||||
/**
|
||||
* List of translations
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $language = array();
|
||||
|
||||
/**
|
||||
* List of loaded language files
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $is_loaded = array();
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
log_message('info', 'Language Class Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Load a language file
|
||||
*
|
||||
* @param mixed $langfile Language file name
|
||||
* @param string $idiom Language name (english, etc.)
|
||||
* @param bool $return Whether to return the loaded array of translations
|
||||
* @param bool $add_suffix Whether to add suffix to $langfile
|
||||
* @param string $alt_path Alternative path to look for the language file
|
||||
*
|
||||
* @return void|string[] Array containing translations, if $return is set to TRUE
|
||||
*/
|
||||
public function load($langfile, $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
|
||||
{
|
||||
if (is_array($langfile))
|
||||
{
|
||||
foreach ($langfile as $value)
|
||||
{
|
||||
$this->load($value, $idiom, $return, $add_suffix, $alt_path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$langfile = str_replace('.php', '', $langfile);
|
||||
|
||||
if ($add_suffix === TRUE)
|
||||
{
|
||||
$langfile = preg_replace('/_lang$/', '', $langfile).'_lang';
|
||||
}
|
||||
|
||||
$langfile .= '.php';
|
||||
|
||||
if (empty($idiom) OR ! preg_match('/^[a-z_-]+$/i', $idiom))
|
||||
{
|
||||
$config =& get_config();
|
||||
$idiom = empty($config['language']) ? 'english' : $config['language'];
|
||||
}
|
||||
|
||||
if ($return === FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the base file, so any others found can override it
|
||||
$basepath = BASEPATH.'language/'.$idiom.'/'.$langfile;
|
||||
if (($found = file_exists($basepath)) === TRUE)
|
||||
{
|
||||
include($basepath);
|
||||
}
|
||||
|
||||
// Do we have an alternative path to look in?
|
||||
if ($alt_path !== '')
|
||||
{
|
||||
$alt_path .= 'language/'.$idiom.'/'.$langfile;
|
||||
if (file_exists($alt_path))
|
||||
{
|
||||
include($alt_path);
|
||||
$found = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (get_instance()->load->get_package_paths(TRUE) as $package_path)
|
||||
{
|
||||
$package_path .= 'language/'.$idiom.'/'.$langfile;
|
||||
if ($basepath !== $package_path && file_exists($package_path))
|
||||
{
|
||||
include($package_path);
|
||||
$found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($found !== TRUE)
|
||||
{
|
||||
show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile);
|
||||
}
|
||||
|
||||
if ( ! isset($lang) OR ! is_array($lang))
|
||||
{
|
||||
log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
|
||||
|
||||
if ($return === TRUE)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($return === TRUE)
|
||||
{
|
||||
return $lang;
|
||||
}
|
||||
|
||||
$this->is_loaded[$langfile] = $idiom;
|
||||
$this->language = array_merge($this->language, $lang);
|
||||
|
||||
log_message('info', 'Language file loaded: language/'.$idiom.'/'.$langfile);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Language line
|
||||
*
|
||||
* Fetches a single line of text from the language array
|
||||
*
|
||||
* @param string $line Language line key
|
||||
* @param bool $log_errors Whether to log an error message if the line is not found
|
||||
* @return string Translation
|
||||
*/
|
||||
public function line($line, $log_errors = TRUE)
|
||||
{
|
||||
$value = isset($this->language[$line]) ? $this->language[$line] : FALSE;
|
||||
|
||||
// Because killer robots like unicorns!
|
||||
if ($value === FALSE && $log_errors === TRUE)
|
||||
{
|
||||
log_message('error', 'Could not find the language line "'.$line.'"');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
1415
system/core/Loader.php
Normal file
1415
system/core/Loader.php
Normal file
File diff suppressed because it is too large
Load Diff
296
system/core/Log.php
Normal file
296
system/core/Log.php
Normal file
@ -0,0 +1,296 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Logging Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Logging
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/general/errors.html
|
||||
*/
|
||||
class CI_Log {
|
||||
|
||||
/**
|
||||
* Path to save log files
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_log_path;
|
||||
|
||||
/**
|
||||
* File permissions
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_file_permissions = 0644;
|
||||
|
||||
/**
|
||||
* Level of logging
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_threshold = 1;
|
||||
|
||||
/**
|
||||
* Array of threshold levels to log
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_threshold_array = array();
|
||||
|
||||
/**
|
||||
* Format of timestamp for log files
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_date_fmt = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* Filename extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_file_ext;
|
||||
|
||||
/**
|
||||
* Whether or not the logger can write to the log files
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_enabled = TRUE;
|
||||
|
||||
/**
|
||||
* Predefined logging levels
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4);
|
||||
|
||||
/**
|
||||
* mbstring.func_overload flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $func_overload;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$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->_file_ext = (isset($config['log_file_extension']) && $config['log_file_extension'] !== '')
|
||||
? ltrim($config['log_file_extension'], '.') : 'php';
|
||||
|
||||
file_exists($this->_log_path) OR mkdir($this->_log_path, 0755, TRUE);
|
||||
|
||||
if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path))
|
||||
{
|
||||
$this->_enabled = FALSE;
|
||||
}
|
||||
|
||||
if (is_numeric($config['log_threshold']))
|
||||
{
|
||||
$this->_threshold = (int) $config['log_threshold'];
|
||||
}
|
||||
elseif (is_array($config['log_threshold']))
|
||||
{
|
||||
$this->_threshold = 0;
|
||||
$this->_threshold_array = array_flip($config['log_threshold']);
|
||||
}
|
||||
|
||||
if ( ! empty($config['log_date_format']))
|
||||
{
|
||||
$this->_date_fmt = $config['log_date_format'];
|
||||
}
|
||||
|
||||
if ( ! empty($config['log_file_permissions']) && is_int($config['log_file_permissions']))
|
||||
{
|
||||
$this->_file_permissions = $config['log_file_permissions'];
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Write Log File
|
||||
*
|
||||
* Generally this function will be called using the global log_message() function
|
||||
*
|
||||
* @param string $level The error level: 'error', 'debug' or 'info'
|
||||
* @param string $msg The error message
|
||||
* @return bool
|
||||
*/
|
||||
public function write_log($level, $msg)
|
||||
{
|
||||
if ($this->_enabled === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$level = strtoupper($level);
|
||||
|
||||
if (( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
|
||||
&& ! isset($this->_threshold_array[$this->_levels[$level]]))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$filepath = $this->_log_path.'log-'.date('Y-m-d').'.'.$this->_file_ext;
|
||||
$message = '';
|
||||
|
||||
if ( ! file_exists($filepath))
|
||||
{
|
||||
$newfile = TRUE;
|
||||
// Only add protection to php files
|
||||
if ($this->_file_ext === 'php')
|
||||
{
|
||||
$message .= "<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $fp = @fopen($filepath, 'ab'))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
flock($fp, LOCK_EX);
|
||||
|
||||
// Instantiating DateTime with microseconds appended to initial date is needed for proper support of this format
|
||||
if (strpos($this->_date_fmt, 'u') !== FALSE)
|
||||
{
|
||||
$microtime_full = microtime(TRUE);
|
||||
$microtime_short = sprintf("%06d", ($microtime_full - floor($microtime_full)) * 1000000);
|
||||
$date = new DateTime(date('Y-m-d H:i:s.'.$microtime_short, $microtime_full));
|
||||
$date = $date->format($this->_date_fmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
$date = date($this->_date_fmt);
|
||||
}
|
||||
|
||||
$message .= $this->_format_line($level, $date, $msg);
|
||||
|
||||
for ($written = 0, $length = self::strlen($message); $written < $length; $written += $result)
|
||||
{
|
||||
if (($result = fwrite($fp, self::substr($message, $written))) === FALSE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
|
||||
if (isset($newfile) && $newfile === TRUE)
|
||||
{
|
||||
chmod($filepath, $this->_file_permissions);
|
||||
}
|
||||
|
||||
return is_int($result);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Format the log line.
|
||||
*
|
||||
* This is for extensibility of log formatting
|
||||
* If you want to change the log format, extend the CI_Log class and override this method
|
||||
*
|
||||
* @param string $level The error level
|
||||
* @param string $date Formatted date string
|
||||
* @param string $message The log message
|
||||
* @return string Formatted log line with a new line character '\n' at the end
|
||||
*/
|
||||
protected function _format_line($level, $date, $message)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
76
system/core/Model.php
Normal file
76
system/core/Model.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Model Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/libraries/config.html
|
||||
*/
|
||||
class CI_Model {
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @link https://github.com/bcit-ci/CodeIgniter/issues/5332
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {}
|
||||
|
||||
/**
|
||||
* __get magic
|
||||
*
|
||||
* Allows models to access CI's loaded classes using the same
|
||||
* syntax as controllers.
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
// Debugging note:
|
||||
// If you're here because you're getting an error message
|
||||
// saying 'Undefined Property: system/core/Model.php', it's
|
||||
// most likely a typo in your model code.
|
||||
return get_instance()->$key;
|
||||
}
|
||||
|
||||
}
|
||||
842
system/core/Output.php
Normal file
842
system/core/Output.php
Normal file
@ -0,0 +1,842 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Output Class
|
||||
*
|
||||
* Responsible for sending final output to the browser.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Output
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/libraries/output.html
|
||||
*/
|
||||
class CI_Output {
|
||||
|
||||
/**
|
||||
* Final output string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $final_output;
|
||||
|
||||
/**
|
||||
* Cache expiration time
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $cache_expiration = 0;
|
||||
|
||||
/**
|
||||
* List of server headers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $headers = array();
|
||||
|
||||
/**
|
||||
* List of mime types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $mimes = array();
|
||||
|
||||
/**
|
||||
* Mime-type for the current page
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mime_type = 'text/html';
|
||||
|
||||
/**
|
||||
* Enable Profiler flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $enable_profiler = FALSE;
|
||||
|
||||
/**
|
||||
* php.ini zlib.output_compression flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_zlib_oc = FALSE;
|
||||
|
||||
/**
|
||||
* CI output compression flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_compress_output = FALSE;
|
||||
|
||||
/**
|
||||
* List of profiler sections
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_profiler_sections = array();
|
||||
|
||||
/**
|
||||
* Parse markers flag
|
||||
*
|
||||
* Whether or not to parse variables like {elapsed_time} and {memory_usage}.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $parse_exec_vars = TRUE;
|
||||
|
||||
/**
|
||||
* mbstring.func_overload flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $func_overload;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Determines whether zLib output compression will be used.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_zlib_oc = (bool) ini_get('zlib.output_compression');
|
||||
$this->_compress_output = (
|
||||
$this->_zlib_oc === FALSE
|
||||
&& config_item('compress_output') === TRUE
|
||||
&& extension_loaded('zlib')
|
||||
);
|
||||
|
||||
isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));
|
||||
|
||||
// Get mime types for later
|
||||
$this->mimes =& get_mimes();
|
||||
|
||||
log_message('info', 'Output Class Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Output
|
||||
*
|
||||
* Returns the current output string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_output()
|
||||
{
|
||||
return $this->final_output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Output
|
||||
*
|
||||
* Sets the output string.
|
||||
*
|
||||
* @param string $output Output data
|
||||
* @return CI_Output
|
||||
*/
|
||||
public function set_output($output)
|
||||
{
|
||||
$this->final_output = $output;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Append Output
|
||||
*
|
||||
* Appends data onto the output string.
|
||||
*
|
||||
* @param string $output Data to append
|
||||
* @return CI_Output
|
||||
*/
|
||||
public function append_output($output)
|
||||
{
|
||||
$this->final_output .= $output;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Header
|
||||
*
|
||||
* Lets you set a server header which will be sent with the final output.
|
||||
*
|
||||
* Note: If a file is cached, headers will not be sent.
|
||||
* @todo We need to figure out how to permit headers to be cached.
|
||||
*
|
||||
* @param string $header Header
|
||||
* @param bool $replace Whether to replace the old header value, if already set
|
||||
* @return CI_Output
|
||||
*/
|
||||
public function set_header($header, $replace = TRUE)
|
||||
{
|
||||
// If zlib.output_compression is enabled it will compress the output,
|
||||
// but it will not modify the content-length header to compensate for
|
||||
// the reduction, causing the browser to hang waiting for more data.
|
||||
// We'll just skip content-length in those cases.
|
||||
if ($this->_zlib_oc && strncasecmp($header, 'content-length', 14) === 0)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->headers[] = array($header, $replace);
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Content-Type Header
|
||||
*
|
||||
* @param string $mime_type Extension of the file we're outputting
|
||||
* @param string $charset Character set (default: NULL)
|
||||
* @return CI_Output
|
||||
*/
|
||||
public function set_content_type($mime_type, $charset = NULL)
|
||||
{
|
||||
if (strpos($mime_type, '/') === FALSE)
|
||||
{
|
||||
$extension = ltrim($mime_type, '.');
|
||||
|
||||
// Is this extension supported?
|
||||
if (isset($this->mimes[$extension]))
|
||||
{
|
||||
$mime_type =& $this->mimes[$extension];
|
||||
|
||||
if (is_array($mime_type))
|
||||
{
|
||||
$mime_type = current($mime_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->mime_type = $mime_type;
|
||||
|
||||
if (empty($charset))
|
||||
{
|
||||
$charset = config_item('charset');
|
||||
}
|
||||
|
||||
$header = 'Content-Type: '.$mime_type
|
||||
.(empty($charset) ? '' : '; charset='.$charset);
|
||||
|
||||
$this->headers[] = array($header, TRUE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Current Content-Type Header
|
||||
*
|
||||
* @return string 'text/html', if not already set
|
||||
*/
|
||||
public function get_content_type()
|
||||
{
|
||||
for ($i = 0, $c = count($this->headers); $i < $c; $i++)
|
||||
{
|
||||
if (sscanf($this->headers[$i][0], 'Content-Type: %[^;]', $content_type) === 1)
|
||||
{
|
||||
return $content_type;
|
||||
}
|
||||
}
|
||||
|
||||
return 'text/html';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Header
|
||||
*
|
||||
* @param string $header
|
||||
* @return string
|
||||
*/
|
||||
public function get_header($header)
|
||||
{
|
||||
// Combine headers already sent with our batched headers
|
||||
$headers = array_merge(
|
||||
// We only need [x][0] from our multi-dimensional array
|
||||
array_map('array_shift', $this->headers),
|
||||
headers_list()
|
||||
);
|
||||
|
||||
if (empty($headers) OR empty($header))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Count backwards, in order to get the last matching header
|
||||
for ($c = count($headers) - 1; $c > -1; $c--)
|
||||
{
|
||||
if (strncasecmp($header, $headers[$c], $l = self::strlen($header)) === 0)
|
||||
{
|
||||
return trim(self::substr($headers[$c], $l+1));
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set HTTP Status Header
|
||||
*
|
||||
* As of version 1.7.2, this is an alias for common function
|
||||
* set_status_header().
|
||||
*
|
||||
* @param int $code Status code (default: 200)
|
||||
* @param string $text Optional message
|
||||
* @return CI_Output
|
||||
*/
|
||||
public function set_status_header($code = 200, $text = '')
|
||||
{
|
||||
set_status_header($code, $text);
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Enable/disable Profiler
|
||||
*
|
||||
* @param bool $val TRUE to enable or FALSE to disable
|
||||
* @return CI_Output
|
||||
*/
|
||||
public function enable_profiler($val = TRUE)
|
||||
{
|
||||
$this->enable_profiler = is_bool($val) ? $val : TRUE;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Profiler Sections
|
||||
*
|
||||
* Allows override of default/config settings for
|
||||
* Profiler section display.
|
||||
*
|
||||
* @param array $sections Profiler sections
|
||||
* @return CI_Output
|
||||
*/
|
||||
public function set_profiler_sections($sections)
|
||||
{
|
||||
if (isset($sections['query_toggle_count']))
|
||||
{
|
||||
$this->_profiler_sections['query_toggle_count'] = (int) $sections['query_toggle_count'];
|
||||
unset($sections['query_toggle_count']);
|
||||
}
|
||||
|
||||
foreach ($sections as $section => $enable)
|
||||
{
|
||||
$this->_profiler_sections[$section] = ($enable !== FALSE);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Cache
|
||||
*
|
||||
* @param int $time Cache expiration time in minutes
|
||||
* @return CI_Output
|
||||
*/
|
||||
public function cache($time)
|
||||
{
|
||||
$this->cache_expiration = is_numeric($time) ? $time : 0;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Display Output
|
||||
*
|
||||
* Processes and sends finalized output data to the browser along
|
||||
* with any server headers and profile data. It also stops benchmark
|
||||
* timers so the page rendering speed and memory usage can be shown.
|
||||
*
|
||||
* Note: All "view" data is automatically put into $this->final_output
|
||||
* by controller class.
|
||||
*
|
||||
* @uses CI_Output::$final_output
|
||||
* @param string $output Output data override
|
||||
* @return void
|
||||
*/
|
||||
public function _display($output = '')
|
||||
{
|
||||
// Note: We use load_class() because we can't use $CI =& get_instance()
|
||||
// since this function is sometimes called by the caching mechanism,
|
||||
// which happens before the CI super object is available.
|
||||
$BM =& load_class('Benchmark', 'core');
|
||||
$CFG =& load_class('Config', 'core');
|
||||
|
||||
// Grab the super object if we can.
|
||||
if (class_exists('CI_Controller', FALSE))
|
||||
{
|
||||
$CI =& get_instance();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Set the output data
|
||||
if ($output === '')
|
||||
{
|
||||
$output =& $this->final_output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Do we need to write a cache file? Only if the controller does not have its
|
||||
// own _output() method and we are not dealing with a cache file, which we
|
||||
// can determine by the existence of the $CI object above
|
||||
if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output'))
|
||||
{
|
||||
$this->_write_cache($output);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Parse out the elapsed time and memory usage,
|
||||
// then swap the pseudo-variables with the data
|
||||
|
||||
$elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end');
|
||||
|
||||
if ($this->parse_exec_vars === TRUE)
|
||||
{
|
||||
$memory = round(memory_get_usage() / 1024 / 1024, 2).'MB';
|
||||
$output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Is compression requested?
|
||||
if (isset($CI) // This means that we're not serving a cache file, if we were, it would already be compressed
|
||||
&& $this->_compress_output === TRUE
|
||||
&& isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
|
||||
{
|
||||
ob_start('ob_gzhandler');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Are there any server headers to send?
|
||||
if (count($this->headers) > 0)
|
||||
{
|
||||
foreach ($this->headers as $header)
|
||||
{
|
||||
@header($header[0], $header[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Does the $CI object exist?
|
||||
// If not we know we are dealing with a cache file so we'll
|
||||
// simply echo out the data and exit.
|
||||
if ( ! isset($CI))
|
||||
{
|
||||
if ($this->_compress_output === TRUE)
|
||||
{
|
||||
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
|
||||
{
|
||||
header('Content-Encoding: gzip');
|
||||
header('Content-Length: '.self::strlen($output));
|
||||
}
|
||||
else
|
||||
{
|
||||
// User agent doesn't support gzip compression,
|
||||
// so we'll have to decompress our cache
|
||||
$output = gzinflate(self::substr($output, 10, -8));
|
||||
}
|
||||
}
|
||||
|
||||
echo $output;
|
||||
log_message('info', 'Final output sent to browser');
|
||||
log_message('debug', 'Total execution time: '.$elapsed);
|
||||
return;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Do we need to generate profile data?
|
||||
// If so, load the Profile class and run it.
|
||||
if ($this->enable_profiler === TRUE)
|
||||
{
|
||||
$CI->load->library('profiler');
|
||||
if ( ! empty($this->_profiler_sections))
|
||||
{
|
||||
$CI->profiler->set_sections($this->_profiler_sections);
|
||||
}
|
||||
|
||||
// If the output data contains closing </body> and </html> tags
|
||||
// we will remove them and add them back after we insert the profile data
|
||||
$output = preg_replace('|</body>.*?</html>|is', '', $output, -1, $count).$CI->profiler->run();
|
||||
if ($count > 0)
|
||||
{
|
||||
$output .= '</body></html>';
|
||||
}
|
||||
}
|
||||
|
||||
// Does the controller contain a function named _output()?
|
||||
// If so send the output there. Otherwise, echo it.
|
||||
if (method_exists($CI, '_output'))
|
||||
{
|
||||
$CI->_output($output);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $output; // Send it to the browser!
|
||||
}
|
||||
|
||||
log_message('info', 'Final output sent to browser');
|
||||
log_message('debug', 'Total execution time: '.$elapsed);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Write Cache
|
||||
*
|
||||
* @param string $output Output data to cache
|
||||
* @return void
|
||||
*/
|
||||
public function _write_cache($output)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$path = $CI->config->item('cache_path');
|
||||
$cache_path = ($path === '') ? APPPATH.'cache/' : $path;
|
||||
|
||||
if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
|
||||
{
|
||||
log_message('error', 'Unable to write cache file: '.$cache_path);
|
||||
return;
|
||||
}
|
||||
|
||||
$uri = $CI->config->item('base_url')
|
||||
.$CI->config->item('index_page')
|
||||
.$CI->uri->uri_string();
|
||||
|
||||
if (($cache_query_string = $CI->config->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING']))
|
||||
{
|
||||
if (is_array($cache_query_string))
|
||||
{
|
||||
$uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$uri .= '?'.$_SERVER['QUERY_STRING'];
|
||||
}
|
||||
}
|
||||
|
||||
$cache_path .= md5($uri);
|
||||
|
||||
if ( ! $fp = @fopen($cache_path, 'w+b'))
|
||||
{
|
||||
log_message('error', 'Unable to write cache file: '.$cache_path);
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
// itself, so that we don't have to do that each time
|
||||
// we're serving it
|
||||
if ($this->_compress_output === TRUE)
|
||||
{
|
||||
$output = gzencode($output);
|
||||
|
||||
if ($this->get_header('content-type') === NULL)
|
||||
{
|
||||
$this->set_content_type($this->mime_type);
|
||||
}
|
||||
}
|
||||
|
||||
$expire = time() + ($this->cache_expiration * 60);
|
||||
|
||||
// Put together our serialized info.
|
||||
$cache_info = serialize(array(
|
||||
'expire' => $expire,
|
||||
'headers' => $this->headers
|
||||
));
|
||||
|
||||
$output = $cache_info.'ENDCI--->'.$output;
|
||||
|
||||
for ($written = 0, $length = self::strlen($output); $written < $length; $written += $result)
|
||||
{
|
||||
if (($result = fwrite($fp, self::substr($output, $written))) === FALSE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
|
||||
if ( ! is_int($result))
|
||||
{
|
||||
@unlink($cache_path);
|
||||
log_message('error', 'Unable to write the complete cache content at: '.$cache_path);
|
||||
return;
|
||||
}
|
||||
|
||||
chmod($cache_path, 0640);
|
||||
log_message('debug', 'Cache file written: '.$cache_path);
|
||||
|
||||
// Send HTTP cache-control headers to browser to match file cache settings.
|
||||
$this->set_cache_header($_SERVER['REQUEST_TIME'], $expire);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update/serve cached output
|
||||
*
|
||||
* @uses CI_Config
|
||||
* @uses CI_URI
|
||||
*
|
||||
* @param object &$CFG CI_Config class instance
|
||||
* @param object &$URI CI_URI class instance
|
||||
* @return bool TRUE on success or FALSE on failure
|
||||
*/
|
||||
public function _display_cache(&$CFG, &$URI)
|
||||
{
|
||||
$cache_path = ($CFG->item('cache_path') === '') ? APPPATH.'cache/' : $CFG->item('cache_path');
|
||||
|
||||
// Build the file path. The file name is an MD5 hash of the full URI
|
||||
$uri = $CFG->item('base_url').$CFG->item('index_page').$URI->uri_string;
|
||||
|
||||
if (($cache_query_string = $CFG->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING']))
|
||||
{
|
||||
if (is_array($cache_query_string))
|
||||
{
|
||||
$uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$uri .= '?'.$_SERVER['QUERY_STRING'];
|
||||
}
|
||||
}
|
||||
|
||||
$filepath = $cache_path.md5($uri);
|
||||
|
||||
if ( ! file_exists($filepath) OR ! $fp = @fopen($filepath, 'rb'))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
flock($fp, LOCK_SH);
|
||||
|
||||
$cache = (filesize($filepath) > 0) ? fread($fp, filesize($filepath)) : '';
|
||||
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
|
||||
// Look for embedded serialized file info.
|
||||
if ( ! preg_match('/^(.*)ENDCI--->/', $cache, $match))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$cache_info = unserialize($match[1]);
|
||||
$expire = $cache_info['expire'];
|
||||
|
||||
$last_modified = filemtime($filepath);
|
||||
|
||||
// Has the file expired?
|
||||
if ($_SERVER['REQUEST_TIME'] >= $expire && is_really_writable($cache_path))
|
||||
{
|
||||
// If so we'll delete it.
|
||||
@unlink($filepath);
|
||||
log_message('debug', 'Cache file has expired. File deleted.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Send the HTTP cache control headers
|
||||
$this->set_cache_header($last_modified, $expire);
|
||||
|
||||
// Add headers from cache file.
|
||||
foreach ($cache_info['headers'] as $header)
|
||||
{
|
||||
$this->set_header($header[0], $header[1]);
|
||||
}
|
||||
|
||||
// Display the cache
|
||||
$this->_display(self::substr($cache, self::strlen($match[0])));
|
||||
log_message('debug', 'Cache file is current. Sending it to browser.');
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete cache
|
||||
*
|
||||
* @param string $uri URI string
|
||||
* @return bool
|
||||
*/
|
||||
public function delete_cache($uri = '')
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$cache_path = $CI->config->item('cache_path');
|
||||
if ($cache_path === '')
|
||||
{
|
||||
$cache_path = APPPATH.'cache/';
|
||||
}
|
||||
|
||||
if ( ! is_dir($cache_path))
|
||||
{
|
||||
log_message('error', 'Unable to find cache path: '.$cache_path);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (empty($uri))
|
||||
{
|
||||
$uri = $CI->uri->uri_string();
|
||||
|
||||
if (($cache_query_string = $CI->config->item('cache_query_string')) && ! empty($_SERVER['QUERY_STRING']))
|
||||
{
|
||||
if (is_array($cache_query_string))
|
||||
{
|
||||
$uri .= '?'.http_build_query(array_intersect_key($_GET, array_flip($cache_query_string)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$uri .= '?'.$_SERVER['QUERY_STRING'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cache_path .= md5($CI->config->item('base_url').$CI->config->item('index_page').ltrim($uri, '/'));
|
||||
|
||||
if ( ! @unlink($cache_path))
|
||||
{
|
||||
log_message('error', 'Unable to delete cache file for '.$uri);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Cache Header
|
||||
*
|
||||
* Set the HTTP headers to match the server-side file cache settings
|
||||
* in order to reduce bandwidth.
|
||||
*
|
||||
* @param int $last_modified Timestamp of when the page was last modified
|
||||
* @param int $expiration Timestamp of when should the requested page expire from cache
|
||||
* @return void
|
||||
*/
|
||||
public function set_cache_header($last_modified, $expiration)
|
||||
{
|
||||
$max_age = $expiration - $_SERVER['REQUEST_TIME'];
|
||||
|
||||
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']))
|
||||
{
|
||||
$this->set_status_header(304);
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Pragma: public');
|
||||
header('Cache-Control: max-age='.$max_age.', public');
|
||||
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');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
515
system/core/Router.php
Normal file
515
system/core/Router.php
Normal file
@ -0,0 +1,515 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Router Class
|
||||
*
|
||||
* Parses URIs and determines routing
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/general/routing.html
|
||||
*/
|
||||
class CI_Router {
|
||||
|
||||
/**
|
||||
* CI_Config class object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $config;
|
||||
|
||||
/**
|
||||
* List of routes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $routes = array();
|
||||
|
||||
/**
|
||||
* Current class name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $class = '';
|
||||
|
||||
/**
|
||||
* Current method name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $method = 'index';
|
||||
|
||||
/**
|
||||
* Sub-directory that contains the requested controller class
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $directory;
|
||||
|
||||
/**
|
||||
* Default controller (and method if specific)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $default_controller;
|
||||
|
||||
/**
|
||||
* Translate URI dashes
|
||||
*
|
||||
* Determines whether dashes in controller & method segments
|
||||
* should be automatically replaced by underscores.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $translate_uri_dashes = FALSE;
|
||||
|
||||
/**
|
||||
* Enable query strings flag
|
||||
*
|
||||
* Determines whether to use GET parameters or segment URIs
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $enable_query_strings = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Runs the route mapping function.
|
||||
*
|
||||
* @param array $routing
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($routing = NULL)
|
||||
{
|
||||
$this->config =& load_class('Config', 'core');
|
||||
$this->uri =& load_class('URI', 'core');
|
||||
|
||||
$this->enable_query_strings = ( ! is_cli() && $this->config->item('enable_query_strings') === TRUE);
|
||||
|
||||
// If a directory override is configured, it has to be set before any dynamic routing logic
|
||||
is_array($routing) && isset($routing['directory']) && $this->set_directory($routing['directory']);
|
||||
$this->_set_routing();
|
||||
|
||||
// Set any routing overrides that may exist in the main index file
|
||||
if (is_array($routing))
|
||||
{
|
||||
empty($routing['controller']) OR $this->set_class($routing['controller']);
|
||||
empty($routing['function']) OR $this->set_method($routing['function']);
|
||||
}
|
||||
|
||||
log_message('info', 'Router Class Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set route mapping
|
||||
*
|
||||
* Determines what should be served based on the URI request,
|
||||
* as well as any "routes" that have been set in the routing config file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _set_routing()
|
||||
{
|
||||
// Load the routes.php file. It would be great if we could
|
||||
// skip this for enable_query_strings = TRUE, but then
|
||||
// default_controller would be empty ...
|
||||
if (file_exists(APPPATH.'config/routes.php'))
|
||||
{
|
||||
include(APPPATH.'config/routes.php');
|
||||
}
|
||||
|
||||
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
|
||||
{
|
||||
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
|
||||
}
|
||||
|
||||
// Validate & get reserved routes
|
||||
if (isset($route) && is_array($route))
|
||||
{
|
||||
isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
|
||||
isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
|
||||
unset($route['default_controller'], $route['translate_uri_dashes']);
|
||||
$this->routes = $route;
|
||||
}
|
||||
|
||||
// Are query strings enabled in the config file? Normally CI doesn't utilize query strings
|
||||
// since URI segments are more search-engine friendly, but they can optionally be used.
|
||||
// If this feature is enabled, we will gather the directory/class/method a little differently
|
||||
if ($this->enable_query_strings)
|
||||
{
|
||||
// If the directory is set at this time, it means an override exists, so skip the checks
|
||||
if ( ! isset($this->directory))
|
||||
{
|
||||
$_d = $this->config->item('directory_trigger');
|
||||
$_d = isset($_GET[$_d]) ? trim($_GET[$_d], " \t\n\r\0\x0B/") : '';
|
||||
|
||||
if ($_d !== '')
|
||||
{
|
||||
$this->uri->filter_uri($_d);
|
||||
$this->set_directory($_d);
|
||||
}
|
||||
}
|
||||
|
||||
$_c = trim($this->config->item('controller_trigger'));
|
||||
if ( ! empty($_GET[$_c]))
|
||||
{
|
||||
$this->uri->filter_uri($_GET[$_c]);
|
||||
$this->set_class($_GET[$_c]);
|
||||
|
||||
$_f = trim($this->config->item('function_trigger'));
|
||||
if ( ! empty($_GET[$_f]))
|
||||
{
|
||||
$this->uri->filter_uri($_GET[$_f]);
|
||||
$this->set_method($_GET[$_f]);
|
||||
}
|
||||
|
||||
$this->uri->rsegments = array(
|
||||
1 => $this->class,
|
||||
2 => $this->method
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_set_default_controller();
|
||||
}
|
||||
|
||||
// Routing rules don't apply to query strings and we don't need to detect
|
||||
// directories, so we're done here
|
||||
return;
|
||||
}
|
||||
|
||||
// Is there anything to parse?
|
||||
if ($this->uri->uri_string !== '')
|
||||
{
|
||||
$this->_parse_routes();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_set_default_controller();
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set request route
|
||||
*
|
||||
* Takes an array of URI segments as input and sets the class/method
|
||||
* to be called.
|
||||
*
|
||||
* @used-by CI_Router::_parse_routes()
|
||||
* @param array $segments URI segments
|
||||
* @return void
|
||||
*/
|
||||
protected function _set_request($segments = array())
|
||||
{
|
||||
$segments = $this->_validate_request($segments);
|
||||
// If we don't have any segments left - try the default controller;
|
||||
// WARNING: Directories get shifted out of the segments array!
|
||||
if (empty($segments))
|
||||
{
|
||||
$this->_set_default_controller();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->translate_uri_dashes === TRUE)
|
||||
{
|
||||
$segments[0] = str_replace('-', '_', $segments[0]);
|
||||
if (isset($segments[1]))
|
||||
{
|
||||
$segments[1] = str_replace('-', '_', $segments[1]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_class($segments[0]);
|
||||
if (isset($segments[1]))
|
||||
{
|
||||
$this->set_method($segments[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$segments[1] = 'index';
|
||||
}
|
||||
|
||||
array_unshift($segments, NULL);
|
||||
unset($segments[0]);
|
||||
$this->uri->rsegments = $segments;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set default controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _set_default_controller()
|
||||
{
|
||||
if (empty($this->default_controller))
|
||||
{
|
||||
show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
|
||||
}
|
||||
|
||||
// Is the method being specified?
|
||||
if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2)
|
||||
{
|
||||
$method = 'index';
|
||||
}
|
||||
|
||||
if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php'))
|
||||
{
|
||||
// This will trigger 404 later
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_class($class);
|
||||
$this->set_method($method);
|
||||
|
||||
// Assign routed segments, index starting from 1
|
||||
$this->uri->rsegments = array(
|
||||
1 => $class,
|
||||
2 => $method
|
||||
);
|
||||
|
||||
log_message('debug', 'No URI present. Default controller set.');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Validate request
|
||||
*
|
||||
* Attempts validate the URI request and determine the controller path.
|
||||
*
|
||||
* @used-by CI_Router::_set_request()
|
||||
* @param array $segments URI segments
|
||||
* @return mixed URI segments
|
||||
*/
|
||||
protected function _validate_request($segments)
|
||||
{
|
||||
$c = count($segments);
|
||||
$directory_override = isset($this->directory);
|
||||
|
||||
// Loop through our segments and return as soon as a controller
|
||||
// is found or when such a directory doesn't exist
|
||||
while ($c-- > 0)
|
||||
{
|
||||
$test = $this->directory
|
||||
.ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]);
|
||||
|
||||
if ( ! file_exists(APPPATH.'controllers/'.$test.'.php')
|
||||
&& $directory_override === FALSE
|
||||
&& is_dir(APPPATH.'controllers/'.$this->directory.$segments[0])
|
||||
)
|
||||
{
|
||||
$this->set_directory(array_shift($segments), TRUE);
|
||||
continue;
|
||||
}
|
||||
|
||||
return $segments;
|
||||
}
|
||||
|
||||
// This means that all segments were actually directories
|
||||
return $segments;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse Routes
|
||||
*
|
||||
* Matches any routes that may exist in the config/routes.php file
|
||||
* against the URI to determine if the class/method need to be remapped.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _parse_routes()
|
||||
{
|
||||
// Turn the segment array into a URI string
|
||||
$uri = implode('/', $this->uri->segments);
|
||||
|
||||
// Get HTTP verb
|
||||
$http_verb = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'cli';
|
||||
|
||||
// Loop through the route array looking for wildcards
|
||||
foreach ($this->routes as $key => $val)
|
||||
{
|
||||
// Check if route format is using HTTP verbs
|
||||
if (is_array($val))
|
||||
{
|
||||
$val = array_change_key_case($val, CASE_LOWER);
|
||||
if (isset($val[$http_verb]))
|
||||
{
|
||||
$val = $val[$http_verb];
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert wildcards to RegEx
|
||||
$key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key);
|
||||
|
||||
// Does the RegEx match?
|
||||
if (preg_match('#^'.$key.'$#', $uri, $matches))
|
||||
{
|
||||
// Are we using callbacks to process back-references?
|
||||
if ( ! is_string($val) && is_callable($val))
|
||||
{
|
||||
// Remove the original string from the matches array.
|
||||
array_shift($matches);
|
||||
|
||||
// Execute the callback using the values in matches as its parameters.
|
||||
$val = call_user_func_array($val, $matches);
|
||||
}
|
||||
// Are we using the default routing method for back-references?
|
||||
elseif (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE)
|
||||
{
|
||||
$val = preg_replace('#^'.$key.'$#', $val, $uri);
|
||||
}
|
||||
|
||||
$this->_set_request(explode('/', $val));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If we got this far it means we didn't encounter a
|
||||
// matching route so we'll set the site default route
|
||||
$this->_set_request(array_values($this->uri->segments));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set class name
|
||||
*
|
||||
* @param string $class Class name
|
||||
* @return void
|
||||
*/
|
||||
public function set_class($class)
|
||||
{
|
||||
$this->class = str_replace(array('/', '.'), '', $class);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch the current class
|
||||
*
|
||||
* @deprecated 3.0.0 Read the 'class' property instead
|
||||
* @return string
|
||||
*/
|
||||
public function fetch_class()
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set method name
|
||||
*
|
||||
* @param string $method Method name
|
||||
* @return void
|
||||
*/
|
||||
public function set_method($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch the current method
|
||||
*
|
||||
* @deprecated 3.0.0 Read the 'method' property instead
|
||||
* @return string
|
||||
*/
|
||||
public function fetch_method()
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set directory name
|
||||
*
|
||||
* @param string $dir Directory name
|
||||
* @param bool $append Whether we're appending rather than setting the full value
|
||||
* @return void
|
||||
*/
|
||||
public function set_directory($dir, $append = FALSE)
|
||||
{
|
||||
if ($append !== TRUE OR empty($this->directory))
|
||||
{
|
||||
$this->directory = str_replace('.', '', trim($dir, '/')).'/';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->directory .= str_replace('.', '', trim($dir, '/')).'/';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch directory
|
||||
*
|
||||
* Feches the sub-directory (if any) that contains the requested
|
||||
* controller class.
|
||||
*
|
||||
* @deprecated 3.0.0 Read the 'directory' property instead
|
||||
* @return string
|
||||
*/
|
||||
public function fetch_directory()
|
||||
{
|
||||
return $this->directory;
|
||||
}
|
||||
|
||||
}
|
||||
1090
system/core/Security.php
Normal file
1090
system/core/Security.php
Normal file
File diff suppressed because it is too large
Load Diff
643
system/core/URI.php
Normal file
643
system/core/URI.php
Normal file
@ -0,0 +1,643 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* URI Class
|
||||
*
|
||||
* Parses URIs and determines routing
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category URI
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/libraries/uri.html
|
||||
*/
|
||||
class CI_URI {
|
||||
|
||||
/**
|
||||
* List of cached URI segments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $keyval = array();
|
||||
|
||||
/**
|
||||
* Current URI string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $uri_string = '';
|
||||
|
||||
/**
|
||||
* List of URI segments
|
||||
*
|
||||
* Starts at 1 instead of 0.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $segments = array();
|
||||
|
||||
/**
|
||||
* List of routed URI segments
|
||||
*
|
||||
* Starts at 1 instead of 0.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $rsegments = array();
|
||||
|
||||
/**
|
||||
* Permitted URI chars
|
||||
*
|
||||
* PCRE character group allowed in URI segments
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_permitted_uri_chars;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->config =& load_class('Config', 'core');
|
||||
|
||||
// If query strings are enabled, we don't need to parse any segments.
|
||||
// However, they don't make sense under CLI.
|
||||
if (is_cli() OR $this->config->item('enable_query_strings') !== TRUE)
|
||||
{
|
||||
$this->_permitted_uri_chars = $this->config->item('permitted_uri_chars');
|
||||
|
||||
// If it's a CLI request, ignore the configuration
|
||||
if (is_cli())
|
||||
{
|
||||
$uri = $this->_parse_argv();
|
||||
}
|
||||
else
|
||||
{
|
||||
$protocol = $this->config->item('uri_protocol');
|
||||
empty($protocol) && $protocol = 'REQUEST_URI';
|
||||
|
||||
switch ($protocol)
|
||||
{
|
||||
case 'AUTO': // For BC purposes only
|
||||
case 'REQUEST_URI':
|
||||
$uri = $this->_parse_request_uri();
|
||||
break;
|
||||
case 'QUERY_STRING':
|
||||
$uri = $this->_parse_query_string();
|
||||
break;
|
||||
case 'PATH_INFO':
|
||||
default:
|
||||
$uri = isset($_SERVER[$protocol])
|
||||
? $_SERVER[$protocol]
|
||||
: $this->_parse_request_uri();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_set_uri_string($uri);
|
||||
}
|
||||
|
||||
log_message('info', 'URI Class Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set URI String
|
||||
*
|
||||
* @param string $str
|
||||
* @return void
|
||||
*/
|
||||
protected function _set_uri_string($str)
|
||||
{
|
||||
// Filter out control characters and trim slashes
|
||||
$this->uri_string = trim(remove_invisible_characters($str, FALSE), '/');
|
||||
|
||||
if ($this->uri_string !== '')
|
||||
{
|
||||
// Remove the URL suffix, if present
|
||||
if (($suffix = (string) $this->config->item('url_suffix')) !== '')
|
||||
{
|
||||
$slen = strlen($suffix);
|
||||
|
||||
if (substr($this->uri_string, -$slen) === $suffix)
|
||||
{
|
||||
$this->uri_string = substr($this->uri_string, 0, -$slen);
|
||||
}
|
||||
}
|
||||
|
||||
$this->segments[0] = NULL;
|
||||
// Populate the segments array
|
||||
foreach (explode('/', trim($this->uri_string, '/')) as $val)
|
||||
{
|
||||
$val = trim($val);
|
||||
// Filter segments for security
|
||||
$this->filter_uri($val);
|
||||
|
||||
if ($val !== '')
|
||||
{
|
||||
$this->segments[] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
unset($this->segments[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse REQUEST_URI
|
||||
*
|
||||
* Will parse REQUEST_URI and automatically detect the URI from it,
|
||||
* while fixing the query string if necessary.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _parse_request_uri()
|
||||
{
|
||||
if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// parse_url() returns false if no host is present, but the path or query string
|
||||
// contains a colon followed by a number
|
||||
$uri = parse_url('http://dummy'.$_SERVER['REQUEST_URI']);
|
||||
$query = isset($uri['query']) ? $uri['query'] : '';
|
||||
$uri = isset($uri['path']) ? $uri['path'] : '';
|
||||
|
||||
if (isset($_SERVER['SCRIPT_NAME'][0]))
|
||||
{
|
||||
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
|
||||
{
|
||||
$uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME']));
|
||||
}
|
||||
elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
|
||||
{
|
||||
$uri = (string) substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
|
||||
}
|
||||
}
|
||||
|
||||
// This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct
|
||||
// URI is found, and also fixes the QUERY_STRING server var and $_GET array.
|
||||
if (trim($uri, '/') === '' && strncmp($query, '/', 1) === 0)
|
||||
{
|
||||
$query = explode('?', $query, 2);
|
||||
$uri = $query[0];
|
||||
$_SERVER['QUERY_STRING'] = isset($query[1]) ? $query[1] : '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$_SERVER['QUERY_STRING'] = $query;
|
||||
}
|
||||
|
||||
parse_str($_SERVER['QUERY_STRING'], $_GET);
|
||||
|
||||
if ($uri === '/' OR $uri === '')
|
||||
{
|
||||
return '/';
|
||||
}
|
||||
|
||||
// Do some final cleaning of the URI and return it
|
||||
return $this->_remove_relative_directory($uri);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse QUERY_STRING
|
||||
*
|
||||
* Will parse QUERY_STRING and automatically detect the URI from it.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _parse_query_string()
|
||||
{
|
||||
$uri = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
|
||||
|
||||
if (trim($uri, '/') === '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
elseif (strncmp($uri, '/', 1) === 0)
|
||||
{
|
||||
$uri = explode('?', $uri, 2);
|
||||
$_SERVER['QUERY_STRING'] = isset($uri[1]) ? $uri[1] : '';
|
||||
$uri = $uri[0];
|
||||
}
|
||||
|
||||
parse_str($_SERVER['QUERY_STRING'], $_GET);
|
||||
|
||||
return $this->_remove_relative_directory($uri);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse CLI arguments
|
||||
*
|
||||
* Take each command line argument and assume it is a URI segment.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _parse_argv()
|
||||
{
|
||||
$args = array_slice($_SERVER['argv'], 1);
|
||||
return $args ? implode('/', $args) : '';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Remove relative directory (../) and multi slashes (///)
|
||||
*
|
||||
* Do some final cleaning of the URI and return it, currently only used in self::_parse_request_uri()
|
||||
*
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
protected function _remove_relative_directory($uri)
|
||||
{
|
||||
$uris = array();
|
||||
$tok = strtok($uri, '/');
|
||||
while ($tok !== FALSE)
|
||||
{
|
||||
if (( ! empty($tok) OR $tok === '0') && $tok !== '..')
|
||||
{
|
||||
$uris[] = $tok;
|
||||
}
|
||||
$tok = strtok('/');
|
||||
}
|
||||
|
||||
return implode('/', $uris);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Filter URI
|
||||
*
|
||||
* Filters segments for malicious characters.
|
||||
*
|
||||
* @param string $str
|
||||
* @return void
|
||||
*/
|
||||
public function filter_uri(&$str)
|
||||
{
|
||||
if ( ! empty($str) && ! empty($this->_permitted_uri_chars) && ! preg_match('/^['.$this->_permitted_uri_chars.']+$/i'.(UTF8_ENABLED ? 'u' : ''), $str))
|
||||
{
|
||||
show_error('The URI you submitted has disallowed characters.', 400);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch URI Segment
|
||||
*
|
||||
* @see CI_URI::$segments
|
||||
* @param int $n Index
|
||||
* @param mixed $no_result What to return if the segment index is not found
|
||||
* @return mixed
|
||||
*/
|
||||
public function segment($n, $no_result = NULL)
|
||||
{
|
||||
return isset($this->segments[$n]) ? $this->segments[$n] : $no_result;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch URI "routed" Segment
|
||||
*
|
||||
* Returns the re-routed URI segment (assuming routing rules are used)
|
||||
* based on the index provided. If there is no routing, will return
|
||||
* the same result as CI_URI::segment().
|
||||
*
|
||||
* @see CI_URI::$rsegments
|
||||
* @see CI_URI::segment()
|
||||
* @param int $n Index
|
||||
* @param mixed $no_result What to return if the segment index is not found
|
||||
* @return mixed
|
||||
*/
|
||||
public function rsegment($n, $no_result = NULL)
|
||||
{
|
||||
return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* URI to assoc
|
||||
*
|
||||
* Generates an associative array of URI data starting at the supplied
|
||||
* segment index. For example, if this is your URI:
|
||||
*
|
||||
* example.com/user/search/name/joe/location/UK/gender/male
|
||||
*
|
||||
* You can use this method to generate an array with this prototype:
|
||||
*
|
||||
* array (
|
||||
* name => joe
|
||||
* location => UK
|
||||
* gender => male
|
||||
* )
|
||||
*
|
||||
* @param int $n Index (default: 3)
|
||||
* @param array $default Default values
|
||||
* @return array
|
||||
*/
|
||||
public function uri_to_assoc($n = 3, $default = array())
|
||||
{
|
||||
return $this->_uri_to_assoc($n, $default, 'segment');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Routed URI to assoc
|
||||
*
|
||||
* Identical to CI_URI::uri_to_assoc(), only it uses the re-routed
|
||||
* segment array.
|
||||
*
|
||||
* @see CI_URI::uri_to_assoc()
|
||||
* @param int $n Index (default: 3)
|
||||
* @param array $default Default values
|
||||
* @return array
|
||||
*/
|
||||
public function ruri_to_assoc($n = 3, $default = array())
|
||||
{
|
||||
return $this->_uri_to_assoc($n, $default, 'rsegment');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Internal URI-to-assoc
|
||||
*
|
||||
* Generates a key/value pair from the URI string or re-routed URI string.
|
||||
*
|
||||
* @used-by CI_URI::uri_to_assoc()
|
||||
* @used-by CI_URI::ruri_to_assoc()
|
||||
* @param int $n Index (default: 3)
|
||||
* @param array $default Default values
|
||||
* @param string $which Array name ('segment' or 'rsegment')
|
||||
* @return array
|
||||
*/
|
||||
protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment')
|
||||
{
|
||||
if ( ! is_numeric($n))
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
|
||||
if (isset($this->keyval[$which], $this->keyval[$which][$n]))
|
||||
{
|
||||
return $this->keyval[$which][$n];
|
||||
}
|
||||
|
||||
$total_segments = "total_{$which}s";
|
||||
$segment_array = "{$which}_array";
|
||||
|
||||
if ($this->$total_segments() < $n)
|
||||
{
|
||||
return (count($default) === 0)
|
||||
? array()
|
||||
: array_fill_keys($default, NULL);
|
||||
}
|
||||
|
||||
$segments = array_slice($this->$segment_array(), ($n - 1));
|
||||
$i = 0;
|
||||
$lastval = '';
|
||||
$retval = array();
|
||||
foreach ($segments as $seg)
|
||||
{
|
||||
if ($i % 2)
|
||||
{
|
||||
$retval[$lastval] = $seg;
|
||||
}
|
||||
else
|
||||
{
|
||||
$retval[$seg] = NULL;
|
||||
$lastval = $seg;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (count($default) > 0)
|
||||
{
|
||||
foreach ($default as $val)
|
||||
{
|
||||
if ( ! array_key_exists($val, $retval))
|
||||
{
|
||||
$retval[$val] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cache the array for reuse
|
||||
isset($this->keyval[$which]) OR $this->keyval[$which] = array();
|
||||
$this->keyval[$which][$n] = $retval;
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Assoc to URI
|
||||
*
|
||||
* Generates a URI string from an associative array.
|
||||
*
|
||||
* @param array $array Input array of key/value pairs
|
||||
* @return string URI string
|
||||
*/
|
||||
public function assoc_to_uri($array)
|
||||
{
|
||||
$temp = array();
|
||||
foreach ((array) $array as $key => $val)
|
||||
{
|
||||
$temp[] = $key;
|
||||
$temp[] = $val;
|
||||
}
|
||||
|
||||
return implode('/', $temp);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Slash segment
|
||||
*
|
||||
* Fetches an URI segment with a slash.
|
||||
*
|
||||
* @param int $n Index
|
||||
* @param string $where Where to add the slash ('trailing' or 'leading')
|
||||
* @return string
|
||||
*/
|
||||
public function slash_segment($n, $where = 'trailing')
|
||||
{
|
||||
return $this->_slash_segment($n, $where, 'segment');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Slash routed segment
|
||||
*
|
||||
* Fetches an URI routed segment with a slash.
|
||||
*
|
||||
* @param int $n Index
|
||||
* @param string $where Where to add the slash ('trailing' or 'leading')
|
||||
* @return string
|
||||
*/
|
||||
public function slash_rsegment($n, $where = 'trailing')
|
||||
{
|
||||
return $this->_slash_segment($n, $where, 'rsegment');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Internal Slash segment
|
||||
*
|
||||
* Fetches an URI Segment and adds a slash to it.
|
||||
*
|
||||
* @used-by CI_URI::slash_segment()
|
||||
* @used-by CI_URI::slash_rsegment()
|
||||
*
|
||||
* @param int $n Index
|
||||
* @param string $where Where to add the slash ('trailing' or 'leading')
|
||||
* @param string $which Array name ('segment' or 'rsegment')
|
||||
* @return string
|
||||
*/
|
||||
protected function _slash_segment($n, $where = 'trailing', $which = 'segment')
|
||||
{
|
||||
$leading = $trailing = '/';
|
||||
|
||||
if ($where === 'trailing')
|
||||
{
|
||||
$leading = '';
|
||||
}
|
||||
elseif ($where === 'leading')
|
||||
{
|
||||
$trailing = '';
|
||||
}
|
||||
|
||||
return $leading.$this->$which($n).$trailing;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Segment Array
|
||||
*
|
||||
* @return array CI_URI::$segments
|
||||
*/
|
||||
public function segment_array()
|
||||
{
|
||||
return $this->segments;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Routed Segment Array
|
||||
*
|
||||
* @return array CI_URI::$rsegments
|
||||
*/
|
||||
public function rsegment_array()
|
||||
{
|
||||
return $this->rsegments;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Total number of segments
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function total_segments()
|
||||
{
|
||||
return count($this->segments);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Total number of routed segments
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function total_rsegments()
|
||||
{
|
||||
return count($this->rsegments);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch URI string
|
||||
*
|
||||
* @return string CI_URI::$uri_string
|
||||
*/
|
||||
public function uri_string()
|
||||
{
|
||||
return $this->uri_string;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Re-routed URI string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ruri_string()
|
||||
{
|
||||
return ltrim(load_class('Router', 'core')->directory, '/').implode('/', $this->rsegments);
|
||||
}
|
||||
|
||||
}
|
||||
164
system/core/Utf8.php
Normal file
164
system/core/Utf8.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 2.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Utf8 Class
|
||||
*
|
||||
* Provides support for UTF-8 environments
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category UTF-8
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/libraries/utf8.html
|
||||
*/
|
||||
class CI_Utf8 {
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Determines if UTF-8 support is to be enabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (
|
||||
defined('PREG_BAD_UTF8_ERROR') // PCRE must support UTF-8
|
||||
&& (ICONV_ENABLED === TRUE OR MB_ENABLED === TRUE) // iconv or mbstring must be installed
|
||||
&& strtoupper(config_item('charset')) === 'UTF-8' // Application charset must be UTF-8
|
||||
)
|
||||
{
|
||||
define('UTF8_ENABLED', TRUE);
|
||||
log_message('debug', 'UTF-8 Support Enabled');
|
||||
}
|
||||
else
|
||||
{
|
||||
define('UTF8_ENABLED', FALSE);
|
||||
log_message('debug', 'UTF-8 Support Disabled');
|
||||
}
|
||||
|
||||
log_message('info', 'Utf8 Class Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clean UTF-8 strings
|
||||
*
|
||||
* Ensures strings contain only valid UTF-8 characters.
|
||||
*
|
||||
* @param string $str String to clean
|
||||
* @return string
|
||||
*/
|
||||
public function clean_string($str)
|
||||
{
|
||||
if ($this->is_ascii($str) === FALSE)
|
||||
{
|
||||
if (MB_ENABLED)
|
||||
{
|
||||
$str = mb_convert_encoding($str, 'UTF-8', 'UTF-8');
|
||||
}
|
||||
elseif (ICONV_ENABLED)
|
||||
{
|
||||
$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Remove ASCII control characters
|
||||
*
|
||||
* Removes all ASCII control characters except horizontal tabs,
|
||||
* line feeds, and carriage returns, as all others can cause
|
||||
* problems in XML.
|
||||
*
|
||||
* @param string $str String to clean
|
||||
* @return string
|
||||
*/
|
||||
public function safe_ascii_for_xml($str)
|
||||
{
|
||||
return remove_invisible_characters($str, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Convert to UTF-8
|
||||
*
|
||||
* Attempts to convert a string to UTF-8.
|
||||
*
|
||||
* @param string $str Input string
|
||||
* @param string $encoding Input encoding
|
||||
* @return string $str encoded in UTF-8 or FALSE on failure
|
||||
*/
|
||||
public function convert_to_utf8($str, $encoding)
|
||||
{
|
||||
if (MB_ENABLED)
|
||||
{
|
||||
return mb_convert_encoding($str, 'UTF-8', $encoding);
|
||||
}
|
||||
elseif (ICONV_ENABLED)
|
||||
{
|
||||
return @iconv($encoding, 'UTF-8', $str);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is ASCII?
|
||||
*
|
||||
* Tests if a string is standard 7-bit ASCII or not.
|
||||
*
|
||||
* @param string $str String to check
|
||||
* @return bool
|
||||
*/
|
||||
public function is_ascii($str)
|
||||
{
|
||||
return (preg_match('/[^\x00-\x7F]/S', $str) === 0);
|
||||
}
|
||||
|
||||
}
|
||||
254
system/core/compat/hash.php
Normal file
254
system/core/compat/hash.php
Normal file
@ -0,0 +1,254 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PHP ext/hash compatibility package
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage CodeIgniter
|
||||
* @category Compatibility
|
||||
* @author Andrey Andreev
|
||||
* @link https://codeigniter.com/user_guide/
|
||||
* @link http://php.net/hash
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (is_php('5.6'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('hash_equals'))
|
||||
{
|
||||
/**
|
||||
* hash_equals()
|
||||
*
|
||||
* @link http://php.net/hash_equals
|
||||
* @param string $known_string
|
||||
* @param string $user_string
|
||||
* @return bool
|
||||
*/
|
||||
function hash_equals($known_string, $user_string)
|
||||
{
|
||||
if ( ! is_string($known_string))
|
||||
{
|
||||
trigger_error('hash_equals(): Expected known_string to be a string, '.strtolower(gettype($known_string)).' given', E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
elseif ( ! is_string($user_string))
|
||||
{
|
||||
trigger_error('hash_equals(): Expected user_string to be a string, '.strtolower(gettype($user_string)).' given', E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
elseif (($length = strlen($known_string)) !== strlen($user_string))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$diff = 0;
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
{
|
||||
$diff |= ord($known_string[$i]) ^ ord($user_string[$i]);
|
||||
}
|
||||
|
||||
return ($diff === 0);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (is_php('5.5'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('hash_pbkdf2'))
|
||||
{
|
||||
/**
|
||||
* hash_pbkdf2()
|
||||
*
|
||||
* @link http://php.net/hash_pbkdf2
|
||||
* @param string $algo
|
||||
* @param string $password
|
||||
* @param string $salt
|
||||
* @param int $iterations
|
||||
* @param int $length
|
||||
* @param bool $raw_output
|
||||
* @return string
|
||||
*/
|
||||
function hash_pbkdf2($algo, $password, $salt, $iterations, $length = 0, $raw_output = FALSE)
|
||||
{
|
||||
if ( ! in_array(strtolower($algo), hash_algos(), TRUE))
|
||||
{
|
||||
trigger_error('hash_pbkdf2(): Unknown hashing algorithm: '.$algo, E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (($type = gettype($iterations)) !== 'integer')
|
||||
{
|
||||
if ($type === 'object' && method_exists($iterations, '__toString'))
|
||||
{
|
||||
$iterations = (string) $iterations;
|
||||
}
|
||||
|
||||
if (is_string($iterations) && is_numeric($iterations))
|
||||
{
|
||||
$iterations = (int) $iterations;
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error('hash_pbkdf2() expects parameter 4 to be long, '.$type.' given', E_USER_WARNING);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ($iterations < 1)
|
||||
{
|
||||
trigger_error('hash_pbkdf2(): Iterations must be a positive integer: '.$iterations, E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (($type = gettype($length)) !== 'integer')
|
||||
{
|
||||
if ($type === 'object' && method_exists($length, '__toString'))
|
||||
{
|
||||
$length = (string) $length;
|
||||
}
|
||||
|
||||
if (is_string($length) && is_numeric($length))
|
||||
{
|
||||
$length = (int) $length;
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error('hash_pbkdf2() expects parameter 5 to be long, '.$type.' given', E_USER_WARNING);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ($length < 0)
|
||||
{
|
||||
trigger_error('hash_pbkdf2(): Length must be greater than or equal to 0: '.$length, E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$hash_length = defined('MB_OVERLOAD_STRING')
|
||||
? mb_strlen(hash($algo, NULL, TRUE), '8bit')
|
||||
: strlen(hash($algo, NULL, TRUE));
|
||||
empty($length) && $length = $hash_length;
|
||||
|
||||
// Pre-hash password inputs longer than the algorithm's block size
|
||||
// (i.e. prepare HMAC key) to mitigate potential DoS attacks.
|
||||
static $block_sizes;
|
||||
empty($block_sizes) && $block_sizes = array(
|
||||
'gost' => 32,
|
||||
'haval128,3' => 128,
|
||||
'haval160,3' => 128,
|
||||
'haval192,3' => 128,
|
||||
'haval224,3' => 128,
|
||||
'haval256,3' => 128,
|
||||
'haval128,4' => 128,
|
||||
'haval160,4' => 128,
|
||||
'haval192,4' => 128,
|
||||
'haval224,4' => 128,
|
||||
'haval256,4' => 128,
|
||||
'haval128,5' => 128,
|
||||
'haval160,5' => 128,
|
||||
'haval192,5' => 128,
|
||||
'haval224,5' => 128,
|
||||
'haval256,5' => 128,
|
||||
'md2' => 16,
|
||||
'md4' => 64,
|
||||
'md5' => 64,
|
||||
'ripemd128' => 64,
|
||||
'ripemd160' => 64,
|
||||
'ripemd256' => 64,
|
||||
'ripemd320' => 64,
|
||||
'salsa10' => 64,
|
||||
'salsa20' => 64,
|
||||
'sha1' => 64,
|
||||
'sha224' => 64,
|
||||
'sha256' => 64,
|
||||
'sha384' => 128,
|
||||
'sha512' => 128,
|
||||
'snefru' => 32,
|
||||
'snefru256' => 32,
|
||||
'tiger128,3' => 64,
|
||||
'tiger160,3' => 64,
|
||||
'tiger192,3' => 64,
|
||||
'tiger128,4' => 64,
|
||||
'tiger160,4' => 64,
|
||||
'tiger192,4' => 64,
|
||||
'whirlpool' => 64
|
||||
);
|
||||
|
||||
if (isset($block_sizes[$algo], $password[$block_sizes[$algo]]))
|
||||
{
|
||||
$password = hash($algo, $password, TRUE);
|
||||
}
|
||||
|
||||
$hash = '';
|
||||
// Note: Blocks are NOT 0-indexed
|
||||
for ($bc = (int) ceil($length / $hash_length), $bi = 1; $bi <= $bc; $bi++)
|
||||
{
|
||||
$key = $derived_key = hash_hmac($algo, $salt.pack('N', $bi), $password, TRUE);
|
||||
for ($i = 1; $i < $iterations; $i++)
|
||||
{
|
||||
$derived_key ^= $key = hash_hmac($algo, $key, $password, TRUE);
|
||||
}
|
||||
|
||||
$hash .= $derived_key;
|
||||
}
|
||||
|
||||
// This is not RFC-compatible, but we're aiming for natural PHP compatibility
|
||||
if ( ! $raw_output)
|
||||
{
|
||||
$hash = bin2hex($hash);
|
||||
}
|
||||
|
||||
return defined('MB_OVERLOAD_STRING')
|
||||
? mb_substr($hash, 0, $length, '8bit')
|
||||
: substr($hash, 0, $length);
|
||||
}
|
||||
}
|
||||
11
system/core/compat/index.html
Normal file
11
system/core/compat/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
149
system/core/compat/mbstring.php
Normal file
149
system/core/compat/mbstring.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PHP ext/mbstring compatibility package
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage CodeIgniter
|
||||
* @category Compatibility
|
||||
* @author Andrey Andreev
|
||||
* @link https://codeigniter.com/user_guide/
|
||||
* @link http://php.net/mbstring
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (MB_ENABLED === TRUE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('mb_strlen'))
|
||||
{
|
||||
/**
|
||||
* mb_strlen()
|
||||
*
|
||||
* WARNING: This function WILL fall-back to strlen()
|
||||
* if iconv is not available!
|
||||
*
|
||||
* @link http://php.net/mb_strlen
|
||||
* @param string $str
|
||||
* @param string $encoding
|
||||
* @return int
|
||||
*/
|
||||
function mb_strlen($str, $encoding = NULL)
|
||||
{
|
||||
if (ICONV_ENABLED === TRUE)
|
||||
{
|
||||
return iconv_strlen($str, isset($encoding) ? $encoding : config_item('charset'));
|
||||
}
|
||||
|
||||
log_message('debug', 'Compatibility (mbstring): iconv_strlen() is not available, falling back to strlen().');
|
||||
return strlen($str);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('mb_strpos'))
|
||||
{
|
||||
/**
|
||||
* mb_strpos()
|
||||
*
|
||||
* WARNING: This function WILL fall-back to strpos()
|
||||
* if iconv is not available!
|
||||
*
|
||||
* @link http://php.net/mb_strpos
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
* @param int $offset
|
||||
* @param string $encoding
|
||||
* @return mixed
|
||||
*/
|
||||
function mb_strpos($haystack, $needle, $offset = 0, $encoding = NULL)
|
||||
{
|
||||
if (ICONV_ENABLED === TRUE)
|
||||
{
|
||||
return iconv_strpos($haystack, $needle, $offset, isset($encoding) ? $encoding : config_item('charset'));
|
||||
}
|
||||
|
||||
log_message('debug', 'Compatibility (mbstring): iconv_strpos() is not available, falling back to strpos().');
|
||||
return strpos($haystack, $needle, $offset);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('mb_substr'))
|
||||
{
|
||||
/**
|
||||
* mb_substr()
|
||||
*
|
||||
* WARNING: This function WILL fall-back to substr()
|
||||
* if iconv is not available.
|
||||
*
|
||||
* @link http://php.net/mb_substr
|
||||
* @param string $str
|
||||
* @param int $start
|
||||
* @param int $length
|
||||
* @param string $encoding
|
||||
* @return string
|
||||
*/
|
||||
function mb_substr($str, $start, $length = NULL, $encoding = NULL)
|
||||
{
|
||||
if (ICONV_ENABLED === TRUE)
|
||||
{
|
||||
isset($encoding) OR $encoding = config_item('charset');
|
||||
return iconv_substr(
|
||||
$str,
|
||||
$start,
|
||||
isset($length) ? $length : iconv_strlen($str, $encoding), // NULL doesn't work
|
||||
$encoding
|
||||
);
|
||||
}
|
||||
|
||||
log_message('debug', 'Compatibility (mbstring): iconv_substr() is not available, falling back to substr().');
|
||||
return isset($length)
|
||||
? substr($str, $start, $length)
|
||||
: substr($str, $start);
|
||||
}
|
||||
}
|
||||
251
system/core/compat/password.php
Normal file
251
system/core/compat/password.php
Normal file
@ -0,0 +1,251 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PHP ext/standard/password compatibility package
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage CodeIgniter
|
||||
* @category Compatibility
|
||||
* @author Andrey Andreev
|
||||
* @link https://codeigniter.com/user_guide/
|
||||
* @link http://php.net/password
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (is_php('5.5') OR ! defined('CRYPT_BLOWFISH') OR CRYPT_BLOWFISH !== 1 OR defined('HHVM_VERSION'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
defined('PASSWORD_BCRYPT') OR define('PASSWORD_BCRYPT', 1);
|
||||
defined('PASSWORD_DEFAULT') OR define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('password_get_info'))
|
||||
{
|
||||
/**
|
||||
* password_get_info()
|
||||
*
|
||||
* @link http://php.net/password_get_info
|
||||
* @param string $hash
|
||||
* @return array
|
||||
*/
|
||||
function password_get_info($hash)
|
||||
{
|
||||
return (strlen($hash) < 60 OR sscanf($hash, '$2y$%d', $hash) !== 1)
|
||||
? array('algo' => 0, 'algoName' => 'unknown', 'options' => array())
|
||||
: array('algo' => 1, 'algoName' => 'bcrypt', 'options' => array('cost' => $hash));
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('password_hash'))
|
||||
{
|
||||
/**
|
||||
* password_hash()
|
||||
*
|
||||
* @link http://php.net/password_hash
|
||||
* @param string $password
|
||||
* @param int $algo
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
function password_hash($password, $algo, array $options = array())
|
||||
{
|
||||
static $func_overload;
|
||||
isset($func_overload) OR $func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));
|
||||
|
||||
if ($algo !== 1)
|
||||
{
|
||||
trigger_error('password_hash(): Unknown hashing algorithm: '.(int) $algo, E_USER_WARNING);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (isset($options['cost']) && ($options['cost'] < 4 OR $options['cost'] > 31))
|
||||
{
|
||||
trigger_error('password_hash(): Invalid bcrypt cost parameter specified: '.(int) $options['cost'], E_USER_WARNING);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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);
|
||||
return NULL;
|
||||
}
|
||||
elseif ( ! isset($options['salt']))
|
||||
{
|
||||
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);
|
||||
}
|
||||
elseif (DIRECTORY_SEPARATOR === '/' && (is_readable($dev = '/dev/arandom') OR is_readable($dev = '/dev/urandom')))
|
||||
{
|
||||
if (($fp = fopen($dev, 'rb')) === FALSE)
|
||||
{
|
||||
log_message('error', 'compat/password: Unable to open '.$dev.' for reading.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Try not to waste entropy ...
|
||||
is_php('5.4') && stream_set_chunk_size($fp, 16);
|
||||
|
||||
$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)
|
||||
{
|
||||
log_message('error', 'compat/password: Error while reading from '.$dev.'.');
|
||||
return FALSE;
|
||||
}
|
||||
$options['salt'] .= $read;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
log_message('error', 'compat/password: No CSPRNG available.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$options['salt'] = str_replace('+', '.', rtrim(base64_encode($options['salt']), '='));
|
||||
}
|
||||
elseif ( ! preg_match('#^[a-zA-Z0-9./]+$#D', $options['salt']))
|
||||
{
|
||||
$options['salt'] = str_replace('+', '.', rtrim(base64_encode($options['salt']), '='));
|
||||
}
|
||||
|
||||
isset($options['cost']) OR $options['cost'] = 10;
|
||||
|
||||
return (strlen($password = crypt($password, sprintf('$2y$%02d$%s', $options['cost'], $options['salt']))) === 60)
|
||||
? $password
|
||||
: FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('password_needs_rehash'))
|
||||
{
|
||||
/**
|
||||
* password_needs_rehash()
|
||||
*
|
||||
* @link http://php.net/password_needs_rehash
|
||||
* @param string $hash
|
||||
* @param int $algo
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
function password_needs_rehash($hash, $algo, array $options = array())
|
||||
{
|
||||
$info = password_get_info($hash);
|
||||
|
||||
if ($algo !== $info['algo'])
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
elseif ($algo === 1)
|
||||
{
|
||||
$options['cost'] = isset($options['cost']) ? (int) $options['cost'] : 10;
|
||||
return ($info['options']['cost'] !== $options['cost']);
|
||||
}
|
||||
|
||||
// Odd at first glance, but according to a comment in PHP's own unit tests,
|
||||
// because it is an unknown algorithm - it's valid and therefore doesn't
|
||||
// need rehashing.
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('password_verify'))
|
||||
{
|
||||
/**
|
||||
* password_verify()
|
||||
*
|
||||
* @link http://php.net/password_verify
|
||||
* @param string $password
|
||||
* @param string $hash
|
||||
* @return bool
|
||||
*/
|
||||
function password_verify($password, $hash)
|
||||
{
|
||||
if (strlen($hash) !== 60 OR strlen($password = crypt($password, $hash)) !== 60)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$compare = 0;
|
||||
for ($i = 0; $i < 60; $i++)
|
||||
{
|
||||
$compare |= (ord($password[$i]) ^ ord($hash[$i]));
|
||||
}
|
||||
|
||||
return ($compare === 0);
|
||||
}
|
||||
}
|
||||
182
system/core/compat/standard.php
Normal file
182
system/core/compat/standard.php
Normal file
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PHP ext/standard compatibility package
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage CodeIgniter
|
||||
* @category Compatibility
|
||||
* @author Andrey Andreev
|
||||
* @link https://codeigniter.com/user_guide/
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (is_php('5.5'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('array_column'))
|
||||
{
|
||||
/**
|
||||
* array_column()
|
||||
*
|
||||
* @link http://php.net/array_column
|
||||
* @param array $array
|
||||
* @param mixed $column_key
|
||||
* @param mixed $index_key
|
||||
* @return array
|
||||
*/
|
||||
function array_column(array $array, $column_key, $index_key = NULL)
|
||||
{
|
||||
if ( ! in_array($type = gettype($column_key), array('integer', 'string', 'NULL'), TRUE))
|
||||
{
|
||||
if ($type === 'double')
|
||||
{
|
||||
$column_key = (int) $column_key;
|
||||
}
|
||||
elseif ($type === 'object' && method_exists($column_key, '__toString'))
|
||||
{
|
||||
$column_key = (string) $column_key;
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! in_array($type = gettype($index_key), array('integer', 'string', 'NULL'), TRUE))
|
||||
{
|
||||
if ($type === 'double')
|
||||
{
|
||||
$index_key = (int) $index_key;
|
||||
}
|
||||
elseif ($type === 'object' && method_exists($index_key, '__toString'))
|
||||
{
|
||||
$index_key = (string) $index_key;
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($array as &$a)
|
||||
{
|
||||
if ($column_key === NULL)
|
||||
{
|
||||
$value = $a;
|
||||
}
|
||||
elseif (is_array($a) && array_key_exists($column_key, $a))
|
||||
{
|
||||
$value = $a[$column_key];
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($index_key === NULL OR ! array_key_exists($index_key, $a))
|
||||
{
|
||||
$result[] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result[$a[$index_key]] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (is_php('5.4'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('hex2bin'))
|
||||
{
|
||||
/**
|
||||
* hex2bin()
|
||||
*
|
||||
* @link http://php.net/hex2bin
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
function hex2bin($data)
|
||||
{
|
||||
if (in_array($type = gettype($data), array('array', 'double', 'object', 'resource'), TRUE))
|
||||
{
|
||||
if ($type === 'object' && method_exists($data, '__toString'))
|
||||
{
|
||||
$data = (string) $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error('hex2bin() expects parameter 1 to be string, '.$type.' given', E_USER_WARNING);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($data) % 2 !== 0)
|
||||
{
|
||||
trigger_error('Hexadecimal input string must have an even length', E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
elseif ( ! preg_match('/^[0-9a-f]*$/i', $data))
|
||||
{
|
||||
trigger_error('Input string must be hexadecimal string', E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return pack('H*', $data);
|
||||
}
|
||||
}
|
||||
11
system/core/index.html
Normal file
11
system/core/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
218
system/database/DB.php
Normal file
218
system/database/DB.php
Normal file
@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Initialize the database
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*
|
||||
* @param string|string[] $params
|
||||
* @param bool $query_builder_override
|
||||
* Determines if query builder should be used or not
|
||||
*/
|
||||
function &DB($params = '', $query_builder_override = NULL)
|
||||
{
|
||||
// Load the DB config file if a DSN string wasn't passed
|
||||
if (is_string($params) && strpos($params, '://') === FALSE)
|
||||
{
|
||||
// Is the config file in the environment folder?
|
||||
if ( ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php')
|
||||
&& ! file_exists($file_path = APPPATH.'config/database.php'))
|
||||
{
|
||||
show_error('The configuration file database.php does not exist.');
|
||||
}
|
||||
|
||||
include($file_path);
|
||||
|
||||
// Make packages contain database config files,
|
||||
// given that the controller instance already exists
|
||||
if (class_exists('CI_Controller', FALSE))
|
||||
{
|
||||
foreach (get_instance()->load->get_package_paths() as $path)
|
||||
{
|
||||
if ($path !== APPPATH)
|
||||
{
|
||||
if (file_exists($file_path = $path.'config/'.ENVIRONMENT.'/database.php'))
|
||||
{
|
||||
include($file_path);
|
||||
}
|
||||
elseif (file_exists($file_path = $path.'config/database.php'))
|
||||
{
|
||||
include($file_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! isset($db) OR count($db) === 0)
|
||||
{
|
||||
show_error('No database connection settings were found in the database config file.');
|
||||
}
|
||||
|
||||
if ($params !== '')
|
||||
{
|
||||
$active_group = $params;
|
||||
}
|
||||
|
||||
if ( ! isset($active_group))
|
||||
{
|
||||
show_error('You have not specified a database connection group via $active_group in your config/database.php file.');
|
||||
}
|
||||
elseif ( ! isset($db[$active_group]))
|
||||
{
|
||||
show_error('You have specified an invalid database connection group ('.$active_group.') in your config/database.php file.');
|
||||
}
|
||||
|
||||
$params = $db[$active_group];
|
||||
}
|
||||
elseif (is_string($params))
|
||||
{
|
||||
/**
|
||||
* Parse the URL from the DSN string
|
||||
* Database settings can be passed as discreet
|
||||
* parameters or as a data source name in the first
|
||||
* parameter. DSNs must have this prototype:
|
||||
* $dsn = 'driver://username:password@hostname/database';
|
||||
*/
|
||||
if (($dsn = @parse_url($params)) === FALSE)
|
||||
{
|
||||
show_error('Invalid DB Connection String');
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'dbdriver' => $dsn['scheme'],
|
||||
'hostname' => isset($dsn['host']) ? rawurldecode($dsn['host']) : '',
|
||||
'port' => isset($dsn['port']) ? rawurldecode($dsn['port']) : '',
|
||||
'username' => isset($dsn['user']) ? rawurldecode($dsn['user']) : '',
|
||||
'password' => isset($dsn['pass']) ? rawurldecode($dsn['pass']) : '',
|
||||
'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : ''
|
||||
);
|
||||
|
||||
// Were additional config items set?
|
||||
if (isset($dsn['query']))
|
||||
{
|
||||
parse_str($dsn['query'], $extra);
|
||||
|
||||
foreach ($extra as $key => $val)
|
||||
{
|
||||
if (is_string($val) && in_array(strtoupper($val), array('TRUE', 'FALSE', 'NULL')))
|
||||
{
|
||||
$val = var_export($val, TRUE);
|
||||
}
|
||||
|
||||
$params[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No DB specified yet? Beat them senseless...
|
||||
if (empty($params['dbdriver']))
|
||||
{
|
||||
show_error('You have not selected a database type to connect to.');
|
||||
}
|
||||
|
||||
// Load the DB classes. Note: Since the query builder class is optional
|
||||
// we need to dynamically create a class that extends proper parent class
|
||||
// based on whether we're using the query builder class or not.
|
||||
if ($query_builder_override !== NULL)
|
||||
{
|
||||
$query_builder = $query_builder_override;
|
||||
}
|
||||
// Backwards compatibility work-around for keeping the
|
||||
// $active_record config variable working. Should be
|
||||
// removed in v3.1
|
||||
elseif ( ! isset($query_builder) && isset($active_record))
|
||||
{
|
||||
$query_builder = $active_record;
|
||||
}
|
||||
|
||||
require_once(BASEPATH.'database/DB_driver.php');
|
||||
|
||||
if ( ! isset($query_builder) OR $query_builder === TRUE)
|
||||
{
|
||||
require_once(BASEPATH.'database/DB_query_builder.php');
|
||||
if ( ! class_exists('CI_DB', FALSE))
|
||||
{
|
||||
/**
|
||||
* CI_DB
|
||||
*
|
||||
* Acts as an alias for both CI_DB_driver and CI_DB_query_builder.
|
||||
*
|
||||
* @see CI_DB_query_builder
|
||||
* @see CI_DB_driver
|
||||
*/
|
||||
class CI_DB extends CI_DB_query_builder { }
|
||||
}
|
||||
}
|
||||
elseif ( ! class_exists('CI_DB', FALSE))
|
||||
{
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
class CI_DB extends CI_DB_driver { }
|
||||
}
|
||||
|
||||
// Load the DB driver
|
||||
$driver_file = BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php';
|
||||
|
||||
file_exists($driver_file) OR show_error('Invalid DB driver');
|
||||
require_once($driver_file);
|
||||
|
||||
// Instantiate the DB adapter
|
||||
$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
|
||||
$DB = new $driver($params);
|
||||
|
||||
// Check for a subdriver
|
||||
if ( ! empty($DB->subdriver))
|
||||
{
|
||||
$driver_file = BASEPATH.'database/drivers/'.$DB->dbdriver.'/subdrivers/'.$DB->dbdriver.'_'.$DB->subdriver.'_driver.php';
|
||||
|
||||
if (file_exists($driver_file))
|
||||
{
|
||||
require_once($driver_file);
|
||||
$driver = 'CI_DB_'.$DB->dbdriver.'_'.$DB->subdriver.'_driver';
|
||||
$DB = new $driver($params);
|
||||
}
|
||||
}
|
||||
|
||||
$DB->initialize();
|
||||
return $DB;
|
||||
}
|
||||
221
system/database/DB_cache.php
Normal file
221
system/database/DB_cache.php
Normal file
@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Database Cache Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_Cache {
|
||||
|
||||
/**
|
||||
* CI Singleton
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $CI;
|
||||
|
||||
/**
|
||||
* Database object
|
||||
*
|
||||
* Allows passing of DB object so that multiple database connections
|
||||
* and returned DB objects can be supported.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $db;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object &$db
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
// Assign the main CI object to $this->CI and load the file helper since we use it a lot
|
||||
$this->CI =& get_instance();
|
||||
$this->db =& $db;
|
||||
$this->CI->load->helper('file');
|
||||
|
||||
$this->check_path();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Cache Directory Path
|
||||
*
|
||||
* @param string $path Path to the cache directory
|
||||
* @return bool
|
||||
*/
|
||||
public function check_path($path = '')
|
||||
{
|
||||
if ($path === '')
|
||||
{
|
||||
if ($this->db->cachedir === '')
|
||||
{
|
||||
return $this->db->cache_off();
|
||||
}
|
||||
|
||||
$path = $this->db->cachedir;
|
||||
}
|
||||
|
||||
// Add a trailing slash to the path if needed
|
||||
$path = realpath($path)
|
||||
? rtrim(realpath($path), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR
|
||||
: rtrim($path, '/').'/';
|
||||
|
||||
if ( ! is_dir($path))
|
||||
{
|
||||
log_message('debug', 'DB cache path error: '.$path);
|
||||
|
||||
// If the path is wrong we'll turn off caching
|
||||
return $this->db->cache_off();
|
||||
}
|
||||
|
||||
if ( ! is_really_writable($path))
|
||||
{
|
||||
log_message('debug', 'DB cache dir not writable: '.$path);
|
||||
|
||||
// If the path is not really writable we'll turn off caching
|
||||
return $this->db->cache_off();
|
||||
}
|
||||
|
||||
$this->db->cachedir = $path;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Retrieve a cached query
|
||||
*
|
||||
* The URI being requested will become the name of the cache sub-folder.
|
||||
* An MD5 hash of the SQL statement will become the cache file name.
|
||||
*
|
||||
* @param string $sql
|
||||
* @return string
|
||||
*/
|
||||
public function read($sql)
|
||||
{
|
||||
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
|
||||
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
|
||||
$filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql);
|
||||
|
||||
if ( ! is_file($filepath) OR FALSE === ($cachedata = file_get_contents($filepath)))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return unserialize($cachedata);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Write a query to a cache file
|
||||
*
|
||||
* @param string $sql
|
||||
* @param object $object
|
||||
* @return bool
|
||||
*/
|
||||
public function write($sql, $object)
|
||||
{
|
||||
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
|
||||
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
|
||||
$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
|
||||
$filename = md5($sql);
|
||||
|
||||
if ( ! is_dir($dir_path) && ! @mkdir($dir_path, 0750))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (write_file($dir_path.$filename, serialize($object)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
chmod($dir_path.$filename, 0640);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete cache files within a particular directory
|
||||
*
|
||||
* @param string $segment_one
|
||||
* @param string $segment_two
|
||||
* @return void
|
||||
*/
|
||||
public function delete($segment_one = '', $segment_two = '')
|
||||
{
|
||||
if ($segment_one === '')
|
||||
{
|
||||
$segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1);
|
||||
}
|
||||
|
||||
if ($segment_two === '')
|
||||
{
|
||||
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
|
||||
}
|
||||
|
||||
$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
|
||||
delete_files($dir_path, TRUE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete all existing cache files
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_all()
|
||||
{
|
||||
delete_files($this->db->cachedir, TRUE, TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
1991
system/database/DB_driver.php
Normal file
1991
system/database/DB_driver.php
Normal file
File diff suppressed because it is too large
Load Diff
1030
system/database/DB_forge.php
Normal file
1030
system/database/DB_forge.php
Normal file
File diff suppressed because it is too large
Load Diff
2808
system/database/DB_query_builder.php
Normal file
2808
system/database/DB_query_builder.php
Normal file
File diff suppressed because it is too large
Load Diff
665
system/database/DB_result.php
Normal file
665
system/database/DB_result.php
Normal file
@ -0,0 +1,665 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Database Result Class
|
||||
*
|
||||
* This is the platform-independent result class.
|
||||
* This class will not be called directly. Rather, the adapter
|
||||
* class for the specific database will extend and instantiate it.
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_result {
|
||||
|
||||
/**
|
||||
* Connection ID
|
||||
*
|
||||
* @var resource|object
|
||||
*/
|
||||
public $conn_id;
|
||||
|
||||
/**
|
||||
* Result ID
|
||||
*
|
||||
* @var resource|object
|
||||
*/
|
||||
public $result_id;
|
||||
|
||||
/**
|
||||
* Result Array
|
||||
*
|
||||
* @var array[]
|
||||
*/
|
||||
public $result_array = array();
|
||||
|
||||
/**
|
||||
* Result Object
|
||||
*
|
||||
* @var object[]
|
||||
*/
|
||||
public $result_object = array();
|
||||
|
||||
/**
|
||||
* Custom Result Object
|
||||
*
|
||||
* @var object[]
|
||||
*/
|
||||
public $custom_result_object = array();
|
||||
|
||||
/**
|
||||
* Current Row index
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $current_row = 0;
|
||||
|
||||
/**
|
||||
* Number of rows
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_rows;
|
||||
|
||||
/**
|
||||
* Row data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $row_data;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $driver_object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$driver_object)
|
||||
{
|
||||
$this->conn_id = $driver_object->conn_id;
|
||||
$this->result_id = $driver_object->result_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
if (is_int($this->num_rows))
|
||||
{
|
||||
return $this->num_rows;
|
||||
}
|
||||
elseif (count($this->result_array) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_array);
|
||||
}
|
||||
elseif (count($this->result_object) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_object);
|
||||
}
|
||||
|
||||
return $this->num_rows = count($this->result_array());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Query result. Acts as a wrapper function for the following functions.
|
||||
*
|
||||
* @param string $type 'object', 'array' or a custom class name
|
||||
* @return array
|
||||
*/
|
||||
public function result($type = 'object')
|
||||
{
|
||||
if ($type === 'array')
|
||||
{
|
||||
return $this->result_array();
|
||||
}
|
||||
elseif ($type === 'object')
|
||||
{
|
||||
return $this->result_object();
|
||||
}
|
||||
|
||||
return $this->custom_result_object($type);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Custom query result.
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return array
|
||||
*/
|
||||
public function custom_result_object($class_name)
|
||||
{
|
||||
if (isset($this->custom_result_object[$class_name]))
|
||||
{
|
||||
return $this->custom_result_object[$class_name];
|
||||
}
|
||||
elseif ( ! $this->result_id OR $this->num_rows === 0)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
// Don't fetch the result set again if we already have it
|
||||
$_data = NULL;
|
||||
if (($c = count($this->result_array)) > 0)
|
||||
{
|
||||
$_data = 'result_array';
|
||||
}
|
||||
elseif (($c = count($this->result_object)) > 0)
|
||||
{
|
||||
$_data = 'result_object';
|
||||
}
|
||||
|
||||
if ($_data !== NULL)
|
||||
{
|
||||
for ($i = 0; $i < $c; $i++)
|
||||
{
|
||||
$this->custom_result_object[$class_name][$i] = new $class_name();
|
||||
|
||||
foreach ($this->{$_data}[$i] as $key => $value)
|
||||
{
|
||||
$this->custom_result_object[$class_name][$i]->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->custom_result_object[$class_name];
|
||||
}
|
||||
|
||||
is_null($this->row_data) OR $this->data_seek(0);
|
||||
$this->custom_result_object[$class_name] = array();
|
||||
|
||||
while ($row = $this->_fetch_object($class_name))
|
||||
{
|
||||
$this->custom_result_object[$class_name][] = $row;
|
||||
}
|
||||
|
||||
return $this->custom_result_object[$class_name];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Query result. "object" version.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function result_object()
|
||||
{
|
||||
if (count($this->result_object) > 0)
|
||||
{
|
||||
return $this->result_object;
|
||||
}
|
||||
|
||||
// In the event that query caching is on, the result_id variable
|
||||
// will not be a valid resource so we'll simply return an empty
|
||||
// array.
|
||||
if ( ! $this->result_id OR $this->num_rows === 0)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
if (($c = count($this->result_array)) > 0)
|
||||
{
|
||||
for ($i = 0; $i < $c; $i++)
|
||||
{
|
||||
$this->result_object[$i] = (object) $this->result_array[$i];
|
||||
}
|
||||
|
||||
return $this->result_object;
|
||||
}
|
||||
|
||||
is_null($this->row_data) OR $this->data_seek(0);
|
||||
while ($row = $this->_fetch_object())
|
||||
{
|
||||
$this->result_object[] = $row;
|
||||
}
|
||||
|
||||
return $this->result_object;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Query result. "array" version.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function result_array()
|
||||
{
|
||||
if (count($this->result_array) > 0)
|
||||
{
|
||||
return $this->result_array;
|
||||
}
|
||||
|
||||
// In the event that query caching is on, the result_id variable
|
||||
// will not be a valid resource so we'll simply return an empty
|
||||
// array.
|
||||
if ( ! $this->result_id OR $this->num_rows === 0)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
if (($c = count($this->result_object)) > 0)
|
||||
{
|
||||
for ($i = 0; $i < $c; $i++)
|
||||
{
|
||||
$this->result_array[$i] = (array) $this->result_object[$i];
|
||||
}
|
||||
|
||||
return $this->result_array;
|
||||
}
|
||||
|
||||
is_null($this->row_data) OR $this->data_seek(0);
|
||||
while ($row = $this->_fetch_assoc())
|
||||
{
|
||||
$this->result_array[] = $row;
|
||||
}
|
||||
|
||||
return $this->result_array;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Row
|
||||
*
|
||||
* A wrapper method.
|
||||
*
|
||||
* @param mixed $n
|
||||
* @param string $type 'object' or 'array'
|
||||
* @return mixed
|
||||
*/
|
||||
public function row($n = 0, $type = 'object')
|
||||
{
|
||||
if ( ! is_numeric($n))
|
||||
{
|
||||
// We cache the row data for subsequent uses
|
||||
is_array($this->row_data) OR $this->row_data = $this->row_array(0);
|
||||
|
||||
// array_key_exists() instead of isset() to allow for NULL values
|
||||
if (empty($this->row_data) OR ! array_key_exists($n, $this->row_data))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $this->row_data[$n];
|
||||
}
|
||||
|
||||
if ($type === 'object') return $this->row_object($n);
|
||||
elseif ($type === 'array') return $this->row_array($n);
|
||||
|
||||
return $this->custom_row_object($n, $type);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Assigns an item into a particular column slot
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function set_row($key, $value = NULL)
|
||||
{
|
||||
// We cache the row data for subsequent uses
|
||||
if ( ! is_array($this->row_data))
|
||||
{
|
||||
$this->row_data = $this->row_array(0);
|
||||
}
|
||||
|
||||
if (is_array($key))
|
||||
{
|
||||
foreach ($key as $k => $v)
|
||||
{
|
||||
$this->row_data[$k] = $v;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($key !== '' && $value !== NULL)
|
||||
{
|
||||
$this->row_data[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a single result row - custom object version
|
||||
*
|
||||
* @param int $n
|
||||
* @param string $type
|
||||
* @return object
|
||||
*/
|
||||
public function custom_row_object($n, $type)
|
||||
{
|
||||
isset($this->custom_result_object[$type]) OR $this->custom_result_object($type);
|
||||
|
||||
if (count($this->custom_result_object[$type]) === 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($n !== $this->current_row && isset($this->custom_result_object[$type][$n]))
|
||||
{
|
||||
$this->current_row = $n;
|
||||
}
|
||||
|
||||
return $this->custom_result_object[$type][$this->current_row];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a single result row - object version
|
||||
*
|
||||
* @param int $n
|
||||
* @return object
|
||||
*/
|
||||
public function row_object($n = 0)
|
||||
{
|
||||
$result = $this->result_object();
|
||||
if (count($result) === 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($n !== $this->current_row && isset($result[$n]))
|
||||
{
|
||||
$this->current_row = $n;
|
||||
}
|
||||
|
||||
return $result[$this->current_row];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a single result row - array version
|
||||
*
|
||||
* @param int $n
|
||||
* @return array
|
||||
*/
|
||||
public function row_array($n = 0)
|
||||
{
|
||||
$result = $this->result_array();
|
||||
if (count($result) === 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($n !== $this->current_row && isset($result[$n]))
|
||||
{
|
||||
$this->current_row = $n;
|
||||
}
|
||||
|
||||
return $result[$this->current_row];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the "first" row
|
||||
*
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function first_row($type = 'object')
|
||||
{
|
||||
$result = $this->result($type);
|
||||
return (count($result) === 0) ? NULL : $result[0];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the "last" row
|
||||
*
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function last_row($type = 'object')
|
||||
{
|
||||
$result = $this->result($type);
|
||||
return (count($result) === 0) ? NULL : $result[count($result) - 1];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the "next" row
|
||||
*
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function next_row($type = 'object')
|
||||
{
|
||||
$result = $this->result($type);
|
||||
if (count($result) === 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return isset($result[$this->current_row + 1])
|
||||
? $result[++$this->current_row]
|
||||
: NULL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the "previous" row
|
||||
*
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function previous_row($type = 'object')
|
||||
{
|
||||
$result = $this->result($type);
|
||||
if (count($result) === 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (isset($result[$this->current_row - 1]))
|
||||
{
|
||||
--$this->current_row;
|
||||
}
|
||||
return $result[$this->current_row];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an unbuffered row and move pointer to next row
|
||||
*
|
||||
* @param string $type 'array', 'object' or a custom class name
|
||||
* @return mixed
|
||||
*/
|
||||
public function unbuffered_row($type = 'object')
|
||||
{
|
||||
if ($type === 'array')
|
||||
{
|
||||
return $this->_fetch_assoc();
|
||||
}
|
||||
elseif ($type === 'object')
|
||||
{
|
||||
return $this->_fetch_object();
|
||||
}
|
||||
|
||||
return $this->_fetch_object($type);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The following methods are normally overloaded by the identically named
|
||||
* methods in the platform-specific driver -- except when query caching
|
||||
* is used. When caching is enabled we do not load the other driver.
|
||||
* These functions are primarily here to prevent undefined function errors
|
||||
* when a cached result object is in use. They are not otherwise fully
|
||||
* operational due to the unavailability of the database resource IDs with
|
||||
* cached results.
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names.
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data.
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array.
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object.
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return new $class_name();
|
||||
}
|
||||
|
||||
}
|
||||
424
system/database/DB_utility.php
Normal file
424
system/database/DB_utility.php
Normal file
@ -0,0 +1,424 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Database Utility Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
abstract class CI_DB_utility {
|
||||
|
||||
/**
|
||||
* Database object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = FALSE;
|
||||
|
||||
/**
|
||||
* OPTIMIZE TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimize_table = FALSE;
|
||||
|
||||
/**
|
||||
* REPAIR TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_repair_table = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$db Database object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
$this->db =& $db;
|
||||
log_message('info', 'Database Utility Class Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List databases
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_databases()
|
||||
{
|
||||
// Is there a cached result?
|
||||
if (isset($this->db->data_cache['db_names']))
|
||||
{
|
||||
return $this->db->data_cache['db_names'];
|
||||
}
|
||||
elseif ($this->_list_databases === FALSE)
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
$this->db->data_cache['db_names'] = array();
|
||||
|
||||
$query = $this->db->query($this->_list_databases);
|
||||
if ($query === FALSE)
|
||||
{
|
||||
return $this->db->data_cache['db_names'];
|
||||
}
|
||||
|
||||
for ($i = 0, $query = $query->result_array(), $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$this->db->data_cache['db_names'][] = current($query[$i]);
|
||||
}
|
||||
|
||||
return $this->db->data_cache['db_names'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determine if a particular database exists
|
||||
*
|
||||
* @param string $database_name
|
||||
* @return bool
|
||||
*/
|
||||
public function database_exists($database_name)
|
||||
{
|
||||
return in_array($database_name, $this->list_databases());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Optimize Table
|
||||
*
|
||||
* @param string $table_name
|
||||
* @return mixed
|
||||
*/
|
||||
public function optimize_table($table_name)
|
||||
{
|
||||
if ($this->_optimize_table === FALSE)
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
$query = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name)));
|
||||
if ($query !== FALSE)
|
||||
{
|
||||
$query = $query->result_array();
|
||||
return current($query);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Optimize Database
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function optimize_database()
|
||||
{
|
||||
if ($this->_optimize_table === FALSE)
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($this->db->list_tables() as $table_name)
|
||||
{
|
||||
$res = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name)));
|
||||
if (is_bool($res))
|
||||
{
|
||||
return $res;
|
||||
}
|
||||
|
||||
// Build the result array...
|
||||
$res = $res->result_array();
|
||||
$res = current($res);
|
||||
$key = str_replace($this->db->database.'.', '', current($res));
|
||||
$keys = array_keys($res);
|
||||
unset($res[$keys[0]]);
|
||||
|
||||
$result[$key] = $res;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Repair Table
|
||||
*
|
||||
* @param string $table_name
|
||||
* @return mixed
|
||||
*/
|
||||
public function repair_table($table_name)
|
||||
{
|
||||
if ($this->_repair_table === FALSE)
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
$query = $this->db->query(sprintf($this->_repair_table, $this->db->escape_identifiers($table_name)));
|
||||
if (is_bool($query))
|
||||
{
|
||||
return $query;
|
||||
}
|
||||
|
||||
$query = $query->result_array();
|
||||
return current($query);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate CSV from a query result object
|
||||
*
|
||||
* @param object $query Query result object
|
||||
* @param string $delim Delimiter (default: ,)
|
||||
* @param string $newline Newline character (default: \n)
|
||||
* @param string $enclosure Enclosure (default: ")
|
||||
* @return string
|
||||
*/
|
||||
public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"')
|
||||
{
|
||||
if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
|
||||
{
|
||||
show_error('You must submit a valid result object');
|
||||
}
|
||||
|
||||
$out = '';
|
||||
// First generate the headings from the table column names
|
||||
foreach ($query->list_fields() as $name)
|
||||
{
|
||||
$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim;
|
||||
}
|
||||
|
||||
$out = substr($out, 0, -strlen($delim)).$newline;
|
||||
|
||||
// Next blast through the result array and build out the rows
|
||||
while ($row = $query->unbuffered_row('array'))
|
||||
{
|
||||
$line = array();
|
||||
foreach ($row as $item)
|
||||
{
|
||||
$line[] = $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure;
|
||||
}
|
||||
$out .= implode($delim, $line).$newline;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate XML data from a query result object
|
||||
*
|
||||
* @param object $query Query result object
|
||||
* @param array $params Any preferences
|
||||
* @return string
|
||||
*/
|
||||
public function xml_from_result($query, $params = array())
|
||||
{
|
||||
if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
|
||||
{
|
||||
show_error('You must submit a valid result object');
|
||||
}
|
||||
|
||||
// Set our default values
|
||||
foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val)
|
||||
{
|
||||
if ( ! isset($params[$key]))
|
||||
{
|
||||
$params[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// Create variables for convenience
|
||||
extract($params);
|
||||
|
||||
// Load the xml helper
|
||||
get_instance()->load->helper('xml');
|
||||
|
||||
// Generate the result
|
||||
$xml = '<'.$root.'>'.$newline;
|
||||
while ($row = $query->unbuffered_row())
|
||||
{
|
||||
$xml .= $tab.'<'.$element.'>'.$newline;
|
||||
foreach ($row as $key => $val)
|
||||
{
|
||||
$xml .= $tab.$tab.'<'.$key.'>'.xml_convert($val).'</'.$key.'>'.$newline;
|
||||
}
|
||||
$xml .= $tab.'</'.$element.'>'.$newline;
|
||||
}
|
||||
|
||||
return $xml.'</'.$root.'>'.$newline;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database Backup
|
||||
*
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function backup($params = array())
|
||||
{
|
||||
// If the parameters have not been submitted as an
|
||||
// array then we know that it is simply the table
|
||||
// name, which is a valid short cut.
|
||||
if (is_string($params))
|
||||
{
|
||||
$params = array('tables' => $params);
|
||||
}
|
||||
|
||||
// Set up our default preferences
|
||||
$prefs = array(
|
||||
'tables' => array(),
|
||||
'ignore' => array(),
|
||||
'filename' => '',
|
||||
'format' => 'gzip', // gzip, zip, txt
|
||||
'add_drop' => TRUE,
|
||||
'add_insert' => TRUE,
|
||||
'newline' => "\n",
|
||||
'foreign_key_checks' => TRUE
|
||||
);
|
||||
|
||||
// Did the user submit any preferences? If so set them....
|
||||
if (count($params) > 0)
|
||||
{
|
||||
foreach ($prefs as $key => $val)
|
||||
{
|
||||
if (isset($params[$key]))
|
||||
{
|
||||
$prefs[$key] = $params[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Are we backing up a complete database or individual tables?
|
||||
// If no table names were submitted we'll fetch the entire table list
|
||||
if (count($prefs['tables']) === 0)
|
||||
{
|
||||
$prefs['tables'] = $this->db->list_tables();
|
||||
}
|
||||
|
||||
// Validate the format
|
||||
if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE))
|
||||
{
|
||||
$prefs['format'] = 'txt';
|
||||
}
|
||||
|
||||
// Is the encoder supported? If not, we'll either issue an
|
||||
// error or use plain text depending on the debug settings
|
||||
if (($prefs['format'] === 'gzip' && ! function_exists('gzencode'))
|
||||
OR ($prefs['format'] === 'zip' && ! function_exists('gzcompress')))
|
||||
{
|
||||
if ($this->db->db_debug)
|
||||
{
|
||||
return $this->db->display_error('db_unsupported_compression');
|
||||
}
|
||||
|
||||
$prefs['format'] = 'txt';
|
||||
}
|
||||
|
||||
// Was a Zip file requested?
|
||||
if ($prefs['format'] === 'zip')
|
||||
{
|
||||
// Set the filename if not provided (only needed with Zip files)
|
||||
if ($prefs['filename'] === '')
|
||||
{
|
||||
$prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database)
|
||||
.date('Y-m-d_H-i', time()).'.sql';
|
||||
}
|
||||
else
|
||||
{
|
||||
// If they included the .zip file extension we'll remove it
|
||||
if (preg_match('|.+?\.zip$|', $prefs['filename']))
|
||||
{
|
||||
$prefs['filename'] = str_replace('.zip', '', $prefs['filename']);
|
||||
}
|
||||
|
||||
// Tack on the ".sql" file extension if needed
|
||||
if ( ! preg_match('|.+?\.sql$|', $prefs['filename']))
|
||||
{
|
||||
$prefs['filename'] .= '.sql';
|
||||
}
|
||||
}
|
||||
|
||||
// Load the Zip class and output it
|
||||
$CI =& get_instance();
|
||||
$CI->load->library('zip');
|
||||
$CI->zip->add_data($prefs['filename'], $this->_backup($prefs));
|
||||
return $CI->zip->get_zip();
|
||||
}
|
||||
elseif ($prefs['format'] === 'txt') // Was a text file requested?
|
||||
{
|
||||
return $this->_backup($prefs);
|
||||
}
|
||||
elseif ($prefs['format'] === 'gzip') // Was a Gzip file requested?
|
||||
{
|
||||
return gzencode($this->_backup($prefs));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
405
system/database/drivers/cubrid/cubrid_driver.php
Normal file
405
system/database/drivers/cubrid/cubrid_driver.php
Normal file
@ -0,0 +1,405 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 2.1.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CUBRID Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author Esen Sagynov
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_cubrid_driver extends CI_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'cubrid';
|
||||
|
||||
/**
|
||||
* Auto-commit flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $auto_commit = TRUE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '`';
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches))
|
||||
{
|
||||
if (stripos($matches[2], 'autocommit=off') !== FALSE)
|
||||
{
|
||||
$this->auto_commit = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If no port is defined by the user, use the default value
|
||||
empty($this->port) OR $this->port = 33000;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches))
|
||||
{
|
||||
$func = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url';
|
||||
return ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '')
|
||||
? $func($this->dsn, $this->username, $this->password)
|
||||
: $func($this->dsn);
|
||||
}
|
||||
|
||||
$func = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect';
|
||||
return ($this->username !== '')
|
||||
? $func($this->hostname, $this->port, $this->database, $this->username, $this->password)
|
||||
: $func($this->hostname, $this->port, $this->database);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reconnect
|
||||
*
|
||||
* Keep / reestablish the db connection if no queries have been
|
||||
* sent for a length of time exceeding the server's idle timeout
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reconnect()
|
||||
{
|
||||
if (cubrid_ping($this->conn_id) === FALSE)
|
||||
{
|
||||
$this->conn_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
return ( ! $this->conn_id OR ($version = cubrid_get_server_info($this->conn_id)) === FALSE)
|
||||
? FALSE
|
||||
: $this->data_cache['version'] = $version;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return cubrid_query($sql, $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
if (($autocommit = cubrid_get_autocommit($this->conn_id)) === NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
elseif ($autocommit === TRUE)
|
||||
{
|
||||
return cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
if ( ! cubrid_commit($this->conn_id))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id))
|
||||
{
|
||||
return cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
if ( ! cubrid_rollback($this->conn_id))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id))
|
||||
{
|
||||
cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependent string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return cubrid_real_escape_string($str, $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return cubrid_affected_rows();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return cubrid_insert_id($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SHOW TABLES';
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occurred.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => cubrid_errno($this->conn_id), 'message' => cubrid_error($this->conn_id));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FROM tables
|
||||
*
|
||||
* Groups tables in FROM clauses if needed, so there is no confusion
|
||||
* about operator precedence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _from_tables()
|
||||
{
|
||||
if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
|
||||
{
|
||||
return '('.implode(', ', $this->qb_from).')';
|
||||
}
|
||||
|
||||
return implode(', ', $this->qb_from);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
cubrid_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
||||
230
system/database/drivers/cubrid/cubrid_forge.php
Normal file
230
system/database/drivers/cubrid/cubrid_forge.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 2.1.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CUBRID Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author Esen Sagynov
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_cubrid_forge extends CI_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = FALSE;
|
||||
|
||||
/**
|
||||
* CREATE TABLE keys flag
|
||||
*
|
||||
* Whether table keys are created from within the
|
||||
* CREATE TABLE statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_create_table_keys = TRUE;
|
||||
|
||||
/**
|
||||
* DROP DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_database = FALSE;
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SHORT' => 'INTEGER',
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT',
|
||||
'BIGINT' => 'NUMERIC',
|
||||
'FLOAT' => 'DOUBLE',
|
||||
'REAL' => 'DOUBLE'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE ';
|
||||
$sqls[] = $sql.$alter_type.$this->_process_column($field[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
$extra_clause = isset($field['after'])
|
||||
? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
|
||||
|
||||
if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
|
||||
{
|
||||
$extra_clause = ' FIRST';
|
||||
}
|
||||
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['null']
|
||||
.$field['default']
|
||||
.$field['auto_increment']
|
||||
.$field['unique']
|
||||
.$extra_clause;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'LONGTEXT':
|
||||
$attributes['TYPE'] = 'STRING';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table (ignored)
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_indexes($table)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
if (is_array($this->keys[$i]))
|
||||
{
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( ! isset($this->fields[$this->keys[$i]]))
|
||||
{
|
||||
unset($this->keys[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
|
||||
|
||||
$sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
|
||||
.' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
|
||||
}
|
||||
|
||||
$this->keys = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
177
system/database/drivers/cubrid/cubrid_result.php
Normal file
177
system/database/drivers/cubrid/cubrid_result.php
Normal file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 2.1.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CUBRID Result Class
|
||||
*
|
||||
* This class extends the parent result class: CI_DB_result
|
||||
*
|
||||
* @category Database
|
||||
* @author Esen Sagynov
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_cubrid_result extends CI_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
return is_int($this->num_rows)
|
||||
? $this->num_rows
|
||||
: $this->num_rows = cubrid_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return cubrid_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
return cubrid_column_names($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = cubrid_field_name($this->result_id, $i);
|
||||
$retval[$i]->type = cubrid_field_type($this->result_id, $i);
|
||||
$retval[$i]->max_length = cubrid_field_len($this->result_id, $i);
|
||||
$retval[$i]->primary_key = (int) (strpos(cubrid_field_flags($this->result_id, $i), 'primary_key') !== FALSE);
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id) OR
|
||||
(get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id))))
|
||||
{
|
||||
cubrid_close_request($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return cubrid_data_seek($this->result_id, $n);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return cubrid_fetch_assoc($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return cubrid_fetch_object($this->result_id, $class_name);
|
||||
}
|
||||
|
||||
}
|
||||
79
system/database/drivers/cubrid/cubrid_utility.php
Normal file
79
system/database/drivers/cubrid/cubrid_utility.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 2.1.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* CUBRID Utility Class
|
||||
*
|
||||
* @category Database
|
||||
* @author Esen Sagynov
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_cubrid_utility extends CI_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_databases()
|
||||
{
|
||||
if (isset($this->db->data_cache['db_names']))
|
||||
{
|
||||
return $this->db->data_cache['db_names'];
|
||||
}
|
||||
|
||||
return $this->db->data_cache['db_names'] = cubrid_list_dbs($this->db->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CUBRID Export
|
||||
*
|
||||
* @param array Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// No SQL based support in CUBRID as of version 8.4.0. Database or
|
||||
// table backup can be performed using CUBRID Manager
|
||||
// database administration tool.
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
}
|
||||
11
system/database/drivers/cubrid/index.html
Normal file
11
system/database/drivers/cubrid/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
413
system/database/drivers/ibase/ibase_driver.php
Normal file
413
system/database/drivers/ibase/ibase_driver.php
Normal file
@ -0,0 +1,413 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Firebird/Interbase Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_ibase_driver extends CI_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'ibase';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RAND()', 'RAND()');
|
||||
|
||||
/**
|
||||
* IBase Transaction status flag
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $_ibase_trans;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
return ($persistent === TRUE)
|
||||
? ibase_pconnect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set)
|
||||
: ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
if (($service = ibase_service_attach($this->hostname, $this->username, $this->password)))
|
||||
{
|
||||
$this->data_cache['version'] = ibase_server_info($service, IBASE_SVC_SERVER_VERSION);
|
||||
|
||||
// Don't keep the service open
|
||||
ibase_service_detach($service);
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return ibase_query(isset($this->_ibase_trans) ? $this->_ibase_trans : $this->conn_id, $sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
if (($trans_handle = ibase_trans($this->conn_id)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->_ibase_trans = $trans_handle;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
if (ibase_commit($this->_ibase_trans))
|
||||
{
|
||||
$this->_ibase_trans = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
if (ibase_rollback($this->_ibase_trans))
|
||||
{
|
||||
$this->_ibase_trans = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return ibase_affected_rows($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @param string $generator_name
|
||||
* @param int $inc_by
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id($generator_name, $inc_by = 0)
|
||||
{
|
||||
//If a generator hasn't been used before it will return 0
|
||||
return ibase_gen_id('"'.$generator_name.'"', $inc_by);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT TRIM("RDB$RELATION_NAME") AS TABLE_NAME FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\'';
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' AND TRIM("RDB$RELATION_NAME") AS TABLE_NAME LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT TRIM("RDB$FIELD_NAME") AS COLUMN_NAME FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "rfields"."RDB$FIELD_NAME" AS "name",
|
||||
CASE "fields"."RDB$FIELD_TYPE"
|
||||
WHEN 7 THEN \'SMALLINT\'
|
||||
WHEN 8 THEN \'INTEGER\'
|
||||
WHEN 9 THEN \'QUAD\'
|
||||
WHEN 10 THEN \'FLOAT\'
|
||||
WHEN 11 THEN \'DFLOAT\'
|
||||
WHEN 12 THEN \'DATE\'
|
||||
WHEN 13 THEN \'TIME\'
|
||||
WHEN 14 THEN \'CHAR\'
|
||||
WHEN 16 THEN \'INT64\'
|
||||
WHEN 27 THEN \'DOUBLE\'
|
||||
WHEN 35 THEN \'TIMESTAMP\'
|
||||
WHEN 37 THEN \'VARCHAR\'
|
||||
WHEN 40 THEN \'CSTRING\'
|
||||
WHEN 261 THEN \'BLOB\'
|
||||
ELSE NULL
|
||||
END AS "type",
|
||||
"fields"."RDB$FIELD_LENGTH" AS "max_length",
|
||||
"rfields"."RDB$DEFAULT_VALUE" AS "default"
|
||||
FROM "RDB$RELATION_FIELDS" "rfields"
|
||||
JOIN "RDB$FIELDS" "fields" ON "rfields"."RDB$FIELD_SOURCE" = "fields"."RDB$FIELD_NAME"
|
||||
WHERE "rfields"."RDB$RELATION_NAME" = '.$this->escape($table).'
|
||||
ORDER BY "rfields"."RDB$FIELD_POSITION"';
|
||||
|
||||
return (($query = $this->query($sql)) !== FALSE)
|
||||
? $query->result_object()
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occurred.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => ibase_errcode(), 'message' => ibase_errmsg());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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;
|
||||
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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
// Limit clause depends on if Interbase or Firebird
|
||||
if (stripos($this->version(), 'firebird') !== FALSE)
|
||||
{
|
||||
$select = 'FIRST '.$this->qb_limit
|
||||
.($this->qb_offset ? ' SKIP '.$this->qb_offset : '');
|
||||
}
|
||||
else
|
||||
{
|
||||
$select = 'ROWS '
|
||||
.($this->qb_offset ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit);
|
||||
}
|
||||
|
||||
return preg_replace('`SELECT`i', 'SELECT '.$select, $sql, 1);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
ibase_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
||||
251
system/database/drivers/ibase/ibase_forge.php
Normal file
251
system/database/drivers/ibase/ibase_forge.php
Normal file
@ -0,0 +1,251 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Interbase/Firebird Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_ibase_forge extends CI_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* RENAME TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rename_table = FALSE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INTEGER' => 'INT64',
|
||||
'FLOAT' => 'DOUBLE PRECISION'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create database
|
||||
*
|
||||
* @param string $db_name
|
||||
* @return bool
|
||||
*/
|
||||
public function create_database($db_name)
|
||||
{
|
||||
// Firebird databases are flat files, so a path is required
|
||||
|
||||
// Hostname is needed for remote access
|
||||
empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name;
|
||||
|
||||
return parent::create_database('"'.$db_name.'"');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Drop database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function drop_database($db_name)
|
||||
{
|
||||
if ( ! ibase_drop_db($this->conn_id))
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
elseif ( ! empty($this->db->data_cache['db_names']))
|
||||
{
|
||||
$key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
|
||||
if ($key !== FALSE)
|
||||
{
|
||||
unset($this->db->data_cache['db_names'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (isset($field[$i]['type']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identififers($field[$i]['name'])
|
||||
.' TYPE '.$field[$i]['type'].$field[$i]['length'];
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['default']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' SET DEFAULT '.$field[$i]['default'];
|
||||
}
|
||||
|
||||
if (isset($field[$i]['null']))
|
||||
{
|
||||
$sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
|
||||
.($field[$i]['null'] === TRUE ? 'NULL' : '1')
|
||||
.' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
|
||||
.' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['null']
|
||||
.$field['unique']
|
||||
.$field['default'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
return;
|
||||
case 'BIGINT':
|
||||
$attributes['TYPE'] = 'INT64';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported
|
||||
}
|
||||
|
||||
}
|
||||
161
system/database/drivers/ibase/ibase_result.php
Normal file
161
system/database/drivers/ibase/ibase_result.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Interbase/Firebird Result Class
|
||||
*
|
||||
* This class extends the parent result class: CI_DB_result
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_ibase_result extends CI_DB_result {
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return ibase_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++)
|
||||
{
|
||||
$info = ibase_field_info($this->result_id, $i);
|
||||
$field_names[] = $info['name'];
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$info = ibase_field_info($this->result_id, $i);
|
||||
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $info['name'];
|
||||
$retval[$i]->type = $info['type'];
|
||||
$retval[$i]->max_length = $info['length'];
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
ibase_free_result($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
$row = ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS);
|
||||
|
||||
if ($class_name === 'stdClass' OR ! $row)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
|
||||
$class_name = new $class_name();
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
$class_name->$key = $value;
|
||||
}
|
||||
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
}
|
||||
69
system/database/drivers/ibase/ibase_utility.php
Normal file
69
system/database/drivers/ibase/ibase_utility.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Interbase/Firebird Utility Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_ibase_utility extends CI_DB_utility {
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param string $filename
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($filename)
|
||||
{
|
||||
if ($service = ibase_service_attach($this->db->hostname, $this->db->username, $this->db->password))
|
||||
{
|
||||
$res = ibase_backup($service, $this->db->database, $filename.'.fbk');
|
||||
|
||||
// Close the service connection
|
||||
ibase_service_detach($service);
|
||||
return $res;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
11
system/database/drivers/ibase/index.html
Normal file
11
system/database/drivers/ibase/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
system/database/drivers/index.html
Normal file
11
system/database/drivers/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
11
system/database/drivers/mssql/index.html
Normal file
11
system/database/drivers/mssql/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
518
system/database/drivers/mssql/mssql_driver.php
Normal file
518
system/database/drivers/mssql/mssql_driver.php
Normal file
@ -0,0 +1,518 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MS SQL Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mssql_driver extends CI_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'mssql';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('NEWID()', 'RAND(%d)');
|
||||
|
||||
/**
|
||||
* Quoted identifier flag
|
||||
*
|
||||
* Whether to use SQL-92 standard quoted identifier
|
||||
* (double quotes) or brackets for identifier escaping.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_quoted_identifier = TRUE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Appends the port number to the hostname, if needed.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if ( ! empty($this->port))
|
||||
{
|
||||
$this->hostname .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$this->conn_id = ($persistent)
|
||||
? mssql_pconnect($this->hostname, $this->username, $this->password)
|
||||
: mssql_connect($this->hostname, $this->username, $this->password);
|
||||
|
||||
if ( ! $this->conn_id)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
// Select the DB... assuming a database name is specified in the config file
|
||||
if ($this->database !== '' && ! $this->db_select())
|
||||
{
|
||||
log_message('error', 'Unable to select database: '.$this->database);
|
||||
|
||||
return ($this->db_debug === TRUE)
|
||||
? $this->display_error('db_unable_to_select', $this->database)
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// Determine how identifiers are escaped
|
||||
$query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
|
||||
$query = $query->row_array();
|
||||
$this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
|
||||
$this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select the database
|
||||
*
|
||||
* @param string $database
|
||||
* @return bool
|
||||
*/
|
||||
public function db_select($database = '')
|
||||
{
|
||||
if ($database === '')
|
||||
{
|
||||
$database = $this->database;
|
||||
}
|
||||
|
||||
// Note: Escaping is required in the event that the DB name
|
||||
// contains reserved characters.
|
||||
if (mssql_select_db('['.$database.']', $this->conn_id))
|
||||
{
|
||||
$this->database = $database;
|
||||
$this->data_cache = array();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return mixed resource if rows are returned, bool otherwise
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return mssql_query($sql, $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return $this->simple_query('BEGIN TRAN');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
return $this->simple_query('COMMIT TRAN');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
return $this->simple_query('ROLLBACK TRAN');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return mssql_rows_affected($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* Returns the last id created in the Identity column.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
$query = version_compare($this->version(), '8', '>=')
|
||||
? 'SELECT SCOPE_IDENTITY() AS last_id'
|
||||
: 'SELECT @@IDENTITY AS last_id';
|
||||
|
||||
$query = $this->query($query);
|
||||
$query = $query->row();
|
||||
return $query->last_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set client character set
|
||||
*
|
||||
* @param string $charset
|
||||
* @return bool
|
||||
*/
|
||||
protected function _db_set_charset($charset)
|
||||
{
|
||||
return (ini_set('mssql.charset', $charset) !== FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Version number query string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _version()
|
||||
{
|
||||
return "SELECT SERVERPROPERTY('ProductVersion') AS ver";
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT '.$this->escape_identifiers('name')
|
||||
.' FROM '.$this->escape_identifiers('sysobjects')
|
||||
.' WHERE '.$this->escape_identifiers('type')." = 'U'";
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql.' ORDER BY '.$this->escape_identifiers('name');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT COLUMN_NAME
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
$retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION;
|
||||
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occurred.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
// We need this because the error info is discarded by the
|
||||
// server the first time you request it, and query() already
|
||||
// calls error() once for logging purposes when a query fails.
|
||||
static $error = array('code' => 0, 'message' => NULL);
|
||||
|
||||
$message = mssql_get_last_message();
|
||||
if ( ! empty($message))
|
||||
{
|
||||
$error['code'] = $this->query('SELECT @@ERROR AS code')->row()->code;
|
||||
$error['message'] = $message;
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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 'TRUNCATE TABLE '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete';
|
||||
}
|
||||
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
$limit = $this->qb_offset + $this->qb_limit;
|
||||
|
||||
// As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported,
|
||||
// however an ORDER BY clause is required for it to work
|
||||
if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby))
|
||||
{
|
||||
$orderby = $this->_compile_order_by();
|
||||
|
||||
// We have to strip the ORDER BY clause
|
||||
$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
|
||||
if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
|
||||
{
|
||||
$select = '*'; // Inevitable
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use only field names and their aliases, everything else is out of our scope.
|
||||
$select = array();
|
||||
$field_regexp = ($this->_quoted_identifier)
|
||||
? '("[^\"]+")' : '(\[[^\]]+\])';
|
||||
for ($i = 0, $c = count($this->qb_select); $i < $c; $i++)
|
||||
{
|
||||
$select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m)
|
||||
? $m[1] : $this->qb_select[$i];
|
||||
}
|
||||
$select = implode(', ', $select);
|
||||
}
|
||||
|
||||
return 'SELECT '.$select." FROM (\n\n"
|
||||
.preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql)
|
||||
."\n\n) ".$this->escape_identifiers('CI_subquery')
|
||||
."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit;
|
||||
}
|
||||
|
||||
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $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)
|
||||
{
|
||||
// Multiple-value inserts are only supported as of SQL Server 2008
|
||||
if (version_compare($this->version(), '10', '>='))
|
||||
{
|
||||
return parent::_insert_batch($table, $keys, $values);
|
||||
}
|
||||
|
||||
return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
mssql_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
||||
151
system/database/drivers/mssql/mssql_forge.php
Normal file
151
system/database/drivers/mssql/mssql_forge.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MS SQL Forge Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mssql_forge extends CI_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT' => 'SMALLINT',
|
||||
'SMALLINT' => 'INT',
|
||||
'INT' => 'BIGINT',
|
||||
'REAL' => 'FLOAT'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
$sqls[] = $sql.$this->_process_column($field[$i]);
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE)
|
||||
{
|
||||
unset($attributes['CONSTRAINT']);
|
||||
}
|
||||
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INTEGER':
|
||||
$attributes['TYPE'] = 'INT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['auto_increment'] = ' IDENTITY(1,1)';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
198
system/database/drivers/mssql/mssql_result.php
Normal file
198
system/database/drivers/mssql/mssql_result.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MSSQL Result Class
|
||||
*
|
||||
* This class extends the parent result class: CI_DB_result
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mssql_result extends CI_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
return is_int($this->num_rows)
|
||||
? $this->num_rows
|
||||
: $this->num_rows = mssql_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return mssql_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
mssql_field_seek($this->result_id, 0);
|
||||
while ($field = mssql_fetch_field($this->result_id))
|
||||
{
|
||||
$field_names[] = $field->name;
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$field = mssql_fetch_field($this->result_id, $i);
|
||||
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $field->name;
|
||||
$retval[$i]->type = $field->type;
|
||||
$retval[$i]->max_length = $field->max_length;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id))
|
||||
{
|
||||
mssql_free_result($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return mssql_data_seek($this->result_id, $n);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return mssql_fetch_assoc($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
$row = mssql_fetch_object($this->result_id);
|
||||
|
||||
if ($class_name === 'stdClass' OR ! $row)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
|
||||
$class_name = new $class_name();
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
$class_name->$key = $value;
|
||||
}
|
||||
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
}
|
||||
77
system/database/drivers/mssql/mssql_utility.php
Normal file
77
system/database/drivers/mssql/mssql_utility.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MS SQL Utility Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mssql_utility extends CI_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = 'EXEC sp_helpdb'; // Can also be: EXEC sp_databases
|
||||
|
||||
/**
|
||||
* OPTIMIZE TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimize_table = 'ALTER INDEX all ON %s REORGANIZE';
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return bool
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
||||
11
system/database/drivers/mysql/index.html
Normal file
11
system/database/drivers/mysql/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
494
system/database/drivers/mysql/mysql_driver.php
Normal file
494
system/database/drivers/mysql/mysql_driver.php
Normal file
@ -0,0 +1,494 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MySQL Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mysql_driver extends CI_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'mysql';
|
||||
|
||||
/**
|
||||
* Compression flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $compress = FALSE;
|
||||
|
||||
/**
|
||||
* DELETE hack flag
|
||||
*
|
||||
* Whether to use the MySQL "delete hack" which allows the number
|
||||
* of affected rows to be shown. Uses a preg_replace when enabled,
|
||||
* adding a bit more processing to all queries.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $delete_hack = TRUE;
|
||||
|
||||
/**
|
||||
* Strict ON flag
|
||||
*
|
||||
* Whether we're running in strict SQL mode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $stricton;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '`';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if ( ! empty($this->port))
|
||||
{
|
||||
$this->hostname .= ':'.$this->port;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$client_flags = ($this->compress === FALSE) ? 0 : MYSQL_CLIENT_COMPRESS;
|
||||
|
||||
if ($this->encrypt === TRUE)
|
||||
{
|
||||
$client_flags = $client_flags | MYSQL_CLIENT_SSL;
|
||||
}
|
||||
|
||||
// Error suppression is necessary mostly due to PHP 5.5+ issuing E_DEPRECATED messages
|
||||
$this->conn_id = ($persistent === TRUE)
|
||||
? mysql_pconnect($this->hostname, $this->username, $this->password, $client_flags)
|
||||
: mysql_connect($this->hostname, $this->username, $this->password, TRUE, $client_flags);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
// Select the DB... assuming a database name is specified in the config file
|
||||
if ($this->database !== '' && ! $this->db_select())
|
||||
{
|
||||
log_message('error', 'Unable to select database: '.$this->database);
|
||||
|
||||
return ($this->db_debug === TRUE)
|
||||
? $this->display_error('db_unable_to_select', $this->database)
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
if (isset($this->stricton) && is_resource($this->conn_id))
|
||||
{
|
||||
if ($this->stricton)
|
||||
{
|
||||
$this->simple_query('SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->simple_query(
|
||||
'SET SESSION sql_mode =
|
||||
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
|
||||
@@sql_mode,
|
||||
"STRICT_ALL_TABLES,", ""),
|
||||
",STRICT_ALL_TABLES", ""),
|
||||
"STRICT_ALL_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES,", ""),
|
||||
",STRICT_TRANS_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES", "")'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reconnect
|
||||
*
|
||||
* Keep / reestablish the db connection if no queries have been
|
||||
* sent for a length of time exceeding the server's idle timeout
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reconnect()
|
||||
{
|
||||
if (mysql_ping($this->conn_id) === FALSE)
|
||||
{
|
||||
$this->conn_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select the database
|
||||
*
|
||||
* @param string $database
|
||||
* @return bool
|
||||
*/
|
||||
public function db_select($database = '')
|
||||
{
|
||||
if ($database === '')
|
||||
{
|
||||
$database = $this->database;
|
||||
}
|
||||
|
||||
if (mysql_select_db($database, $this->conn_id))
|
||||
{
|
||||
$this->database = $database;
|
||||
$this->data_cache = array();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set client character set
|
||||
*
|
||||
* @param string $charset
|
||||
* @return bool
|
||||
*/
|
||||
protected function _db_set_charset($charset)
|
||||
{
|
||||
return mysql_set_charset($charset, $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
if ( ! $this->conn_id OR ($version = mysql_get_server_info($this->conn_id)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $this->data_cache['version'] = $version;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return mysql_query($this->_prep_query($sql), $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Prep the query
|
||||
*
|
||||
* If needed, each database adapter can prep the query string
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return string
|
||||
*/
|
||||
protected function _prep_query($sql)
|
||||
{
|
||||
// mysql_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
|
||||
// modifies the query so that it a proper number of affected rows is returned.
|
||||
if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
|
||||
{
|
||||
return trim($sql).' WHERE 1=1';
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
$this->simple_query('SET AUTOCOMMIT=0');
|
||||
return $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
if ($this->simple_query('COMMIT'))
|
||||
{
|
||||
$this->simple_query('SET AUTOCOMMIT=1');
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
if ($this->simple_query('ROLLBACK'))
|
||||
{
|
||||
$this->simple_query('SET AUTOCOMMIT=1');
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependent string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return mysql_real_escape_string($str, $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return mysql_affected_rows($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return mysql_insert_id($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SHOW TABLES FROM '.$this->escape_identifiers($this->database);
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occurred.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => mysql_errno($this->conn_id), 'message' => mysql_error($this->conn_id));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FROM tables
|
||||
*
|
||||
* Groups tables in FROM clauses if needed, so there is no confusion
|
||||
* about operator precedence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _from_tables()
|
||||
{
|
||||
if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
|
||||
{
|
||||
return '('.implode(', ', $this->qb_from).')';
|
||||
}
|
||||
|
||||
return implode(', ', $this->qb_from);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
// Error suppression to avoid annoying E_WARNINGs in cases
|
||||
// where the connection has already been closed for some reason.
|
||||
@mysql_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
||||
243
system/database/drivers/mysql/mysql_forge.php
Normal file
243
system/database/drivers/mysql/mysql_forge.php
Normal file
@ -0,0 +1,243 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MySQL Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mysql_forge extends CI_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
|
||||
|
||||
/**
|
||||
* CREATE TABLE keys flag
|
||||
*
|
||||
* Whether table keys are created from within the
|
||||
* CREATE TABLE statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_create_table_keys = TRUE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT',
|
||||
'SMALLINT',
|
||||
'MEDIUMINT',
|
||||
'INT',
|
||||
'INTEGER',
|
||||
'BIGINT',
|
||||
'REAL',
|
||||
'DOUBLE',
|
||||
'DOUBLE PRECISION',
|
||||
'FLOAT',
|
||||
'DECIMAL',
|
||||
'NUMERIC'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CREATE TABLE attributes
|
||||
*
|
||||
* @param array $attributes Associative array of table attributes
|
||||
* @return string
|
||||
*/
|
||||
protected function _create_table_attr($attributes)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
foreach (array_keys($attributes) as $key)
|
||||
{
|
||||
if (is_string($key))
|
||||
{
|
||||
$sql .= ' '.strtoupper($key).' = '.$attributes[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET'))
|
||||
{
|
||||
$sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set;
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE'))
|
||||
{
|
||||
$sql .= ' COLLATE = '.$this->db->dbcollat;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP')
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$field[$i] = ($alter_type === 'ADD')
|
||||
? "\n\tADD ".$field[$i]['_literal']
|
||||
: "\n\tMODIFY ".$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($alter_type === 'ADD')
|
||||
{
|
||||
$field[$i]['_literal'] = "\n\tADD ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
|
||||
}
|
||||
|
||||
$field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return array($sql.implode(',', $field));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
$extra_clause = isset($field['after'])
|
||||
? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
|
||||
|
||||
if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
|
||||
{
|
||||
$extra_clause = ' FIRST';
|
||||
}
|
||||
|
||||
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['null']
|
||||
.$field['default']
|
||||
.$field['auto_increment']
|
||||
.$field['unique']
|
||||
.(empty($field['comment']) ? '' : ' COMMENT '.$field['comment'])
|
||||
.$extra_clause;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table (ignored)
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_indexes($table)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
if (is_array($this->keys[$i]))
|
||||
{
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( ! isset($this->fields[$this->keys[$i]]))
|
||||
{
|
||||
unset($this->keys[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
|
||||
|
||||
$sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
|
||||
.' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
|
||||
}
|
||||
|
||||
$this->keys = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
199
system/database/drivers/mysql/mysql_result.php
Normal file
199
system/database/drivers/mysql/mysql_result.php
Normal file
@ -0,0 +1,199 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MySQL Result Class
|
||||
*
|
||||
* This class extends the parent result class: CI_DB_result
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mysql_result extends CI_DB_result {
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$driver_object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$driver_object)
|
||||
{
|
||||
parent::__construct($driver_object);
|
||||
|
||||
// Required, due to mysql_data_seek() causing nightmares
|
||||
// with empty result sets
|
||||
$this->num_rows = mysql_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
return $this->num_rows;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return mysql_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
mysql_field_seek($this->result_id, 0);
|
||||
while ($field = mysql_fetch_field($this->result_id))
|
||||
{
|
||||
$field_names[] = $field->name;
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = mysql_field_name($this->result_id, $i);
|
||||
$retval[$i]->type = mysql_field_type($this->result_id, $i);
|
||||
$retval[$i]->max_length = mysql_field_len($this->result_id, $i);
|
||||
$retval[$i]->primary_key = (int) (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') !== FALSE);
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id))
|
||||
{
|
||||
mysql_free_result($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return $this->num_rows
|
||||
? mysql_data_seek($this->result_id, $n)
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return mysql_fetch_assoc($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return mysql_fetch_object($this->result_id, $class_name);
|
||||
}
|
||||
|
||||
}
|
||||
211
system/database/drivers/mysql/mysql_utility.php
Normal file
211
system/database/drivers/mysql/mysql_utility.php
Normal file
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MySQL Utility Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mysql_utility extends CI_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = 'SHOW DATABASES';
|
||||
|
||||
/**
|
||||
* OPTIMIZE TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimize_table = 'OPTIMIZE TABLE %s';
|
||||
|
||||
/**
|
||||
* REPAIR TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_repair_table = 'REPAIR TABLE %s';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
if (count($params) === 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Extract the prefs for simplicity
|
||||
extract($params);
|
||||
|
||||
// Build the output
|
||||
$output = '';
|
||||
|
||||
// Do we need to include a statement to disable foreign key checks?
|
||||
if ($foreign_key_checks === FALSE)
|
||||
{
|
||||
$output .= 'SET foreign_key_checks = 0;'.$newline;
|
||||
}
|
||||
|
||||
foreach ( (array) $tables as $table)
|
||||
{
|
||||
// Is the table in the "ignore" list?
|
||||
if (in_array($table, (array) $ignore, TRUE))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the table schema
|
||||
$query = $this->db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table));
|
||||
|
||||
// No result means the table name was invalid
|
||||
if ($query === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Write out the table schema
|
||||
$output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;
|
||||
|
||||
if ($add_drop === TRUE)
|
||||
{
|
||||
$output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$result = $query->result_array();
|
||||
foreach ($result[0] as $val)
|
||||
{
|
||||
if ($i++ % 2)
|
||||
{
|
||||
$output .= $val.';'.$newline.$newline;
|
||||
}
|
||||
}
|
||||
|
||||
// If inserts are not needed we're done...
|
||||
if ($add_insert === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Grab all the data from the current table
|
||||
$query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table));
|
||||
|
||||
if ($query->num_rows() === 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch the field names and determine if the field is an
|
||||
// integer type. We use this info to decide whether to
|
||||
// surround the data with quotes or not
|
||||
|
||||
$i = 0;
|
||||
$field_str = '';
|
||||
$is_int = array();
|
||||
while ($field = mysql_fetch_field($query->result_id))
|
||||
{
|
||||
// Most versions of MySQL store timestamp as a string
|
||||
$is_int[$i] = in_array(strtolower(mysql_field_type($query->result_id, $i)),
|
||||
array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
|
||||
TRUE);
|
||||
|
||||
// Create a string of field names
|
||||
$field_str .= $this->db->escape_identifiers($field->name).', ';
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Trim off the end comma
|
||||
$field_str = preg_replace('/, $/' , '', $field_str);
|
||||
|
||||
// Build the insert string
|
||||
foreach ($query->result_array() as $row)
|
||||
{
|
||||
$val_str = '';
|
||||
|
||||
$i = 0;
|
||||
foreach ($row as $v)
|
||||
{
|
||||
// Is the value NULL?
|
||||
if ($v === NULL)
|
||||
{
|
||||
$val_str .= 'NULL';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Escape the data if it's not an integer
|
||||
$val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v;
|
||||
}
|
||||
|
||||
// Append a comma
|
||||
$val_str .= ', ';
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Remove the comma at the end of the string
|
||||
$val_str = preg_replace('/, $/' , '', $val_str);
|
||||
|
||||
// Build the INSERT string
|
||||
$output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
|
||||
}
|
||||
|
||||
$output .= $newline.$newline;
|
||||
}
|
||||
|
||||
// Do we need to include a statement to re-enable foreign key checks?
|
||||
if ($foreign_key_checks === FALSE)
|
||||
{
|
||||
$output .= 'SET foreign_key_checks = 1;'.$newline;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
11
system/database/drivers/mysqli/index.html
Normal file
11
system/database/drivers/mysqli/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
544
system/database/drivers/mysqli/mysqli_driver.php
Normal file
544
system/database/drivers/mysqli/mysqli_driver.php
Normal file
@ -0,0 +1,544 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MySQLi Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mysqli_driver extends CI_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'mysqli';
|
||||
|
||||
/**
|
||||
* Compression flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $compress = FALSE;
|
||||
|
||||
/**
|
||||
* DELETE hack flag
|
||||
*
|
||||
* Whether to use the MySQL "delete hack" which allows the number
|
||||
* of affected rows to be shown. Uses a preg_replace when enabled,
|
||||
* adding a bit more processing to all queries.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $delete_hack = TRUE;
|
||||
|
||||
/**
|
||||
* Strict ON flag
|
||||
*
|
||||
* Whether we're running in strict SQL mode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $stricton;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '`';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* MySQLi object
|
||||
*
|
||||
* Has to be preserved without being assigned to $conn_id.
|
||||
*
|
||||
* @var MySQLi
|
||||
*/
|
||||
protected $_mysqli;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
// Do we have a socket path?
|
||||
if ($this->hostname[0] === '/')
|
||||
{
|
||||
$hostname = NULL;
|
||||
$port = NULL;
|
||||
$socket = $this->hostname;
|
||||
}
|
||||
else
|
||||
{
|
||||
$hostname = ($persistent === TRUE)
|
||||
? 'p:'.$this->hostname : $this->hostname;
|
||||
$port = empty($this->port) ? NULL : $this->port;
|
||||
$socket = NULL;
|
||||
}
|
||||
|
||||
$client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0;
|
||||
$this->_mysqli = mysqli_init();
|
||||
|
||||
$this->_mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
|
||||
|
||||
if (isset($this->stricton))
|
||||
{
|
||||
if ($this->stricton)
|
||||
{
|
||||
$this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_mysqli->options(MYSQLI_INIT_COMMAND,
|
||||
'SET SESSION sql_mode =
|
||||
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
|
||||
@@sql_mode,
|
||||
"STRICT_ALL_TABLES,", ""),
|
||||
",STRICT_ALL_TABLES", ""),
|
||||
"STRICT_ALL_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES,", ""),
|
||||
",STRICT_TRANS_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES", "")'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($this->encrypt))
|
||||
{
|
||||
$ssl = array();
|
||||
empty($this->encrypt['ssl_key']) OR $ssl['key'] = $this->encrypt['ssl_key'];
|
||||
empty($this->encrypt['ssl_cert']) OR $ssl['cert'] = $this->encrypt['ssl_cert'];
|
||||
empty($this->encrypt['ssl_ca']) OR $ssl['ca'] = $this->encrypt['ssl_ca'];
|
||||
empty($this->encrypt['ssl_capath']) OR $ssl['capath'] = $this->encrypt['ssl_capath'];
|
||||
empty($this->encrypt['ssl_cipher']) OR $ssl['cipher'] = $this->encrypt['ssl_cipher'];
|
||||
|
||||
if ( ! empty($ssl))
|
||||
{
|
||||
if (isset($this->encrypt['ssl_verify']))
|
||||
{
|
||||
if ($this->encrypt['ssl_verify'])
|
||||
{
|
||||
defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') && $this->_mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE);
|
||||
}
|
||||
// Apparently (when it exists), setting MYSQLI_OPT_SSL_VERIFY_SERVER_CERT
|
||||
// to FALSE didn't do anything, so PHP 5.6.16 introduced yet another
|
||||
// constant ...
|
||||
//
|
||||
// https://secure.php.net/ChangeLog-5.php#5.6.16
|
||||
// https://bugs.php.net/bug.php?id=68344
|
||||
elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT'))
|
||||
{
|
||||
$client_flags |= MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
|
||||
}
|
||||
}
|
||||
|
||||
$client_flags |= MYSQLI_CLIENT_SSL;
|
||||
$this->_mysqli->ssl_set(
|
||||
isset($ssl['key']) ? $ssl['key'] : NULL,
|
||||
isset($ssl['cert']) ? $ssl['cert'] : NULL,
|
||||
isset($ssl['ca']) ? $ssl['ca'] : NULL,
|
||||
isset($ssl['capath']) ? $ssl['capath'] : NULL,
|
||||
isset($ssl['cipher']) ? $ssl['cipher'] : NULL
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags))
|
||||
{
|
||||
// Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
|
||||
if (
|
||||
($client_flags & MYSQLI_CLIENT_SSL)
|
||||
&& version_compare($this->_mysqli->client_info, '5.7.3', '<=')
|
||||
&& empty($this->_mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value)
|
||||
)
|
||||
{
|
||||
$this->_mysqli->close();
|
||||
$message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!';
|
||||
log_message('error', $message);
|
||||
return ($this->db_debug) ? $this->display_error($message, '', TRUE) : FALSE;
|
||||
}
|
||||
|
||||
return $this->_mysqli;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reconnect
|
||||
*
|
||||
* Keep / reestablish the db connection if no queries have been
|
||||
* sent for a length of time exceeding the server's idle timeout
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reconnect()
|
||||
{
|
||||
if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE)
|
||||
{
|
||||
$this->conn_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select the database
|
||||
*
|
||||
* @param string $database
|
||||
* @return bool
|
||||
*/
|
||||
public function db_select($database = '')
|
||||
{
|
||||
if ($database === '')
|
||||
{
|
||||
$database = $this->database;
|
||||
}
|
||||
|
||||
if ($this->conn_id->select_db($database))
|
||||
{
|
||||
$this->database = $database;
|
||||
$this->data_cache = array();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set client character set
|
||||
*
|
||||
* @param string $charset
|
||||
* @return bool
|
||||
*/
|
||||
protected function _db_set_charset($charset)
|
||||
{
|
||||
return $this->conn_id->set_charset($charset);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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->server_info;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return $this->conn_id->query($this->_prep_query($sql));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Prep the query
|
||||
*
|
||||
* If needed, each database adapter can prep the query string
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return string
|
||||
*/
|
||||
protected function _prep_query($sql)
|
||||
{
|
||||
// mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
|
||||
// modifies the query so that it a proper number of affected rows is returned.
|
||||
if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
|
||||
{
|
||||
return trim($sql).' WHERE 1=1';
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
$this->conn_id->autocommit(FALSE);
|
||||
return is_php('5.5')
|
||||
? $this->conn_id->begin_transaction()
|
||||
: $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
if ($this->conn_id->commit())
|
||||
{
|
||||
$this->conn_id->autocommit(TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
if ($this->conn_id->rollback())
|
||||
{
|
||||
$this->conn_id->autocommit(TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependent string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return $this->conn_id->real_escape_string($str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return $this->conn_id->affected_rows;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return $this->conn_id->insert_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SHOW TABLES FROM '.$this->escape_identifiers($this->database);
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occurred.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
if ( ! empty($this->_mysqli->connect_errno))
|
||||
{
|
||||
return array(
|
||||
'code' => $this->_mysqli->connect_errno,
|
||||
'message' => $this->_mysqli->connect_error
|
||||
);
|
||||
}
|
||||
|
||||
return array('code' => $this->conn_id->errno, 'message' => $this->conn_id->error);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FROM tables
|
||||
*
|
||||
* Groups tables in FROM clauses if needed, so there is no confusion
|
||||
* about operator precedence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _from_tables()
|
||||
{
|
||||
if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
|
||||
{
|
||||
return '('.implode(', ', $this->qb_from).')';
|
||||
}
|
||||
|
||||
return implode(', ', $this->qb_from);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
$this->conn_id->close();
|
||||
}
|
||||
|
||||
}
|
||||
244
system/database/drivers/mysqli/mysqli_forge.php
Normal file
244
system/database/drivers/mysqli/mysqli_forge.php
Normal file
@ -0,0 +1,244 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MySQLi Forge Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mysqli_forge extends CI_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
|
||||
|
||||
/**
|
||||
* CREATE TABLE keys flag
|
||||
*
|
||||
* Whether table keys are created from within the
|
||||
* CREATE TABLE statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_create_table_keys = TRUE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT',
|
||||
'SMALLINT',
|
||||
'MEDIUMINT',
|
||||
'INT',
|
||||
'INTEGER',
|
||||
'BIGINT',
|
||||
'REAL',
|
||||
'DOUBLE',
|
||||
'DOUBLE PRECISION',
|
||||
'FLOAT',
|
||||
'DECIMAL',
|
||||
'NUMERIC'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CREATE TABLE attributes
|
||||
*
|
||||
* @param array $attributes Associative array of table attributes
|
||||
* @return string
|
||||
*/
|
||||
protected function _create_table_attr($attributes)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
foreach (array_keys($attributes) as $key)
|
||||
{
|
||||
if (is_string($key))
|
||||
{
|
||||
$sql .= ' '.strtoupper($key).' = '.$attributes[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET'))
|
||||
{
|
||||
$sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set;
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE'))
|
||||
{
|
||||
$sql .= ' COLLATE = '.$this->db->dbcollat;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP')
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$field[$i] = ($alter_type === 'ADD')
|
||||
? "\n\tADD ".$field[$i]['_literal']
|
||||
: "\n\tMODIFY ".$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($alter_type === 'ADD')
|
||||
{
|
||||
$field[$i]['_literal'] = "\n\tADD ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
|
||||
}
|
||||
|
||||
$field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return array($sql.implode(',', $field));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
$extra_clause = isset($field['after'])
|
||||
? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
|
||||
|
||||
if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
|
||||
{
|
||||
$extra_clause = ' FIRST';
|
||||
}
|
||||
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['null']
|
||||
.$field['default']
|
||||
.$field['auto_increment']
|
||||
.$field['unique']
|
||||
.(empty($field['comment']) ? '' : ' COMMENT '.$field['comment'])
|
||||
.$extra_clause;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table (ignored)
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_indexes($table)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
if (is_array($this->keys[$i]))
|
||||
{
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( ! isset($this->fields[$this->keys[$i]]))
|
||||
{
|
||||
unset($this->keys[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
|
||||
|
||||
$sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
|
||||
.' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
|
||||
}
|
||||
|
||||
$this->keys = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
232
system/database/drivers/mysqli/mysqli_result.php
Normal file
232
system/database/drivers/mysqli/mysqli_result.php
Normal file
@ -0,0 +1,232 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MySQLi Result Class
|
||||
*
|
||||
* This class extends the parent result class: CI_DB_result
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mysqli_result extends CI_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
return is_int($this->num_rows)
|
||||
? $this->num_rows
|
||||
: $this->num_rows = $this->result_id->num_rows;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return $this->result_id->field_count;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
$this->result_id->field_seek(0);
|
||||
while ($field = $this->result_id->fetch_field())
|
||||
{
|
||||
$field_names[] = $field->name;
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
$field_data = $this->result_id->fetch_fields();
|
||||
for ($i = 0, $c = count($field_data); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $field_data[$i]->name;
|
||||
$retval[$i]->type = static::_get_field_type($field_data[$i]->type);
|
||||
$retval[$i]->max_length = $field_data[$i]->max_length;
|
||||
$retval[$i]->primary_key = (int) ($field_data[$i]->flags & MYSQLI_PRI_KEY_FLAG);
|
||||
$retval[$i]->default = $field_data[$i]->def;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_object($this->result_id))
|
||||
{
|
||||
$this->result_id->free();
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return $this->result_id->data_seek($n);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return $this->result_id->fetch_assoc();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return $this->result_id->fetch_object($class_name);
|
||||
}
|
||||
|
||||
}
|
||||
211
system/database/drivers/mysqli/mysqli_utility.php
Normal file
211
system/database/drivers/mysqli/mysqli_utility.php
Normal file
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* MySQLi Utility Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_mysqli_utility extends CI_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = 'SHOW DATABASES';
|
||||
|
||||
/**
|
||||
* OPTIMIZE TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimize_table = 'OPTIMIZE TABLE %s';
|
||||
|
||||
/**
|
||||
* REPAIR TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_repair_table = 'REPAIR TABLE %s';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
if (count($params) === 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Extract the prefs for simplicity
|
||||
extract($params);
|
||||
|
||||
// Build the output
|
||||
$output = '';
|
||||
|
||||
// Do we need to include a statement to disable foreign key checks?
|
||||
if ($foreign_key_checks === FALSE)
|
||||
{
|
||||
$output .= 'SET foreign_key_checks = 0;'.$newline;
|
||||
}
|
||||
|
||||
foreach ( (array) $tables as $table)
|
||||
{
|
||||
// Is the table in the "ignore" list?
|
||||
if (in_array($table, (array) $ignore, TRUE))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the table schema
|
||||
$query = $this->db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table));
|
||||
|
||||
// No result means the table name was invalid
|
||||
if ($query === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Write out the table schema
|
||||
$output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;
|
||||
|
||||
if ($add_drop === TRUE)
|
||||
{
|
||||
$output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$result = $query->result_array();
|
||||
foreach ($result[0] as $val)
|
||||
{
|
||||
if ($i++ % 2)
|
||||
{
|
||||
$output .= $val.';'.$newline.$newline;
|
||||
}
|
||||
}
|
||||
|
||||
// If inserts are not needed we're done...
|
||||
if ($add_insert === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Grab all the data from the current table
|
||||
$query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table));
|
||||
|
||||
if ($query->num_rows() === 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch the field names and determine if the field is an
|
||||
// integer type. We use this info to decide whether to
|
||||
// surround the data with quotes or not
|
||||
|
||||
$i = 0;
|
||||
$field_str = '';
|
||||
$is_int = array();
|
||||
while ($field = $query->result_id->fetch_field())
|
||||
{
|
||||
// Most versions of MySQL store timestamp as a string
|
||||
$is_int[$i] = in_array($field->type, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_INT24, MYSQLI_TYPE_LONG), TRUE);
|
||||
|
||||
// Create a string of field names
|
||||
$field_str .= $this->db->escape_identifiers($field->name).', ';
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Trim off the end comma
|
||||
$field_str = preg_replace('/, $/' , '', $field_str);
|
||||
|
||||
// Build the insert string
|
||||
foreach ($query->result_array() as $row)
|
||||
{
|
||||
$val_str = '';
|
||||
|
||||
$i = 0;
|
||||
foreach ($row as $v)
|
||||
{
|
||||
// Is the value NULL?
|
||||
if ($v === NULL)
|
||||
{
|
||||
$val_str .= 'NULL';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Escape the data if it's not an integer
|
||||
$val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v;
|
||||
}
|
||||
|
||||
// Append a comma
|
||||
$val_str .= ', ';
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Remove the comma at the end of the string
|
||||
$val_str = preg_replace('/, $/' , '', $val_str);
|
||||
|
||||
// Build the INSERT string
|
||||
$output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
|
||||
}
|
||||
|
||||
$output .= $newline.$newline;
|
||||
}
|
||||
|
||||
// Do we need to include a statement to re-enable foreign key checks?
|
||||
if ($foreign_key_checks === FALSE)
|
||||
{
|
||||
$output .= 'SET foreign_key_checks = 1;'.$newline;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
11
system/database/drivers/oci8/index.html
Normal file
11
system/database/drivers/oci8/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
701
system/database/drivers/oci8/oci8_driver.php
Normal file
701
system/database/drivers/oci8/oci8_driver.php
Normal file
@ -0,0 +1,701 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.4.1
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* oci8 Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
|
||||
/**
|
||||
* oci8 Database Adapter Class
|
||||
*
|
||||
* This is a modification of the DB_driver class to
|
||||
* permit access to oracle databases
|
||||
*
|
||||
* @author Kelly McArdle
|
||||
*/
|
||||
class CI_DB_oci8_driver extends CI_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'oci8';
|
||||
|
||||
/**
|
||||
* Statement ID
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
public $stmt_id;
|
||||
|
||||
/**
|
||||
* Cursor ID
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
public $curs_id;
|
||||
|
||||
/**
|
||||
* Commit mode flag
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $commit_mode = OCI_COMMIT_ON_SUCCESS;
|
||||
|
||||
/**
|
||||
* Limit used flag
|
||||
*
|
||||
* If we use LIMIT, we'll add a field that will
|
||||
* throw off num_fields later.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $limit_used = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reset $stmt_id flag
|
||||
*
|
||||
* Used by stored_procedure() to prevent _execute() from
|
||||
* re-setting the statement ID.
|
||||
*/
|
||||
protected $_reset_stmt_id = TRUE;
|
||||
|
||||
/**
|
||||
* List of reserved identifiers
|
||||
*
|
||||
* Identifiers that must NOT be escaped.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_reserved_identifiers = array('*', 'rownum');
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('ASC', 'ASC'); // not currently supported
|
||||
|
||||
/**
|
||||
* COUNT string
|
||||
*
|
||||
* @used-by CI_DB_driver::count_all()
|
||||
* @used-by CI_DB_query_builder::count_all_results()
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_count_string = 'SELECT COUNT(1) AS ';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
$valid_dsns = array(
|
||||
'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS
|
||||
// Easy Connect string (Oracle 10g+)
|
||||
'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i',
|
||||
'in' => '/^[a-z0-9$_]+$/i' // Instance name (defined in tnsnames.ora)
|
||||
);
|
||||
|
||||
/* Space characters don't have any effect when actually
|
||||
* connecting, but can be a hassle while validating the DSN.
|
||||
*/
|
||||
$this->dsn = str_replace(array("\n", "\r", "\t", ' '), '', $this->dsn);
|
||||
|
||||
if ($this->dsn !== '')
|
||||
{
|
||||
foreach ($valid_dsns as $regexp)
|
||||
{
|
||||
if (preg_match($regexp, $this->dsn))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy support for TNS in the hostname configuration field
|
||||
$this->hostname = str_replace(array("\n", "\r", "\t", ' '), '', $this->hostname);
|
||||
if (preg_match($valid_dsns['tns'], $this->hostname))
|
||||
{
|
||||
$this->dsn = $this->hostname;
|
||||
return;
|
||||
}
|
||||
elseif ($this->hostname !== '' && strpos($this->hostname, '/') === FALSE && strpos($this->hostname, ':') === FALSE
|
||||
&& (( ! empty($this->port) && ctype_digit($this->port)) OR $this->database !== ''))
|
||||
{
|
||||
/* If the hostname field isn't empty, doesn't contain
|
||||
* ':' and/or '/' and if port and/or database aren't
|
||||
* empty, then the hostname field is most likely indeed
|
||||
* just a hostname. Therefore we'll try and build an
|
||||
* Easy Connect string from these 3 settings, assuming
|
||||
* that the database field is a service name.
|
||||
*/
|
||||
$this->dsn = $this->hostname
|
||||
.(( ! empty($this->port) && ctype_digit($this->port)) ? ':'.$this->port : '')
|
||||
.($this->database !== '' ? '/'.ltrim($this->database, '/') : '');
|
||||
|
||||
if (preg_match($valid_dsns['ec'], $this->dsn))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* At this point, we can only try and validate the hostname and
|
||||
* database fields separately as DSNs.
|
||||
*/
|
||||
if (preg_match($valid_dsns['ec'], $this->hostname) OR preg_match($valid_dsns['in'], $this->hostname))
|
||||
{
|
||||
$this->dsn = $this->hostname;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->database = str_replace(array("\n", "\r", "\t", ' '), '', $this->database);
|
||||
foreach ($valid_dsns as $regexp)
|
||||
{
|
||||
if (preg_match($regexp, $this->database))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Well - OK, an empty string should work as well.
|
||||
* PHP will try to use environment variables to
|
||||
* determine which Oracle instance to connect to.
|
||||
*/
|
||||
$this->dsn = '';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$func = ($persistent === TRUE) ? 'oci_pconnect' : 'oci_connect';
|
||||
return empty($this->char_set)
|
||||
? $func($this->username, $this->password, $this->dsn)
|
||||
: $func($this->username, $this->password, $this->dsn, $this->char_set);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
if ( ! $this->conn_id OR ($version_string = oci_server_version($this->conn_id)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
elseif (preg_match('#Release\s(\d+(?:\.\d+)+)#', $version_string, $match))
|
||||
{
|
||||
return $this->data_cache['version'] = $match[1];
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
/* Oracle must parse the query before it is run. All of the actions with
|
||||
* the query are based on the statement id returned by oci_parse().
|
||||
*/
|
||||
if ($this->_reset_stmt_id === TRUE)
|
||||
{
|
||||
$this->stmt_id = oci_parse($this->conn_id, $sql);
|
||||
}
|
||||
|
||||
oci_set_prefetch($this->stmt_id, 1000);
|
||||
return oci_execute($this->stmt_id, $this->commit_mode);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get cursor. Returns a cursor from the database
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function get_cursor()
|
||||
{
|
||||
return $this->curs_id = oci_new_cursor($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Stored Procedure. Executes a stored procedure
|
||||
*
|
||||
* @param string package name in which the stored procedure is in
|
||||
* @param string stored procedure name to execute
|
||||
* @param array parameters
|
||||
* @return mixed
|
||||
*
|
||||
* params array keys
|
||||
*
|
||||
* KEY OPTIONAL NOTES
|
||||
* name no the name of the parameter should be in :<param_name> format
|
||||
* value no the value of the parameter. If this is an OUT or IN OUT parameter,
|
||||
* this should be a reference to a variable
|
||||
* type yes the type of the parameter
|
||||
* length yes the max size of the parameter
|
||||
*/
|
||||
public function stored_procedure($package, $procedure, array $params)
|
||||
{
|
||||
if ($package === '' OR $procedure === '')
|
||||
{
|
||||
log_message('error', 'Invalid query: '.$package.'.'.$procedure);
|
||||
return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE;
|
||||
}
|
||||
|
||||
// Build the query string
|
||||
$sql = 'BEGIN '.$package.'.'.$procedure.'(';
|
||||
|
||||
$have_cursor = FALSE;
|
||||
foreach ($params as $param)
|
||||
{
|
||||
$sql .= $param['name'].',';
|
||||
|
||||
if (isset($param['type']) && $param['type'] === OCI_B_CURSOR)
|
||||
{
|
||||
$have_cursor = TRUE;
|
||||
}
|
||||
}
|
||||
$sql = trim($sql, ',').'); END;';
|
||||
|
||||
$this->_reset_stmt_id = FALSE;
|
||||
$this->stmt_id = oci_parse($this->conn_id, $sql);
|
||||
$this->_bind_params($params);
|
||||
$result = $this->query($sql, FALSE, $have_cursor);
|
||||
$this->_reset_stmt_id = TRUE;
|
||||
return $result;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Bind parameters
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
protected function _bind_params($params)
|
||||
{
|
||||
if ( ! is_array($params) OR ! is_resource($this->stmt_id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($params as $param)
|
||||
{
|
||||
foreach (array('name', 'value', 'type', 'length') as $val)
|
||||
{
|
||||
if ( ! isset($param[$val]))
|
||||
{
|
||||
$param[$val] = '';
|
||||
}
|
||||
}
|
||||
|
||||
oci_bind_by_name($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
$this->commit_mode = OCI_NO_AUTO_COMMIT;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
$this->commit_mode = OCI_COMMIT_ON_SUCCESS;
|
||||
|
||||
return oci_commit($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
$this->commit_mode = OCI_COMMIT_ON_SUCCESS;
|
||||
return oci_rollback($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return oci_num_rows($this->stmt_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
// not supported in oracle
|
||||
return $this->display_error('db_unsupported_function');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"';
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
if (strpos($table, '.') !== FALSE)
|
||||
{
|
||||
sscanf($table, '%[^.].%s', $owner, $table);
|
||||
}
|
||||
else
|
||||
{
|
||||
$owner = $this->username;
|
||||
}
|
||||
|
||||
return 'SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS
|
||||
WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).'
|
||||
AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (strpos($table, '.') !== FALSE)
|
||||
{
|
||||
sscanf($table, '%[^.].%s', $owner, $table);
|
||||
}
|
||||
else
|
||||
{
|
||||
$owner = $this->username;
|
||||
}
|
||||
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHAR_LENGTH, DATA_PRECISION, DATA_LENGTH, DATA_DEFAULT, NULLABLE
|
||||
FROM ALL_TAB_COLUMNS
|
||||
WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).'
|
||||
AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
|
||||
$length = ($query[$i]->CHAR_LENGTH > 0)
|
||||
? $query[$i]->CHAR_LENGTH : $query[$i]->DATA_PRECISION;
|
||||
if ($length === NULL)
|
||||
{
|
||||
$length = $query[$i]->DATA_LENGTH;
|
||||
}
|
||||
$retval[$i]->max_length = $length;
|
||||
|
||||
$default = $query[$i]->DATA_DEFAULT;
|
||||
if ($default === NULL && $query[$i]->NULLABLE === 'N')
|
||||
{
|
||||
$default = '';
|
||||
}
|
||||
$retval[$i]->default = $default;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occurred.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
// oci_error() returns an array that already contains
|
||||
// 'code' and 'message' keys, but it can return false
|
||||
// if there was no error ....
|
||||
if (is_resource($this->curs_id))
|
||||
{
|
||||
$error = oci_error($this->curs_id);
|
||||
}
|
||||
elseif (is_resource($this->stmt_id))
|
||||
{
|
||||
$error = oci_error($this->stmt_id);
|
||||
}
|
||||
elseif (is_resource($this->conn_id))
|
||||
{
|
||||
$error = oci_error($this->conn_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = oci_error();
|
||||
}
|
||||
|
||||
return is_array($error)
|
||||
? $error
|
||||
: array('code' => '', 'message' => '');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected function _insert_batch($table, $keys, $values)
|
||||
{
|
||||
$keys = implode(', ', $keys);
|
||||
$sql = "INSERT ALL\n";
|
||||
|
||||
for ($i = 0, $c = count($values); $i < $c; $i++)
|
||||
{
|
||||
$sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n";
|
||||
}
|
||||
|
||||
return $sql.'SELECT * FROM dual';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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 'TRUNCATE TABLE '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
$this->where('rownum <= ',$this->qb_limit, FALSE);
|
||||
$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)
|
||||
{
|
||||
if (version_compare($this->version(), '12.1', '>='))
|
||||
{
|
||||
// OFFSET-FETCH can be used only with the ORDER BY clause
|
||||
empty($this->qb_orderby) && $sql .= ' ORDER BY 1';
|
||||
|
||||
return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY';
|
||||
}
|
||||
|
||||
$this->limit_used = TRUE;
|
||||
return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')'
|
||||
.($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1) : '');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
187
system/database/drivers/oci8/oci8_forge.php
Normal file
187
system/database/drivers/oci8/oci8_forge.php
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.4.1
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Oracle Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_oci8_forge extends CI_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = FALSE;
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* DROP DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_database = FALSE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP')
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
elseif ($alter_type === 'CHANGE')
|
||||
{
|
||||
$alter_type = 'MODIFY';
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$field[$i] = "\n\t".$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
|
||||
|
||||
if ( ! empty($field[$i]['comment']))
|
||||
{
|
||||
$sqls[] = 'COMMENT ON COLUMN '
|
||||
.$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' IS '.$field[$i]['comment'];
|
||||
}
|
||||
|
||||
if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
|
||||
$field[$i] = "\n\t".$field[$i]['_literal'];
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= ' '.$alter_type.' ';
|
||||
$sql .= (count($field) === 1)
|
||||
? $field[0]
|
||||
: '('.implode(',', $field).')';
|
||||
|
||||
// RENAME COLUMN must be executed after MODIFY
|
||||
array_unshift($sqls, $sql);
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
229
system/database/drivers/oci8/oci8_result.php
Normal file
229
system/database/drivers/oci8/oci8_result.php
Normal file
@ -0,0 +1,229 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.4.1
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* oci8 Result Class
|
||||
*
|
||||
* This class extends the parent result class: CI_DB_result
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_oci8_result extends CI_DB_result {
|
||||
|
||||
/**
|
||||
* Statement ID
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
public $stmt_id;
|
||||
|
||||
/**
|
||||
* Cursor ID
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
public $curs_id;
|
||||
|
||||
/**
|
||||
* Limit used flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $limit_used;
|
||||
|
||||
/**
|
||||
* Commit mode flag
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $commit_mode;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$driver_object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$driver_object)
|
||||
{
|
||||
parent::__construct($driver_object);
|
||||
|
||||
$this->stmt_id = $driver_object->stmt_id;
|
||||
$this->curs_id = $driver_object->curs_id;
|
||||
$this->limit_used = $driver_object->limit_used;
|
||||
$this->commit_mode =& $driver_object->commit_mode;
|
||||
$driver_object->stmt_id = FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
$count = oci_num_fields($this->stmt_id);
|
||||
|
||||
// if we used a limit we subtract it
|
||||
return ($this->limit_used) ? $count - 1 : $count;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
|
||||
{
|
||||
$field_names[] = oci_field_name($this->stmt_id, $c);
|
||||
}
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
|
||||
{
|
||||
$F = new stdClass();
|
||||
$F->name = oci_field_name($this->stmt_id, $c);
|
||||
$F->type = oci_field_type($this->stmt_id, $c);
|
||||
$F->max_length = oci_field_size($this->stmt_id, $c);
|
||||
|
||||
$retval[] = $F;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id))
|
||||
{
|
||||
oci_free_statement($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
|
||||
if (is_resource($this->stmt_id))
|
||||
{
|
||||
oci_free_statement($this->stmt_id);
|
||||
}
|
||||
|
||||
if (is_resource($this->curs_id))
|
||||
{
|
||||
oci_cancel($this->curs_id);
|
||||
$this->curs_id = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
$id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
|
||||
return oci_fetch_assoc($id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
$row = ($this->curs_id)
|
||||
? oci_fetch_object($this->curs_id)
|
||||
: oci_fetch_object($this->stmt_id);
|
||||
|
||||
if ($class_name === 'stdClass' OR ! $row)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
|
||||
$class_name = new $class_name();
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
$class_name->$key = $value;
|
||||
}
|
||||
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
}
|
||||
68
system/database/drivers/oci8/oci8_utility.php
Normal file
68
system/database/drivers/oci8/oci8_utility.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.4.1
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Oracle Utility Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_oci8_utility extends CI_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = 'SELECT username FROM dba_users'; // Schemas are actual usernames
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
||||
11
system/database/drivers/odbc/index.html
Normal file
11
system/database/drivers/odbc/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
425
system/database/drivers/odbc/odbc_driver.php
Normal file
425
system/database/drivers/odbc/odbc_driver.php
Normal file
@ -0,0 +1,425 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* ODBC Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_odbc_driver extends CI_DB_driver {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'odbc';
|
||||
|
||||
/**
|
||||
* Database schema
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $schema = 'public';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* Must be empty for ODBC.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '';
|
||||
|
||||
/**
|
||||
* ESCAPE statement string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_like_escape_str = " {escape '%s'} ";
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RND()', 'RND(%d)');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
// Legacy support for DSN in the hostname field
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = $this->hostname;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
return ($persistent === TRUE)
|
||||
? odbc_pconnect($this->dsn, $this->username, $this->password)
|
||||
: odbc_connect($this->dsn, $this->username, $this->password);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
if ( ! isset($this->odbc_result))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return odbc_autocommit($this->conn_id, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
if (odbc_commit($this->conn_id))
|
||||
{
|
||||
odbc_autocommit($this->conn_id, TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
if (odbc_rollback($this->conn_id))
|
||||
{
|
||||
odbc_autocommit($this->conn_id, TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines if a query is a "write" type.
|
||||
*
|
||||
* @param string An SQL query string
|
||||
* @return bool
|
||||
*/
|
||||
public function is_write_type($sql)
|
||||
{
|
||||
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::is_write_type($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependent string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
$this->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return odbc_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'";
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data query
|
||||
*
|
||||
* Generates a platform-specific query so that the column data can be retrieved
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _field_data($table)
|
||||
{
|
||||
return 'SELECT TOP 1 FROM '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occurred.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
odbc_close($this->conn_id);
|
||||
}
|
||||
}
|
||||
86
system/database/drivers/odbc/odbc_forge.php
Normal file
86
system/database/drivers/odbc/odbc_forge.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* ODBC Forge Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/database/
|
||||
*/
|
||||
class CI_DB_odbc_forge extends CI_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported (in most databases at least)
|
||||
}
|
||||
|
||||
}
|
||||
268
system/database/drivers/odbc/odbc_result.php
Normal file
268
system/database/drivers/odbc/odbc_result.php
Normal file
@ -0,0 +1,268 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* ODBC Result Class
|
||||
*
|
||||
* This class extends the parent result class: CI_DB_result
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_odbc_result extends CI_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
if (is_int($this->num_rows))
|
||||
{
|
||||
return $this->num_rows;
|
||||
}
|
||||
elseif (($this->num_rows = odbc_num_rows($this->result_id)) !== -1)
|
||||
{
|
||||
return $this->num_rows;
|
||||
}
|
||||
|
||||
// Work-around for ODBC subdrivers that don't support num_rows()
|
||||
if (count($this->result_array) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_array);
|
||||
}
|
||||
elseif (count($this->result_object) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_object);
|
||||
}
|
||||
|
||||
return $this->num_rows = count($this->result_array());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return odbc_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
$num_fields = $this->num_fields();
|
||||
|
||||
if ($num_fields > 0)
|
||||
{
|
||||
for ($i = 1; $i <= $num_fields; $i++)
|
||||
{
|
||||
$field_names[] = odbc_field_name($this->result_id, $i);
|
||||
}
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = odbc_field_name($this->result_id, $odbc_index);
|
||||
$retval[$i]->type = odbc_field_type($this->result_id, $odbc_index);
|
||||
$retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index);
|
||||
$retval[$i]->primary_key = 0;
|
||||
$retval[$i]->default = '';
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id))
|
||||
{
|
||||
odbc_free_result($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return odbc_fetch_array($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
$row = odbc_fetch_object($this->result_id);
|
||||
|
||||
if ($class_name === 'stdClass' OR ! $row)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
|
||||
$class_name = new $class_name();
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
$class_name->$key = $value;
|
||||
}
|
||||
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('odbc_fetch_array'))
|
||||
{
|
||||
/**
|
||||
* ODBC Fetch array
|
||||
*
|
||||
* Emulates the native odbc_fetch_array() function when
|
||||
* it is not available (odbc_fetch_array() requires unixODBC)
|
||||
*
|
||||
* @param resource &$result
|
||||
* @param int $rownumber
|
||||
* @return array
|
||||
*/
|
||||
function odbc_fetch_array(&$result, $rownumber = 1)
|
||||
{
|
||||
$rs = array();
|
||||
if ( ! odbc_fetch_into($result, $rs, $rownumber))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$rs_assoc = array();
|
||||
foreach ($rs as $k => $v)
|
||||
{
|
||||
$field_name = odbc_field_name($result, $k+1);
|
||||
$rs_assoc[$field_name] = $v;
|
||||
}
|
||||
|
||||
return $rs_assoc;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('odbc_fetch_object'))
|
||||
{
|
||||
/**
|
||||
* ODBC Fetch object
|
||||
*
|
||||
* Emulates the native odbc_fetch_object() function when
|
||||
* it is not available.
|
||||
*
|
||||
* @param resource &$result
|
||||
* @param int $rownumber
|
||||
* @return object
|
||||
*/
|
||||
function odbc_fetch_object(&$result, $rownumber = 1)
|
||||
{
|
||||
$rs = array();
|
||||
if ( ! odbc_fetch_into($result, $rs, $rownumber))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$rs_object = new stdClass();
|
||||
foreach ($rs as $k => $v)
|
||||
{
|
||||
$field_name = odbc_field_name($result, $k+1);
|
||||
$rs_object->$field_name = $v;
|
||||
}
|
||||
|
||||
return $rs_object;
|
||||
}
|
||||
}
|
||||
63
system/database/drivers/odbc/odbc_utility.php
Normal file
63
system/database/drivers/odbc/odbc_utility.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* ODBC Utility Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/database/
|
||||
*/
|
||||
class CI_DB_odbc_utility extends CI_DB_utility {
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
||||
11
system/database/drivers/pdo/index.html
Normal file
11
system/database/drivers/pdo/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
329
system/database/drivers/pdo/pdo_driver.php
Normal file
329
system/database/drivers/pdo/pdo_driver.php
Normal file
@ -0,0 +1,329 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 2.1.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_driver extends CI_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'pdo';
|
||||
|
||||
/**
|
||||
* PDO Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $options = array();
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Validates the DSN string and/or detects the subdriver.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (preg_match('/([^:]+):/', $this->dsn, $match) && count($match) === 2)
|
||||
{
|
||||
// If there is a minimum valid dsn string pattern found, we're done
|
||||
// This is for general PDO users, who tend to have a full DSN string.
|
||||
$this->subdriver = $match[1];
|
||||
return;
|
||||
}
|
||||
// Legacy support for DSN specified in the hostname field
|
||||
elseif (preg_match('/([^:]+):/', $this->hostname, $match) && count($match) === 2)
|
||||
{
|
||||
$this->dsn = $this->hostname;
|
||||
$this->hostname = NULL;
|
||||
$this->subdriver = $match[1];
|
||||
return;
|
||||
}
|
||||
elseif (in_array($this->subdriver, array('mssql', 'sybase'), TRUE))
|
||||
{
|
||||
$this->subdriver = 'dblib';
|
||||
}
|
||||
elseif ($this->subdriver === '4D')
|
||||
{
|
||||
$this->subdriver = '4d';
|
||||
}
|
||||
elseif ( ! in_array($this->subdriver, array('4d', 'cubrid', 'dblib', 'firebird', 'ibm', 'informix', 'mysql', 'oci', 'odbc', 'pgsql', 'sqlite', 'sqlsrv'), TRUE))
|
||||
{
|
||||
log_message('error', 'PDO: Invalid or non-existent subdriver');
|
||||
|
||||
if ($this->db_debug)
|
||||
{
|
||||
show_error('Invalid or non-existent PDO subdriver');
|
||||
}
|
||||
}
|
||||
|
||||
$this->dsn = NULL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
if ($persistent === TRUE)
|
||||
{
|
||||
$this->options[PDO::ATTR_PERSISTENT] = TRUE;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new PDO($this->dsn, $this->username, $this->password, $this->options);
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
if ($this->db_debug && empty($this->failover))
|
||||
{
|
||||
$this->display_error($e->getMessage(), '', TRUE);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
// Not all subdrivers support the getAttribute() method
|
||||
try
|
||||
{
|
||||
return $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
return parent::version();
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql SQL query
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return $this->conn_id->query($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return $this->conn_id->beginTransaction();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
return $this->conn_id->commit();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
return $this->conn_id->rollBack();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependent string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
// Escape the string
|
||||
$str = $this->conn_id->quote($str);
|
||||
|
||||
// If there are duplicated quotes, trim them away
|
||||
return ($str[0] === "'")
|
||||
? substr($str, 1, -1)
|
||||
: $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return is_object($this->result_id) ? $this->result_id->rowCount() : 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @param string $name
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id($name = NULL)
|
||||
{
|
||||
return $this->conn_id->lastInsertId($name);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data query
|
||||
*
|
||||
* Generates a platform-specific query so that the column data can be retrieved
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _field_data($table)
|
||||
{
|
||||
return 'SELECT TOP 1 * FROM '.$this->protect_identifiers($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occurred.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
$error = array('code' => '00000', 'message' => '');
|
||||
$pdo_error = $this->conn_id->errorInfo();
|
||||
|
||||
if (empty($pdo_error[0]))
|
||||
{
|
||||
return $error;
|
||||
}
|
||||
|
||||
$error['code'] = isset($pdo_error[1]) ? $pdo_error[0].'/'.$pdo_error[1] : $pdo_error[0];
|
||||
if (isset($pdo_error[2]))
|
||||
{
|
||||
$error['message'] = $pdo_error[2];
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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 'TRUNCATE TABLE '.$table;
|
||||
}
|
||||
|
||||
}
|
||||
65
system/database/drivers/pdo/pdo_forge.php
Normal file
65
system/database/drivers/pdo/pdo_forge.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 2.1.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO Forge Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/database/
|
||||
*/
|
||||
class CI_DB_pdo_forge extends CI_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = FALSE;
|
||||
|
||||
}
|
||||
198
system/database/drivers/pdo/pdo_result.php
Normal file
198
system/database/drivers/pdo/pdo_result.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 2.1.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO Result Class
|
||||
*
|
||||
* This class extends the parent result class: CI_DB_result
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_result extends CI_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
if (is_int($this->num_rows))
|
||||
{
|
||||
return $this->num_rows;
|
||||
}
|
||||
elseif (count($this->result_array) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_array);
|
||||
}
|
||||
elseif (count($this->result_object) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_object);
|
||||
}
|
||||
elseif (($num_rows = $this->result_id->rowCount()) > 0)
|
||||
{
|
||||
return $this->num_rows = $num_rows;
|
||||
}
|
||||
|
||||
return $this->num_rows = count($this->result_array());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return $this->result_id->columnCount();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
// Might trigger an E_WARNING due to not all subdrivers
|
||||
// supporting getColumnMeta()
|
||||
$field_names[$i] = @$this->result_id->getColumnMeta($i);
|
||||
$field_names[$i] = $field_names[$i]['name'];
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
try
|
||||
{
|
||||
$retval = array();
|
||||
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$field = $this->result_id->getColumnMeta($i);
|
||||
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $field['name'];
|
||||
$retval[$i]->type = $field['native_type'];
|
||||
$retval[$i]->max_length = ($field['len'] > 0) ? $field['len'] : NULL;
|
||||
$retval[$i]->primary_key = (int) ( ! empty($field['flags']) && in_array('primary_key', $field['flags'], TRUE));
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
if ($this->db->db_debug)
|
||||
{
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_object($this->result_id))
|
||||
{
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return $this->result_id->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return $this->result_id->fetchObject($class_name);
|
||||
}
|
||||
|
||||
}
|
||||
63
system/database/drivers/pdo/pdo_utility.php
Normal file
63
system/database/drivers/pdo/pdo_utility.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 2.1.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO Utility Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/database/
|
||||
*/
|
||||
class CI_DB_pdo_utility extends CI_DB_utility {
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
||||
11
system/database/drivers/pdo/subdrivers/index.html
Normal file
11
system/database/drivers/pdo/subdrivers/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
200
system/database/drivers/pdo/subdrivers/pdo_4d_driver.php
Normal file
200
system/database/drivers/pdo/subdrivers/pdo_4d_driver.php
Normal file
@ -0,0 +1,200 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO 4D Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = '4d';
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_escape_char = array('[', ']');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = '4D:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
empty($this->port) OR $this->dsn .= ';port='.$this->port;
|
||||
empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 3) === FALSE)
|
||||
{
|
||||
$this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT '.$this->escape_identifiers('TABLE_NAME').' FROM '.$this->escape_identifiers('_USER_TABLES');
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' WHERE '.$this->escape_identifiers('TABLE_NAME')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT '.$this->escape_identifiers('COLUMN_NAME').' FROM '.$this->escape_identifiers('_USER_COLUMNS')
|
||||
.' WHERE '.$this->escape_identifiers('TABLE_NAME').' = '.$this->escape($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data query
|
||||
*
|
||||
* Generates a platform-specific query so that the column data can be retrieved
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _field_data($table)
|
||||
{
|
||||
return 'SELECT * FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' LIMIT 1';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : '');
|
||||
}
|
||||
|
||||
}
|
||||
217
system/database/drivers/pdo/subdrivers/pdo_4d_forge.php
Normal file
217
system/database/drivers/pdo/subdrivers/pdo_4d_forge.php
Normal file
@ -0,0 +1,217 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO 4D Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_4d_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = 'CREATE SCHEMA %s';
|
||||
|
||||
/**
|
||||
* DROP DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_database = 'DROP SCHEMA %s';
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
|
||||
|
||||
/**
|
||||
* RENAME TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rename_table = FALSE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = 'DROP TABLE IF EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'INT16' => 'INT',
|
||||
'SMALLINT' => 'INT',
|
||||
'INT' => 'INT64',
|
||||
'INT32' => 'INT64'
|
||||
);
|
||||
|
||||
/**
|
||||
* DEFAULT value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_default = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
// No method of modifying columns is supported
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['null']
|
||||
.$field['unique']
|
||||
.$field['auto_increment'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INTEGER':
|
||||
$attributes['TYPE'] = 'INT';
|
||||
return;
|
||||
case 'BIGINT':
|
||||
$attributes['TYPE'] = 'INT64';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute UNIQUE
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_unique(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
|
||||
{
|
||||
$field['unique'] = ' UNIQUE';
|
||||
|
||||
// UNIQUE must be used with NOT NULL
|
||||
$field['null'] = ' NOT NULL';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
|
||||
{
|
||||
if (stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['auto_increment'] = ' AUTO_INCREMENT';
|
||||
}
|
||||
elseif (strcasecmp($field['type'], 'UUID') === 0)
|
||||
{
|
||||
$field['auto_increment'] = ' AUTO_GENERATE';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
209
system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
Normal file
209
system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php
Normal file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO CUBRID Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'cubrid';
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '`';
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'cubrid:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
empty($this->port) OR $this->dsn .= ';port='.$this->port;
|
||||
empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SHOW TABLES';
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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 'TRUNCATE '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FROM tables
|
||||
*
|
||||
* Groups tables in FROM clauses if needed, so there is no confusion
|
||||
* about operator precedence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _from_tables()
|
||||
{
|
||||
if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
|
||||
{
|
||||
return '('.implode(', ', $this->qb_from).')';
|
||||
}
|
||||
|
||||
return implode(', ', $this->qb_from);
|
||||
}
|
||||
|
||||
}
|
||||
230
system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php
Normal file
230
system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO CUBRID Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_cubrid_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = FALSE;
|
||||
|
||||
/**
|
||||
* DROP DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_database = FALSE;
|
||||
|
||||
/**
|
||||
* CREATE TABLE keys flag
|
||||
*
|
||||
* Whether table keys are created from within the
|
||||
* CREATE TABLE statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_create_table_keys = TRUE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = 'DROP TABLE IF EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SHORT' => 'INTEGER',
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT',
|
||||
'BIGINT' => 'NUMERIC',
|
||||
'FLOAT' => 'DOUBLE',
|
||||
'REAL' => 'DOUBLE'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE ';
|
||||
$sqls[] = $sql.$alter_type.$this->_process_column($field[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
$extra_clause = isset($field['after'])
|
||||
? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
|
||||
|
||||
if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
|
||||
{
|
||||
$extra_clause = ' FIRST';
|
||||
}
|
||||
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['null']
|
||||
.$field['default']
|
||||
.$field['auto_increment']
|
||||
.$field['unique']
|
||||
.$extra_clause;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'LONGTEXT':
|
||||
$attributes['TYPE'] = 'STRING';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table (ignored)
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_indexes($table)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
if (is_array($this->keys[$i]))
|
||||
{
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( ! isset($this->fields[$this->keys[$i]]))
|
||||
{
|
||||
unset($this->keys[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
|
||||
|
||||
$sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
|
||||
.' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
|
||||
}
|
||||
|
||||
$this->keys = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
353
system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
Normal file
353
system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php
Normal file
@ -0,0 +1,353 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO DBLIB Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'dblib';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('NEWID()', 'RAND(%d)');
|
||||
|
||||
/**
|
||||
* Quoted identifier flag
|
||||
*
|
||||
* Whether to use SQL-92 standard quoted identifier
|
||||
* (double quotes) or brackets for identifier escaping.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_quoted_identifier;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = $params['subdriver'].':host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
if ( ! empty($this->port))
|
||||
{
|
||||
$this->dsn .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port;
|
||||
}
|
||||
|
||||
empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
empty($this->appname) OR $this->dsn .= ';appname='.$this->appname;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE)
|
||||
{
|
||||
$this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
|
||||
$this->subdriver = 'dblib';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
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))
|
||||
{
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// Determine how identifiers are escaped
|
||||
$query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
|
||||
$query = $query->row_array();
|
||||
$this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
|
||||
$this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT '.$this->escape_identifiers('name')
|
||||
.' FROM '.$this->escape_identifiers('sysobjects')
|
||||
.' WHERE '.$this->escape_identifiers('type')." = 'U'";
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql.' ORDER BY '.$this->escape_identifiers('name');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT COLUMN_NAME
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
$retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION;
|
||||
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete';
|
||||
}
|
||||
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
$limit = $this->qb_offset + $this->qb_limit;
|
||||
|
||||
// As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported,
|
||||
// however an ORDER BY clause is required for it to work
|
||||
if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby))
|
||||
{
|
||||
$orderby = $this->_compile_order_by();
|
||||
|
||||
// We have to strip the ORDER BY clause
|
||||
$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
|
||||
if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
|
||||
{
|
||||
$select = '*'; // Inevitable
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use only field names and their aliases, everything else is out of our scope.
|
||||
$select = array();
|
||||
$field_regexp = ($this->_quoted_identifier)
|
||||
? '("[^\"]+")' : '(\[[^\]]+\])';
|
||||
for ($i = 0, $c = count($this->qb_select); $i < $c; $i++)
|
||||
{
|
||||
$select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m)
|
||||
? $m[1] : $this->qb_select[$i];
|
||||
}
|
||||
$select = implode(', ', $select);
|
||||
}
|
||||
|
||||
return 'SELECT '.$select." FROM (\n\n"
|
||||
.preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql)
|
||||
."\n\n) ".$this->escape_identifiers('CI_subquery')
|
||||
."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit;
|
||||
}
|
||||
|
||||
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $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)
|
||||
{
|
||||
// Multiple-value inserts are only supported as of SQL Server 2008
|
||||
if (version_compare($this->version(), '10', '>='))
|
||||
{
|
||||
return parent::_insert_batch($table, $keys, $values);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
149
system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php
Normal file
149
system/database/drivers/pdo/subdrivers/pdo_dblib_forge.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO DBLIB Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_dblib_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT' => 'SMALLINT',
|
||||
'SMALLINT' => 'INT',
|
||||
'INT' => 'BIGINT',
|
||||
'REAL' => 'FLOAT'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
$sqls[] = $sql.$this->_process_column($field[$i]);
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE)
|
||||
{
|
||||
unset($attributes['CONSTRAINT']);
|
||||
}
|
||||
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INTEGER':
|
||||
$attributes['TYPE'] = 'INT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['auto_increment'] = ' IDENTITY(1,1)';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
279
system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
Normal file
279
system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php
Normal file
@ -0,0 +1,279 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO Firebird Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'firebird';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RAND()', 'RAND()');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'firebird:';
|
||||
|
||||
if ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'dbname='.$this->database;
|
||||
}
|
||||
elseif ( ! empty($this->hostname))
|
||||
{
|
||||
$this->dsn .= 'dbname='.$this->hostname;
|
||||
}
|
||||
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
empty($this->role) OR $this->dsn .= ';role='.$this->role;
|
||||
}
|
||||
elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 9) === FALSE)
|
||||
{
|
||||
$this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "RDB$RELATION_NAME" FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\'';
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT "RDB$FIELD_NAME" FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "rfields"."RDB$FIELD_NAME" AS "name",
|
||||
CASE "fields"."RDB$FIELD_TYPE"
|
||||
WHEN 7 THEN \'SMALLINT\'
|
||||
WHEN 8 THEN \'INTEGER\'
|
||||
WHEN 9 THEN \'QUAD\'
|
||||
WHEN 10 THEN \'FLOAT\'
|
||||
WHEN 11 THEN \'DFLOAT\'
|
||||
WHEN 12 THEN \'DATE\'
|
||||
WHEN 13 THEN \'TIME\'
|
||||
WHEN 14 THEN \'CHAR\'
|
||||
WHEN 16 THEN \'INT64\'
|
||||
WHEN 27 THEN \'DOUBLE\'
|
||||
WHEN 35 THEN \'TIMESTAMP\'
|
||||
WHEN 37 THEN \'VARCHAR\'
|
||||
WHEN 40 THEN \'CSTRING\'
|
||||
WHEN 261 THEN \'BLOB\'
|
||||
ELSE NULL
|
||||
END AS "type",
|
||||
"fields"."RDB$FIELD_LENGTH" AS "max_length",
|
||||
"rfields"."RDB$DEFAULT_VALUE" AS "default"
|
||||
FROM "RDB$RELATION_FIELDS" "rfields"
|
||||
JOIN "RDB$FIELDS" "fields" ON "rfields"."RDB$FIELD_SOURCE" = "fields"."RDB$FIELD_NAME"
|
||||
WHERE "rfields"."RDB$RELATION_NAME" = '.$this->escape($table).'
|
||||
ORDER BY "rfields"."RDB$FIELD_POSITION"';
|
||||
|
||||
return (($query = $this->query($sql)) !== FALSE)
|
||||
? $query->result_object()
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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;
|
||||
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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
// Limit clause depends on if Interbase or Firebird
|
||||
if (stripos($this->version(), 'firebird') !== FALSE)
|
||||
{
|
||||
$select = 'FIRST '.$this->qb_limit
|
||||
.($this->qb_offset > 0 ? ' SKIP '.$this->qb_offset : '');
|
||||
}
|
||||
else
|
||||
{
|
||||
$select = 'ROWS '
|
||||
.($this->qb_offset > 0 ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
237
system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php
Normal file
237
system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php
Normal file
@ -0,0 +1,237 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO Firebird Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_firebird_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* RENAME TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rename_table = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INTEGER' => 'INT64',
|
||||
'FLOAT' => 'DOUBLE PRECISION'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create database
|
||||
*
|
||||
* @param string $db_name
|
||||
* @return string
|
||||
*/
|
||||
public function create_database($db_name)
|
||||
{
|
||||
// Firebird databases are flat files, so a path is required
|
||||
|
||||
// Hostname is needed for remote access
|
||||
empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name;
|
||||
|
||||
return parent::create_database('"'.$db_name.'"');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Drop database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function drop_database($db_name)
|
||||
{
|
||||
if ( ! ibase_drop_db($this->conn_id))
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
elseif ( ! empty($this->db->data_cache['db_names']))
|
||||
{
|
||||
$key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
|
||||
if ($key !== FALSE)
|
||||
{
|
||||
unset($this->db->data_cache['db_names'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (isset($field[$i]['type']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TYPE '.$field[$i]['type'].$field[$i]['length'];
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['default']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' SET DEFAULT '.$field[$i]['default'];
|
||||
}
|
||||
|
||||
if (isset($field[$i]['null']))
|
||||
{
|
||||
$sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
|
||||
.($field[$i]['null'] === TRUE ? 'NULL' : '1')
|
||||
.' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
|
||||
.' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['null']
|
||||
.$field['unique']
|
||||
.$field['default'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
return;
|
||||
case 'BIGINT':
|
||||
$attributes['TYPE'] = 'INT64';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported
|
||||
}
|
||||
|
||||
}
|
||||
244
system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php
Normal file
244
system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php
Normal file
@ -0,0 +1,244 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO IBM DB2 Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'ibm';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'ibm:';
|
||||
|
||||
// Pre-defined DSN
|
||||
if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT))
|
||||
{
|
||||
if (isset($this->DSN))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->DSN;
|
||||
}
|
||||
elseif ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->database;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';';
|
||||
|
||||
if (isset($this->DATABASE))
|
||||
{
|
||||
$this->dsn .= 'DATABASE='.$this->DATABASE.';';
|
||||
}
|
||||
elseif ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'DATABASE='.$this->database.';';
|
||||
}
|
||||
|
||||
if (isset($this->HOSTNAME))
|
||||
{
|
||||
$this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';');
|
||||
}
|
||||
|
||||
if (isset($this->PORT))
|
||||
{
|
||||
$this->dsn .= 'PORT='.$this->port.';';
|
||||
}
|
||||
elseif ( ! empty($this->port))
|
||||
{
|
||||
$this->dsn .= ';PORT='.$this->port.';';
|
||||
}
|
||||
|
||||
$this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;');
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "tabname" FROM "syscat"."tables"
|
||||
WHERE "type" = \'T\' AND LOWER("tabschema") = '.$this->escape(strtolower($this->database));
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND "tabname" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT "colname" FROM "syscat"."columns"
|
||||
WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).'
|
||||
AND LOWER("tabname") = '.$this->escape(strtolower($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "colname" AS "name", "typename" AS "type", "default" AS "default", "length" AS "max_length",
|
||||
CASE "keyseq" WHEN NULL THEN 0 ELSE 1 END AS "primary_key"
|
||||
FROM "syscat"."columns"
|
||||
WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).'
|
||||
AND LOWER("tabname") = '.$this->escape(strtolower($table)).'
|
||||
ORDER BY "colno"';
|
||||
|
||||
return (($query = $this->query($sql)) !== FALSE)
|
||||
? $query->result_object()
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
$sql .= ' FETCH FIRST '.($this->qb_limit + $this->qb_offset).' ROWS ONLY';
|
||||
|
||||
return ($this->qb_offset)
|
||||
? 'SELECT * FROM ('.$sql.') WHERE rownum > '.$this->qb_offset
|
||||
: $sql;
|
||||
}
|
||||
|
||||
}
|
||||
154
system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php
Normal file
154
system/database/drivers/pdo/subdrivers/pdo_ibm_forge.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO IBM DB2 Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_ibm_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* RENAME TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rename_table = 'RENAME TABLE %s TO %s';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT'
|
||||
);
|
||||
|
||||
/**
|
||||
* DEFAULT value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_default = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'CHANGE')
|
||||
{
|
||||
$alter_type = 'MODIFY';
|
||||
}
|
||||
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute UNIQUE
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_unique(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
|
||||
{
|
||||
$field['unique'] = ' UNIQUE';
|
||||
|
||||
// UNIQUE must be used with NOT NULL
|
||||
$field['null'] = ' NOT NULL';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported
|
||||
}
|
||||
|
||||
}
|
||||
309
system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
Normal file
309
system/database/drivers/pdo/subdrivers/pdo_informix_driver.php
Normal file
@ -0,0 +1,309 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO Informix Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'informix';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('ASC', 'ASC'); // Currently not supported
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'informix:';
|
||||
|
||||
// Pre-defined DSN
|
||||
if (empty($this->hostname) && empty($this->host) && empty($this->port) && empty($this->service))
|
||||
{
|
||||
if (isset($this->DSN))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->DSN;
|
||||
}
|
||||
elseif ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->database;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->host))
|
||||
{
|
||||
$this->dsn .= 'host='.$this->host;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dsn .= 'host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
}
|
||||
|
||||
if (isset($this->service))
|
||||
{
|
||||
$this->dsn .= '; service='.$this->service;
|
||||
}
|
||||
elseif ( ! empty($this->port))
|
||||
{
|
||||
$this->dsn .= '; service='.$this->port;
|
||||
}
|
||||
|
||||
empty($this->database) OR $this->dsn .= '; database='.$this->database;
|
||||
empty($this->server) OR $this->dsn .= '; server='.$this->server;
|
||||
|
||||
$this->dsn .= '; protocol='.(isset($this->protocol) ? $this->protocol : 'onsoctcp')
|
||||
.'; EnableScrollableCursors=1';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "tabname" FROM "systables"
|
||||
WHERE "tabid" > 99 AND "tabtype" = \'T\' AND LOWER("owner") = '.$this->escape(strtolower($this->username));
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND "tabname" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
if (strpos($table, '.') !== FALSE)
|
||||
{
|
||||
sscanf($table, '%[^.].%s', $owner, $table);
|
||||
}
|
||||
else
|
||||
{
|
||||
$owner = $this->username;
|
||||
}
|
||||
|
||||
return 'SELECT "colname" FROM "systables", "syscolumns"
|
||||
WHERE "systables"."tabid" = "syscolumns"."tabid"
|
||||
AND "systables"."tabtype" = \'T\'
|
||||
AND LOWER("systables"."owner") = '.$this->escape(strtolower($owner)).'
|
||||
AND LOWER("systables"."tabname") = '.$this->escape(strtolower($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "syscolumns"."colname" AS "name",
|
||||
CASE "syscolumns"."coltype"
|
||||
WHEN 0 THEN \'CHAR\'
|
||||
WHEN 1 THEN \'SMALLINT\'
|
||||
WHEN 2 THEN \'INTEGER\'
|
||||
WHEN 3 THEN \'FLOAT\'
|
||||
WHEN 4 THEN \'SMALLFLOAT\'
|
||||
WHEN 5 THEN \'DECIMAL\'
|
||||
WHEN 6 THEN \'SERIAL\'
|
||||
WHEN 7 THEN \'DATE\'
|
||||
WHEN 8 THEN \'MONEY\'
|
||||
WHEN 9 THEN \'NULL\'
|
||||
WHEN 10 THEN \'DATETIME\'
|
||||
WHEN 11 THEN \'BYTE\'
|
||||
WHEN 12 THEN \'TEXT\'
|
||||
WHEN 13 THEN \'VARCHAR\'
|
||||
WHEN 14 THEN \'INTERVAL\'
|
||||
WHEN 15 THEN \'NCHAR\'
|
||||
WHEN 16 THEN \'NVARCHAR\'
|
||||
WHEN 17 THEN \'INT8\'
|
||||
WHEN 18 THEN \'SERIAL8\'
|
||||
WHEN 19 THEN \'SET\'
|
||||
WHEN 20 THEN \'MULTISET\'
|
||||
WHEN 21 THEN \'LIST\'
|
||||
WHEN 22 THEN \'Unnamed ROW\'
|
||||
WHEN 40 THEN \'LVARCHAR\'
|
||||
WHEN 41 THEN \'BLOB/CLOB/BOOLEAN\'
|
||||
WHEN 4118 THEN \'Named ROW\'
|
||||
ELSE "syscolumns"."coltype"
|
||||
END AS "type",
|
||||
"syscolumns"."collength" as "max_length",
|
||||
CASE "sysdefaults"."type"
|
||||
WHEN \'L\' THEN "sysdefaults"."default"
|
||||
ELSE NULL
|
||||
END AS "default"
|
||||
FROM "syscolumns", "systables", "sysdefaults"
|
||||
WHERE "syscolumns"."tabid" = "systables"."tabid"
|
||||
AND "systables"."tabid" = "sysdefaults"."tabid"
|
||||
AND "syscolumns"."colno" = "sysdefaults"."colno"
|
||||
AND "systables"."tabtype" = \'T\'
|
||||
AND LOWER("systables"."owner") = '.$this->escape(strtolower($this->username)).'
|
||||
AND LOWER("systables"."tabname") = '.$this->escape(strtolower($table)).'
|
||||
ORDER BY "syscolumns"."colno"';
|
||||
|
||||
return (($query = $this->query($sql)) !== FALSE)
|
||||
? $query->result_object()
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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 'TRUNCATE TABLE ONLY '.$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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql $SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
$select = 'SELECT '.($this->qb_offset ? 'SKIP '.$this->qb_offset : '').'FIRST '.$this->qb_limit.' ';
|
||||
return preg_replace('/^(SELECT\s)/i', $select, $sql, 1);
|
||||
}
|
||||
|
||||
}
|
||||
163
system/database/drivers/pdo/subdrivers/pdo_informix_forge.php
Normal file
163
system/database/drivers/pdo/subdrivers/pdo_informix_forge.php
Normal file
@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO Informix Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_informix_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* RENAME TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rename_table = 'RENAME TABLE %s TO %s';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT',
|
||||
'REAL' => 'DOUBLE PRECISION',
|
||||
'SMALLFLOAT' => 'DOUBLE PRECISION'
|
||||
);
|
||||
|
||||
/**
|
||||
* DEFAULT value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_default = ', ';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'CHANGE')
|
||||
{
|
||||
$alter_type = 'MODIFY';
|
||||
}
|
||||
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'BYTE':
|
||||
case 'TEXT':
|
||||
case 'BLOB':
|
||||
case 'CLOB':
|
||||
$attributes['UNIQUE'] = FALSE;
|
||||
if (isset($attributes['DEFAULT']))
|
||||
{
|
||||
unset($attributes['DEFAULT']);
|
||||
}
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute UNIQUE
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_unique(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
|
||||
{
|
||||
$field['unique'] = ' UNIQUE CONSTRAINT '.$this->db->escape_identifiers($field['name']);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported
|
||||
}
|
||||
|
||||
}
|
||||
374
system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
Normal file
374
system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
Normal file
@ -0,0 +1,374 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO MySQL Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'mysql';
|
||||
|
||||
/**
|
||||
* Compression flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $compress = FALSE;
|
||||
|
||||
/**
|
||||
* Strict ON flag
|
||||
*
|
||||
* Whether we're running in strict SQL mode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $stricton;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '`';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'mysql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
empty($this->port) OR $this->dsn .= ';port='.$this->port;
|
||||
empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE)
|
||||
{
|
||||
$this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
if (isset($this->stricton))
|
||||
{
|
||||
if ($this->stricton)
|
||||
{
|
||||
$sql = 'CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
|
||||
@@sql_mode,
|
||||
"STRICT_ALL_TABLES,", ""),
|
||||
",STRICT_ALL_TABLES", ""),
|
||||
"STRICT_ALL_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES,", ""),
|
||||
",STRICT_TRANS_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES", "")';
|
||||
}
|
||||
|
||||
if ( ! empty($sql))
|
||||
{
|
||||
if (empty($this->options[PDO::MYSQL_ATTR_INIT_COMMAND]))
|
||||
{
|
||||
$this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode = '.$sql;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->options[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', @@session.sql_mode = '.$sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->compress === TRUE)
|
||||
{
|
||||
$this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE;
|
||||
}
|
||||
|
||||
if (is_array($this->encrypt))
|
||||
{
|
||||
$ssl = array();
|
||||
empty($this->encrypt['ssl_key']) OR $ssl[PDO::MYSQL_ATTR_SSL_KEY] = $this->encrypt['ssl_key'];
|
||||
empty($this->encrypt['ssl_cert']) OR $ssl[PDO::MYSQL_ATTR_SSL_CERT] = $this->encrypt['ssl_cert'];
|
||||
empty($this->encrypt['ssl_ca']) OR $ssl[PDO::MYSQL_ATTR_SSL_CA] = $this->encrypt['ssl_ca'];
|
||||
empty($this->encrypt['ssl_capath']) OR $ssl[PDO::MYSQL_ATTR_SSL_CAPATH] = $this->encrypt['ssl_capath'];
|
||||
empty($this->encrypt['ssl_cipher']) OR $ssl[PDO::MYSQL_ATTR_SSL_CIPHER] = $this->encrypt['ssl_cipher'];
|
||||
|
||||
// DO NOT use array_merge() here!
|
||||
// It re-indexes numeric keys and the PDO_MYSQL_ATTR_SSL_* constants are integers.
|
||||
empty($ssl) OR $this->options += $ssl;
|
||||
}
|
||||
|
||||
// Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
|
||||
if (
|
||||
($pdo = parent::db_connect($persistent)) !== FALSE
|
||||
&& ! empty($ssl)
|
||||
&& version_compare($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), '5.7.3', '<=')
|
||||
&& empty($pdo->query("SHOW STATUS LIKE 'ssl_cipher'")->fetchObject()->Value)
|
||||
)
|
||||
{
|
||||
$message = 'PDO_MYSQL was configured for an SSL connection, but got an unencrypted connection instead!';
|
||||
log_message('error', $message);
|
||||
return ($this->db_debug) ? $this->display_error($message, '', TRUE) : FALSE;
|
||||
}
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select the database
|
||||
*
|
||||
* @param string $database
|
||||
* @return bool
|
||||
*/
|
||||
public function db_select($database = '')
|
||||
{
|
||||
if ($database === '')
|
||||
{
|
||||
$database = $this->database;
|
||||
}
|
||||
|
||||
if (FALSE !== $this->simple_query('USE '.$this->escape_identifiers($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 FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SHOW TABLES';
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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 'TRUNCATE '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FROM tables
|
||||
*
|
||||
* Groups tables in FROM clauses if needed, so there is no confusion
|
||||
* about operator precedence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _from_tables()
|
||||
{
|
||||
if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
|
||||
{
|
||||
return '('.implode(', ', $this->qb_from).')';
|
||||
}
|
||||
|
||||
return implode(', ', $this->qb_from);
|
||||
}
|
||||
|
||||
}
|
||||
256
system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php
Normal file
256
system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php
Normal file
@ -0,0 +1,256 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO MySQL Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_mysql_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
|
||||
|
||||
/**
|
||||
* CREATE TABLE keys flag
|
||||
*
|
||||
* Whether table keys are created from within the
|
||||
* CREATE TABLE statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_create_table_keys = TRUE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = 'DROP TABLE IF EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT',
|
||||
'SMALLINT',
|
||||
'MEDIUMINT',
|
||||
'INT',
|
||||
'INTEGER',
|
||||
'BIGINT',
|
||||
'REAL',
|
||||
'DOUBLE',
|
||||
'DOUBLE PRECISION',
|
||||
'FLOAT',
|
||||
'DECIMAL',
|
||||
'NUMERIC'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CREATE TABLE attributes
|
||||
*
|
||||
* @param array $attributes Associative array of table attributes
|
||||
* @return string
|
||||
*/
|
||||
protected function _create_table_attr($attributes)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
foreach (array_keys($attributes) as $key)
|
||||
{
|
||||
if (is_string($key))
|
||||
{
|
||||
$sql .= ' '.strtoupper($key).' = '.$attributes[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET'))
|
||||
{
|
||||
$sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set;
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE'))
|
||||
{
|
||||
$sql .= ' COLLATE = '.$this->db->dbcollat;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP')
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$field[$i] = ($alter_type === 'ADD')
|
||||
? "\n\tADD ".$field[$i]['_literal']
|
||||
: "\n\tMODIFY ".$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($alter_type === 'ADD')
|
||||
{
|
||||
$field[$i]['_literal'] = "\n\tADD ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
|
||||
}
|
||||
|
||||
$field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return array($sql.implode(',', $field));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
$extra_clause = isset($field['after'])
|
||||
? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
|
||||
|
||||
if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
|
||||
{
|
||||
$extra_clause = ' FIRST';
|
||||
}
|
||||
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['null']
|
||||
.$field['default']
|
||||
.$field['auto_increment']
|
||||
.$field['unique']
|
||||
.(empty($field['comment']) ? '' : ' COMMENT '.$field['comment'])
|
||||
.$extra_clause;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table (ignored)
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_indexes($table)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
if (is_array($this->keys[$i]))
|
||||
{
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( ! isset($this->fields[$this->keys[$i]]))
|
||||
{
|
||||
unset($this->keys[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
|
||||
|
||||
$sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
|
||||
.' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
|
||||
}
|
||||
|
||||
$this->keys = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
326
system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
Normal file
326
system/database/drivers/pdo/subdrivers/pdo_oci_driver.php
Normal file
@ -0,0 +1,326 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO Oracle Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'oci';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List of reserved identifiers
|
||||
*
|
||||
* Identifiers that must NOT be escaped.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_reserved_identifiers = array('*', 'rownum');
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('ASC', 'ASC'); // Currently not supported
|
||||
|
||||
/**
|
||||
* COUNT string
|
||||
*
|
||||
* @used-by CI_DB_driver::count_all()
|
||||
* @used-by CI_DB_query_builder::count_all_results()
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_count_string = 'SELECT COUNT(1) AS ';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'oci:dbname=';
|
||||
|
||||
// Oracle has a slightly different PDO DSN format (Easy Connect),
|
||||
// which also supports pre-defined DSNs.
|
||||
if (empty($this->hostname) && empty($this->port))
|
||||
{
|
||||
$this->dsn .= $this->database;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dsn .= '//'.(empty($this->hostname) ? '127.0.0.1' : $this->hostname)
|
||||
.(empty($this->port) ? '' : ':'.$this->port).'/';
|
||||
|
||||
empty($this->database) OR $this->dsn .= $this->database;
|
||||
}
|
||||
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 4) === FALSE)
|
||||
{
|
||||
$this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
$version_string = parent::version();
|
||||
if (preg_match('#Release\s(?<version>\d+(?:\.\d+)+)#', $version_string, $match))
|
||||
{
|
||||
return $this->data_cache['version'] = $match[1];
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"';
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
if (strpos($table, '.') !== FALSE)
|
||||
{
|
||||
sscanf($table, '%[^.].%s', $owner, $table);
|
||||
}
|
||||
else
|
||||
{
|
||||
$owner = $this->username;
|
||||
}
|
||||
|
||||
return 'SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS
|
||||
WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).'
|
||||
AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (strpos($table, '.') !== FALSE)
|
||||
{
|
||||
sscanf($table, '%[^.].%s', $owner, $table);
|
||||
}
|
||||
else
|
||||
{
|
||||
$owner = $this->username;
|
||||
}
|
||||
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHAR_LENGTH, DATA_PRECISION, DATA_LENGTH, DATA_DEFAULT, NULLABLE
|
||||
FROM ALL_TAB_COLUMNS
|
||||
WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).'
|
||||
AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
|
||||
$length = ($query[$i]->CHAR_LENGTH > 0)
|
||||
? $query[$i]->CHAR_LENGTH : $query[$i]->DATA_PRECISION;
|
||||
if ($length === NULL)
|
||||
{
|
||||
$length = $query[$i]->DATA_LENGTH;
|
||||
}
|
||||
$retval[$i]->max_length = $length;
|
||||
|
||||
$default = $query[$i]->DATA_DEFAULT;
|
||||
if ($default === NULL && $query[$i]->NULLABLE === 'N')
|
||||
{
|
||||
$default = '';
|
||||
}
|
||||
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert batch statement
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string
|
||||
*/
|
||||
protected function _insert_batch($table, $keys, $values)
|
||||
{
|
||||
$keys = implode(', ', $keys);
|
||||
$sql = "INSERT ALL\n";
|
||||
|
||||
for ($i = 0, $c = count($values); $i < $c; $i++)
|
||||
{
|
||||
$sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n";
|
||||
}
|
||||
|
||||
return $sql.'SELECT * FROM dual';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
$this->where('rownum <= ',$this->qb_limit, FALSE);
|
||||
$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)
|
||||
{
|
||||
if (version_compare($this->version(), '12.1', '>='))
|
||||
{
|
||||
// OFFSET-FETCH can be used only with the ORDER BY clause
|
||||
empty($this->qb_orderby) && $sql .= ' ORDER BY 1';
|
||||
|
||||
return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY';
|
||||
}
|
||||
|
||||
return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')'
|
||||
.($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1): '');
|
||||
}
|
||||
|
||||
}
|
||||
176
system/database/drivers/pdo/subdrivers/pdo_oci_forge.php
Normal file
176
system/database/drivers/pdo/subdrivers/pdo_oci_forge.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO Oracle Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_oci_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = FALSE;
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* DROP DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_database = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP')
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
elseif ($alter_type === 'CHANGE')
|
||||
{
|
||||
$alter_type = 'MODIFY';
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$field[$i] = "\n\t".$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
|
||||
|
||||
if ( ! empty($field[$i]['comment']))
|
||||
{
|
||||
$sqls[] = 'COMMENT ON COLUMN '
|
||||
.$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' IS '.$field[$i]['comment'];
|
||||
}
|
||||
|
||||
if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= ' '.$alter_type.' ';
|
||||
$sql .= (count($field) === 1)
|
||||
? $field[0]
|
||||
: '('.implode(',', $field).')';
|
||||
|
||||
// RENAME COLUMN must be executed after MODIFY
|
||||
array_unshift($sqls, $sql);
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
229
system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
Normal file
229
system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php
Normal file
@ -0,0 +1,229 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO ODBC Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'odbc';
|
||||
|
||||
/**
|
||||
* Database schema
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $schema = 'public';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* Must be empty for ODBC.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '';
|
||||
|
||||
/**
|
||||
* ESCAPE statement string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_like_escape_str = " {escape '%s'} ";
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RND()', 'RND(%d)');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'odbc:';
|
||||
|
||||
// Pre-defined DSN
|
||||
if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT))
|
||||
{
|
||||
if (isset($this->DSN))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->DSN;
|
||||
}
|
||||
elseif ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->database;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If the DSN is not pre-configured - try to build an IBM DB2 connection string
|
||||
$this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';';
|
||||
|
||||
if (isset($this->DATABASE))
|
||||
{
|
||||
$this->dsn .= 'DATABASE='.$this->DATABASE.';';
|
||||
}
|
||||
elseif ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'DATABASE='.$this->database.';';
|
||||
}
|
||||
|
||||
if (isset($this->HOSTNAME))
|
||||
{
|
||||
$this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';');
|
||||
}
|
||||
|
||||
if (isset($this->PORT))
|
||||
{
|
||||
$this->dsn .= 'PORT='.$this->port.';';
|
||||
}
|
||||
elseif ( ! empty($this->port))
|
||||
{
|
||||
$this->dsn .= ';PORT='.$this->port.';';
|
||||
}
|
||||
|
||||
$this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;');
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param string An SQL query string
|
||||
* @return bool
|
||||
*/
|
||||
public function is_write_type($sql)
|
||||
{
|
||||
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::is_write_type($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'";
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT column_name FROM information_schema.columns WHERE table_name = '.$this->escape($table);
|
||||
}
|
||||
}
|
||||
70
system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php
Normal file
70
system/database/drivers/pdo/subdrivers/pdo_odbc_forge.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO ODBC Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/database/
|
||||
*/
|
||||
class CI_DB_pdo_odbc_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported (in most databases at least)
|
||||
}
|
||||
|
||||
}
|
||||
384
system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
Normal file
384
system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
Normal file
@ -0,0 +1,384 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO PostgreSQL Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'pgsql';
|
||||
|
||||
/**
|
||||
* Database schema
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $schema = 'public';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM()');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'pgsql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
empty($this->port) OR $this->dsn .= ';port='.$this->port;
|
||||
empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
|
||||
|
||||
if ( ! empty($this->username))
|
||||
{
|
||||
$this->dsn .= ';username='.$this->username;
|
||||
empty($this->password) OR $this->dsn .= ';password='.$this->password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$this->conn_id = parent::db_connect($persistent);
|
||||
|
||||
if (is_object($this->conn_id) && ! empty($this->schema))
|
||||
{
|
||||
$this->simple_query('SET search_path TO '.$this->schema.',public');
|
||||
}
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @param string $name
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id($name = NULL)
|
||||
{
|
||||
if ($name === NULL && version_compare($this->version(), '8.1', '>='))
|
||||
{
|
||||
$query = $this->query('SELECT LASTVAL() AS ins_id');
|
||||
$query = $query->row();
|
||||
return $query->ins_id;
|
||||
}
|
||||
|
||||
return $this->conn_id->lastInsertId($name);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines if a query is a "write" type.
|
||||
*
|
||||
* @param string An SQL query string
|
||||
* @return bool
|
||||
*/
|
||||
public function is_write_type($sql)
|
||||
{
|
||||
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::is_write_type($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* "Smart" Escape String
|
||||
*
|
||||
* Escapes data based on type
|
||||
*
|
||||
* @param string $str
|
||||
* @return mixed
|
||||
*/
|
||||
public function escape($str)
|
||||
{
|
||||
if (is_bool($str))
|
||||
{
|
||||
return ($str) ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
|
||||
return parent::escape($str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY
|
||||
*
|
||||
* @param string $orderby
|
||||
* @param string $direction ASC, DESC or RANDOM
|
||||
* @param bool $escape
|
||||
* @return object
|
||||
*/
|
||||
public function order_by($orderby, $direction = '', $escape = NULL)
|
||||
{
|
||||
$direction = strtoupper(trim($direction));
|
||||
if ($direction === 'RANDOM')
|
||||
{
|
||||
if ( ! is_float($orderby) && ctype_digit((string) $orderby))
|
||||
{
|
||||
$orderby = ($orderby > 1)
|
||||
? (float) '0.'.$orderby
|
||||
: (float) $orderby;
|
||||
}
|
||||
|
||||
if (is_float($orderby))
|
||||
{
|
||||
$this->simple_query('SET SEED '.$orderby);
|
||||
}
|
||||
|
||||
$orderby = $this->_random_keyword[0];
|
||||
$direction = '';
|
||||
$escape = FALSE;
|
||||
}
|
||||
|
||||
return parent::order_by($orderby, $direction, $escape);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'";
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' AND "table_name" LIKE \''
|
||||
.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT "column_name"
|
||||
FROM "information_schema"."columns"
|
||||
WHERE LOWER("table_name") = '.$this->escape(strtolower($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default"
|
||||
FROM "information_schema"."columns"
|
||||
WHERE LOWER("table_name") = '.$this->escape(strtolower($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->column_name;
|
||||
$retval[$i]->type = $query[$i]->data_type;
|
||||
$retval[$i]->max_length = ($query[$i]->character_maximum_length > 0) ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
|
||||
$retval[$i]->default = $query[$i]->column_default;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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]['value'];
|
||||
|
||||
foreach (array_keys($val) as $field)
|
||||
{
|
||||
if ($field !== $index)
|
||||
{
|
||||
$final[$val[$field]['field']][] = 'WHEN '.$val[$index]['value'].' THEN '.$val[$field]['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cases = '';
|
||||
foreach ($final as $k => $v)
|
||||
{
|
||||
$cases .= $k.' = (CASE '.$val[$index]['field']."\n"
|
||||
.implode("\n", $v)."\n"
|
||||
.'ELSE '.$k.' END), ';
|
||||
}
|
||||
|
||||
$this->where($val[$index]['field'].' IN('.implode(',', $ids).')', NULL, FALSE);
|
||||
|
||||
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : '');
|
||||
}
|
||||
|
||||
}
|
||||
210
system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php
Normal file
210
system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php
Normal file
@ -0,0 +1,210 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO PostgreSQL Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_pgsql_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = 'DROP TABLE IF EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'INT2' => 'INTEGER',
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INT4' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT',
|
||||
'INT8' => 'NUMERIC',
|
||||
'BIGINT' => 'NUMERIC',
|
||||
'REAL' => 'DOUBLE PRECISION',
|
||||
'FLOAT' => 'DOUBLE PRECISION'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$db Database object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
parent::__construct($db);
|
||||
|
||||
if (version_compare($this->db->version(), '9.0', '>'))
|
||||
{
|
||||
$this->create_table_if = 'CREATE TABLE IF NOT EXISTS';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TYPE '.$field[$i]['type'].$field[$i]['length'];
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['default']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' SET DEFAULT '.$field[$i]['default'];
|
||||
}
|
||||
|
||||
if (isset($field[$i]['null']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['comment']))
|
||||
{
|
||||
$sqls[] = 'COMMENT ON COLUMN '
|
||||
.$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' IS '.$field[$i]['comment'];
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
// Reset field lengths for data types that don't support it
|
||||
if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
|
||||
{
|
||||
$attributes['CONSTRAINT'] = NULL;
|
||||
}
|
||||
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'TINYINT':
|
||||
$attributes['TYPE'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
|
||||
{
|
||||
$field['type'] = ($field['type'] === 'NUMERIC')
|
||||
? 'BIGSERIAL'
|
||||
: 'SERIAL';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
219
system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
Normal file
219
system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php
Normal file
@ -0,0 +1,219 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO SQLite Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'sqlite';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM()');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'sqlite:';
|
||||
|
||||
if (empty($this->database) && empty($this->hostname))
|
||||
{
|
||||
$this->database = ':memory:';
|
||||
}
|
||||
|
||||
$this->database = empty($this->database) ? $this->hostname : $this->database;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'';
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields($table)
|
||||
{
|
||||
// Is there a cached result?
|
||||
if (isset($this->data_cache['field_names'][$table]))
|
||||
{
|
||||
return $this->data_cache['field_names'][$table];
|
||||
}
|
||||
|
||||
if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->data_cache['field_names'][$table] = array();
|
||||
foreach ($result->result_array() as $row)
|
||||
{
|
||||
$this->data_cache['field_names'][$table][] = $row['name'];
|
||||
}
|
||||
|
||||
return $this->data_cache['field_names'][$table];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$query = $query->result_array();
|
||||
if (empty($query))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]['name'];
|
||||
$retval[$i]->type = $query[$i]['type'];
|
||||
$retval[$i]->max_length = NULL;
|
||||
$retval[$i]->default = $query[$i]['dflt_value'];
|
||||
$retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Replace statement
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string
|
||||
*/
|
||||
protected function _replace($table, $keys, $values)
|
||||
{
|
||||
return 'INSERT OR '.parent::_replace($table, $keys, $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;
|
||||
}
|
||||
|
||||
}
|
||||
238
system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php
Normal file
238
system/database/drivers/pdo/subdrivers/pdo_sqlite_forge.php
Normal file
@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO SQLite Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_sqlite_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = 'DROP TABLE IF EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$db Database object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
parent::__construct($db);
|
||||
|
||||
if (version_compare($this->db->version(), '3.3', '<'))
|
||||
{
|
||||
$this->_create_table_if = FALSE;
|
||||
$this->_drop_table_if = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function create_database($db_name)
|
||||
{
|
||||
// In SQLite, a database is created when you connect to the database.
|
||||
// We'll return TRUE so that an error isn't generated
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Drop database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function drop_database($db_name)
|
||||
{
|
||||
// In SQLite, a database is dropped when we delete a file
|
||||
if (file_exists($this->db->database))
|
||||
{
|
||||
// We need to close the pseudo-connection first
|
||||
$this->db->close();
|
||||
if ( ! @unlink($this->db->database))
|
||||
{
|
||||
return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
elseif ( ! empty($this->db->data_cache['db_names']))
|
||||
{
|
||||
$key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
|
||||
if ($key !== FALSE)
|
||||
{
|
||||
unset($this->db->data_cache['db_names'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP' OR $alter_type === 'CHANGE')
|
||||
{
|
||||
// drop_column():
|
||||
// BEGIN TRANSACTION;
|
||||
// CREATE TEMPORARY TABLE t1_backup(a,b);
|
||||
// INSERT INTO t1_backup SELECT a,b FROM t1;
|
||||
// DROP TABLE t1;
|
||||
// CREATE TABLE t1(a,b);
|
||||
// INSERT INTO t1 SELECT a,b FROM t1_backup;
|
||||
// DROP TABLE t1_backup;
|
||||
// COMMIT;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.' '.$field['type']
|
||||
.$field['auto_increment']
|
||||
.$field['null']
|
||||
.$field['unique']
|
||||
.$field['default'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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 'ENUM':
|
||||
case 'SET':
|
||||
$attributes['TYPE'] = 'TEXT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['type'] = 'INTEGER PRIMARY KEY';
|
||||
$field['default'] = '';
|
||||
$field['null'] = '';
|
||||
$field['unique'] = '';
|
||||
$field['auto_increment'] = ' AUTOINCREMENT';
|
||||
|
||||
$this->primary_keys = array();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
369
system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
Normal file
369
system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
Normal file
@ -0,0 +1,369 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO SQLSRV Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'sqlsrv';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('NEWID()', 'RAND(%d)');
|
||||
|
||||
/**
|
||||
* Quoted identifier flag
|
||||
*
|
||||
* Whether to use SQL-92 standard quoted identifier
|
||||
* (double quotes) or brackets for identifier escaping.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_quoted_identifier;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'sqlsrv:Server='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
empty($this->port) OR $this->dsn .= ','.$this->port;
|
||||
empty($this->database) OR $this->dsn .= ';Database='.$this->database;
|
||||
|
||||
// Some custom options
|
||||
|
||||
if (isset($this->QuotedId))
|
||||
{
|
||||
$this->dsn .= ';QuotedId='.$this->QuotedId;
|
||||
$this->_quoted_identifier = (bool) $this->QuotedId;
|
||||
}
|
||||
|
||||
if (isset($this->ConnectionPooling))
|
||||
{
|
||||
$this->dsn .= ';ConnectionPooling='.$this->ConnectionPooling;
|
||||
}
|
||||
|
||||
if ($this->encrypt === TRUE)
|
||||
{
|
||||
$this->dsn .= ';Encrypt=1';
|
||||
}
|
||||
|
||||
if (isset($this->TraceOn))
|
||||
{
|
||||
$this->dsn .= ';TraceOn='.$this->TraceOn;
|
||||
}
|
||||
|
||||
if (isset($this->TrustServerCertificate))
|
||||
{
|
||||
$this->dsn .= ';TrustServerCertificate='.$this->TrustServerCertificate;
|
||||
}
|
||||
|
||||
empty($this->APP) OR $this->dsn .= ';APP='.$this->APP;
|
||||
empty($this->Failover_Partner) OR $this->dsn .= ';Failover_Partner='.$this->Failover_Partner;
|
||||
empty($this->LoginTimeout) OR $this->dsn .= ';LoginTimeout='.$this->LoginTimeout;
|
||||
empty($this->MultipleActiveResultSets) OR $this->dsn .= ';MultipleActiveResultSets='.$this->MultipleActiveResultSets;
|
||||
empty($this->TraceFile) OR $this->dsn .= ';TraceFile='.$this->TraceFile;
|
||||
empty($this->WSID) OR $this->dsn .= ';WSID='.$this->WSID;
|
||||
}
|
||||
elseif (preg_match('/QuotedId=(0|1)/', $this->dsn, $match))
|
||||
{
|
||||
$this->_quoted_identifier = (bool) $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
if ( ! empty($this->char_set) && preg_match('/utf[^8]*8/i', $this->char_set))
|
||||
{
|
||||
$this->options[PDO::SQLSRV_ENCODING_UTF8] = 1;
|
||||
}
|
||||
|
||||
$this->conn_id = parent::db_connect($persistent);
|
||||
|
||||
if ( ! is_object($this->conn_id) OR is_bool($this->_quoted_identifier))
|
||||
{
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// Determine how identifiers are escaped
|
||||
$query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
|
||||
$query = $query->row_array();
|
||||
$this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
|
||||
$this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT '.$this->escape_identifiers('name')
|
||||
.' FROM '.$this->escape_identifiers('sysobjects')
|
||||
.' WHERE '.$this->escape_identifiers('type')." = 'U'";
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql.' ORDER BY '.$this->escape_identifiers('name');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT COLUMN_NAME
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
$retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION;
|
||||
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete';
|
||||
}
|
||||
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
// As of SQL Server 2012 (11.0.*) OFFSET is supported
|
||||
if (version_compare($this->version(), '11', '>='))
|
||||
{
|
||||
// SQL Server OFFSET-FETCH can be used only with the ORDER BY clause
|
||||
empty($this->qb_orderby) && $sql .= ' ORDER BY 1';
|
||||
|
||||
return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY';
|
||||
}
|
||||
|
||||
$limit = $this->qb_offset + $this->qb_limit;
|
||||
|
||||
// An ORDER BY clause is required for ROW_NUMBER() to work
|
||||
if ($this->qb_offset && ! empty($this->qb_orderby))
|
||||
{
|
||||
$orderby = $this->_compile_order_by();
|
||||
|
||||
// We have to strip the ORDER BY clause
|
||||
$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
|
||||
if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
|
||||
{
|
||||
$select = '*'; // Inevitable
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use only field names and their aliases, everything else is out of our scope.
|
||||
$select = array();
|
||||
$field_regexp = ($this->_quoted_identifier)
|
||||
? '("[^\"]+")' : '(\[[^\]]+\])';
|
||||
for ($i = 0, $c = count($this->qb_select); $i < $c; $i++)
|
||||
{
|
||||
$select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m)
|
||||
? $m[1] : $this->qb_select[$i];
|
||||
}
|
||||
$select = implode(', ', $select);
|
||||
}
|
||||
|
||||
return 'SELECT '.$select." FROM (\n\n"
|
||||
.preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql)
|
||||
."\n\n) ".$this->escape_identifiers('CI_subquery')
|
||||
."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit;
|
||||
}
|
||||
|
||||
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $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)
|
||||
{
|
||||
// Multiple-value inserts are only supported as of SQL Server 2008
|
||||
if (version_compare($this->version(), '10', '>='))
|
||||
{
|
||||
return parent::_insert_batch($table, $keys, $values);
|
||||
}
|
||||
|
||||
return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
149
system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php
Normal file
149
system/database/drivers/pdo/subdrivers/pdo_sqlsrv_forge.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 3.0.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* PDO SQLSRV Forge Class
|
||||
*
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_pdo_sqlsrv_forge extends CI_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT' => 'SMALLINT',
|
||||
'SMALLINT' => 'INT',
|
||||
'INT' => 'BIGINT',
|
||||
'REAL' => 'FLOAT'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
$sqls[] = $sql.$this->_process_column($field[$i]);
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
if (isset($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') !== FALSE)
|
||||
{
|
||||
unset($attributes['CONSTRAINT']);
|
||||
}
|
||||
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INTEGER':
|
||||
$attributes['TYPE'] = 'INT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['auto_increment'] = ' IDENTITY(1,1)';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
system/database/drivers/postgre/index.html
Normal file
11
system/database/drivers/postgre/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
619
system/database/drivers/postgre/postgre_driver.php
Normal file
619
system/database/drivers/postgre/postgre_driver.php
Normal file
@ -0,0 +1,619 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 - 2018, British Columbia Institute of Technology
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
|
||||
* @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 1.3.0
|
||||
* @filesource
|
||||
*/
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Postgre Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
*/
|
||||
class CI_DB_postgre_driver extends CI_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'postgre';
|
||||
|
||||
/**
|
||||
* Database schema
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $schema = 'public';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM()');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Creates a DSN string to be used for db_connect() and db_pconnect()
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if ( ! empty($this->dsn))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dsn === '' OR $this->dsn = '';
|
||||
|
||||
if (strpos($this->hostname, '/') !== FALSE)
|
||||
{
|
||||
// If UNIX sockets are used, we shouldn't set a port
|
||||
$this->port = '';
|
||||
}
|
||||
|
||||
$this->hostname === '' OR $this->dsn = 'host='.$this->hostname.' ';
|
||||
|
||||
if ( ! empty($this->port) && ctype_digit($this->port))
|
||||
{
|
||||
$this->dsn .= 'port='.$this->port.' ';
|
||||
}
|
||||
|
||||
if ($this->username !== '')
|
||||
{
|
||||
$this->dsn .= 'user='.$this->username.' ';
|
||||
|
||||
/* An empty password is valid!
|
||||
*
|
||||
* $db['password'] = NULL must be done in order to ignore it.
|
||||
*/
|
||||
$this->password === NULL OR $this->dsn .= "password='".$this->password."' ";
|
||||
}
|
||||
|
||||
$this->database === '' OR $this->dsn .= 'dbname='.$this->database.' ';
|
||||
|
||||
/* We don't have these options as elements in our standard configuration
|
||||
* array, but they might be set by parse_url() if the configuration was
|
||||
* provided via string. Example:
|
||||
*
|
||||
* postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1
|
||||
*/
|
||||
foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key)
|
||||
{
|
||||
if (isset($this->$key) && is_string($this->$key) && $this->$key !== '')
|
||||
{
|
||||
$this->dsn .= $key."='".$this->$key."' ";
|
||||
}
|
||||
}
|
||||
|
||||
$this->dsn = rtrim($this->dsn);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$this->conn_id = ($persistent === TRUE)
|
||||
? pg_pconnect($this->dsn)
|
||||
: pg_connect($this->dsn);
|
||||
|
||||
if ($this->conn_id !== FALSE)
|
||||
{
|
||||
if ($persistent === TRUE
|
||||
&& pg_connection_status($this->conn_id) === PGSQL_CONNECTION_BAD
|
||||
&& pg_ping($this->conn_id) === FALSE
|
||||
)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
empty($this->schema) OR $this->simple_query('SET search_path TO '.$this->schema.',public');
|
||||
}
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reconnect
|
||||
*
|
||||
* Keep / reestablish the db connection if no queries have been
|
||||
* sent for a length of time exceeding the server's idle timeout
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reconnect()
|
||||
{
|
||||
if (pg_ping($this->conn_id) === FALSE)
|
||||
{
|
||||
$this->conn_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set client character set
|
||||
*
|
||||
* @param string $charset
|
||||
* @return bool
|
||||
*/
|
||||
protected function _db_set_charset($charset)
|
||||
{
|
||||
return (pg_set_client_encoding($this->conn_id, $charset) === 0);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
if ( ! $this->conn_id OR ($pg_version = pg_version($this->conn_id)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If PHP was compiled with PostgreSQL lib versions earlier
|
||||
* than 7.4, pg_version() won't return the server version
|
||||
* and so we'll have to fall back to running a query in
|
||||
* order to get it.
|
||||
*/
|
||||
return (isset($pg_version['server']) && preg_match('#^(\d+\.\d+)#', $pg_version['server'], $match))
|
||||
? $this->data_cache['version'] = $match[1]
|
||||
: parent::version();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return pg_query($this->conn_id, $sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return (bool) pg_query($this->conn_id, 'BEGIN');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
return (bool) pg_query($this->conn_id, 'COMMIT');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
return (bool) pg_query($this->conn_id, 'ROLLBACK');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines if a query is a "write" type.
|
||||
*
|
||||
* @param string An SQL query string
|
||||
* @return bool
|
||||
*/
|
||||
public function is_write_type($sql)
|
||||
{
|
||||
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::is_write_type($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependent string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return pg_escape_string($this->conn_id, $str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* "Smart" Escape String
|
||||
*
|
||||
* Escapes data based on type
|
||||
*
|
||||
* @param string $str
|
||||
* @return mixed
|
||||
*/
|
||||
public function escape($str)
|
||||
{
|
||||
if (is_php('5.4.4') && (is_string($str) OR (is_object($str) && method_exists($str, '__toString'))))
|
||||
{
|
||||
return pg_escape_literal($this->conn_id, $str);
|
||||
}
|
||||
elseif (is_bool($str))
|
||||
{
|
||||
return ($str) ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
|
||||
return parent::escape($str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return pg_affected_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
$v = $this->version();
|
||||
|
||||
$table = (func_num_args() > 0) ? func_get_arg(0) : NULL;
|
||||
$column = (func_num_args() > 1) ? func_get_arg(1) : NULL;
|
||||
|
||||
if ($table === NULL && $v >= '8.1')
|
||||
{
|
||||
$sql = 'SELECT LASTVAL() AS ins_id';
|
||||
}
|
||||
elseif ($table !== NULL)
|
||||
{
|
||||
if ($column !== NULL && $v >= '8.0')
|
||||
{
|
||||
$sql = 'SELECT pg_get_serial_sequence(\''.$table."', '".$column."') AS seq";
|
||||
$query = $this->query($sql);
|
||||
$query = $query->row();
|
||||
$seq = $query->seq;
|
||||
}
|
||||
else
|
||||
{
|
||||
// seq_name passed in table parameter
|
||||
$seq = $table;
|
||||
}
|
||||
|
||||
$sql = 'SELECT CURRVAL(\''.$seq."') AS ins_id";
|
||||
}
|
||||
else
|
||||
{
|
||||
return pg_last_oid($this->result_id);
|
||||
}
|
||||
|
||||
$query = $this->query($sql);
|
||||
$query = $query->row();
|
||||
return (int) $query->ins_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'";
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' AND "table_name" LIKE \''
|
||||
.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT "column_name"
|
||||
FROM "information_schema"."columns"
|
||||
WHERE LOWER("table_name") = '.$this->escape(strtolower($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default"
|
||||
FROM "information_schema"."columns"
|
||||
WHERE LOWER("table_name") = '.$this->escape(strtolower($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->column_name;
|
||||
$retval[$i]->type = $query[$i]->data_type;
|
||||
$retval[$i]->max_length = ($query[$i]->character_maximum_length > 0) ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
|
||||
$retval[$i]->default = $query[$i]->column_default;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occurred.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => '', 'message' => pg_last_error($this->conn_id));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY
|
||||
*
|
||||
* @param string $orderby
|
||||
* @param string $direction ASC, DESC or RANDOM
|
||||
* @param bool $escape
|
||||
* @return object
|
||||
*/
|
||||
public function order_by($orderby, $direction = '', $escape = NULL)
|
||||
{
|
||||
$direction = strtoupper(trim($direction));
|
||||
if ($direction === 'RANDOM')
|
||||
{
|
||||
if ( ! is_float($orderby) && ctype_digit((string) $orderby))
|
||||
{
|
||||
$orderby = ($orderby > 1)
|
||||
? (float) '0.'.$orderby
|
||||
: (float) $orderby;
|
||||
}
|
||||
|
||||
if (is_float($orderby))
|
||||
{
|
||||
$this->simple_query('SET SEED '.$orderby);
|
||||
}
|
||||
|
||||
$orderby = $this->_random_keyword[0];
|
||||
$direction = '';
|
||||
$escape = FALSE;
|
||||
}
|
||||
|
||||
return parent::order_by($orderby, $direction, $escape);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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]['value'];
|
||||
|
||||
foreach (array_keys($val) as $field)
|
||||
{
|
||||
if ($field !== $index)
|
||||
{
|
||||
$final[$val[$field]['field']][] = 'WHEN '.$val[$index]['value'].' THEN '.$val[$field]['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cases = '';
|
||||
foreach ($final as $k => $v)
|
||||
{
|
||||
$cases .= $k.' = (CASE '.$val[$index]['field']."\n"
|
||||
.implode("\n", $v)."\n"
|
||||
.'ELSE '.$k.' END), ';
|
||||
}
|
||||
|
||||
$this->where($val[$index]['field'].' IN('.implode(',', $ids).')', NULL, FALSE);
|
||||
|
||||
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : '');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
pg_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user