diff options
Diffstat (limited to 'system')
36 files changed, 505 insertions, 614 deletions
diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php index f6b634deb..c17e95a19 100755 --- a/system/core/Benchmark.php +++ b/system/core/Benchmark.php @@ -46,7 +46,7 @@ class CI_Benchmark { * * @var array */ - public $marker = array(); + public $marker = array(); // -------------------------------------------------------------------- @@ -61,7 +61,7 @@ class CI_Benchmark { */ public function mark($name) { - $this->marker[$name] = microtime(); + $this->marker[$name] = microtime(TRUE); } // -------------------------------------------------------------------- @@ -93,13 +93,10 @@ class CI_Benchmark { if ( ! isset($this->marker[$point2])) { - $this->marker[$point2] = microtime(); + $this->marker[$point2] = microtime(TRUE); } - list($sm, $ss) = explode(' ', $this->marker[$point1]); - list($em, $es) = explode(' ', $this->marker[$point2]); - - return number_format(($em + $es) - ($sm + $ss), $decimals); + return number_format($this->marker[$point2] - $this->marker[$point1], $decimals); } // -------------------------------------------------------------------- diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 9714d095c..793c4687e 100755 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * System Initialization File * @@ -42,7 +40,7 @@ /** * CodeIgniter Version * - * @var string + * @var string * */ define('CI_VERSION', '3.0-dev'); @@ -282,12 +280,12 @@ { $x = explode('/', $RTR->routes['404_override'], 2); $class = $x[0]; - $method = (isset($x[1]) ? $x[1] : 'index'); + $method = isset($x[1]) ? $x[1] : 'index'; if ( ! class_exists($class)) { if ( ! file_exists(APPPATH.'controllers/'.$class.'.php')) { - show_404("{$class}/{$method}"); + show_404($class.'/'.$method); } include_once(APPPATH.'controllers/'.$class.'.php'); @@ -295,7 +293,7 @@ } else { - show_404("{$class}/{$method}"); + show_404($class.'/'.$method); } } @@ -344,12 +342,12 @@ { $x = explode('/', $RTR->routes['404_override'], 2); $class = $x[0]; - $method = (isset($x[1]) ? $x[1] : 'index'); + $method = isset($x[1]) ? $x[1] : 'index'; if ( ! class_exists($class)) { if ( ! file_exists(APPPATH.'controllers/'.$class.'.php')) { - show_404("{$class}/{$method}"); + show_404($class.'/'.$method); } include_once(APPPATH.'controllers/'.$class.'.php'); @@ -359,7 +357,7 @@ } else { - show_404("{$class}/{$method}"); + show_404($class.'/'.$method); } } @@ -400,10 +398,10 @@ * Close the DB connection if one exists * ------------------------------------------------------ */ - if (class_exists('CI_DB') && isset($CI->db)) + if (class_exists('CI_DB') && isset($CI->db) && ! $CI->db->pconnect) { $CI->db->close(); } /* End of file CodeIgniter.php */ -/* Location: ./system/core/CodeIgniter.php */ +/* Location: ./system/core/CodeIgniter.php */
\ No newline at end of file diff --git a/system/core/Common.php b/system/core/Common.php index 075b221bd..78aa6e874 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -39,7 +39,6 @@ // ------------------------------------------------------------------------ - if ( ! function_exists('is_php')) { /** diff --git a/system/core/Config.php b/system/core/Config.php index fc6183444..1eab08b82 100755 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -45,14 +45,14 @@ class CI_Config { * * @var array */ - public $config = array(); + public $config = array(); /** * List of all loaded config files * * @var array */ - public $is_loaded = array(); + public $is_loaded = array(); /** * List of paths to search when trying to load a config file. @@ -60,7 +60,7 @@ class CI_Config { * * @var array */ - public $_config_paths = array(APPPATH); + public $_config_paths = array(APPPATH); /** * Constructor diff --git a/system/core/Controller.php b/system/core/Controller.php index 0c6c47183..1f69146d0 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -42,7 +42,7 @@ class CI_Controller { /** * Reference to the global CI instance * - * @var object + * @var object */ private static $instance; diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index f55f9fcba..2e9f0c766 100755 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -39,14 +39,14 @@ class CI_Exceptions { /** * Nesting level of the output buffering mechanism * - * @var int + * @var int */ public $ob_level; /** * List if available error levels * - * @var array + * @var array */ public $levels = array( E_ERROR => 'Error', diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 672fe29dd..b42ecbe20 100755 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -43,21 +43,21 @@ class CI_Hooks { * * @var bool */ - public $enabled = FALSE; + public $enabled = FALSE; /** * List of all hooks set in config/hooks.php * * @var array */ - public $hooks = array(); + public $hooks = array(); /** * Determines wether hook is in progress, used to prevent infinte loops * * @var bool */ - public $in_progress = FALSE; + public $in_progress = FALSE; /** * Initialize the Hooks Preferences diff --git a/system/core/Input.php b/system/core/Input.php index 7ee8f3685..fc2a550bc 100755 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -43,28 +43,28 @@ class CI_Input { * * @var string */ - public $ip_address = FALSE; + public $ip_address = FALSE; /** * user agent (web browser) being used by the current user * * @var string */ - public $user_agent = FALSE; + public $user_agent = FALSE; /** * If FALSE, then $_GET will be set to an empty array * * @var bool */ - protected $_allow_get_array = TRUE; + protected $_allow_get_array = TRUE; /** * If TRUE, then newlines are standardized * * @var bool */ - protected $_standardize_newlines = TRUE; + protected $_standardize_newlines = TRUE; /** * Determines whether the XSS filter is always active when GET, POST or COOKIE data is encountered @@ -72,7 +72,7 @@ class CI_Input { * * @var bool */ - protected $_enable_xss = FALSE; + protected $_enable_xss = FALSE; /** * Enables a CSRF cookie token to be set. @@ -80,14 +80,14 @@ class CI_Input { * * @var bool */ - protected $_enable_csrf = FALSE; + protected $_enable_csrf = FALSE; /** * List of all HTTP request headers * * @var array */ - protected $headers = array(); + protected $headers = array(); /** * Constructor diff --git a/system/core/Lang.php b/system/core/Lang.php index 7abdc6102..2963012fc 100755 --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -41,14 +41,14 @@ class CI_Lang { * * @var array */ - public $language = array(); + public $language = array(); /** * List of loaded language files * * @var array */ - public $is_loaded = array(); + public $is_loaded = array(); /** * Initialize language class diff --git a/system/core/Loader.php b/system/core/Loader.php index b99ce6964..bf7f6cb02 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -51,77 +51,77 @@ class CI_Loader { * * @var array */ - protected $_ci_view_paths = array(); + protected $_ci_view_paths = array(); /** * List of paths to load libraries from * * @var array */ - protected $_ci_library_paths = array(); + protected $_ci_library_paths = array(); /** * List of paths to load models from * * @var array */ - protected $_ci_model_paths = array(); + protected $_ci_model_paths = array(); /** * List of paths to load helpers from * * @var array */ - protected $_ci_helper_paths = array(); + protected $_ci_helper_paths = array(); /** * List of loaded base classes * * @var array */ - protected $_base_classes = array(); // Set by the controller class + protected $_base_classes = array(); // Set by the controller class /** * List of cached variables * * @var array */ - protected $_ci_cached_vars = array(); + protected $_ci_cached_vars = array(); /** * List of loaded classes * * @var array */ - protected $_ci_classes = array(); + protected $_ci_classes = array(); /** * List of loaded files * * @var array */ - protected $_ci_loaded_files = array(); + protected $_ci_loaded_files = array(); /** * List of loaded models * * @var array */ - protected $_ci_models = array(); + protected $_ci_models = array(); /** * List of loaded helpers * * @var array */ - protected $_ci_helpers = array(); + protected $_ci_helpers = array(); /** * List of class name mappings * * @var array */ - protected $_ci_varmap = array( + protected $_ci_varmap = array( 'unit_test' => 'unit', 'user_agent' => 'agent' ); @@ -323,16 +323,16 @@ class CI_Loader { * * @param string the DB credentials * @param bool whether to return the DB object - * @param bool whether to enable active record (this allows us to override the config setting) + * @param bool whether to enable query builder (this allows us to override the config setting) * @return object */ - public function database($params = '', $return = FALSE, $active_record = NULL) + public function database($params = '', $return = FALSE, $query_builder = NULL) { // Grab the super object $CI =& get_instance(); // Do we even need to load the database class? - if (class_exists('CI_DB') && $return == FALSE && $active_record == NULL && isset($CI->db) && is_object($CI->db)) + if (class_exists('CI_DB') && $return == FALSE && $query_builder == NULL && isset($CI->db) && is_object($CI->db)) { return FALSE; } @@ -341,7 +341,7 @@ class CI_Loader { if ($return === TRUE) { - return DB($params, $active_record); + return DB($params, $query_builder); } // Initialize the db variable. Needed to prevent @@ -349,7 +349,7 @@ class CI_Loader { $CI->db = ''; // Load the DB class - $CI->db =& DB($params, $active_record); + $CI->db =& DB($params, $query_builder); } // -------------------------------------------------------------------- @@ -683,7 +683,7 @@ class CI_Loader { // Add config file path $config =& $this->_ci_get_component('config'); - array_unshift($config->_config_paths, $path); + array_push($config->_config_paths, $path); } // -------------------------------------------------------------------- @@ -723,7 +723,7 @@ class CI_Loader { array_shift($this->_ci_model_paths); array_shift($this->_ci_helper_paths); array_shift($this->_ci_view_paths); - array_shift($config->_config_paths); + array_pop($config->_config_paths); } else { @@ -1263,4 +1263,4 @@ class CI_Loader { } /* End of file Loader.php */ -/* Location: ./system/core/Loader.php */
\ No newline at end of file +/* Location: ./system/core/Loader.php */ diff --git a/system/core/Output.php b/system/core/Output.php index 0683539c9..513c657a6 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -50,49 +50,49 @@ class CI_Output { * * @var int */ - public $cache_expiration = 0; + public $cache_expiration = 0; /** * List of server headers * * @var array */ - public $headers = array(); + public $headers = array(); /** * List of mime types * * @var array */ - public $mime_types = array(); + public $mime_types = array(); /** * Determines wether profiler is enabled * * @var book */ - public $enable_profiler = FALSE; + public $enable_profiler = FALSE; /** * Determines if output compression is enabled * * @var bool */ - protected $_zlib_oc = FALSE; + protected $_zlib_oc = FALSE; /** * List of profiler sections * * @var array */ - protected $_profiler_sections = array(); + protected $_profiler_sections = array(); /** * Whether or not to parse variables like {elapsed_time} and {memory_usage} * * @var bool */ - public $parse_exec_vars = TRUE; + public $parse_exec_vars = TRUE; /** * Set up Output class diff --git a/system/core/Router.php b/system/core/Router.php index b5c200214..fe9909b06 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -50,35 +50,35 @@ class CI_Router { * * @var array */ - public $routes = array(); + public $routes = array(); /** * List of error routes * * @var array */ - public $error_routes = array(); + public $error_routes = array(); /** * Current class name * * @var string */ - public $class = ''; + public $class = ''; /** * Current method name * * @var string */ - public $method = 'index'; + public $method = 'index'; /** * Sub-directory that contains the requested controller class * * @var string */ - public $directory = ''; + public $directory = ''; /** * Default controller (and method if specific) @@ -242,9 +242,12 @@ class CI_Router { $segments[1] = 'index'; } + // This is being routed to a file in a sub directory + $this->directory and array_unshift($segments, trim($this->directory, '/')); + // Update our "routed" segment array to contain the segments. // Note: If there is no custom routing, this array will be - // identical to $this->uri->segments + // identical to $this->uri->segments $this->uri->rsegments = $segments; } diff --git a/system/core/Security.php b/system/core/Security.php index 139511661..974e2e428 100755 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -41,14 +41,14 @@ class CI_Security { * * @var string */ - protected $_xss_hash = ''; + protected $_xss_hash = ''; /** * Random Hash for Cross Site Request Forgery Protection Cookie * * @var string */ - protected $_csrf_hash = ''; + protected $_csrf_hash = ''; /** * Expiration time for Cross Site Request Forgery Protection Cookie @@ -56,28 +56,28 @@ class CI_Security { * * @var int */ - protected $_csrf_expire = 7200; + protected $_csrf_expire = 7200; /** * Token name for Cross Site Request Forgery Protection Cookie * * @var string */ - protected $_csrf_token_name = 'ci_csrf_token'; + protected $_csrf_token_name = 'ci_csrf_token'; /** * Cookie name for Cross Site Request Forgery Protection Cookie * * @var string */ - protected $_csrf_cookie_name = 'ci_csrf_token'; + protected $_csrf_cookie_name = 'ci_csrf_token'; /** * List of never allowed strings * * @var array */ - protected $_never_allowed_str = array( + protected $_never_allowed_str = array( 'document.cookie' => '[removed]', 'document.write' => '[removed]', '.parentNode' => '[removed]', @@ -95,7 +95,7 @@ class CI_Security { * * @var array */ - protected $_never_allowed_regex = array( + protected $_never_allowed_regex = array( 'javascript\s*:', 'expression\s*(\(|&\#40;)', // CSS and IE 'vbscript\s*:', // IE, surprise! diff --git a/system/core/URI.php b/system/core/URI.php index 140295338..705575a0c 100755 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -42,7 +42,7 @@ class CI_URI { * * @var array */ - public $keyval = array(); + public $keyval = array(); /** * Current uri string @@ -56,7 +56,7 @@ class CI_URI { * * @var array */ - public $segments = array(); + public $segments = array(); /** * Re-indexed list of uri segments @@ -64,7 +64,7 @@ class CI_URI { * * @var array */ - public $rsegments = array(); + public $rsegments = array(); /** * Constructor @@ -645,7 +645,7 @@ class CI_URI { */ public function ruri_string() { - return '/'.implode('/', $this->rsegment_array()); + return implode('/', $this->rsegment_array()); } } diff --git a/system/database/DB.php b/system/database/DB.php index 0d81e40d3..b28439b29 100755 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -32,9 +32,9 @@ * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/database/ * @param string - * @param bool Determines if active record should be used or not + * @param bool Determines if query builder should be used or not */ -function &DB($params = '', $active_record_override = NULL) +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) @@ -111,22 +111,22 @@ function &DB($params = '', $active_record_override = NULL) show_error('You have not selected a database type to connect to.'); } - // Load the DB classes. Note: Since the active record class is optional + // 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 active record class or not. - if ($active_record_override !== NULL) + // based on whether we're using the query builder class or not. + if ($query_builder_override !== NULL) { - $active_record = $active_record_override; + $query_builder = $query_builder_override; } require_once(BASEPATH.'database/DB_driver.php'); - if ( ! isset($active_record) OR $active_record == TRUE) + if ( ! isset($query_builder) OR $query_builder == TRUE) { - require_once(BASEPATH.'database/DB_active_rec.php'); + require_once(BASEPATH.'database/DB_query_builder.php'); if ( ! class_exists('CI_DB')) { - class CI_DB extends CI_DB_active_record { } + class CI_DB extends CI_DB_query_builder { } } } elseif ( ! class_exists('CI_DB')) @@ -159,4 +159,4 @@ function &DB($params = '', $active_record_override = NULL) } /* End of file DB.php */ -/* Location: ./system/database/DB.php */
\ No newline at end of file +/* Location: ./system/database/DB.php */ diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 61b05d52b..ef77b594e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -335,7 +335,7 @@ abstract class CI_DB_driver { } // Start the Query Timer - $time_start = list($sm, $ss) = explode(' ', microtime()); + $time_start = microtime(TRUE); // Run the Query if (FALSE === ($this->result_id = $this->simple_query($sql))) @@ -370,12 +370,12 @@ abstract class CI_DB_driver { } // Stop and aggregate the query time results - $time_end = list($em, $es) = explode(' ', microtime()); - $this->benchmark += ($em + $es) - ($sm + $ss); + $time_end = microtime(TRUE); + $this->benchmark += $time_end - $time_start; if ($this->save_queries == TRUE) { - $this->query_times[] = ($em + $es) - ($sm + $ss); + $this->query_times[] = $time_end - $time_start; } // Increment the query counter @@ -1208,7 +1208,7 @@ abstract class CI_DB_driver { /** * Protect Identifiers * - * This function is used extensively by the Active Record class, and by + * This function is used extensively by the Query Builder class, and by * a couple functions in this class. * It takes a column or table name (optionally with an alias) and inserts * the table prefix onto it. Some logic is necessary in order to deal with @@ -1283,7 +1283,7 @@ abstract class CI_DB_driver { // Does the first segment of the exploded item match // one of the aliases previously identified? If so, // we have nothing more to do other than escape the item - if (in_array($parts[0], $this->ar_aliased_tables)) + if (in_array($parts[0], $this->qb_aliased_tables)) { if ($protect_identifiers === TRUE) { @@ -1380,7 +1380,7 @@ abstract class CI_DB_driver { // -------------------------------------------------------------------- /** - * Dummy method that allows Active Record class to be disabled + * Dummy method that allows Query Builder class to be disabled * * This function is used extensively by every db driver. * @@ -1393,4 +1393,4 @@ abstract class CI_DB_driver { } /* End of file DB_driver.php */ -/* Location: ./system/database/DB_driver.php */
\ No newline at end of file +/* Location: ./system/database/DB_driver.php */ diff --git a/system/database/DB_active_rec.php b/system/database/DB_query_builder.php index e78b2a893..393a1cd75 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_query_builder.php @@ -26,9 +26,9 @@ */ /** - * Active Record Class + * Query Builder Class * - * This is the platform-independent base Active Record implementation class. + * This is the platform-independent base Query Builder implementation class. * * @package CodeIgniter * @subpackage Drivers @@ -36,46 +36,47 @@ * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/database/ */ -abstract class CI_DB_active_record extends CI_DB_driver { + +abstract class CI_DB_query_builder extends CI_DB_driver { protected $return_delete_sql = FALSE; protected $reset_delete_data = FALSE; - protected $ar_select = array(); - protected $ar_distinct = FALSE; - protected $ar_from = array(); - protected $ar_join = array(); - protected $ar_where = array(); - protected $ar_like = array(); - protected $ar_groupby = array(); - protected $ar_having = array(); - protected $ar_keys = array(); - protected $ar_limit = FALSE; - protected $ar_offset = FALSE; - protected $ar_order = FALSE; - protected $ar_orderby = array(); - protected $ar_set = array(); - protected $ar_wherein = array(); - protected $ar_aliased_tables = array(); - protected $ar_store_array = array(); - protected $ar_where_group_started = FALSE; - protected $ar_where_group_count = 0; - - // Active Record Caching variables - protected $ar_caching = FALSE; - protected $ar_cache_exists = array(); - protected $ar_cache_select = array(); - protected $ar_cache_from = array(); - protected $ar_cache_join = array(); - protected $ar_cache_where = array(); - protected $ar_cache_like = array(); - protected $ar_cache_groupby = array(); - protected $ar_cache_having = array(); - protected $ar_cache_orderby = array(); - protected $ar_cache_set = array(); - - protected $ar_no_escape = array(); - protected $ar_cache_no_escape = array(); + protected $qb_select = array(); + protected $qb_distinct = FALSE; + protected $qb_from = array(); + protected $qb_join = array(); + protected $qb_where = array(); + protected $qb_like = array(); + protected $qb_groupby = array(); + protected $qb_having = array(); + protected $qb_keys = array(); + protected $qb_limit = FALSE; + protected $qb_offset = FALSE; + protected $qb_order = FALSE; + protected $qb_orderby = array(); + protected $qb_set = array(); + protected $qb_wherein = array(); + protected $qb_aliased_tables = array(); + protected $qb_store_array = array(); + protected $qb_where_group_started = FALSE; + protected $qb_where_group_count = 0; + + // Query Builder Caching variables + protected $qb_caching = FALSE; + protected $qb_cache_exists = array(); + protected $qb_cache_select = array(); + protected $qb_cache_from = array(); + protected $qb_cache_join = array(); + protected $qb_cache_where = array(); + protected $qb_cache_like = array(); + protected $qb_cache_groupby = array(); + protected $qb_cache_having = array(); + protected $qb_cache_orderby = array(); + protected $qb_cache_set = array(); + + protected $qb_no_escape = array(); + protected $qb_cache_no_escape = array(); /** * Select @@ -98,14 +99,14 @@ abstract class CI_DB_active_record extends CI_DB_driver { if ($val != '') { - $this->ar_select[] = $val; - $this->ar_no_escape[] = $escape; + $this->qb_select[] = $val; + $this->qb_no_escape[] = $escape; - if ($this->ar_caching === TRUE) + if ($this->qb_caching === TRUE) { - $this->ar_cache_select[] = $val; - $this->ar_cache_exists[] = 'select'; - $this->ar_cache_no_escape[] = $escape; + $this->qb_cache_select[] = $val; + $this->qb_cache_exists[] = 'select'; + $this->qb_cache_no_escape[] = $escape; } } } @@ -211,13 +212,14 @@ abstract class CI_DB_active_record extends CI_DB_driver { } $sql = $this->protect_identifiers($type.'('.trim($select).')').' AS '.$this->protect_identifiers(trim($alias)); - $this->ar_select[] = $sql; - $this->ar_no_escape[] = NULL; + + $this->qb_select[] = $sql; + $this->qb_no_escape[] = NULL; - if ($this->ar_caching === TRUE) + if ($this->qb_caching === TRUE) { - $this->ar_cache_select[] = $sql; - $this->ar_cache_exists[] = 'select'; + $this->qb_cache_select[] = $sql; + $this->qb_cache_exists[] = 'select'; } return $this; @@ -254,7 +256,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { */ public function distinct($val = TRUE) { - $this->ar_distinct = (is_bool($val)) ? $val : TRUE; + $this->qb_distinct = (is_bool($val)) ? $val : TRUE; return $this; } @@ -278,12 +280,13 @@ abstract class CI_DB_active_record extends CI_DB_driver { { $v = trim($v); $this->_track_aliases($v); - $v = $this->ar_from[] = $this->protect_identifiers($v, TRUE, NULL, FALSE); - if ($this->ar_caching === TRUE) + $v = $this->qb_from[] = $this->protect_identifiers($v, TRUE, NULL, FALSE); + + if ($this->qb_caching === TRUE) { - $this->ar_cache_from[] = $v; - $this->ar_cache_exists[] = 'from'; + $this->qb_cache_from[] = $v; + $this->qb_cache_exists[] = 'from'; } } } @@ -292,14 +295,15 @@ abstract class CI_DB_active_record extends CI_DB_driver { $val = trim($val); // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix + // in the protect_identifiers to know whether to add a table prefix $this->_track_aliases($val); - $this->ar_from[] = $val = $this->protect_identifiers($val, TRUE, NULL, FALSE); - if ($this->ar_caching === TRUE) + $this->qb_from[] = $val = $this->protect_identifiers($val, TRUE, NULL, FALSE); + + if ($this->qb_caching === TRUE) { - $this->ar_cache_from[] = $val; - $this->ar_cache_exists[] = 'from'; + $this->qb_cache_from[] = $val; + $this->qb_cache_exists[] = 'from'; } } } @@ -336,7 +340,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { } // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix + // in the protect_identifiers to know whether to add a table prefix $this->_track_aliases($table); // Strip apart the condition and protect the identifiers @@ -346,12 +350,12 @@ abstract class CI_DB_active_record extends CI_DB_driver { } // Assemble the JOIN statement - $this->ar_join[] = $join = $type.'JOIN '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; + $this->qb_join[] = $join = $type.'JOIN '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; - if ($this->ar_caching === TRUE) + if ($this->qb_caching === TRUE) { - $this->ar_cache_join[] = $join; - $this->ar_cache_exists[] = 'join'; + $this->qb_cache_join[] = $join; + $this->qb_cache_exists[] = 'join'; } return $this; @@ -420,7 +424,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { - $prefix = (count($this->ar_where) === 0 && count($this->ar_cache_where) === 0) ? '' : $type; + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type; if (is_null($v) && ! $this->_has_operator($k)) { @@ -446,11 +450,11 @@ abstract class CI_DB_active_record extends CI_DB_driver { $k = $this->protect_identifiers($k, FALSE, $escape); } - $this->ar_where[] = $prefix.$k.$v; - if ($this->ar_caching === TRUE) + $this->qb_where[] = $prefix.$k.$v; + if ($this->qb_caching === TRUE) { - $this->ar_cache_where[] = $prefix.$k.$v; - $this->ar_cache_exists[] = 'where'; + $this->qb_cache_where[] = $prefix.$k.$v; + $this->qb_cache_exists[] = 'where'; } } @@ -557,20 +561,20 @@ abstract class CI_DB_active_record extends CI_DB_driver { foreach ($values as $value) { - $this->ar_wherein[] = $this->escape($value); + $this->qb_wherein[] = $this->escape($value); } - $prefix = (count($this->ar_where) === 0) ? '' : $type; - $this->ar_where[] = $where_in = $prefix.$this->protect_identifiers($key).$not.' IN ('.implode(', ', $this->ar_wherein).') '; + $prefix = (count($this->qb_where) === 0) ? '' : $type; + $this->qb_where[] = $where_in = $prefix.$this->protect_identifiers($key).$not.' IN ('.implode(', ', $this->qb_wherein).') '; - if ($this->ar_caching === TRUE) + if ($this->qb_caching === TRUE) { - $this->ar_cache_where[] = $where_in; - $this->ar_cache_exists[] = 'where'; + $this->qb_cache_where[] = $where_in; + $this->qb_cache_exists[] = 'where'; } // reset the array for multiple calls - $this->ar_wherein = array(); + $this->qb_wherein = array(); return $this; } @@ -666,7 +670,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { foreach ($field as $k => $v) { $k = $this->protect_identifiers($k); - $prefix = (count($this->ar_like) === 0) ? '' : $type; + $prefix = (count($this->qb_like) === 0) ? '' : $type; $v = $this->escape_like_str($v); if ($side === 'none') @@ -692,11 +696,11 @@ abstract class CI_DB_active_record extends CI_DB_driver { $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr); } - $this->ar_like[] = $like_statement; - if ($this->ar_caching === TRUE) + $this->qb_like[] = $like_statement; + if ($this->qb_caching === TRUE) { - $this->ar_cache_like[] = $like_statement; - $this->ar_cache_exists[] = 'like'; + $this->qb_cache_like[] = $like_statement; + $this->qb_cache_exists[] = 'like'; } } @@ -716,13 +720,14 @@ abstract class CI_DB_active_record extends CI_DB_driver { public function group_start($not = '', $type = 'AND ') { $type = $this->_group_get_type($type); - $this->ar_where_group_started = TRUE; - $prefix = (count($this->ar_where) === 0 && count($this->ar_cache_where) === 0) ? '' : $type; - $this->ar_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->ar_where_group_count).' ('; - if ($this->ar_caching) + $this->qb_where_group_started = TRUE; + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type; + $this->qb_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' ('; + + if ($this->qb_caching) { - $this->ar_cache_where[] = $value; + $this->qb_cache_where[] = $value; } return $this; @@ -773,12 +778,12 @@ abstract class CI_DB_active_record extends CI_DB_driver { */ public function group_end() { - $this->ar_where_group_started = FALSE; - $this->ar_where[] = $value = str_repeat(' ', $this->ar_where_group_count--) . ')'; + $this->qb_where_group_started = FALSE; + $this->qb_where[] = $value = str_repeat(' ', $this->qb_where_group_count--) . ')'; - if ($this->ar_caching) + if ($this->qb_caching) { - $this->ar_cache_where[] = $value; + $this->qb_cache_where[] = $value; } return $this; @@ -796,10 +801,10 @@ abstract class CI_DB_active_record extends CI_DB_driver { */ protected function _group_get_type($type) { - if ($this->ar_where_group_started) + if ($this->qb_where_group_started) { $type = ''; - $this->ar_where_group_started = FALSE; + $this->qb_where_group_started = FALSE; } return $type; @@ -826,12 +831,12 @@ abstract class CI_DB_active_record extends CI_DB_driver { if ($val != '') { - $this->ar_groupby[] = $val = $this->protect_identifiers($val); + $this->qb_groupby[] = $val = $this->protect_identifiers($val); - if ($this->ar_caching === TRUE) + if ($this->qb_caching === TRUE) { - $this->ar_cache_groupby[] = $val; - $this->ar_cache_exists[] = 'groupby'; + $this->qb_cache_groupby[] = $val; + $this->qb_cache_exists[] = 'groupby'; } } } @@ -891,7 +896,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { - $prefix = (count($this->ar_having) === 0) ? '' : $type; + $prefix = (count($this->qb_having) === 0) ? '' : $type; if ($escape === TRUE) { @@ -908,11 +913,11 @@ abstract class CI_DB_active_record extends CI_DB_driver { $v = ' '.$this->escape($v); } - $this->ar_having[] = $prefix.$k.$v; - if ($this->ar_caching === TRUE) + $this->qb_having[] = $prefix.$k.$v; + if ($this->qb_caching === TRUE) { - $this->ar_cache_having[] = $prefix.$k.$v; - $this->ar_cache_exists[] = 'having'; + $this->qb_cache_having[] = $prefix.$k.$v; + $this->qb_cache_exists[] = 'having'; } } @@ -948,7 +953,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { foreach (explode(',', $orderby) as $part) { $part = trim($part); - if ( ! in_array($part, $this->ar_aliased_tables)) + if ( ! in_array($part, $this->qb_aliased_tables)) { $part = $this->protect_identifiers(trim($part)); } @@ -966,12 +971,12 @@ abstract class CI_DB_active_record extends CI_DB_driver { } } - $this->ar_orderby[] = $orderby_statement = $orderby.$direction; + $this->qb_orderby[] = $orderby_statement = $orderby.$direction; - if ($this->ar_caching === TRUE) + if ($this->qb_caching === TRUE) { - $this->ar_cache_orderby[] = $orderby_statement; - $this->ar_cache_exists[] = 'orderby'; + $this->qb_cache_orderby[] = $orderby_statement; + $this->qb_cache_exists[] = 'orderby'; } return $this; @@ -988,11 +993,11 @@ abstract class CI_DB_active_record extends CI_DB_driver { */ public function limit($value, $offset = NULL) { - $this->ar_limit = (int) $value; + $this->qb_limit = (int) $value; if ( ! is_null($offset)) { - $this->ar_offset = (int) $offset; + $this->qb_offset = (int) $offset; } return $this; @@ -1008,7 +1013,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { */ public function offset($offset) { - $this->ar_offset = (int) $offset; + $this->qb_offset = (int) $offset; return $this; } @@ -1035,11 +1040,11 @@ abstract class CI_DB_active_record extends CI_DB_driver { { if ($escape === FALSE) { - $this->ar_set[$this->protect_identifiers($k)] = $v; + $this->qb_set[$this->protect_identifiers($k)] = $v; } else { - $this->ar_set[$this->protect_identifiers($k, FALSE, TRUE)] = $this->escape($v); + $this->qb_set[$this->protect_identifiers($k, FALSE, TRUE)] = $this->escape($v); } } @@ -1054,7 +1059,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { * Compiles a SELECT query string and returns the sql. * * @param string the table name to select from (optional) - * @param bool TRUE: resets AR values; FALSE: leave AR vaules alone + * @param bool TRUE: resets QB values; FALSE: leave QB vaules alone * @return string */ public function get_compiled_select($table = '', $reset = TRUE) @@ -1110,7 +1115,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { * "Count All Results" query * * Generates a platform-specific query string that counts all records - * returned by an Active Record query. + * returned by an Query Builder query. * * @param string * @return string @@ -1186,7 +1191,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { $this->set_insert_batch($set); } - if (count($this->ar_set) === 0) + if (count($this->qb_set) === 0) { if ($this->db_debug) { @@ -1198,18 +1203,18 @@ abstract class CI_DB_active_record extends CI_DB_driver { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } - $table = $this->ar_from[0]; + $table = $this->qb_from[0]; } // Batch this baby - for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100) + for ($i = 0, $total = count($this->qb_set); $i < $total; $i += 100) { - $this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100))); + $this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, 100))); } $this->_reset_write(); @@ -1261,7 +1266,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0) { // batch function above returns an error on an empty array - $this->ar_set[] = array(); + $this->qb_set[] = array(); return; } @@ -1269,7 +1274,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { if ($escape === FALSE) { - $this->ar_set[] = '('.implode(',', $row).')'; + $this->qb_set[] = '('.implode(',', $row).')'; } else { @@ -1279,13 +1284,13 @@ abstract class CI_DB_active_record extends CI_DB_driver { $clean[] = $this->escape($value); } - $this->ar_set[] = '('.implode(',', $clean).')'; + $this->qb_set[] = '('.implode(',', $clean).')'; } } foreach ($keys as $k) { - $this->ar_keys[] = $this->protect_identifiers($k); + $this->qb_keys[] = $this->protect_identifiers($k); } return $this; @@ -1299,7 +1304,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { * Compiles an insert query and returns the sql * * @param string the table to insert into - * @param bool TRUE: reset AR values; FALSE: leave AR values alone + * @param bool TRUE: reset QB values; FALSE: leave QB values alone * @return string */ public function get_compiled_insert($table = '', $reset = TRUE) @@ -1310,9 +1315,11 @@ abstract class CI_DB_active_record extends CI_DB_driver { } $sql = $this->_insert( - $this->protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), - array_keys($this->ar_set), - array_values($this->ar_set) + $this->protect_identifiers( + $this->qb_from[0], TRUE, NULL, FALSE + ), + array_keys($this->qb_set), + array_values($this->qb_set) ); if ($reset === TRUE) @@ -1347,9 +1354,11 @@ abstract class CI_DB_active_record extends CI_DB_driver { } $sql = $this->_insert( - $this->protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), - array_keys($this->ar_set), - array_values($this->ar_set) + $this->protect_identifiers( + $this->qb_from[0], TRUE, NULL, FALSE + ), + array_keys($this->qb_set), + array_values($this->qb_set) ); $this->_reset_write(); @@ -1387,21 +1396,21 @@ abstract class CI_DB_active_record extends CI_DB_driver { */ protected function _validate_insert($table = '') { - if (count($this->ar_set) === 0) + if (count($this->qb_set) === 0) { return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } if ($table == '') { - if ( ! isset($this->ar_from[0])) + if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } } else { - $this->ar_from[0] = $table; + $this->qb_from[0] = $table; } return TRUE; @@ -1425,22 +1434,23 @@ abstract class CI_DB_active_record extends CI_DB_driver { $this->set($set); } - if (count($this->ar_set) === 0) + if (count($this->qb_set) === 0) { return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } if ($table == '') { - if ( ! isset($this->ar_from[0])) + if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } - $table = $this->ar_from[0]; + $table = $this->qb_from[0]; } - $sql = $this->_replace($this->protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); + $sql = $this->_replace($this->protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->qb_set), array_values($this->qb_set)); + $this->_reset_write(); return $this->query($sql); } @@ -1470,7 +1480,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { * Compiles an update query and returns the sql * * @param string the table to update - * @param bool TRUE: reset AR values; FALSE: leave AR values alone + * @param bool TRUE: reset QB values; FALSE: leave QB values alone * @return string */ public function get_compiled_update($table = '', $reset = TRUE) @@ -1483,7 +1493,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { return FALSE; } - $sql = $this->_update($this->protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); + $sql = $this->_update($this->protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set, $this->qb_where, $this->qb_orderby, $this->qb_limit); if ($reset === TRUE) { @@ -1530,7 +1540,8 @@ abstract class CI_DB_active_record extends CI_DB_driver { $this->limit($limit); } - $sql = $this->_update($this->protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit, $this->ar_like); + $sql = $this->_update($this->protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set, $this->qb_where, $this->qb_orderby, $this->qb_limit, $this->qb_like); + $this->_reset_write(); return $this->query($sql); } @@ -1584,21 +1595,21 @@ abstract class CI_DB_active_record extends CI_DB_driver { */ protected function _validate_update($table = '') { - if (count($this->ar_set) == 0) + if (count($this->qb_set) == 0) { return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } if ($table == '') { - if ( ! isset($this->ar_from[0])) + if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } } else { - $this->ar_from[0] = $table; + $this->qb_from[0] = $table; } return TRUE; @@ -1631,25 +1642,25 @@ abstract class CI_DB_active_record extends CI_DB_driver { $this->set_update_batch($set, $index); } - if (count($this->ar_set) === 0) + if (count($this->qb_set) === 0) { return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } if ($table == '') { - if ( ! isset($this->ar_from[0])) + if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } - $table = $this->ar_from[0]; + $table = $this->qb_from[0]; } // Batch this baby - for ($i = 0, $total = count($this->ar_set); $i < $total; $i += 100) + for ($i = 0, $total = count($this->qb_set); $i < $total; $i += 100) { - $this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->protect_identifiers($index), $this->ar_where)); + $this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set, $i, 100), $this->protect_identifiers($index), $this->qb_where)); } $this->_reset_write(); @@ -1698,7 +1709,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { return $this->display_error('db_batch_missing_index'); } - $this->ar_set[] = $clean; + $this->qb_set[] = $clean; } return $this; @@ -1718,12 +1729,12 @@ abstract class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } - $table = $this->ar_from[0]; + $table = $this->qb_from[0]; } else { @@ -1751,12 +1762,12 @@ abstract class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } - $table = $this->ar_from[0]; + $table = $this->qb_from[0]; } else { @@ -1794,7 +1805,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { * Compiles a delete query string and returns the sql * * @param string the table to delete from - * @param bool TRUE: reset AR values; FALSE: leave AR values alone + * @param bool TRUE: reset QB values; FALSE: leave QB values alone * @return string */ public function get_compiled_delete($table = '', $reset = TRUE) @@ -1825,12 +1836,12 @@ abstract class CI_DB_active_record extends CI_DB_driver { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if ( ! isset($this->qb_from[0])) { return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } - $table = $this->ar_from[0]; + $table = $this->qb_from[0]; } elseif (is_array($table)) { @@ -1857,12 +1868,12 @@ abstract class CI_DB_active_record extends CI_DB_driver { $this->limit($limit); } - if (count($this->ar_where) === 0 && count($this->ar_wherein) === 0 && count($this->ar_like) === 0) + if (count($this->qb_where) === 0 && count($this->qb_wherein) === 0 && count($this->qb_like) === 0) { return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE; } - $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit); + $sql = $this->_delete($table, $this->qb_where, $this->qb_like, $this->qb_limit); if ($reset_data) { $this->_reset_write(); @@ -1969,9 +1980,9 @@ abstract class CI_DB_active_record extends CI_DB_driver { $table = trim(strrchr($table, ' ')); // Store the alias, if it doesn't already exist - if ( ! in_array($table, $this->ar_aliased_tables)) + if ( ! in_array($table, $this->qb_aliased_tables)) { - $this->ar_aliased_tables[] = $table; + $this->qb_aliased_tables[] = $table; } } } @@ -1998,9 +2009,9 @@ abstract class CI_DB_active_record extends CI_DB_driver { } else { - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + $sql = ( ! $this->qb_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - if (count($this->ar_select) === 0) + if (count($this->qb_select) === 0) { $sql .= '*'; } @@ -2009,73 +2020,73 @@ abstract class CI_DB_active_record extends CI_DB_driver { // Cycle through the "select" portion of the query and prep each column name. // The reason we protect identifiers here rather then in the select() function // is because until the user calls the from() function we don't know if there are aliases - foreach ($this->ar_select as $key => $val) + foreach ($this->qb_select as $key => $val) { - $no_escape = isset($this->ar_no_escape[$key]) ? $this->ar_no_escape[$key] : NULL; - $this->ar_select[$key] = $this->protect_identifiers($val, FALSE, $no_escape); + $no_escape = isset($this->qb_no_escape[$key]) ? $this->qb_no_escape[$key] : NULL; + $this->qb_select[$key] = $this->protect_identifiers($val, FALSE, $no_escape); } - $sql .= implode(', ', $this->ar_select); + $sql .= implode(', ', $this->qb_select); } } // Write the "FROM" portion of the query - if (count($this->ar_from) > 0) + if (count($this->qb_from) > 0) { - $sql .= "\nFROM ".$this->_from_tables($this->ar_from); + $sql .= "\nFROM ".$this->_from_tables($this->qb_from); } // Write the "JOIN" portion of the query - if (count($this->ar_join) > 0) + if (count($this->qb_join) > 0) { - $sql .= "\n".implode("\n", $this->ar_join); + $sql .= "\n".implode("\n", $this->qb_join); } // Write the "WHERE" portion of the query - if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) + if (count($this->qb_where) > 0 OR count($this->qb_like) > 0) { $sql .= "\nWHERE "; } - $sql .= implode("\n", $this->ar_where); + $sql .= implode("\n", $this->qb_where); // Write the "LIKE" portion of the query - if (count($this->ar_like) > 0) + if (count($this->qb_like) > 0) { - if (count($this->ar_where) > 0) + if (count($this->qb_where) > 0) { $sql .= "\nAND "; } - $sql .= implode("\n", $this->ar_like); + $sql .= implode("\n", $this->qb_like); } // Write the "GROUP BY" portion of the query - if (count($this->ar_groupby) > 0) + if (count($this->qb_groupby) > 0) { - $sql .= "\nGROUP BY ".implode(', ', $this->ar_groupby); + $sql .= "\nGROUP BY ".implode(', ', $this->qb_groupby); } // Write the "HAVING" portion of the query - if (count($this->ar_having) > 0) + if (count($this->qb_having) > 0) { - $sql .= "\nHAVING ".implode("\n", $this->ar_having); + $sql .= "\nHAVING ".implode("\n", $this->qb_having); } // Write the "ORDER BY" portion of the query - if (count($this->ar_orderby) > 0) + if (count($this->qb_orderby) > 0) { - $sql .= "\nORDER BY ".implode(', ', $this->ar_orderby); - if ($this->ar_order !== FALSE) + $sql .= "\nORDER BY ".implode(', ', $this->qb_orderby); + if ($this->qb_order !== FALSE) { - $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; + $sql .= ($this->qb_order == 'desc') ? ' DESC' : ' ASC'; } } // Write the "LIMIT" portion of the query - if (is_numeric($this->ar_limit)) + if (is_numeric($this->qb_limit)) { - return $this->_limit($sql."\n", $this->ar_limit, $this->ar_offset); + return $this->_limit($sql."\n", $this->qb_limit, $this->qb_offset); } return $sql; @@ -2153,13 +2164,13 @@ abstract class CI_DB_active_record extends CI_DB_driver { /** * Start Cache * - * Starts AR caching + * Starts QB caching * * @return void */ public function start_cache() { - $this->ar_caching = TRUE; + $this->qb_caching = TRUE; } // -------------------------------------------------------------------- @@ -2167,13 +2178,13 @@ abstract class CI_DB_active_record extends CI_DB_driver { /** * Stop Cache * - * Stops AR caching + * Stops QB caching * * @return void */ public function stop_cache() { - $this->ar_caching = FALSE; + $this->qb_caching = FALSE; } // -------------------------------------------------------------------- @@ -2181,24 +2192,24 @@ abstract class CI_DB_active_record extends CI_DB_driver { /** * Flush Cache * - * Empties the AR cache + * Empties the QB cache * * @return void */ public function flush_cache() { $this->_reset_run(array( - 'ar_cache_select' => array(), - 'ar_cache_from' => array(), - 'ar_cache_join' => array(), - 'ar_cache_where' => array(), - 'ar_cache_like' => array(), - 'ar_cache_groupby' => array(), - 'ar_cache_having' => array(), - 'ar_cache_orderby' => array(), - 'ar_cache_set' => array(), - 'ar_cache_exists' => array(), - 'ar_cache_no_escape' => array() + 'qb_cache_select' => array(), + 'qb_cache_from' => array(), + 'qb_cache_join' => array(), + 'qb_cache_where' => array(), + 'qb_cache_like' => array(), + 'qb_cache_groupby' => array(), + 'qb_cache_having' => array(), + 'qb_cache_orderby' => array(), + 'qb_cache_set' => array(), + 'qb_cache_exists' => array(), + 'qb_cache_no_escape' => array() )); } @@ -2207,47 +2218,47 @@ abstract class CI_DB_active_record extends CI_DB_driver { /** * Merge Cache * - * When called, this function merges any cached AR arrays with + * When called, this function merges any cached QB arrays with * locally called ones. * * @return void */ protected function _merge_cache() { - if (count($this->ar_cache_exists) === 0) + if (count($this->qb_cache_exists) === 0) { return; } - foreach ($this->ar_cache_exists as $val) + foreach ($this->qb_cache_exists as $val) { - $ar_variable = 'ar_'.$val; - $ar_cache_var = 'ar_cache_'.$val; + $qb_variable = 'qb_'.$val; + $qb_cache_var = 'qb_cache_'.$val; - if (count($this->$ar_cache_var) === 0) + if (count($this->$qb_cache_var) === 0) { continue; } - $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable)); + $this->$qb_variable = array_unique(array_merge($this->$qb_cache_var, $this->$qb_variable)); } // If we are "protecting identifiers" we need to examine the "from" // portion of the query to determine if there are any aliases - if ($this->_protect_identifiers === TRUE && count($this->ar_cache_from) > 0) + if ($this->_protect_identifiers === TRUE && count($this->qb_cache_from) > 0) { - $this->_track_aliases($this->ar_from); + $this->_track_aliases($this->qb_from); } - $this->ar_no_escape = $this->ar_cache_no_escape; + $this->qb_no_escape = $this->qb_cache_no_escape; } // -------------------------------------------------------------------- /** - * Reset Active Record values. + * Reset Query Builder values. * - * Publicly-visible method to reset the AR values. + * Publicly-visible method to reset the QB values. * * @return void */ @@ -2260,16 +2271,16 @@ abstract class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record values. Called by the get() function + * Resets the query builder values. Called by the get() function * * @param array An array of fields to reset * @return void */ - protected function _reset_run($ar_reset_items) + protected function _reset_run($qb_reset_items) { - foreach ($ar_reset_items as $item => $default_value) + foreach ($qb_reset_items as $item => $default_value) { - if ( ! in_array($item, $this->ar_store_array)) + if ( ! in_array($item, $this->qb_store_array)) { $this->$item = $default_value; } @@ -2279,28 +2290,28 @@ abstract class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record values. Called by the get() function + * Resets the query builder values. Called by the get() function * * @return void */ protected function _reset_select() { $this->_reset_run(array( - 'ar_select' => array(), - 'ar_from' => array(), - 'ar_join' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_groupby' => array(), - 'ar_having' => array(), - 'ar_orderby' => array(), - 'ar_wherein' => array(), - 'ar_aliased_tables' => array(), - 'ar_no_escape' => array(), - 'ar_distinct' => FALSE, - 'ar_limit' => FALSE, - 'ar_offset' => FALSE, - 'ar_order' => FALSE + 'qb_select' => array(), + 'qb_from' => array(), + 'qb_join' => array(), + 'qb_where' => array(), + 'qb_like' => array(), + 'qb_groupby' => array(), + 'qb_having' => array(), + 'qb_orderby' => array(), + 'qb_wherein' => array(), + 'qb_aliased_tables' => array(), + 'qb_no_escape' => array(), + 'qb_distinct' => FALSE, + 'qb_limit' => FALSE, + 'qb_offset' => FALSE, + 'qb_order' => FALSE ) ); } @@ -2308,7 +2319,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record "write" values. + * Resets the query builder "write" values. * * Called by the insert() update() insert_batch() update_batch() and delete() functions * @@ -2317,19 +2328,19 @@ abstract class CI_DB_active_record extends CI_DB_driver { protected function _reset_write() { $this->_reset_run(array( - 'ar_set' => array(), - 'ar_from' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_orderby' => array(), - 'ar_keys' => array(), - 'ar_limit' => FALSE, - 'ar_order' => FALSE + 'qb_set' => array(), + 'qb_from' => array(), + 'qb_where' => array(), + 'qb_like' => array(), + 'qb_orderby' => array(), + 'qb_keys' => array(), + 'qb_limit' => FALSE, + 'qb_order' => FALSE ) ); } } -/* End of file DB_active_rec.php */ -/* Location: ./system/database/DB_active_rec.php */
\ No newline at end of file +/* End of file DB_query_builder.php */ +/* Location: ./system/database/DB_query_builder.php */
\ No newline at end of file diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index 7a5c048f9..1373faa88 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -21,7 +21,7 @@ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com - * @since Version 2.0.2 + * @since Version 2.1 * @filesource */ @@ -29,7 +29,7 @@ * CUBRID Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter @@ -43,7 +43,7 @@ class CI_DB_cubrid_driver extends CI_DB { public $dbdriver = 'cubrid'; // The character used for escaping - no need in CUBRID - protected $_escape_char = ''; + protected $_escape_char = '`'; // clause and character used for LIKE escape sequences - not used in CUBRID protected $_like_escape_str = ''; @@ -192,13 +192,8 @@ class CI_DB_cubrid_driver extends CI_DB { */ public function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) - { - return TRUE; - } - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -206,7 +201,7 @@ class CI_DB_cubrid_driver extends CI_DB { // Reset the transaction failure flag. // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; + $this->_trans_failure = ($test_mode === TRUE); if (cubrid_get_autocommit($this->conn_id)) { @@ -225,13 +220,8 @@ class CI_DB_cubrid_driver extends CI_DB { */ public function trans_commit() { - if ( ! $this->trans_enabled) - { - return TRUE; - } - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -255,13 +245,8 @@ class CI_DB_cubrid_driver extends CI_DB { */ public function trans_rollback() { - if ( ! $this->trans_enabled) - { - return TRUE; - } - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -297,7 +282,9 @@ class CI_DB_cubrid_driver extends CI_DB { return $str; } - if (function_exists('cubrid_real_escape_string') AND is_resource($this->conn_id)) + if (function_exists('cubrid_real_escape_string') && + (is_resource($this->conn_id) + OR (get_resource_type($this->conn_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->conn_id))))) { $str = cubrid_real_escape_string($str, $this->conn_id); } @@ -309,7 +296,7 @@ class CI_DB_cubrid_driver extends CI_DB { // escape LIKE condition wildcards if ($like === TRUE) { - $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); + return str_replace(array('%', '_'), array('\\%', '\\_'), $str); } return $str; @@ -363,9 +350,9 @@ class CI_DB_cubrid_driver extends CI_DB { return 0; } - $row = $query->row(); + $query = $query->row(); $this->_reset_select(); - return (int) $row->numrows; + return (int) $query->numrows; } // -------------------------------------------------------------------- @@ -380,11 +367,11 @@ class CI_DB_cubrid_driver extends CI_DB { */ protected function _list_tables($prefix_limit = FALSE) { - $sql = "SHOW TABLES"; + $sql = 'SHOW TABLES'; - if ($prefix_limit !== FALSE AND $this->dbprefix != '') + if ($prefix_limit !== FALSE && $this->dbprefix != '') { - $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } return $sql; @@ -417,7 +404,7 @@ class CI_DB_cubrid_driver extends CI_DB { */ protected function _field_data($table) { - return "SELECT * FROM ".$table." LIMIT 1"; + return 'SELECT * FROM '.$table.' LIMIT 1'; } // -------------------------------------------------------------------- @@ -471,8 +458,6 @@ class CI_DB_cubrid_driver extends CI_DB { protected function _update_batch($table, $values, $index, $where = NULL) { $ids = array(); - $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; - foreach ($values as $key => $val) { $ids[] = $val[$index]; @@ -486,29 +471,21 @@ class CI_DB_cubrid_driver extends CI_DB { } } - $sql = "UPDATE ".$table." SET "; $cases = ''; - foreach ($final as $k => $v) { - $cases .= $k.' = CASE '."\n"; - foreach ($v as $row) - { - $cases .= $row."\n"; - } - - $cases .= 'ELSE '.$k.' END, '; + $cases .= $k." = CASE \n" + .implode("\n", $v) + .'ELSE '.$k.' END, '; } - $sql .= substr($cases, 0, -2); - - $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; - - return $sql; + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) + .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') + .$index.' IN ('.implode(',', $ids).')'; } // -------------------------------------------------------------------- - + /** * Limit string * @@ -521,16 +498,7 @@ class CI_DB_cubrid_driver extends CI_DB { */ protected function _limit($sql, $limit, $offset) { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; + return $sql.'LIMIT '.($offset == 0 ? '' : $offset.', ').$limit; } // -------------------------------------------------------------------- @@ -549,4 +517,4 @@ class CI_DB_cubrid_driver extends CI_DB { } /* End of file cubrid_driver.php */ -/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */
\ No newline at end of file +/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index 16478ee11..4e66f81e3 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -21,7 +21,7 @@ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com - * @since Version 1.0 + * @since Version 2.1 * @filesource */ @@ -55,24 +55,19 @@ class CI_DB_cubrid_forge extends CI_DB_forge { // entered the field information, so we'll simply add it to the list if (is_numeric($field)) { - $sql .= "\n\t$attributes"; + $sql .= "\n\t".$attributes; } else { $attributes = array_change_key_case($attributes, CASE_UPPER); + $sql .= "\n\t".$this->db->protect_identifiers($field) + .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : ''); - $sql .= "\n\t\"".$this->db->protect_identifiers($field).'"'; - - if (array_key_exists('NAME', $attributes)) - { - $sql .= ' '.$this->db->protect_identifiers($attributes['NAME']).' '; - } - - if (array_key_exists('TYPE', $attributes)) + if ( ! empty($attributes['TYPE'])) { $sql .= ' '.$attributes['TYPE']; - if (array_key_exists('CONSTRAINT', $attributes)) + if ( ! empty($attributes['CONSTRAINT'])) { switch ($attributes['TYPE']) { @@ -81,9 +76,10 @@ class CI_DB_cubrid_forge extends CI_DB_forge { case 'numeric': $sql .= '('.implode(',', $attributes['CONSTRAINT']).')'; break; - case 'enum': // As of version 8.4.0 CUBRID does not support - // enum data type. - break; + case 'enum': + // Will be supported in the future as part a part of + // MySQL compatibility features. + break; case 'set': $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")'; break; @@ -93,36 +89,19 @@ class CI_DB_cubrid_forge extends CI_DB_forge { } } - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - //$sql .= ' UNSIGNED'; - // As of version 8.4.0 CUBRID does not support UNSIGNED INTEGER data type. - // Will be supported in the next release as a part of MySQL Compatibility. - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else + /* As of version 8.4.1 CUBRID does not support UNSIGNED INTEGER data type. + * Will be supported in the next release as a part of MySQL Compatibility. + * + if (isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) { - $sql .= ' NOT NULL'; + $sql .= ' UNSIGNED'; } + */ - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - - if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE) - { - $sql .= ' UNIQUE'; - } + $sql .= (isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '') + .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') + .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '') + .(( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : ''); } // don't add a comma on the end of the last field @@ -151,21 +130,20 @@ class CI_DB_cubrid_forge extends CI_DB_forge { { $sql = 'CREATE TABLE '; + /* As of version 8.4.1 CUBRID does not support this SQL syntax. if ($if_not_exists === TRUE) { - //$sql .= 'IF NOT EXISTS '; - // As of version 8.4.0 CUBRID does not support this SQL syntax. + $sql .= 'IF NOT EXISTS '; } + */ $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields); // If there is a PK defined if (count($primary_keys) > 0) { - $key_name = 'pk_'.$table.'_'.$this->db->protect_identifiers(implode('_', $primary_keys)); - - $primary_keys = $this->db->protect_identifiers($primary_keys); - $sql .= ",\n\tCONSTRAINT " . $key_name . " PRIMARY KEY(" . implode(', ', $primary_keys) . ")"; + $key_name = $this->db->protect_identifiers('pk_'.$table.'_'.implode('_', $primary_keys)); + $sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->protect_identifiers($primary_keys)).')'; } if (is_array($keys) && count($keys) > 0) @@ -174,22 +152,20 @@ class CI_DB_cubrid_forge extends CI_DB_forge { { if (is_array($key)) { - $key_name = $this->db->protect_identifiers(implode('_', $key)); + $key_name = $this->db->protect_identifiers('idx_'.$table.implode('_', $key)); $key = $this->db->protect_identifiers($key); } else { - $key_name = $this->db->protect_identifiers($key); + $key_name = $this->db->protect_identifiers('idx_'.$table.$key); $key = array($key_name); } - $sql .= ",\n\tKEY \"{$key_name}\" (" . implode(', ', $key) . ")"; + $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')'; } } - $sql .= "\n);"; - - return $sql; + return $sql."\n);"; } // -------------------------------------------------------------------- @@ -211,19 +187,13 @@ class CI_DB_cubrid_forge extends CI_DB_forge { $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '; // DROP has everything it needs now. - if ($alter_type == 'DROP') + if ($alter_type === 'DROP') { return $sql.$this->db->protect_identifiers($fields); } - $sql .= $this->_process_fields($fields); - - if ($after_field != '') - { - return $sql.' AFTER '.$this->db->protect_identifiers($after_field); - } - - return $sql; + return $sql.$this->_process_fields($fields) + .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : ''); } } diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php index 58dcff29a..3eb9f7e3d 100644 --- a/system/database/drivers/cubrid/cubrid_result.php +++ b/system/database/drivers/cubrid/cubrid_result.php @@ -21,7 +21,7 @@ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com - * @since Version 2.0.2 + * @since Version 2.1 * @filesource */ @@ -84,53 +84,20 @@ class CI_DB_cubrid_result extends CI_DB_result { public function field_data() { $retval = array(); - - $tablePrimaryKeys = array(); + $i = 0; while ($field = cubrid_fetch_field($this->result_id)) { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; - $F->default = $field->def; - $F->max_length = $field->max_length; - - // At this moment primary_key property is not returned when - // cubrid_fetch_field is called. The following code will - // provide a patch for it. primary_key property will be added - // in the next release. - - // TODO: later version of CUBRID will provide primary_key - // property. - // When PK is defined in CUBRID, an index is automatically - // created in the db_index system table in the form of - // pk_tblname_fieldname. So the following will count how many - // columns are there which satisfy this format. - // The query will search for exact single columns, thus - // compound PK is not supported. - $res = cubrid_query($this->conn_id, - "SELECT COUNT(*) FROM db_index WHERE class_name = '" . $field->table . - "' AND is_primary_key = 'YES' AND index_name = 'pk_" . - $field->table . "_" . $field->name . "'" - ); - - if ($res) - { - $row = cubrid_fetch_array($res, CUBRID_NUM); - $F->primary_key = ($row[0] > 0 ? 1 : null); - } - else - { - $F->primary_key = null; - } - - if (is_resource($res)) - { - cubrid_close_request($res); - $this->result_id = FALSE; - } - - $retval[] = $F; + $retval[$i] = new stdClass(); + $retval[$i]->name = $field->name; + // CUBRID returns type as e.g. varchar(100), + // so we need to remove all digits and brackets. + $retval[$i]->type = preg_replace('/[\d()]/', '', $field->type); + $retval[$i]->default = $field->def; + // Use CUBRID's native API to obtain column's max_length, + // otherwise $field->max_length has incorrect info + $retval[$i]->max_length = cubrid_field_len($this->result_id, $i); + $retval[$i++]->primary_key = $field->primary_key; } return $retval; @@ -145,9 +112,8 @@ class CI_DB_cubrid_result extends CI_DB_result { */ public function free_result() { - if(is_resource($this->result_id) || - get_resource_type($this->result_id) == "Unknown" && - preg_match('/Resource id #/', strval($this->result_id))) + 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; diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php index 274ff6a48..c8cee99b6 100644 --- a/system/database/drivers/cubrid/cubrid_utility.php +++ b/system/database/drivers/cubrid/cubrid_utility.php @@ -21,7 +21,7 @@ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com - * @since Version 1.0 + * @since Version 2.1 * @filesource */ diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 6587d72ff..1b18de803 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -29,7 +29,7 @@ * Firebird/Interbase Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 90609a84d..f60ec8168 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -29,7 +29,7 @@ * MS SQL Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter @@ -534,4 +534,4 @@ class CI_DB_mssql_driver extends CI_DB { } /* End of file mssql_driver.php */ -/* Location: ./system/database/drivers/mssql/mssql_driver.php */
\ No newline at end of file +/* Location: ./system/database/drivers/mssql/mssql_driver.php */ diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index c2fccc1f7..32c51865d 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -29,7 +29,7 @@ * MySQL Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter @@ -531,4 +531,4 @@ class CI_DB_mysql_driver extends CI_DB { } /* End of file mysql_driver.php */ -/* Location: ./system/database/drivers/mysql/mysql_driver.php */
\ No newline at end of file +/* Location: ./system/database/drivers/mysql/mysql_driver.php */ diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index a690682be..e2684e4f2 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -29,7 +29,7 @@ * MySQLi Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter @@ -535,4 +535,4 @@ class CI_DB_mysqli_driver extends CI_DB { } /* End of file mysqli_driver.php */ -/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */
\ No newline at end of file +/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 1b66178c6..33a89df94 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -29,7 +29,7 @@ * oci8 Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter @@ -682,4 +682,4 @@ class CI_DB_oci8_driver extends CI_DB { } /* End of file oci8_driver.php */ -/* Location: ./system/database/drivers/oci8/oci8_driver.php */
\ No newline at end of file +/* Location: ./system/database/drivers/oci8/oci8_driver.php */ diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 38416cf90..e36f2d233 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -29,7 +29,7 @@ * ODBC Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter @@ -413,4 +413,4 @@ class CI_DB_odbc_driver extends CI_DB { } /* End of file odbc_driver.php */ -/* Location: ./system/database/drivers/odbc/odbc_driver.php */
\ No newline at end of file +/* Location: ./system/database/drivers/odbc/odbc_driver.php */ diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 60151b900..89e69676d 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -29,7 +29,7 @@ * PDO Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter @@ -225,7 +225,7 @@ class CI_DB_pdo_driver extends CI_DB { * * Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php */ - if ($this->subdriver === 'mysql' && ! is_php('5.3.6') && ! empty($this->char_set)) + if ($this->pdodriver === 'mysql' && ! is_php('5.3.6') && ! empty($this->char_set)) { $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES '.$this->char_set .( ! empty($this->db_collat) ? " COLLATE '".$this->dbcollat."'" : ''); @@ -683,4 +683,4 @@ class CI_DB_pdo_driver extends CI_DB { } /* End of file pdo_driver.php */ -/* Location: ./system/database/drivers/pdo/pdo_driver.php */
\ No newline at end of file +/* Location: ./system/database/drivers/pdo/pdo_driver.php */ diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 14259be52..84bf768ee 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -29,7 +29,7 @@ * Postgre Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter @@ -164,8 +164,8 @@ class CI_DB_postgre_driver extends CI_DB { /** * Set client character set * - * @param string - * @return bool + * @param string + * @return bool */ protected function _db_set_charset($charset) { @@ -219,6 +219,7 @@ class CI_DB_postgre_driver extends CI_DB { /** * Begin Transaction * + * @param bool * @return bool */ public function trans_begin($test_mode = FALSE) @@ -234,7 +235,7 @@ class CI_DB_postgre_driver extends CI_DB { // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE); - return @pg_query($this->conn_id, 'BEGIN'); + return (bool) @pg_query($this->conn_id, 'BEGIN'); } // -------------------------------------------------------------------- @@ -252,7 +253,7 @@ class CI_DB_postgre_driver extends CI_DB { return TRUE; } - return @pg_query($this->conn_id, 'COMMIT'); + return (bool) @pg_query($this->conn_id, 'COMMIT'); } // -------------------------------------------------------------------- @@ -270,7 +271,7 @@ class CI_DB_postgre_driver extends CI_DB { return TRUE; } - return @pg_query($this->conn_id, 'ROLLBACK'); + return (bool) @pg_query($this->conn_id, 'ROLLBACK'); } // -------------------------------------------------------------------- @@ -328,34 +329,41 @@ class CI_DB_postgre_driver extends CI_DB { */ public function insert_id() { - $v = $this->version(); + $v = pg_version($this->conn_id); + $v = isset($v['server']) ? $v['server'] : 0; // 'server' key is only available since PosgreSQL 7.4 - $table = func_num_args() > 0 ? func_get_arg(0) : NULL; - $column = func_num_args() > 1 ? func_get_arg(1) : NULL; + $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 && $column != NULL && $v >= '8.0') - { - $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); - $query = $this->query($sql); - $row = $query->row(); - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); + $sql = 'SELECT LASTVAL() AS ins_id'; } elseif ($table != NULL) { - // seq_name passed in table parameter - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); + 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); - $row = $query->row(); - return $row->ins_id; + $query = $query->row(); + return (int) $query->ins_id; } // -------------------------------------------------------------------- @@ -382,9 +390,9 @@ class CI_DB_postgre_driver extends CI_DB { return 0; } - $row = $query->row(); + $query = $query->row(); $this->_reset_select(); - return (int) $row->numrows; + return (int) $query->numrows; } // -------------------------------------------------------------------- @@ -401,9 +409,9 @@ class CI_DB_postgre_driver extends CI_DB { { $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - if ($prefix_limit !== FALSE AND $this->dbprefix != '') + if ($prefix_limit !== FALSE && $this->dbprefix != '') { - $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); + return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; @@ -421,7 +429,7 @@ class CI_DB_postgre_driver extends CI_DB { */ protected function _list_columns($table = '') { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; + return "SELECT column_name FROM information_schema.columns WHERE table_name = '".$table."'"; } // -------------------------------------------------------------------- @@ -432,11 +440,11 @@ class CI_DB_postgre_driver extends CI_DB { * Generates a platform-specific query so that the column data can be retrieved * * @param string the table name - * @return object + * @return string */ protected function _field_data($table) { - return "SELECT * FROM ".$table." LIMIT 1"; + return 'SELECT * FROM '.$table.' LIMIT 1'; } // -------------------------------------------------------------------- @@ -531,6 +539,7 @@ class CI_DB_postgre_driver extends CI_DB { } // -------------------------------------------------------------------- + /** * Limit string * @@ -543,14 +552,7 @@ class CI_DB_postgre_driver extends CI_DB { */ protected function _limit($sql, $limit, $offset) { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; + return $sql.' LIMIT '.$limit.($offset == 0 ? '' : ' OFFSET '.$offset); } // -------------------------------------------------------------------- @@ -569,4 +571,4 @@ class CI_DB_postgre_driver extends CI_DB { } /* End of file postgre_driver.php */ -/* Location: ./system/database/drivers/postgre/postgre_driver.php */
\ No newline at end of file +/* Location: ./system/database/drivers/postgre/postgre_driver.php */ diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 8b214ebe6..94c97af50 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -42,7 +42,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { * @param mixed the fields * @return string */ - protected function _process_fields($fields, $primary_keys=array()) + protected function _process_fields($fields, $primary_keys = array()) { $sql = ''; $current_field_count = 0; @@ -54,15 +54,14 @@ class CI_DB_postgre_forge extends CI_DB_forge { // entered the field information, so we'll simply add it to the list if (is_numeric($field)) { - $sql .= "\n\t$attributes"; + $sql .= "\n\t".$attributes; } else { - $attributes = array_change_key_case($attributes, CASE_UPPER); - $sql .= "\n\t".$this->db->protect_identifiers($field); - $is_unsigned = (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE); + $attributes = array_change_key_case($attributes, CASE_UPPER); + $is_unsigned = ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE); // Convert datatypes to be PostgreSQL-compatible switch (strtoupper($attributes['TYPE'])) @@ -94,44 +93,24 @@ class CI_DB_postgre_forge extends CI_DB_forge { case 'BLOB': $attributes['TYPE'] = 'BYTEA'; break; + default: + break; } // If this is an auto-incrementing primary key, use the serial data type instead - if (in_array($field, $primary_keys) && array_key_exists('AUTO_INCREMENT', $attributes) - && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' SERIAL'; - } - else - { - $sql .= ' '.$attributes['TYPE']; - } + $sql .= (in_array($field, $primary_keys) && ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) + ? ' SERIAL' : ' '.$attributes['TYPE']; // Modified to prevent constraints with integer data types - if (array_key_exists('CONSTRAINT', $attributes) && strpos($attributes['TYPE'], 'INT') === false) + if ( ! empty($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') === FALSE) { $sql .= '('.$attributes['CONSTRAINT'].')'; } - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - // Added new attribute to create unqite fields. Also works with MySQL - if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE) - { - $sql .= ' UNIQUE'; - } + $sql .= (isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '') + .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') + // Added new attribute to create unqite fields. Also works with MySQL + .(( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : ''); } // don't add a comma on the end of the last field @@ -179,7 +158,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { $primary_keys[$index] = $this->db->protect_identifiers($key); } - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')'; } $sql .= "\n);"; @@ -199,7 +178,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { foreach ($key as $field) { - $sql .= "CREATE INDEX " . $table . "_" . str_replace(array('"', "'"), '', $field) . "_index ON $table ($field); "; + $sql .= 'CREATE INDEX '.$table.'_'.str_replace(array('"', "'"), '', $field).'_index ON '.$table.' ('.$field.'); '; } } } @@ -220,7 +199,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { * @param string the table name * @param string the column definition * @param string the default value - * @param boolean should 'NOT NULL' be added + * @param bool should 'NOT NULL' be added * @param string the field after which we should add the new field * @return string */ @@ -229,19 +208,13 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '; // DROP has everything it needs now. - if ($alter_type == 'DROP') + if ($alter_type === 'DROP') { return $sql.$this->db->protect_identifiers($fields); } - $sql .= $this->_process_fields($fields); - - if ($after_field != '') - { - return $sql.' AFTER '.$this->db->protect_identifiers($after_field); - } - - return $sql; + return $sql.$this->_process_fields($fields) + .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : ''); } } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 5021deb63..551704f83 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -29,7 +29,7 @@ * SQLite Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter @@ -461,4 +461,4 @@ class CI_DB_sqlite_driver extends CI_DB { } /* End of file sqlite_driver.php */ -/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */
\ No newline at end of file +/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index fb45bee9c..d22f6a442 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -29,7 +29,7 @@ * SQLite3 Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 951567033..8cc500f55 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -29,7 +29,7 @@ * SQLSRV Database Adapter Class * * Note: _DB is an extender class that the app controller - * creates dynamically based on whether the active record + * creates dynamically based on whether the query builder * class is being used or not. * * @package CodeIgniter @@ -440,7 +440,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); } - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).' WHERE '.$where; + return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; } // -------------------------------------------------------------------- @@ -521,4 +521,4 @@ class CI_DB_sqlsrv_driver extends CI_DB { } /* End of file sqlsrv_driver.php */ -/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.php */
\ No newline at end of file +/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.php */ diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 19192a147..8b87f8179 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -100,6 +100,9 @@ if ( ! function_exists('force_download')) $x[count($x) - 1] = strtoupper($extension); $filename = implode('.', $x); } + + // Clean output buffer + ob_clean(); // Generate the server headers header('Content-Type: '.$mime); diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 3a373efd3..a5aabecd6 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -145,7 +145,7 @@ if ( ! function_exists('delete_files')) { delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs); } - elseif ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php))$/', $filename)) + elseif ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) { @unlink($path.DIRECTORY_SEPARATOR.$filename); } diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 48c3bf3ab..103c3cb25 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1891,6 +1891,7 @@ class CI_Email { 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'css' => 'text/css', + 'ics' => 'text/calendar', 'html' => 'text/html', 'htm' => 'text/html', 'shtml' => 'text/html', |