From 24abcb98d4281dcf857cb08a86a58af286a2f94a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jan 2012 20:40:15 +0200 Subject: Numerous improvements to the Oracle (oci8) driver and DB_driver --- system/database/DB_driver.php | 242 ++++------ system/database/drivers/oci8/oci8_driver.php | 82 +--- system/database/drivers/oci8/oci8_forge.php | 45 +- system/database/drivers/oci8/oci8_result.php | 624 ++++++++++++++++++++++++-- system/database/drivers/oci8/oci8_utility.php | 36 +- 5 files changed, 741 insertions(+), 288 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 661b42ced..41d170875 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,13 +1,13 @@ -_db_set_charset($this->char_set, $this->dbcollat)) { @@ -227,10 +222,9 @@ class CI_DB_driver { /** * The name of the platform in use (mysql, mssql, etc...) * - * @access public * @return string */ - function platform() + public function platform() { return $this->dbdriver; } @@ -241,10 +235,9 @@ class CI_DB_driver { * Database Version Number. Returns a string containing the * version of the database being used * - * @access public * @return string */ - function version() + public function version() { if (FALSE === ($sql = $this->_version())) { @@ -281,12 +274,11 @@ class CI_DB_driver { * FALSE upon failure, and if the $db_debug variable is set to TRUE * will raise an error. * - * @access public * @param string An SQL query string * @param array An array of binding data * @return mixed */ - function query($sql, $binds = FALSE, $return_object = TRUE) + public function query($sql, $binds = FALSE, $return_object = TRUE) { if ($sql == '') { @@ -410,23 +402,21 @@ class CI_DB_driver { } // Load and instantiate the result driver - $driver = $this->load_rdriver(); $RES = new $driver(); - $RES->conn_id = $this->conn_id; - $RES->result_id = $this->result_id; + $RES->conn_id = $this->conn_id; + $RES->result_id = $this->result_id; if ($this->dbdriver == 'oci8') { $RES->stmt_id = $this->stmt_id; - $RES->curs_id = NULL; + $RES->curs_id = $this->curs_id; $RES->limit_used = $this->limit_used; + // Passing the next one by reference to make sure it's updated, if needed: + $RES->commit_mode = &$this->_commit; $this->stmt_id = FALSE; } - // oci8 vars must be set before calling this - $RES->num_rows = $RES->num_rows(); - // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) @@ -438,9 +428,9 @@ class CI_DB_driver { // result object, so we'll have to compile the data // and save it) $CR = new CI_DB_result(); - $CR->num_rows = $RES->num_rows(); $CR->result_object = $RES->result_object(); $CR->result_array = $RES->result_array(); + $CR->num_rows = $RES->num_rows(); // Reset these since cached objects can not utilize resource IDs. $CR->conn_id = NULL; @@ -457,10 +447,9 @@ class CI_DB_driver { /** * Load the result drivers * - * @access public * @return string the name of the result class */ - function load_rdriver() + public function load_rdriver() { $driver = 'CI_DB_'.$this->dbdriver.'_result'; @@ -481,11 +470,10 @@ class CI_DB_driver { * we only use it when running transaction commands since they do * not require all the features of the main query() function. * - * @access public * @param string the sql query * @return mixed */ - function simple_query($sql) + public function simple_query($sql) { if ( ! $this->conn_id) { @@ -504,7 +492,7 @@ class CI_DB_driver { * @access public * @return void */ - function trans_off() + public function trans_off() { $this->trans_enabled = FALSE; } @@ -521,7 +509,7 @@ class CI_DB_driver { * @access public * @return void */ - function trans_strict($mode = TRUE) + public function trans_strict($mode = TRUE) { $this->trans_strict = is_bool($mode) ? $mode : TRUE; } @@ -531,10 +519,9 @@ class CI_DB_driver { /** * Start Transaction * - * @access public * @return void */ - function trans_start($test_mode = FALSE) + public function trans_start($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -557,10 +544,9 @@ class CI_DB_driver { /** * Complete Transaction * - * @access public * @return bool */ - function trans_complete() + public function trans_complete() { if ( ! $this->trans_enabled) { @@ -604,10 +590,9 @@ class CI_DB_driver { /** * Lets you retrieve the transaction flag to determine if it has failed * - * @access public * @return bool */ - function trans_status() + public function trans_status() { return $this->_trans_status; } @@ -617,12 +602,11 @@ class CI_DB_driver { /** * Compile Bindings * - * @access public * @param string the sql statement * @param array an array of bind data * @return string */ - function compile_binds($sql, $binds) + public function compile_binds($sql, $binds) { if (strpos($sql, $this->bind_marker) === FALSE) { @@ -660,11 +644,10 @@ class CI_DB_driver { /** * Determines if a query is a "write" type. * - * @access public * @param string An SQL query string * @return boolean */ - function is_write_type($sql) + public function is_write_type($sql) { if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) { @@ -678,11 +661,10 @@ class CI_DB_driver { /** * Calculate the aggregate query elapsed time * - * @access public * @param integer The number of decimal places * @return integer */ - function elapsed_time($decimals = 6) + public function elapsed_time($decimals = 6) { return number_format($this->benchmark, $decimals); } @@ -692,10 +674,9 @@ class CI_DB_driver { /** * Returns the total number of queries * - * @access public * @return integer */ - function total_queries() + public function total_queries() { return $this->query_count; } @@ -705,10 +686,9 @@ class CI_DB_driver { /** * Returns the last query that was executed * - * @access public * @return void */ - function last_query() + public function last_query() { return end($this->queries); } @@ -721,11 +701,10 @@ class CI_DB_driver { * Escapes data based on type * Sets boolean and null types * - * @access public * @param string * @return mixed */ - function escape($str) + public function escape($str) { if (is_string($str)) { @@ -751,11 +730,10 @@ class CI_DB_driver { * Calls the individual driver for platform * specific escaping for LIKE conditions * - * @access public * @param string * @return mixed */ - function escape_like_str($str) + public function escape_like_str($str) { return $this->escape_str($str, TRUE); } @@ -768,11 +746,10 @@ class CI_DB_driver { * Retrieves the primary key. It assumes that the row in the first * position is the primary key * - * @access public * @param string the table name * @return string */ - function primary($table = '') + public function primary($table = '') { $fields = $this->list_fields($table); @@ -789,10 +766,9 @@ class CI_DB_driver { /** * Returns an array of table names * - * @access public * @return array */ - function list_tables($constrain_by_prefix = FALSE) + public function list_tables($constrain_by_prefix = FALSE) { // Is there a cached result? if (isset($this->data_cache['table_names'])) @@ -835,12 +811,12 @@ class CI_DB_driver { /** * Determine if a particular table exists - * @access public + * * @return boolean */ - function table_exists($table_name) + public function table_exists($table_name) { - return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE; + return in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables()); } // -------------------------------------------------------------------- @@ -848,11 +824,10 @@ class CI_DB_driver { /** * Fetch MySQL Field Names * - * @access public * @param string the table name * @return array */ - function list_fields($table = '') + public function list_fields($table = '') { // Is there a cached result? if (isset($this->data_cache['field_names'][$table])) @@ -901,14 +876,14 @@ class CI_DB_driver { /** * Determine if a particular field exists - * @access public + * * @param string * @param string * @return boolean */ - function field_exists($field_name, $table_name) + public function field_exists($field_name, $table_name) { - return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; + return in_array($field_name, $this->list_fields($table_name)); } // -------------------------------------------------------------------- @@ -916,11 +891,10 @@ class CI_DB_driver { /** * Returns an object with field data * - * @access public * @param string the table name * @return object */ - function field_data($table = '') + public function field_data($table = '') { if ($table == '') { @@ -932,7 +906,6 @@ class CI_DB_driver { } $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE))); - return $query->field_data(); } @@ -941,12 +914,11 @@ class CI_DB_driver { /** * Generate an insert string * - * @access public * @param string the table upon which the query will be performed * @param array an associative array data of key/values * @return string */ - function insert_string($table, $data) + public function insert_string($table, $data) { $fields = array(); $values = array(); @@ -965,13 +937,12 @@ class CI_DB_driver { /** * Generate an update string * - * @access public * @param string the table upon which the query will be performed * @param array an associative array data of key/values * @param mixed the "where" statement * @return string */ - function update_string($table, $data, $where) + public function update_string($table, $data, $where) { if ($where == '') { @@ -1018,19 +989,12 @@ class CI_DB_driver { /** * Tests whether the string has an SQL operator * - * @access private * @param string * @return bool */ - function _has_operator($str) + protected function _has_operator($str) { - $str = trim($str); - if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) - { - return FALSE; - } - - return TRUE; + return (bool) preg_match('/(\s|<|>|!|=|is null|is not null)/i', trim($str)); } // -------------------------------------------------------------------- @@ -1038,12 +1002,11 @@ class CI_DB_driver { /** * Enables a native PHP function to be run, using a platform agnostic wrapper. * - * @access public * @param string the function name * @param mixed any parameters needed by the function * @return mixed */ - function call_function($function) + public function call_function($function) { $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; @@ -1080,11 +1043,10 @@ class CI_DB_driver { /** * Set Cache Directory Path * - * @access public * @param string the path to the cache directory * @return void */ - function cache_set_path($path = '') + public function cache_set_path($path = '') { $this->cachedir = $path; } @@ -1094,13 +1056,11 @@ class CI_DB_driver { /** * Enable Query Caching * - * @access public * @return void */ - function cache_on() + public function cache_on() { - $this->cache_on = TRUE; - return TRUE; + return $this->cache_on = TRUE; } // -------------------------------------------------------------------- @@ -1108,13 +1068,11 @@ class CI_DB_driver { /** * Disable Query Caching * - * @access public * @return void */ - function cache_off() + public function cache_off() { - $this->cache_on = FALSE; - return FALSE; + return $this->cache_on = FALSE; } @@ -1123,10 +1081,9 @@ class CI_DB_driver { /** * Delete the cache files associated with a particular URI * - * @access public * @return void */ - function cache_delete($segment_one = '', $segment_two = '') + public function cache_delete($segment_one = '', $segment_two = '') { if ( ! $this->_cache_init()) { @@ -1140,10 +1097,9 @@ class CI_DB_driver { /** * Delete All cache files * - * @access public * @return void */ - function cache_delete_all() + public function cache_delete_all() { if ( ! $this->_cache_init()) { @@ -1158,22 +1114,18 @@ class CI_DB_driver { /** * Initialize the Cache Class * - * @access private * @return void */ - function _cache_init() + private function _cache_init() { if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) { return TRUE; } - if ( ! class_exists('CI_DB_Cache')) + if ( ! class_exists('CI_DB_Cache') AND ! @include(BASEPATH.'database/DB_cache.php')) { - if ( ! @include(BASEPATH.'database/DB_cache.php')) - { - return $this->cache_off(); - } + return $this->cache_off(); } $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects @@ -1185,10 +1137,9 @@ class CI_DB_driver { /** * Close DB Connection * - * @access public * @return void */ - function close() + public function close() { if (is_resource($this->conn_id) OR is_object($this->conn_id)) { @@ -1202,13 +1153,12 @@ class CI_DB_driver { /** * Display an error message * - * @access public * @param string the error message * @param string any "swap" values * @param boolean whether to localize the message * @return string sends the application/error_db.php template */ - function display_error($error = '', $swap = '', $native = FALSE) + public function display_error($error = '', $swap = '', $native = FALSE) { $LANG =& load_class('Lang', 'core'); $LANG->load('db'); @@ -1254,11 +1204,10 @@ class CI_DB_driver { * * This function adds backticks if appropriate based on db type * - * @access private * @param mixed the item to escape * @return mixed the item with backticks */ - function protect_identifiers($item, $prefix_single = FALSE) + public function protect_identifiers($item, $prefix_single = FALSE) { return $this->_protect_identifiers($item, $prefix_single); } @@ -1285,14 +1234,14 @@ class CI_DB_driver { * insert the table prefix (if it exists) in the proper position, and escape only * the correct identifiers. * - * @access private + * @access public (DB Forge needs it to be public!) * @param string * @param bool * @param mixed * @param bool * @return string */ - function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) + public function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) { if ( ! is_bool($protect_identifiers)) { @@ -1440,6 +1389,5 @@ class CI_DB_driver { } - /* End of file DB_driver.php */ /* Location: ./system/database/DB_driver.php */ diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index c6621901b..cc9557e7d 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -1,13 +1,13 @@ -stmt_id = FALSE; $this->_set_stmt_id($sql); oci_set_prefetch($this->stmt_id, 1000); @@ -187,7 +181,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * Generate a statement ID * - * @access private * @param string an SQL query * @return none */ @@ -206,7 +199,6 @@ class CI_DB_oci8_driver extends CI_DB { * * If needed, each database adapter can prep the query string * - * @access private called by execute() * @param string an SQL query * @return string */ @@ -220,7 +212,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * getCursor. Returns a cursor from the datbase * - * @access public * @return cursor id */ public function get_cursor() @@ -234,7 +225,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * Stored Procedure. Executes a stored procedure * - * @access public * @param package package stored procedure is in * @param procedure stored procedure to execute * @param params array of parameters @@ -287,7 +277,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * Bind parameters * - * @access private * @return none */ private function _bind_params($params) @@ -316,7 +305,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * Begin Transaction * - * @access public * @return bool */ public function trans_begin($test_mode = FALSE) @@ -337,7 +325,7 @@ class CI_DB_oci8_driver extends CI_DB { // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - $this->_commit = OCI_DEFAULT; + $this->_commit = (is_php('5.3.2')) ? OCI_NO_AUTO_COMMIT : OCI_DEFAULT; return TRUE; } @@ -346,7 +334,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * Commit Transaction * - * @access public * @return bool */ public function trans_commit() @@ -362,9 +349,8 @@ class CI_DB_oci8_driver extends CI_DB { return TRUE; } - $ret = oci_commit($this->conn_id); $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; + return oci_commit($this->conn_id); } // -------------------------------------------------------------------- @@ -372,7 +358,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * Rollback Transaction * - * @access public * @return bool */ public function trans_rollback() @@ -388,9 +373,8 @@ class CI_DB_oci8_driver extends CI_DB { return TRUE; } - $ret = oci_rollback($this->conn_id); $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; + return oci_rollback($this->conn_id); } // -------------------------------------------------------------------- @@ -398,7 +382,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * Escape String * - * @access public * @param string * @param bool whether or not the string will be used in a LIKE condition * @return string @@ -434,7 +417,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * Affected Rows * - * @access public * @return integer */ public function affected_rows() @@ -447,7 +429,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * Insert ID * - * @access public * @return integer */ public function insert_id() @@ -464,7 +445,6 @@ class CI_DB_oci8_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @access public * @param string * @return string */ @@ -494,7 +474,6 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @access protected * @param boolean * @return string */ @@ -517,7 +496,6 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the column names can be fetched * - * @access protected * @param string the table name * @return string */ @@ -533,7 +511,6 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query so that the column data can be retrieved * - * @access public * @param string the table name * @return object */ @@ -547,7 +524,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message string * - * @access protected * @return string */ protected function _error_message() @@ -562,7 +538,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message number * - * @access protected * @return integer */ protected function _error_number() @@ -579,7 +554,6 @@ class CI_DB_oci8_driver extends CI_DB { * * This function escapes column and table names * - * @access protected * @param string * @return string */ @@ -622,7 +596,6 @@ class CI_DB_oci8_driver extends CI_DB { * This function implicitly groups FROM tables so there is no confusion * about operator precedence in harmony with SQL standards * - * @access protected * @param type * @return type */ @@ -643,7 +616,6 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @access public * @param string the table name * @param array the insert keys * @param array the insert values @@ -688,7 +660,6 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific update string from the supplied data * - * @access protected * @param string the table name * @param array the update data * @param array the where clause @@ -705,12 +676,10 @@ class CI_DB_oci8_driver extends CI_DB { $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $orderby = (count($orderby) > 0) ? ' ORDER BY '.implode(', ', $orderby) : ''; + $sql = 'UPDATE '.$table.' SET '.implode(', ', $valstr); + $sql .= ($where != '' AND count($where) > 0) ? ' WHERE '.implode(' ', $where) : ''; $sql .= $orderby.$limit; return $sql; @@ -725,7 +694,6 @@ class CI_DB_oci8_driver extends CI_DB { * If the database does not support the truncate() command * This function maps to "DELETE FROM table" * - * @access protected * @param string the table name * @return string */ @@ -741,7 +709,6 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific delete string from the supplied data * - * @access protected * @param string the table name * @param array the where clause * @param string the limit clause @@ -775,7 +742,6 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific LIMIT clause * - * @access protected * @param string the sql query string * @param integer the number of rows to limit the query to * @param integer the offset value @@ -802,7 +768,6 @@ class CI_DB_oci8_driver extends CI_DB { /** * Close DB Connection * - * @access protected * @param resource * @return void */ @@ -811,10 +776,7 @@ class CI_DB_oci8_driver extends CI_DB { @oci_close($conn_id); } - } - - /* End of file oci8_driver.php */ /* Location: ./system/database/drivers/oci8/oci8_driver.php */ diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index b4a24cdca..6975f2a5f 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -1,13 +1,13 @@ -db->_protect_identifiers($field); - - $sql .= ' '.$attributes['TYPE']; + $sql .= "\n\t".$this->db->_protect_identifiers($field).' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { @@ -127,11 +124,6 @@ class CI_DB_oci8_forge extends CI_DB_forge { { $sql .= ' NOT NULL'; } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } } // don't add a comma on the end of the last field @@ -174,12 +166,11 @@ class CI_DB_oci8_forge extends CI_DB_forge { /** * Drop Table * - * @access private - * @return bool + * @return string */ - function _drop_table($table) + public function _drop_table($table) { - return FALSE; + return 'DROP TABLE ' . $this->db->_protect_identifiers($table); } // -------------------------------------------------------------------- @@ -190,7 +181,6 @@ class CI_DB_oci8_forge extends CI_DB_forge { * Generates a platform-specific query so that a table can be altered * Called by add_column(), drop_column(), and column_alter(), * - * @access private * @param string the ALTER type (ADD, DROP, CHANGE) * @param string the column name * @param string the table name @@ -198,9 +188,9 @@ class CI_DB_oci8_forge extends CI_DB_forge { * @param string the default value * @param boolean should 'NOT NULL' be added * @param string the field after which we should add the new field - * @return object + * @return string */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') { $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); @@ -242,12 +232,11 @@ class CI_DB_oci8_forge extends CI_DB_forge { * * Generates a platform-specific query so that a table can be renamed * - * @access private * @param string the old table name * @param string the new table name * @return string */ - function _rename_table($table_name, $new_table_name) + public function _rename_table($table_name, $new_table_name) { $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); return $sql; @@ -257,4 +246,4 @@ class CI_DB_oci8_forge extends CI_DB_forge { } /* End of file oci8_forge.php */ -/* Location: ./system/database/drivers/oci8/oci8_forge.php */ \ No newline at end of file +/* Location: ./system/database/drivers/oci8/oci8_forge.php */ diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 0f69fa9ef..cbf4bec52 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -1,13 +1,13 @@ -num_rows === 0 && count($this->result_array()) > 0) + if ( ! is_int($this->num_rows)) { - $this->num_rows = count($this->result_array()); - @oci_execute($this->stmt_id, OCI_DEFAULT); - - if ($this->curs_id) + if (count($this->result_array) > 0) + { + return $this->num_rows = count($this->result_array); + } + elseif (count($this->result_object) > 0) { - @oci_execute($this->curs_id, OCI_DEFAULT); + return $this->num_rows = count($this->result_array); } + + return $this->num_rows = count($this->result_array()); } return $this->num_rows; @@ -73,7 +82,6 @@ class CI_DB_oci8_result extends CI_DB_result { /** * Number of fields in the result set * - * @access public * @return integer */ public function num_fields() @@ -83,7 +91,7 @@ class CI_DB_oci8_result extends CI_DB_result { // if we used a limit we subtract it if ($this->limit_used) { - $count = $count - 1; + return $count - 1; } return $count; @@ -96,7 +104,6 @@ class CI_DB_oci8_result extends CI_DB_result { * * Generates an array of column names * - * @access public * @return array */ public function list_fields() @@ -116,7 +123,6 @@ class CI_DB_oci8_result extends CI_DB_result { * * Generates an array of objects containing field meta-data * - * @access public * @return array */ public function field_data() @@ -140,7 +146,7 @@ class CI_DB_oci8_result extends CI_DB_result { /** * Free the result * - * @return null + * @return void */ public function free_result() { @@ -149,6 +155,17 @@ class CI_DB_oci8_result extends CI_DB_result { 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; + } } // -------------------------------------------------------------------- @@ -158,7 +175,6 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an array * - * @access protected * @return array */ protected function _fetch_assoc() @@ -174,22 +190,47 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an object * - * @access protected * @return object */ protected function _fetch_object() { $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - return @oci_fetch_object($id); + return oci_fetch_object($id); + } + + // -------------------------------------------------------------------- + + /* Query result + * + * Acts as a wrapper for result_array(), result_object() + * and custom_result_object(). + * + * @param string ('object', 'array' or a custom class name) + * @return array + */ + + public function result($type = 'object') + { + if ($type === 'object') + { + return $this->result_object(); + } + elseif ($type === 'array') + { + return $this->result_array(); + } + else + { + return $this->custom_result_object($type); + } } // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. "array" version. * - * @access public - * @return array + * @return array */ public function result_array() { @@ -197,14 +238,488 @@ class CI_DB_oci8_result extends CI_DB_result { { return $this->result_array; } + elseif (count($this->result_object) > 0) + { + for ($i = 0, $c = count($this->result_object); $i < $c; $i++) + { + $this->result_array[$i] = (array) $this->result_object[$i]; + } + + return $this->result_array; + } + elseif (is_array($this->row_data)) + { + if (count($this->row_data) === 0) + { + return $this->result_array; + } + else + { + $row_index = count($this->row_data); + } + } + else + { + $row_index = 0; + $this->row_data = array(); + } $row = NULL; while ($row = $this->_fetch_assoc()) { - $this->result_array[] = $row; + $this->row_data[$row_index++] = $row; + } + + // Un-comment the following line, in case it becomes needed + // $this->_data_seek(); + return $this->result_array = $this->row_data; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @return array + */ + public function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + elseif (count($this->result_array) > 0) + { + for ($i = 0, $c = count($this->result_array); $i < $c; $i++) + { + $this->result_object[] = (object) $this->result_array[$i]; + } + + return $this->result_object; + } + elseif (is_array($this->row_data)) + { + if (count($this->row_data) === 0) + { + return $this->result_object; + } + else + { + $row_index = count($this->row_data); + for ($i = 0; $i < $row_index; $i++) + { + $this->result_object[$i] = (object) $this->row_data[$i]; + } + } + } + else + { + $row_index = 0; + $this->row_data = array(); + } + + $row = NULL; + while ($row = $this->_fetch_object()) + { + $this->row_data[$row_index] = (array) $row; + $this->result_object[$row_index++] = $row; + } + + // Un-comment the following line, in case it becomes needed + // $this->_data_seek(); + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. Custom object version. + * + * @param string class name used to instantiate rows to + * @return array + */ + public function custom_result_object($class_name) + { + if (array_key_exists($class_name, $this->custom_result_object)) + { + return $this->custom_result_object[$class_name]; + } + + if ( ! class_exists($class_name) OR $this->result_id === FALSE OR $this->num_rows() === 0) + { + return array(); + } + + // add the data to the object + $result_object = array(); + $data = NULL; + + /* First check if we don't already have the data. + * If so - pass by reference, as we don't know how + * large it might be and we don't want 1000 row + * sets being copied. + */ + if (count($this->result_array) > 0) + { + $data = &$this->result_array; + } + elseif (count($this->result_object) > 0) + { + $data = &$this->result_object; + } + + if ( ! is_null($data)) + { + for ($i = 0, $c = count($data); $i < $c; $i++) + { + $result_object[$i] = new $class_name(); + foreach ($data[$i] as $key => $value) + { + $result_object[$i]->$key = $value; + } + } + } + else + { + // No prefetched result set + if (is_array($this->row_data)) + { + $row_index = count($this->row_data); + if ($row_index === 0) + { + return array(); + } + else + { + for ($i = 0; $i < $row_index; $i++) + { + $result_object[$i] = new $class_name(); + foreach ($this->row_data[$i] as $key => $value) + { + $result_object[$i]->$key = $value; + } + } + } + } + else + { + $row_index = 0; + $this->row_data = array(); + } + + while ($row = $this->_fetch_assoc()) + { + $data = new $class_name(); + foreach ($row as $key => $value) + { + $data->$key = $value; + } + + $this->row_data[$row_index] = $row; + $result_object[$row_index++] = $data; + } + // Un-comment the following line, in case it becomes needed + // $this->_data_seek(); + } + + /* As described for the num_rows() method - there's no easy + * way to get the number of rows selected. Our work-around + * solution (as in here as well) first checks if result_array + * or result_object exist and returns their count. It doesn't + * however check for a custom_object_result, so - do it here. + */ + if ( ! is_int($this->num_rows)) + { + $this->num_rows = count($result_object); + } + + // Cache and return the array + return $this->custom_result_object[$class_name] = $result_object; + } + + // -------------------------------------------------------------------- + + /* Single row result. + * + * Acts as a wrapper for row_object(), row_array() + * and custom_row_object(). Also used by first_row(), next_row() + * and previous_row(). + * + * @param int row index + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + + public function row($n = 0, $type = 'object') + { + if ($type === 'object') return $this->row_object($n); + elseif ($type === 'array') return $this->row_array($n); + else return $this->custom_row_object($n, $type); + } + + // -------------------------------------------------------------------- + + /* Single row result. Array version. + * + * @param int row index + * @return array + */ + + public function row_array($n = 0) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; } - return $this->result_array; + /* If row_data is initialized, it means that we've already tried + * (at least) to fetch some data, so ... check if we already have + * this row. + */ + if (is_array($this->row_data)) + { + /* If we already have row_data[$n] - return it. + * + * If we enter the elseif, there's a number of reasons to + * return an empty array: + * + * - count($this->row_data) === 0 means there are no results + * - num_rows being set, result_array and/or result_object + * having count() > 0 means that we've already fetched all + * data and $n is greater than our highest row index available + * - $n < $this->current_row means that if such row existed, + * we would've already returned it, therefore $n is an + * invalid index + */ + if (isset($this->row_data[$n])) // We already have this row + { + $this->current_row = $n; + return $this->row_data[$n]; + } + elseif (count($this->row_data) === 0 OR is_int($this->num_rows) + OR count($this->result_array) > 0 OR count($this->result_object) > 0 + OR $n < $this->current_row) + { + // No such row exists + return array(); + } + + // Get the next row index that would actually need to be fetched + $current_row = ($this->current_row < count($this->row_data)) ? count($this->row_data) : $this->current_row + 1; + } + else + { + $current_row = $this->current_row = 0; + $this->row_data = array(); + } + + /* Fetch more data, if available + * + * NOTE: Operator precedence is important here, if you change + * 'AND' with '&&' - it WILL BREAK the results, as + * $row will be assigned the scalar value of both + * expressions! + */ + while ($row = $this->_fetch_assoc() AND $current_row <= $n) + { + $this->row_data[$current_row++] = $row; + } + + // This would mean that there's no (more) data to fetch + if ( ! is_array($this->row_data) OR ! isset($this->row_data[$n])) + { + // Cache what we already have + if (is_array($this->row_data)) + { + $this->num_rows = count($this->row_data); + /* Usually, row_data could have less elements than result_array, + * but at this point - they should be exactly the same. + */ + $this->result_array = $this->row_data; + } + else + { + $this->num_rows = 0; + } + + return array(); + } + + $this->current_row = $n; + return $this->row_data[$n]; + } + + // -------------------------------------------------------------------- + + /* Single row result. Object version. + * + * @param int row index + * @return mixed object if row found; empty array if not + */ + public function row_object($n = 0) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + /* Logic here is exactly the same as in row_array, + * except we have to cast row_data[$n] to an object. + * + * If we already have result_object though - we can + * directly return from it. + */ + if (isset($this->result_object[$n])) + { + $this->current_row = $n; + // Set this, if not already done. + if ( ! is_int($this->num_rows)) + { + $this->num_rows = count($this->result_object); + } + + return $this->result_object[$n]; + } + + $row = $this->row_array($n); + // Cast only if the row exists + if (count($row) > 0) + { + $this->current_row = $n; + return (object) $row; + } + + return array(); + } + + // -------------------------------------------------------------------- + + /* Single row result. Custom object version. + * + * @param int row index + * @param string custom class name + * @return mixed custom object if row found; empty array otherwise + */ + + public function custom_row_object($n = 0, $class_name) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + + if (array_key_exists($class_name, $this->custom_result_object)) + { + /* We already have a the whole result set with this class_name, + * return the specified row if it exists, and an empty array if + * it doesn't. + */ + if (isset($this->custom_result_object[$class_name][$n])) + { + $this->current_row = $n; + return $this->custom_result_object[$class_name][$n]; + } + else + { + return array(); + } + } + elseif ( ! class_exists($class_name)) // No such class exists + { + return array(); + } + + $row = $this->row_array($n); + // An array would mean that the row doesn't exist + if (is_array($row)) + { + return $row; + } + + // Convert to the desired class and return + $row_object = new $class_name(); + foreach ($row as $key => $value) + { + $row_object->$key = $value; + } + + $this->current_row = $n; + return $row_object; + } + + // -------------------------------------------------------------------- + + /* First row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + + public function first_row($type = 'object') + { + return $this->row(0, $type); + } + + // -------------------------------------------------------------------- + + /* Last row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function last_row($type = 'object') + { + $result = &$this->result($type); + if ( ! isset($this->num_rows)) + { + $this->num_rows = count($result); + } + $this->current_row = $this->num_rows - 1; + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /* Next row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function next_row($type = 'object') + { + if (is_array($this->row_data)) + { + $count = count($this->row_data); + if ($this->current_row > $count OR ($this->current_row === 0 && $count === 0)) + { + $n = $count; + } + else + { + $n = $this->current_row + 1; + } + } + else + { + $n = 0; + } + + return $this->row($n, $type); + } + + // -------------------------------------------------------------------- + + /* Previous row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function previous_row($type = 'object') + { + $n = ($this->current_row !== 0) ? $this->current_row - 1 : 0; + return $this->row($n, $type); } // -------------------------------------------------------------------- @@ -212,20 +727,59 @@ class CI_DB_oci8_result extends CI_DB_result { /** * Data Seek * - * Moves the internal pointer to the desired offset. We call + * Moves the internal pointer to the desired offset. We call * this internally before fetching results to make sure the - * result set starts at zero + * result set starts at zero. * - * @access protected - * @return array + * Oracle's PHP extension doesn't have an easy way of doing this + * and the only workaround is to (re)execute the statement or cursor + * in order to go to the first (zero) index of the result set. + * Then, we would need to "dummy" fetch ($n - 1) rows to get to the + * right one. + * + * This is as ridiculous as it sounds and it's the reason why every + * other method that is fetching data tries to use an already "cached" + * result set. Keeping this just in case it becomes needed at + * some point in the future, but it will only work for resetting the + * pointer to zero. + * + * @return bool */ - protected function _data_seek($n = 0) + protected function _data_seek() { - return FALSE; // Not needed + /* The PHP manual says that if OCI_NO_AUTO_COMMIT mode + * is used, and oci_rollback() and/or oci_commit() are + * not subsequently called - this will cause an unnecessary + * rollback to be triggered at the end of the script execution. + * + * Therefore we'll try to avoid using that mode flag + * if we're not currently in the middle of a transaction. + */ + if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS) + { + $result = @oci_execute($this->stmt_id, $this->commit_mode); + } + else + { + $result = @oci_execute($this->stmt_id); + } + + if ($result && $this->curs_id) + { + if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS) + { + return @oci_execute($this->curs_id, $this->commit_mode); + } + else + { + return @oci_execute($this->curs_id); + } + } + + return $result; } } - /* End of file oci8_result.php */ /* Location: ./system/database/drivers/oci8/oci8_result.php */ diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index d60f98bc4..317ff91eb 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -1,13 +1,13 @@ -db->display_error('db_unsuported_feature'); } + } /* End of file oci8_utility.php */ -/* Location: ./system/database/drivers/oci8/oci8_utility.php */ \ No newline at end of file +/* Location: ./system/database/drivers/oci8/oci8_utility.php */ -- cgit v1.2.3-24-g4f1b From 7b62bff30cd80b6ddde4489f8a59948766334c20 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jan 2012 20:43:57 +0200 Subject: Fix a method description --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 41d170875..e667c25d3 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -822,7 +822,7 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Fetch MySQL Field Names + * Fetch Field Names * * @param string the table name * @return array -- cgit v1.2.3-24-g4f1b From 6ea08e60670e4bb7ce184b695d515626d472489d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jan 2012 21:43:17 +0200 Subject: Fix issue 413 --- system/database/drivers/oci8/oci8_driver.php | 29 ++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index cc9557e7d..dea08ffe4 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -528,8 +528,7 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _error_message() { - // If the error was during connection, no conn_id should be passed - $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error(); + $error = self::_get_error_data(); return $error['message']; } @@ -542,13 +541,35 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _error_number() { - // Same as _error_message() - $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error(); + $error = self::_get_error_data(); return $error['code']; } // -------------------------------------------------------------------- + /* Get error data + * + * Used by _error_message() and _error_number() + * + * @return array + */ + private function _get_error_data() + { + $res = NULL; + foreach (array('curs_id', 'stmt_id', 'conn_id') as $key) + { + if (is_resource($this->$key)) + { + $res = $key; + break; + } + } + + return ( ! is_null($res)) ? oci_error($res) : oci_error(); + } + + // -------------------------------------------------------------------- + /** * Escape the SQL Identifiers * -- cgit v1.2.3-24-g4f1b From 6684ce5c7957b1095ad137faa981e80723f5e848 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jan 2012 22:05:14 +0200 Subject: Really fix error handling :) --- system/database/drivers/oci8/oci8_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index dea08ffe4..f520f7c76 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -560,7 +560,7 @@ class CI_DB_oci8_driver extends CI_DB { { if (is_resource($this->$key)) { - $res = $key; + $res = $this->$key; break; } } -- cgit v1.2.3-24-g4f1b From 901573ce19e905ce28a3f3345c33dedf9c703cd4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 11 Jan 2012 01:40:48 +0200 Subject: Fix issue 863 --- system/libraries/Form_validation.php | 122 +++++++++++------------------------ 1 file changed, 38 insertions(+), 84 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 0a6a2af0d..78b1ae016 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Form Validation Class * @@ -48,9 +46,6 @@ class CI_Form_validation { protected $error_string = ''; protected $_safe_form_data = FALSE; - /** - * Constructor - */ public function __construct($rules = array()) { $this->CI =& get_instance(); @@ -67,7 +62,7 @@ class CI_Form_validation { mb_internal_encoding($this->CI->config->item('charset')); } - log_message('debug', "Form Validation Class Initialized"); + log_message('debug', 'Form Validation Class Initialized'); } // -------------------------------------------------------------------- @@ -179,7 +174,6 @@ class CI_Form_validation { } $this->_error_messages = array_merge($this->_error_messages, $lang); - return $this; } @@ -198,7 +192,6 @@ class CI_Form_validation { { $this->_error_prefix = $prefix; $this->_error_suffix = $suffix; - return $this; } @@ -313,10 +306,10 @@ class CI_Form_validation { $this->set_rules($this->_config_rules); } - // We're we able to set the rules correctly? + // Were we able to set the rules correctly? if (count($this->_field_data) === 0) { - log_message('debug', "Unable to find validation rules"); + log_message('debug', 'Unable to find validation rules'); return FALSE; } } @@ -330,17 +323,13 @@ class CI_Form_validation { { // Fetch the data from the corresponding $_POST array and cache it in the _field_data array. // Depending on whether the field name is an array or a string will determine where we get it from. - if ($row['is_array'] === TRUE) { $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']); } - else + elseif (isset($_POST[$field]) AND $_POST[$field] != '') { - if (isset($_POST[$field]) AND $_POST[$field] != "") - { - $this->_field_data[$field]['postdata'] = $_POST[$field]; - } + $this->_field_data[$field]['postdata'] = $_POST[$field]; } $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); @@ -348,7 +337,6 @@ class CI_Form_validation { // Did we end up with any errors? $total_errors = count($this->_error_array); - if ($total_errors > 0) { $this->_safe_form_data = TRUE; @@ -462,14 +450,12 @@ class CI_Form_validation { return; } - // -------------------------------------------------------------------- - // If the field is blank, but NOT required, no further tests are necessary $callback = FALSE; if ( ! in_array('required', $rules) AND is_null($postdata)) { // Before we bail out, does the rule contain a callback? - if (preg_match("/(callback_\w+(\[.*?\])?)/", implode(' ', $rules), $match)) + if (preg_match('/(callback_\w+(\[.*?\])?)/', implode(' ', $rules), $match)) { $callback = TRUE; $rules = (array('1' => $match[1])); @@ -480,8 +466,6 @@ class CI_Form_validation { } } - // -------------------------------------------------------------------- - // Isset Test. Typically this rule will only apply to checkboxes. if (is_null($postdata) AND $callback === FALSE) { @@ -543,11 +527,9 @@ class CI_Form_validation { $postdata = $this->_field_data[$row['field']]['postdata']; } - // -------------------------------------------------------------------- - // Is the rule a callback? $callback = FALSE; - if (substr($rule, 0, 9) == 'callback_') + if (strpos($rule, 'callback_') === 0) { $rule = substr($rule, 9); $callback = TRUE; @@ -556,7 +538,7 @@ class CI_Form_validation { // Strip the parameter (if exists) from the rule // Rules can contain a parameter: max_length[5] $param = FALSE; - if (preg_match("/(.*?)\[(.*)\]/", $rule, $match)) + if (preg_match('/(.*?)\[(.*)\]/', $rule, $match)) { $rule = $match[1]; $param = $match[2]; @@ -567,11 +549,14 @@ class CI_Form_validation { { if ( ! method_exists($this->CI, $rule)) { - continue; + log_message('debug', 'Unable to find callback validation rule: '.$rule); + $result = FALSE; + } + else + { + // Run the function and grab the result + $result = $this->CI->$rule($postdata, $param); } - - // Run the function and grab the result - $result = $this->CI->$rule($postdata, $param); // Re-assign the result to the master data array if ($_in_array === TRUE) @@ -610,13 +595,14 @@ class CI_Form_validation { } else { - log_message('debug', "Unable to find validation rule: ".$rule); + log_message('debug', 'Unable to find validation rule: '.$rule); + $result = FALSE; } - - continue; } - - $result = $this->$rule($postdata, $param); + else + { + $result = $this->$rule($postdata, $param); + } if ($_in_array === TRUE) { @@ -628,7 +614,7 @@ class CI_Form_validation { } } - // Did the rule test negatively? If so, grab the error. + // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { if ( ! isset($this->_error_messages[$rule])) @@ -644,7 +630,7 @@ class CI_Form_validation { } // Is the parameter we are inserting into the error message the name - // of another field? If so we need to grab its "field label" + // of another field? If so we need to grab its "field label" if (isset($this->_field_data[$param], $this->_field_data[$param]['label'])) { $param = $this->_translate_fieldname($this->_field_data[$param]['label']); @@ -678,7 +664,7 @@ class CI_Form_validation { { // Do we need to translate the field name? // We look for the prefix lang: to determine this - if (substr($fieldname, 0, 5) === 'lang:') + if (strpos($fieldname, 'lang:') === 0) { // Grab the variable $line = substr($fieldname, 5); @@ -738,15 +724,10 @@ class CI_Form_validation { { if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) { - if ($default === TRUE AND count($this->_field_data) === 0) - { - return ' selected="selected"'; - } - return ''; + return ($default === TRUE AND count($this->_field_data) === 0) ? ' selected="selected"' : ''; } $field = $this->_field_data[$field]['postdata']; - if (is_array($field)) { if ( ! in_array($value, $field)) @@ -754,12 +735,9 @@ class CI_Form_validation { return ''; } } - else + elseif (($field == '' OR $value == '') OR ($field != $value)) { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } + return ''; } return ' selected="selected"'; @@ -781,15 +759,10 @@ class CI_Form_validation { { if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) { - if ($default === TRUE AND count($this->_field_data) === 0) - { - return ' checked="checked"'; - } - return ''; + return ($default === TRUE AND count($this->_field_data) === 0) ? ' checked="checked"' : ''; } $field = $this->_field_data[$field]['postdata']; - if (is_array($field)) { if ( ! in_array($value, $field)) @@ -797,12 +770,9 @@ class CI_Form_validation { return ''; } } - else + elseif (($field == '' OR $value == '') OR ($field != $value)) { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } + return ''; } return ' checked="checked"'; @@ -869,9 +839,7 @@ class CI_Form_validation { return FALSE; } - $field = $_POST[$field]; - - return ($str === $field); + return ($str === $_POST[$field]); } // -------------------------------------------------------------------- @@ -908,7 +876,7 @@ class CI_Form_validation { */ public function min_length($str, $val) { - if (preg_match("/[^0-9]/", $val)) + if (preg_match('/[^0-9]/', $val)) { return FALSE; } @@ -932,7 +900,7 @@ class CI_Form_validation { */ public function max_length($str, $val) { - if (preg_match("/[^0-9]/", $val)) + if (preg_match('/[^0-9]/', $val)) { return FALSE; } @@ -956,7 +924,7 @@ class CI_Form_validation { */ public function exact_length($str, $val) { - if (preg_match("/[^0-9]/", $val)) + if (preg_match('/[^0-9]/', $val)) { return FALSE; } @@ -1076,19 +1044,6 @@ class CI_Form_validation { // -------------------------------------------------------------------- - /** - * Is Numeric - * - * @param string - * @return bool - */ - public function is_numeric($str) - { - return is_numeric($str); - } - - // -------------------------------------------------------------------- - /** * Integer * @@ -1217,7 +1172,7 @@ class CI_Form_validation { return $data; } - return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); + return str_replace(array("'", '"', '<', '>'), array(''', '"', '<', '>'), stripslashes($data)); } // -------------------------------------------------------------------- @@ -1230,14 +1185,14 @@ class CI_Form_validation { */ public function prep_url($str = '') { - if ($str == 'http://' OR $str == '') + if ($str === 'http://' OR $str == '') { return ''; } - if (substr($str, 0, 7) !== 'http://' && substr($str, 0, 8) !== 'https://') + if (strpos($str, 'http://') !== 0 && strpos($str, 'https://') !== 0) { - $str = 'http://'.$str; + return 'http://'.$str; } return $str; @@ -1283,7 +1238,6 @@ class CI_Form_validation { } } -// END Form Validation Class /* End of file Form_validation.php */ /* Location: ./system/libraries/Form_validation.php */ -- cgit v1.2.3-24-g4f1b From cde43687ef19aa23ee6796925270961b760369f3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 13 Jan 2012 20:16:35 +0200 Subject: Allow native PHP functions used as rules to accept an additional parameter --- system/libraries/Form_validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 78b1ae016..9aa07a1a8 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -582,7 +582,7 @@ class CI_Form_validation { // Users can use any native PHP function call that has one param. if (function_exists($rule)) { - $result = $rule($postdata); + $result = ($param !== FALSE) ? $rule($postdata, $param) : $rule($postdata); if ($_in_array === TRUE) { -- cgit v1.2.3-24-g4f1b From aa786c93e48f3081da9aa6d9d13e5857565a1070 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 16 Jan 2012 12:14:45 +0200 Subject: Additional clean-up --- system/database/drivers/oci8/oci8_driver.php | 188 +++++++++++--------------- system/database/drivers/oci8/oci8_forge.php | 86 +++--------- system/database/drivers/oci8/oci8_result.php | 71 +++------- system/database/drivers/oci8/oci8_utility.php | 4 +- 4 files changed, 123 insertions(+), 226 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index f520f7c76..2a5149f9e 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * oci8 Database Adapter Class * @@ -84,7 +82,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Non-persistent database connection * - * @return resource + * @return resource */ public function db_connect() { @@ -96,7 +94,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Persistent database connection * - * @return resource + * @return resource */ public function db_pconnect() { @@ -124,7 +122,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Select the database * - * @return resource + * @return resource */ public function db_select() { @@ -152,7 +150,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Version number query string * - * @return string + * @return string */ protected function _version() { @@ -164,8 +162,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Execute the query * - * @param string an SQL query - * @return resource + * @param string an SQL query + * @return resource */ protected function _execute($sql) { @@ -181,8 +179,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Generate a statement ID * - * @param string an SQL query - * @return none + * @param string an SQL query + * @return void */ private function _set_stmt_id($sql) { @@ -199,8 +197,8 @@ class CI_DB_oci8_driver extends CI_DB { * * If needed, each database adapter can prep the query string * - * @param string an SQL query - * @return string + * @param string an SQL query + * @return string */ private function _prep_query($sql) { @@ -210,14 +208,13 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- /** - * getCursor. Returns a cursor from the datbase + * getCursor. Returns a cursor from the database * - * @return cursor id + * @return resource cursor id */ public function get_cursor() { - $this->curs_id = oci_new_cursor($this->conn_id); - return $this->curs_id; + return $this->curs_id = oci_new_cursor($this->conn_id); } // -------------------------------------------------------------------- @@ -225,19 +222,19 @@ class CI_DB_oci8_driver extends CI_DB { /** * Stored Procedure. Executes a stored procedure * - * @param package package stored procedure is in - * @param procedure stored procedure to execute - * @param params array of parameters - * @return array + * @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 : 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 + * name no the name of the parameter should be in : 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, $params) { @@ -252,24 +249,24 @@ class CI_DB_oci8_driver extends CI_DB { } // build the query string - $sql = "begin $package.$procedure("; + $sql = "BEGIN {$package}.{$procedure}("; $have_cursor = FALSE; foreach ($params as $param) { - $sql .= $param['name'] . ","; + $sql .= $param['name'].','; if (array_key_exists('type', $param) && ($param['type'] === OCI_B_CURSOR)) { $have_cursor = TRUE; } } - $sql = trim($sql, ",") . "); end;"; + $sql = trim($sql, ',') . '); END;'; $this->stmt_id = FALSE; $this->_set_stmt_id($sql); $this->_bind_params($params); - $this->query($sql, FALSE, $have_cursor); + return $this->query($sql, FALSE, $have_cursor); } // -------------------------------------------------------------------- @@ -277,7 +274,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Bind parameters * - * @return none + * @return void */ private function _bind_params($params) { @@ -382,9 +379,9 @@ class CI_DB_oci8_driver extends CI_DB { /** * Escape String * - * @param string + * @param string * @param bool whether or not the string will be used in a LIKE condition - * @return string + * @return string */ public function escape_str($str, $like = FALSE) { @@ -398,15 +395,14 @@ class CI_DB_oci8_driver extends CI_DB { return $str; } - $str = remove_invisible_characters($str); - $str = str_replace("'", "''", $str); + $str = str_replace("'", "''", remove_invisible_characters($str)); // escape LIKE condition wildcards if ($like === TRUE) { - $str = str_replace( array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), - $str); + return str_replace(array('%', '_', $this->_like_escape_chr), + array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + $str); } return $str; @@ -417,7 +413,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Affected Rows * - * @return integer + * @return int */ public function affected_rows() { @@ -429,7 +425,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Insert ID * - * @return integer + * @return int */ public function insert_id() { @@ -445,8 +441,8 @@ class CI_DB_oci8_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @param string - * @return string + * @param string + * @return int */ public function count_all($table = '') { @@ -455,7 +451,7 @@ class CI_DB_oci8_driver extends CI_DB { return 0; } - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); + $query = $this->query($this->_count_string.$this->_protect_identifiers('numrows').' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query == FALSE) { @@ -474,16 +470,16 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @param boolean + * @param bool * @return string */ protected function _list_tables($prefix_limit = FALSE) { - $sql = "SELECT TABLE_NAME FROM ALL_TABLES"; + $sql = 'SELECT TABLE_NAME FROM ALL_TABLES'; if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); + return $sql." WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; @@ -496,12 +492,12 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the column names can be fetched * - * @param string the table name - * @return string + * @param string the table name + * @return string */ protected function _list_columns($table = '') { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + return 'SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = \''.$table.'\''; } // -------------------------------------------------------------------- @@ -511,12 +507,12 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query so that the column data can be retrieved * - * @param string the table name - * @return object + * @param string the table name + * @return string */ protected function _field_data($table) { - return "SELECT * FROM ".$table." where rownum = 1"; + return 'SELECT * FROM '.$table.' WHERE rownum = 1'; } // -------------------------------------------------------------------- @@ -524,7 +520,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message string * - * @return string + * @return string */ protected function _error_message() { @@ -537,7 +533,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message number * - * @return integer + * @return int */ protected function _error_number() { @@ -589,24 +585,20 @@ class CI_DB_oci8_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + $item = str_replace('.', $this->_escape_char.'.', $item); // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); } } if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; + $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); } // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); } // -------------------------------------------------------------------- @@ -617,8 +609,8 @@ class CI_DB_oci8_driver extends CI_DB { * This function implicitly groups FROM tables so there is no confusion * about operator precedence in harmony with SQL standards * - * @param type - * @return type + * @param array + * @return string */ protected function _from_tables($tables) { @@ -637,14 +629,14 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string */ protected function _insert($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } // -------------------------------------------------------------------- @@ -666,12 +658,10 @@ class CI_DB_oci8_driver extends CI_DB { for ($i = 0, $c = count($values); $i < $c; $i++) { - $sql .= ' INTO ' . $table . ' (' . $keys . ') VALUES ' . $values[$i] . "\n"; + $sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i].'\n'; } - $sql .= 'SELECT * FROM dual'; - - return $sql; + return $sql.'SELECT * FROM dual'; } // -------------------------------------------------------------------- @@ -692,18 +682,13 @@ class CI_DB_oci8_driver extends CI_DB { { foreach ($values as $key => $val) { - $valstr[] = $key." = ".$val; + $valstr[] = $key.' = '.$val; } - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) > 0) ? ' ORDER BY '.implode(', ', $orderby) : ''; - - $sql = 'UPDATE '.$table.' SET '.implode(', ', $valstr); - $sql .= ($where != '' AND count($where) > 0) ? ' WHERE '.implode(' ', $where) : ''; - $sql .= $orderby.$limit; - - return $sql; + return 'UPDATE '.$table.' SET '.implode(', ', $valstr) + .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '') + .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') + .( ! $limit ? '' : ' LIMIT '.$limit); } // -------------------------------------------------------------------- @@ -720,7 +705,7 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _truncate($table) { - return "TRUNCATE TABLE ".$table; + return 'TRUNCATE TABLE '.$table; } // -------------------------------------------------------------------- @@ -738,22 +723,18 @@ class CI_DB_oci8_driver extends CI_DB { protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; - if (count($where) > 0 OR count($like) > 0) { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); + $conditions = "\nWHERE ".implode("\n", $this->ar_where); if (count($where) > 0 && count($like) > 0) { - $conditions .= " AND "; + $conditions .= ' AND '; } $conditions .= implode("\n", $like); } - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; + return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit); } // -------------------------------------------------------------------- @@ -763,25 +744,16 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific LIMIT clause * - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string + * @param string the sql query string + * @param int the number of rows to limit the query to + * @param int the offset value + * @return string */ protected function _limit($sql, $limit, $offset) { - $limit = $offset + $limit; - $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; - - if ($offset != 0) - { - $newsql .= " WHERE rnum >= $offset"; - } - - // remember that we used limits $this->limit_used = TRUE; - - return $newsql; + return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit).')' + .($offset != 0 ? ' WHERE rnum >= '.$offset : ''); } // -------------------------------------------------------------------- @@ -789,8 +761,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Close DB Connection * - * @param resource - * @return void + * @param resource + * @return void */ protected function _close($conn_id) { diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 6975f2a5f..6b9a8e8fd 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Oracle Forge Class * @@ -71,7 +69,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { * @param array the fields * @param mixed primary key(s) * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @param bool should 'IF NOT EXISTS' be added to the SQL * @return string */ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) @@ -83,7 +81,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table)." ("; + $sql .= $this->db->_escape_identifiers($table).' ('; $current_field_count = 0; foreach ($fields as $field=>$attributes) @@ -93,37 +91,17 @@ class CI_DB_oci8_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).' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - 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'; - } + $sql .= "\n\t".$this->db->_protect_identifiers($field).' '.$attributes['TYPE'] + .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '') + .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') + .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '') + .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'); } // don't add a comma on the end of the last field @@ -136,7 +114,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { if (count($primary_keys) > 0) { $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')'; } if (is_array($keys) && count($keys) > 0) @@ -152,13 +130,11 @@ class CI_DB_oci8_forge extends CI_DB_forge { $key = array($this->db->_protect_identifiers($key)); } - $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")"; + $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).')'; } } - $sql .= "\n)"; - - return $sql; + return $sql."\n)"; } // -------------------------------------------------------------------- @@ -170,7 +146,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { */ public function _drop_table($table) { - return 'DROP TABLE ' . $this->db->_protect_identifiers($table); + return 'DROP TABLE '.$this->db->_protect_identifiers($table); } // -------------------------------------------------------------------- @@ -186,42 +162,24 @@ class CI_DB_oci8_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 */ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table).' '.$alter_type.' '.$this->db->_protect_identifiers($column_name); // DROP has everything it needs now. - if ($alter_type == 'DROP') + if ($alter_type === 'DROP') { return $sql; } - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; + return $sql.' '.$column_definition + .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '') + .($null === NULL ? ' NULL' : ' NOT NULL') + .($after_field != '' ? ' AFTER '.$this->db->_protect_identifiers($after_field) : ''); } @@ -238,11 +196,9 @@ class CI_DB_oci8_forge extends CI_DB_forge { */ public function _rename_table($table_name, $new_table_name) { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; + return 'ALTER TABLE '.$this->db->_protect_identifiers($table_name).' RENAME TO '.$this->db->_protect_identifiers($new_table_name); } - } /* End of file oci8_forge.php */ diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index cbf4bec52..fad2465df 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * oci8 Result Class * @@ -56,7 +54,7 @@ class CI_DB_oci8_result extends CI_DB_result { * Oracle doesn't have a graceful way to return the number of rows * so we have to use what amounts to a hack. * - * @return integer + * @return int */ public function num_rows() { @@ -82,19 +80,14 @@ class CI_DB_oci8_result extends CI_DB_result { /** * Number of fields in the result set * - * @return integer + * @return int */ public function num_fields() { $count = @oci_num_fields($this->stmt_id); // if we used a limit we subtract it - if ($this->limit_used) - { - return $count - 1; - } - - return $count; + return ($this->limit_used) ? $count - 1 : $count; } // -------------------------------------------------------------------- @@ -123,17 +116,17 @@ class CI_DB_oci8_result extends CI_DB_result { * * Generates an array of objects containing field meta-data * - * @return array + * @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); + $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; } @@ -175,7 +168,7 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an array * - * @return array + * @return array */ protected function _fetch_assoc() { @@ -190,7 +183,7 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an object * - * @return object + * @return object */ protected function _fetch_object() { @@ -200,33 +193,6 @@ class CI_DB_oci8_result extends CI_DB_result { // -------------------------------------------------------------------- - /* Query result - * - * Acts as a wrapper for result_array(), result_object() - * and custom_result_object(). - * - * @param string ('object', 'array' or a custom class name) - * @return array - */ - - public function result($type = 'object') - { - if ($type === 'object') - { - return $this->result_object(); - } - elseif ($type === 'array') - { - return $this->result_array(); - } - else - { - return $this->custom_result_object($type); - } - } - - // -------------------------------------------------------------------- - /** * Query result. "array" version. * @@ -452,9 +418,16 @@ class CI_DB_oci8_result extends CI_DB_result { public function row($n = 0, $type = 'object') { - if ($type === 'object') return $this->row_object($n); - elseif ($type === 'array') return $this->row_array($n); - else return $this->custom_row_object($n, $type); + if ($type === 'object') + { + return $this->row_object($n); + } + elseif ($type === 'array') + { + return $this->row_array($n); + } + + return $this->custom_row_object($n, $type); } // -------------------------------------------------------------------- @@ -464,7 +437,6 @@ class CI_DB_oci8_result extends CI_DB_result { * @param int row index * @return array */ - public function row_array($n = 0) { // Make sure $n is not a string @@ -656,7 +628,6 @@ class CI_DB_oci8_result extends CI_DB_result { * @param string ('object', 'array' or a custom class name) * @return mixed whatever was passed to the second parameter */ - public function first_row($type = 'object') { return $this->row(0, $type); diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 317ff91eb..38d870aa6 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Oracle Utility Class * -- cgit v1.2.3-24-g4f1b From 8ae24c57a1240a5a5e3fbd5755227e5d42b75390 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 16 Jan 2012 13:05:23 +0200 Subject: Add SQLite3 database driver --- system/database/DB_driver.php | 2 +- system/database/drivers/sqlite3/index.html | 10 + system/database/drivers/sqlite3/sqlite3_driver.php | 591 ++++++++++++++++++++ system/database/drivers/sqlite3/sqlite3_forge.php | 223 ++++++++ system/database/drivers/sqlite3/sqlite3_result.php | 617 +++++++++++++++++++++ .../database/drivers/sqlite3/sqlite3_utility.php | 102 ++++ 6 files changed, 1544 insertions(+), 1 deletion(-) create mode 100644 system/database/drivers/sqlite3/index.html create mode 100644 system/database/drivers/sqlite3/sqlite3_driver.php create mode 100644 system/database/drivers/sqlite3/sqlite3_forge.php create mode 100644 system/database/drivers/sqlite3/sqlite3_result.php create mode 100644 system/database/drivers/sqlite3/sqlite3_utility.php (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 661b42ced..43c201ef6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -257,7 +257,7 @@ class CI_DB_driver { // Some DBs have functions that return the version, and don't run special // SQL queries per se. In these instances, just return the result. - $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo'); + $driver_version_exceptions = array('oci8', 'sqlite', 'sqlite3', 'cubrid', 'pdo'); if (in_array($this->dbdriver, $driver_version_exceptions)) { diff --git a/system/database/drivers/sqlite3/index.html b/system/database/drivers/sqlite3/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/database/drivers/sqlite3/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php new file mode 100644 index 000000000..b82ae1ecd --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -0,0 +1,591 @@ +password) + ? new SQLite3($this->database) + : new SQLite3($this->database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password); + } + catch (Exception $e) + { + return FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @return object type SQLite3 + */ + public function db_pconnect() + { + log_message('debug', 'SQLite3 doesn\'t support persistent connections'); + return $this->db_pconnect(); + } + + // -------------------------------------------------------------------- + + /** + * 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() + { + // Not supported + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @return bool + */ + public function db_select() + { + // Not needed, in SQLite every pseudo-connection is a database + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @param string + * @param string + * @return bool + */ + public function db_set_charset($charset, $collation) + { + // Not (natively) supported + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @return string + */ + protected function _version() + { + return implode(' (', $this->conn_id->version()).')'; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string an SQL query + * @return mixed SQLite3Result object or bool + */ + protected function _execute($sql) + { + if ( ! preg_match('/^(SELECT|EXPLAIN).+$/i', ltrim($sql))) + { + return $this->conn_id->exec($sql); + } + + // TODO: Implement use of SQLite3::querySingle(), if needed + // TODO: Use $this->_prep_query(), if needed + return $this->conn_id->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @param string an SQL query + * @return string + */ + private function _prep_query($sql) + { + return $this->conn_id->prepare($sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + 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) + { + return TRUE; + } + + // 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); + + return $this->conn_id->exec('BEGIN TRANSACTION'); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + 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) + { + return TRUE; + } + + return $this->conn_id->exec('END TRANSACTION'); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + 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) + { + return TRUE; + } + + return $this->conn_id->exec('ROLLBACK'); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @param string + * @param bool whether or not the string will be used in a LIKE condition + * @return string + */ + public function escape_str($str, $like = FALSE) + { + if (is_array($str)) + { + foreach ($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + + $str = $this->conn_id->escapeString(remove_invisible_characters($str)); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + return str_replace(array('%', '_', $this->_like_escape_chr), + array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + $str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return $this->conn_id->changes(); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return $this->conn_id->lastInsertRowID(); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @param string + * @return int + */ + public function count_all($table = '') + { + if ($table == '') + { + return 0; + } + + $result = $this->conn_id->querySingle($this->_count_string.$this->_protect_identifiers('numrows') + .' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE)); + + return empty($result) ? 0 : (int) $result; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' + .(($prefix_limit !== FALSE && $this->dbprefix != '') + ? ' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix).'%\' '.sprintf($this->_like_escape_str, $this->_like_escape_chr) + : ''); + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string the table name + * @return string + */ + protected function _list_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @param string the table name + * @return string + */ + protected function _field_data($table) + { + return 'SELECT * FROM '.$table.' LIMIT 0,1'; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @return string + */ + protected function _error_message() + { + return $this->conn_id->lastErrorMsg(); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @return int + */ + protected function _error_number() + { + return $this->conn_id->lastErrorCode(); + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @param string + * @return string + */ + protected function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $item = str_replace('.', $this->_escape_char.'.', $item); + + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); + } + } + + if (strpos($item, '.') !== FALSE) + { + $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); + } + + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @param string + * @return string + */ + protected function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + protected function _insert($table, $keys, $values) + { + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach ($values as $key => $val) + { + $valstr[] = $key.' = '.$val; + } + + return 'UPDATE '.$table.' SET '.implode(', ', $valstr) + .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '') + .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') + .( ! $limit ? '' : ' LIMIT '.$limit); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command, then + * this method maps to "DELETE FROM table" + * + * @param string the table name + * @return string + */ + protected function _truncate($table) + { + return $this->_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + if (count($where) > 0 OR count($like) > 0) + { + $conditions .= "\nWHERE ".implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= ' AND '; + } + $conditions .= implode("\n", $like); + } + + return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @param string the sql query string + * @param int the number of rows to limit the query to + * @param int the offset value + * @return string + */ + protected function _limit($sql, $limit, $offset) + { + return $sql.($offset ? $offset.',' : '').$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + $this->conn_id->close(); + } + +} + +/* End of file sqlite3_driver.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_driver.php */ diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php new file mode 100644 index 000000000..07c25515a --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -0,0 +1,223 @@ +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; + } + + return TRUE; + } + + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param bool should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + { + $sql = 'CREATE TABLE '; + + // IF NOT EXISTS added to SQLite in 3.3.0 + if ($if_not_exists === TRUE && version_compare($this->db->version(), '3.3.0', '>=') === TRUE) + { + $sql .= 'IF NOT EXISTS '; + } + + $sql .= $this->db->_escape_identifiers($table).'('; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t".$attributes; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field) + .' '.$attributes['TYPE'] + .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '') + .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') + .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '') + .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') + .((array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : ''); + } + + // don't add a comma on the end of the last field + if (++$current_field_count < count($fields)) + { + $sql .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')'; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tUNIQUE (".implode(', ', $key).')'; + } + } + + return $sql."\n)"; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @param string the table name + * @return string + */ + public function _drop_table($table) + { + return 'DROP TABLE '.$table.' IF EXISTS'; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param bool should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return string + */ + public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + /* SQLite only supports adding new columns and it does + * NOT support the AFTER statement. Each new column will + * be added as the last one in the table. + */ + if ($alter_type !== 'ADD COLUMN') + { + // Not supported + return FALSE; + } + + return 'ALTER TABLE '.$this->db->_protect_identifiers($table).' '.$alter_type.' '.$this->db->_protect_identifiers($column_name) + .' '.$column_definition + .($default_value != '' ? ' DEFAULT '.$default_value : '') + // If NOT NULL is specified, the field must have a DEFAULT value other than NULL + .(($null !== NULL && $default_value !== 'NULL') ? ' NOT NULL' : ' NULL'); + } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @param string the old table name + * @param string the new table name + * @return string + */ + public function _rename_table($table_name, $new_table_name) + { + return 'ALTER TABLE '.$this->db->_protect_identifiers($table_name).' RENAME TO '.$this->db->_protect_identifiers($new_table_name); + } +} + +/* End of file sqlite3_forge.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_forge.php */ diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php new file mode 100644 index 000000000..7b1b4502a --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -0,0 +1,617 @@ +num_rows) + ? $this->num_rows + : $this->num_rows = count($this->result_array()); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return ( ! is_int($this->_num_fields)) + ? $this->_num_fields = $this->result_id->numColumns() + : $this->_num_fields; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $this->num_fields(); $i++) + { + $field_names[] = $this->result_id->columnName($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, $c = $this->num_fields(); $i < $this->num_fields(); $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $this->result_id->columnName($i); + $retval[$i]->type = 'varchar'; + $retval[$i]->max_length = 0; + $retval[$i]->primary_key = 0; + $retval[$i]->default = ''; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_object($this->result_id)) + { + $this->result_id->finalize(); + $this->result_id = NULL; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return $this->result_id->fetchArray(SQLITE3_ASSOC); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + protected function _fetch_object() + { + // No native support for fetching as an object + $row = $this->_fetch_assoc(); + return ($row !== FALSE) ? (object) $row : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * return array + */ + public function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + elseif (is_array($this->row_data)) + { + if (count($this->row_data) === 0) + { + return $this->result_array; + } + else + { + $row_index = count($this->row_data); + } + } + else + { + $row_index = 0; + $this->row_data = array(); + } + + $row = NULL; + while ($row = $this->_fetch_assoc()) + { + $this->row_data[$row_index++] = $row; + } + + // Un-comment the following line, in case it becomes needed + // $this->_data_seek(); + return $this->result_array = $this->row_data; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @return array + */ + public function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + elseif (count($this->result_array) > 0) + { + for ($i = 0, $c = count($this->result_array); $i < $c; $i++) + { + $this->result_object[] = (object) $this->result_array[$i]; + } + + return $this->result_object; + } + elseif (is_array($this->row_data)) + { + if (count($this->row_data) === 0) + { + return $this->result_object; + } + else + { + $row_index = count($this->row_data); + for ($i = 0; $i < $row_index; $i++) + { + $this->result_object[$i] = (object) $this->row_data[$i]; + } + } + } + else + { + $row_index = 0; + $this->row_data = array(); + } + + $row = NULL; + while ($row = $this->_fetch_assoc()) + { + $this->row_data[$row_index] = $row; + $this->result_object[$row_index++] = (object) $row; + } + + $this->result_array = $this->row_data; + + /* As described for the num_rows() method - there's no easy + * way to get the number of rows selected. Our work-around + * solution (as in here as well) first checks if result_array + * exists and returns its count. It doesn't however check for + * custom_object_result, so - do it here. + */ + if ( ! is_int($this->num_rows)) + { + $this->num_rows = count($this->result_object); + } + + // Un-comment the following line, in case it becomes needed + // $this->_data_seek(); + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. Custom object version. + * + * @param string class name used to instantiate rows to + * @return array + */ + public function custom_result_object($class_name) + { + if (array_key_exists($class_name, $this->custom_result_object)) + { + return $this->custom_result_object[$class_name]; + } + + if ( ! class_exists($class_name) OR ! is_object($this->result_id) OR $this->num_rows() === 0) + { + return array(); + } + + /* Even if result_array hasn't been set prior to custom_result_object being called, + * num_rows() has done it. + */ + $data = &$this->result_array; + + $result_object = array(); + for ($i = 0, $c = count($data); $i < $c; $i++) + { + $result_object[$i] = new $class_name(); + foreach ($data[$i] as $key => $value) + { + $result_object[$i]->$key = $value; + } + } + + /* As described for the num_rows() method - there's no easy + * way to get the number of rows selected. Our work-around + * solution (as in here as well) first checks if result_array + * exists and returns its count. It doesn't however check for + * custom_object_result, so - do it here. + */ + if ( ! is_int($this->num_rows)) + { + $this->num_rows = count($result_object); + } + + // Cache and return the array + return $this->custom_result_object[$class_name] = $result_object; + } + + // -------------------------------------------------------------------- + + /* Single row result. + * + * Acts as a wrapper for row_object(), row_array() + * and custom_row_object(). Also used by first_row(), next_row() + * and previous_row(). + * + * @param int row index + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function row($n = 0, $type = 'object') + { + if ($type === 'object') + { + return $this->row_object($n); + } + elseif ($type === 'array') + { + return $this->row_array($n); + } + + return $this->custom_row_object($n, $type); + } + + // -------------------------------------------------------------------- + + /* Single row result. Array version. + * + * @param int row index + * @return array + */ + public function row_array($n = 0) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + + /* If row_data is initialized, it means that we've already tried + * (at least) to fetch some data, so ... check if we already have + * this row. + */ + if (is_array($this->row_data)) + { + /* If we already have row_data[$n] - return it. + * + * If we enter the elseif, there's a number of reasons to + * return an empty array: + * + * - count($this->row_data) === 0 means there are no results + * - num_rows being set or result_array having count() > 0 means + * that we've already fetched all data and $n is greater than + * our highest row index available + * - $n < $this->current_row means that if such row existed, + * we would've already returned it, therefore $n is an + * invalid index + */ + if (isset($this->row_data[$n])) // We already have this row + { + $this->current_row = $n; + return $this->row_data[$n]; + } + elseif (count($this->row_data) === 0 OR is_int($this->num_rows) + OR count($this->result_array) > 0 OR $n < $this->current_row) + { + // No such row exists + return array(); + } + + // Get the next row index that would actually need to be fetched + $current_row = ($this->current_row < count($this->row_data)) ? count($this->row_data) : $this->current_row + 1; + } + else + { + $current_row = $this->current_row = 0; + $this->row_data = array(); + } + + /* Fetch more data, if available + * + * NOTE: Operator precedence is important here, if you change + * 'AND' with '&&' - it WILL BREAK the results, as + * $row will be assigned the scalar value of both + * expressions! + */ + while ($row = $this->_fetch_assoc() AND $current_row <= $n) + { + $this->row_data[$current_row++] = $row; + } + + // This would mean that there's no (more) data to fetch + if ( ! is_array($this->row_data) OR ! isset($this->row_data[$n])) + { + // Cache what we already have + if (is_array($this->row_data)) + { + $this->num_rows = count($this->row_data); + /* Usually, row_data could have less elements than result_array, + * but at this point - they should be exactly the same. + */ + $this->result_array = $this->row_data; + } + else + { + $this->num_rows = 0; + } + + return array(); + } + + $this->current_row = $n; + return $this->row_data[$n]; + } + + // -------------------------------------------------------------------- + + /* Single row result. Object version. + * + * @param int row index + * @return mixed object if row found; empty array if not + */ + public function row_object($n = 0) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + + /* Logic here is exactly the same as in row_array, + * except we have to cast row_data[$n] to an object. + * + * If we already have result_object though - we can + * directly return from it. + */ + if (isset($this->result_object[$n])) + { + $this->current_row = $n; + return $this->result_object[$n]; + } + + $row = $this->row_array($n); + // Cast only if the row exists + if (count($row) > 0) + { + $this->current_row = $n; + return (object) $row; + } + + return array(); + } + + // -------------------------------------------------------------------- + + /* Single row result. Custom object version. + * + * @param int row index + * @param string custom class name + * @return mixed custom object if row found; empty array otherwise + */ + public function custom_row_object($n = 0, $class_name) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + + if (array_key_exists($class_name, $this->custom_result_object)) + { + /* We already have a the whole result set with this class_name, + * return the specified row if it exists, and an empty array if + * it doesn't. + */ + if (isset($this->custom_result_object[$class_name][$n])) + { + $this->current_row = $n; + return $this->custom_result_object[$class_name][$n]; + } + else + { + return array(); + } + } + elseif ( ! class_exists($class_name)) // No such class exists + { + return array(); + } + + $row = $this->row_array($n); + // An array would mean that the row doesn't exist + if (is_array($row)) + { + return $row; + } + + // Convert to the desired class and return + $row_object = new $class_name(); + foreach ($row as $key => $value) + { + $row_object->$key = $value; + } + + $this->current_row = $n; + return $row_object; + } + + // -------------------------------------------------------------------- + + /* First row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function first_row($type = 'object') + { + return $this->row(0, $type); + } + + // -------------------------------------------------------------------- + + /* Last row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function last_row($type = 'object') + { + $result = &$this->result($type); + if ( ! isset($this->num_rows)) + { + $this->num_rows = count($result); + } + $this->current_row = $this->num_rows - 1; + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /* Next row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function next_row($type = 'object') + { + if (is_array($this->row_data)) + { + $count = count($this->row_data); + $n = ($this->current_row > $count OR ($this->current_row === 0 && $count === 0)) ? $count : $this->current_row + 1; + } + else + { + $n = 0; + } + + return $this->row($n, $type); + } + + // -------------------------------------------------------------------- + + /* Previous row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function previous_row($type = 'object') + { + $n = ($this->current_row !== 0) ? $this->current_row - 1 : 0; + return $this->row($n, $type); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @return array + */ + public function _data_seek($n = 0) + { + // Only resetting to the start of the result set is supported + return $this->result_id->reset(); + } + +} + +/* End of file sqlite3_result.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_result.php */ diff --git a/system/database/drivers/sqlite3/sqlite3_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php new file mode 100644 index 000000000..eae652582 --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_utility.php @@ -0,0 +1,102 @@ +db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Is optimization even supported in SQLite? + * + * @param string the table name + * @return bool + */ + public function _optimize_table($table) + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Are table repairs even supported in SQLite? + * + * @param string the table name + * @return object + */ + public function _repair_table($table) + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * SQLite Export + * + * @param array Preferences + * @return mixed + */ + public function _backup($params = array()) + { + // Not supported + return $this->db->display_error('db_unsuported_feature'); + } +} + +/* End of file sqlite3_utility.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_utility.php */ -- cgit v1.2.3-24-g4f1b From 5cbecb3865c84967692324f283b0bebd7c8efb38 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 16 Jan 2012 13:08:24 +0200 Subject: Add a comment for CI_DB_sqlite3_result::num_rows() --- system/database/drivers/sqlite3/sqlite3_result.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php index 7b1b4502a..c9876fe69 100644 --- a/system/database/drivers/sqlite3/sqlite3_result.php +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -49,6 +49,9 @@ class CI_DB_sqlite3_result extends CI_DB_result { */ public function num_rows() { + /* The SQLite3 driver doesn't have a graceful way to do this, + * so we'll have to do it on our own. + */ return is_int($this->num_rows) ? $this->num_rows : $this->num_rows = count($this->result_array()); -- cgit v1.2.3-24-g4f1b From b5e6f11002a08d29bd0faa2c6c5c437cf9e49523 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 16 Jan 2012 13:25:07 +0200 Subject: Removed some unneeded code and fixed a possible bug --- system/database/drivers/oci8/oci8_result.php | 77 ++++------------------------ 1 file changed, 10 insertions(+), 67 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index fad2465df..e6e932175 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -66,7 +66,7 @@ class CI_DB_oci8_result extends CI_DB_result { } elseif (count($this->result_object) > 0) { - return $this->num_rows = count($this->result_array); + return $this->num_rows = count($this->result_object); } return $this->num_rows = count($this->result_array()); @@ -316,12 +316,10 @@ class CI_DB_oci8_result extends CI_DB_result { return array(); } - // add the data to the object - $result_object = array(); - $data = NULL; - - /* First check if we don't already have the data. - * If so - pass by reference, as we don't know how + /* Even if we didn't have result_array or result_object + * set prior to custom_result_object() being called, + * num_rows() has already done so. + * Pass by reference, as we don't know how * large it might be and we don't want 1000 row * sets being copied. */ @@ -334,70 +332,15 @@ class CI_DB_oci8_result extends CI_DB_result { $data = &$this->result_object; } - if ( ! is_null($data)) + $result_object = array(); + for ($i = 0, $c = count($data); $i < $c; $i++) { - for ($i = 0, $c = count($data); $i < $c; $i++) + $result_object[$i] = new $class_name(); + foreach ($data[$i] as $key => $value) { - $result_object[$i] = new $class_name(); - foreach ($data[$i] as $key => $value) - { - $result_object[$i]->$key = $value; - } + $result_object[$i]->$key = $value; } } - else - { - // No prefetched result set - if (is_array($this->row_data)) - { - $row_index = count($this->row_data); - if ($row_index === 0) - { - return array(); - } - else - { - for ($i = 0; $i < $row_index; $i++) - { - $result_object[$i] = new $class_name(); - foreach ($this->row_data[$i] as $key => $value) - { - $result_object[$i]->$key = $value; - } - } - } - } - else - { - $row_index = 0; - $this->row_data = array(); - } - - while ($row = $this->_fetch_assoc()) - { - $data = new $class_name(); - foreach ($row as $key => $value) - { - $data->$key = $value; - } - - $this->row_data[$row_index] = $row; - $result_object[$row_index++] = $data; - } - // Un-comment the following line, in case it becomes needed - // $this->_data_seek(); - } - - /* As described for the num_rows() method - there's no easy - * way to get the number of rows selected. Our work-around - * solution (as in here as well) first checks if result_array - * or result_object exist and returns their count. It doesn't - * however check for a custom_object_result, so - do it here. - */ - if ( ! is_int($this->num_rows)) - { - $this->num_rows = count($result_object); - } // Cache and return the array return $this->custom_result_object[$class_name] = $result_object; -- cgit v1.2.3-24-g4f1b From 53921cab6f979bedef6deb837aea54f354b1f7e6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 16 Jan 2012 14:35:22 +0200 Subject: Replaced a method with a variable --- system/database/drivers/sqlite3/sqlite3_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php index c9876fe69..e8e3706cd 100644 --- a/system/database/drivers/sqlite3/sqlite3_result.php +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -83,7 +83,7 @@ class CI_DB_sqlite3_result extends CI_DB_result { public function list_fields() { $field_names = array(); - for ($i = 0, $c = $this->num_fields(); $i < $this->num_fields(); $i++) + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) { $field_names[] = $this->result_id->columnName($i); } -- cgit v1.2.3-24-g4f1b From e35d7789a24e811bc147bc56c7a1d79904900b01 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jan 2012 15:56:20 +0200 Subject: Some more cleaning --- system/database/drivers/oci8/oci8_driver.php | 17 +++-------------- system/database/drivers/oci8/oci8_result.php | 3 +-- 2 files changed, 4 insertions(+), 16 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 2a5149f9e..f4b899cf3 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -46,7 +46,6 @@ * permit access to oracle databases * * @author Kelly McArdle - * */ class CI_DB_oci8_driver extends CI_DB { @@ -249,7 +248,7 @@ class CI_DB_oci8_driver extends CI_DB { } // build the query string - $sql = "BEGIN {$package}.{$procedure}("; + $sql = 'BEGIN '.$package.'.'.$procedure.'('; $have_cursor = FALSE; foreach ($params as $param) @@ -359,13 +358,8 @@ class CI_DB_oci8_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; } @@ -614,12 +608,7 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _from_tables($tables) { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); + return is_array($tables) ? implode(', ', $tables) : $tables; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index e6e932175..0e0fe059d 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -194,7 +194,7 @@ class CI_DB_oci8_result extends CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. Array version. * * @return array */ @@ -516,7 +516,6 @@ class CI_DB_oci8_result extends CI_DB_result { * @param string custom class name * @return mixed custom object if row found; empty array otherwise */ - public function custom_row_object($n = 0, $class_name) { // Make sure $n is not a string -- cgit v1.2.3-24-g4f1b From 72d7a6e2cbf1bd797bab7b14912a207f4522953a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jan 2012 16:02:32 +0200 Subject: Some cleaning --- system/database/drivers/sqlite3/sqlite3_driver.php | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index b82ae1ecd..8a7dbe1f1 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -188,13 +188,8 @@ class CI_DB_sqlite3_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; } @@ -216,13 +211,8 @@ class CI_DB_sqlite3_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; } @@ -239,13 +229,8 @@ class CI_DB_sqlite3_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; } -- cgit v1.2.3-24-g4f1b From 1ab62aedc09cc75ac5619d5e881076cc9ca5e090 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 20 Jan 2012 13:04:10 +0200 Subject: Replaced AND with && --- system/database/DB_driver.php | 53 +++++++++++++--------------- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_result.php | 1 - 3 files changed, 25 insertions(+), 31 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index e667c25d3..7f5ec1e20 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -106,7 +106,7 @@ class CI_DB_driver { * Initialize Database Settings * * @param mixed - * @return void + * @return bool */ public function initialize() { @@ -198,7 +198,7 @@ class CI_DB_driver { * * @param string * @param string - * @return resource + * @return bool */ public function db_set_charset($charset, $collation) { @@ -292,15 +292,15 @@ class CI_DB_driver { } // Verify table prefix and replace if necessary - if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) + if (($this->dbprefix != '' && $this->swap_pre != '') && ($this->dbprefix != $this->swap_pre)) { - $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); + $sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql); } // Is query caching enabled? If the query is a "read type" // we will load the caching class and return the previously // cached query if it exists - if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) + if ($this->cache_on == TRUE && stristr($sql, 'SELECT')) { if ($this->_cache_init()) { @@ -385,7 +385,7 @@ class CI_DB_driver { { // If caching is enabled we'll auto-cleanup any // existing files related to this particular URI - if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) + if ($this->cache_on == TRUE && $this->cache_autodel == TRUE && $this->_cache_init()) { $this->CACHE->delete(); } @@ -419,7 +419,7 @@ class CI_DB_driver { // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. - if ($this->cache_on == TRUE AND $this->_cache_init()) + if ($this->cache_on == TRUE && $this->_cache_init()) { // We'll create a new instance of the result object // only without the platform specific driver since @@ -489,7 +489,6 @@ class CI_DB_driver { * Disable Transactions * This permits transactions to be disabled at run-time. * - * @access public * @return void */ public function trans_off() @@ -501,12 +500,12 @@ class CI_DB_driver { /** * Enable/disable Transaction Strict Mode + * * When strict mode is enabled, if you are running multiple groups of * transactions, if one group fails all groups will be rolled back. * If strict mode is disabled, each group is treated autonomously, meaning * a failure of one group will not affect any others * - * @access public * @return void */ public function trans_strict($mode = TRUE) @@ -645,15 +644,11 @@ class CI_DB_driver { * Determines if a query is a "write" type. * * @param string An SQL query string - * @return boolean + * @return bool */ public function is_write_type($sql) { - if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) - { - return FALSE; - } - return TRUE; + return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql); } // -------------------------------------------------------------------- @@ -661,8 +656,8 @@ class CI_DB_driver { /** * Calculate the aggregate query elapsed time * - * @param integer The number of decimal places - * @return integer + * @param int The number of decimal places + * @return string */ public function elapsed_time($decimals = 6) { @@ -743,7 +738,7 @@ class CI_DB_driver { /** * Primary * - * Retrieves the primary key. It assumes that the row in the first + * Retrieves the primary key. It assumes that the row in the first * position is the primary key * * @param string the table name @@ -946,7 +941,7 @@ class CI_DB_driver { { if ($where == '') { - return false; + return FALSE; } $fields = array(); @@ -1118,12 +1113,12 @@ class CI_DB_driver { */ private function _cache_init() { - if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) + if (is_object($this->CACHE) && class_exists('CI_DB_Cache')) { return TRUE; } - if ( ! class_exists('CI_DB_Cache') AND ! @include(BASEPATH.'database/DB_cache.php')) + if ( ! class_exists('CI_DB_Cache') && ! @include(BASEPATH.'database/DB_cache.php')) { return $this->cache_off(); } @@ -1221,7 +1216,7 @@ class CI_DB_driver { * 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 - * column names that include the path. Consider a query like this: + * column names that include the path. Consider a query like this: * * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table * @@ -1289,7 +1284,7 @@ class CI_DB_driver { $parts = explode('.', $item); // Does the first segment of the exploded item match - // one of the aliases previously identified? If so, + // 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)) { @@ -1308,7 +1303,7 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix defined in the config file? If not, no need to do anything + // Is there a table prefix defined in the config file? If not, no need to do anything if ($this->dbprefix != '') { // We now add the table prefix based on some logic. @@ -1341,7 +1336,7 @@ class CI_DB_driver { // Verify table prefix and replace if necessary if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0) { - $parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]); + $parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]); } // We only add the table prefix if it does not already exist @@ -1362,23 +1357,23 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix? If not, no need to insert it + // Is there a table prefix? If not, no need to insert it if ($this->dbprefix != '') { // Verify table prefix and replace if necessary if ($this->swap_pre != '' && strncmp($item, $this->swap_pre, strlen($this->swap_pre)) === 0) { - $item = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $item); + $item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item); } // Do we prefix an item with no segments? - if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) + if ($prefix_single == TRUE && substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) { $item = $this->dbprefix.$item; } } - if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) + if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers)) { $item = $this->_escape_identifiers($item); } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index f4b899cf3..76aca9a66 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -471,7 +471,7 @@ class CI_DB_oci8_driver extends CI_DB { { $sql = 'SELECT TABLE_NAME FROM ALL_TABLES'; - if ($prefix_limit !== FALSE AND $this->dbprefix != '') + 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); } diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 0e0fe059d..221ab2c5f 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -358,7 +358,6 @@ class CI_DB_oci8_result extends CI_DB_result { * @param string ('object', 'array' or a custom class name) * @return mixed whatever was passed to the second parameter */ - public function row($n = 0, $type = 'object') { if ($type === 'object') -- cgit v1.2.3-24-g4f1b From 6de924ce72797a1a8d8d8104f767f42c24e929c3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 20 Jan 2012 13:18:18 +0200 Subject: Replace AND with && --- system/libraries/Form_validation.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 9aa07a1a8..34b7b646d 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -297,7 +297,7 @@ class CI_Form_validation { // Is there a validation rule for the particular URI being accessed? $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group; - if ($uri != '' AND isset($this->_config_rules[$uri])) + if ($uri != '' && isset($this->_config_rules[$uri])) { $this->set_rules($this->_config_rules[$uri]); } @@ -327,7 +327,7 @@ class CI_Form_validation { { $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']); } - elseif (isset($_POST[$field]) AND $_POST[$field] != '') + elseif (isset($_POST[$field]) && $_POST[$field] != '') { $this->_field_data[$field]['postdata'] = $_POST[$field]; } @@ -373,7 +373,7 @@ class CI_Form_validation { /** * Re-populate the _POST array with our finalized and processed data * - * @return null + * @return void */ protected function _reset_post_array() { @@ -452,7 +452,7 @@ class CI_Form_validation { // If the field is blank, but NOT required, no further tests are necessary $callback = FALSE; - if ( ! in_array('required', $rules) AND is_null($postdata)) + if ( ! in_array('required', $rules) && is_null($postdata)) { // Before we bail out, does the rule contain a callback? if (preg_match('/(callback_\w+(\[.*?\])?)/', implode(' ', $rules), $match)) @@ -467,7 +467,7 @@ class CI_Form_validation { } // Isset Test. Typically this rule will only apply to checkboxes. - if (is_null($postdata) AND $callback === FALSE) + if (is_null($postdata) && $callback === FALSE) { if (in_array('isset', $rules, TRUE) OR in_array('required', $rules)) { @@ -510,7 +510,7 @@ class CI_Form_validation { // We set the $postdata variable with the current data in our master array so that // each cycle of the loop is dealing with the processed data from the last cycle - if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata'])) + if ($row['is_array'] == TRUE && is_array($this->_field_data[$row['field']]['postdata'])) { // We shouldn't need this safety, but just in case there isn't an array index // associated with this cycle we'll bail out @@ -569,7 +569,7 @@ class CI_Form_validation { } // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE) + if ( ! in_array('required', $rules, TRUE) && $result !== FALSE) { continue; } @@ -724,7 +724,7 @@ class CI_Form_validation { { if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) { - return ($default === TRUE AND count($this->_field_data) === 0) ? ' selected="selected"' : ''; + return ($default === TRUE && count($this->_field_data) === 0) ? ' selected="selected"' : ''; } $field = $this->_field_data[$field]['postdata']; @@ -759,7 +759,7 @@ class CI_Form_validation { { if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) { - return ($default === TRUE AND count($this->_field_data) === 0) ? ' checked="checked"' : ''; + return ($default === TRUE && count($this->_field_data) === 0) ? ' checked="checked"' : ''; } $field = $this->_field_data[$field]['postdata']; @@ -1125,7 +1125,7 @@ class CI_Form_validation { */ public function is_natural_no_zero($str) { - return ($str != 0 AND preg_match('/^[0-9]+$/', $str)); + return ($str != 0 && preg_match('/^[0-9]+$/', $str)); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 342a466b4739b9c3dd05c417d1ae56f0ca14fd8d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 24 Jan 2012 15:24:00 +0200 Subject: Revert a space in the license agreement :) --- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_forge.php | 2 +- system/database/drivers/oci8/oci8_result.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 76aca9a66..58d9b9ba3 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 6b9a8e8fd..35587a9cc 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 221ab2c5f..7781b5bbd 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 38d870aa6..3fee6a1b6 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it -- cgit v1.2.3-24-g4f1b From f20fb98b36cba430e20eea931e9be392031923ea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 24 Jan 2012 15:26:01 +0200 Subject: Revert a space in the license agreement :) --- system/database/drivers/sqlite3/sqlite3_driver.php | 2 +- system/database/drivers/sqlite3/sqlite3_forge.php | 2 +- system/database/drivers/sqlite3/sqlite3_result.php | 2 +- system/database/drivers/sqlite3/sqlite3_utility.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index 8a7dbe1f1..b14e06c5d 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php index 07c25515a..a94970180 100644 --- a/system/database/drivers/sqlite3/sqlite3_forge.php +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php index e8e3706cd..acda28e6a 100644 --- a/system/database/drivers/sqlite3/sqlite3_result.php +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it diff --git a/system/database/drivers/sqlite3/sqlite3_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php index eae652582..bc9898ee4 100644 --- a/system/database/drivers/sqlite3/sqlite3_utility.php +++ b/system/database/drivers/sqlite3/sqlite3_utility.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it -- cgit v1.2.3-24-g4f1b From b998f3e820c724f16f3b700f094c875af1d28c0f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 24 Jan 2012 15:31:26 +0200 Subject: Revert a space in the license agreement :) --- system/libraries/Form_validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 34b7b646d..20f1faf27 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it -- cgit v1.2.3-24-g4f1b From a3ed086e74f6ea2fc8a529e02e509bbf91dd13c5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 25 Jan 2012 14:46:52 +0200 Subject: Remove an access description line and switch private to protected --- system/database/drivers/sqlite3/sqlite3_driver.php | 2 +- system/database/drivers/sqlite3/sqlite3_result.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index b14e06c5d..2e6589b52 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -174,7 +174,7 @@ class CI_DB_sqlite3_driver extends CI_DB { * @param string an SQL query * @return string */ - private function _prep_query($sql) + protected function _prep_query($sql) { return $this->conn_id->prepare($sql); } diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php index acda28e6a..c88696328 100644 --- a/system/database/drivers/sqlite3/sqlite3_result.php +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -153,7 +153,6 @@ class CI_DB_sqlite3_result extends CI_DB_result { * * Returns the result set as an object * - * @access private * @return object */ protected function _fetch_object() -- cgit v1.2.3-24-g4f1b From af5d5586a5040de24335e483edb17a2657ddeb21 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 25 Jan 2012 21:34:47 +0200 Subject: Improve the base database driver class --- system/database/DB_driver.php | 502 ++++++++++++++++-------------------------- 1 file changed, 189 insertions(+), 313 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 661b42ced..d9d83d55d 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,13 +1,13 @@ -conn_id) OR is_object($this->conn_id)) + /* If an established connection is available, then there's + * no need to connect and select the database. + * + * Depending on the database driver, conn_id can be either + * boolean TRUE, a resource or an object. + */ + if ($this->conn_id) { return TRUE; } @@ -126,7 +123,7 @@ class CI_DB_driver { // Connect to the database and set the connection ID $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - // No connection resource? Check if there is a failover else throw an error + // No connection resource? Check if there is a failover else throw an error if ( ! $this->conn_id) { // Check if there is a failover set @@ -200,12 +197,11 @@ class CI_DB_driver { /** * Set client character set * - * @access public * @param string * @param string - * @return resource + * @return bool */ - function db_set_charset($charset, $collation) + public function db_set_charset($charset, $collation) { if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat)) { @@ -227,10 +223,9 @@ class CI_DB_driver { /** * The name of the platform in use (mysql, mssql, etc...) * - * @access public * @return string */ - function platform() + public function platform() { return $this->dbdriver; } @@ -238,21 +233,16 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Database Version Number. Returns a string containing the + * Database Version Number. Returns a string containing the * version of the database being used * - * @access public * @return string */ - function version() + public function version() { if (FALSE === ($sql = $this->_version())) { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; } // Some DBs have functions that return the version, and don't run special @@ -266,7 +256,8 @@ class CI_DB_driver { else { $query = $this->query($sql); - return $query->row('ver'); + $query = $query->row(); + return $query->ver; } } @@ -281,42 +272,34 @@ class CI_DB_driver { * FALSE upon failure, and if the $db_debug variable is set to TRUE * will raise an error. * - * @access public * @param string An SQL query string * @param array An array of binding data * @return mixed */ - function query($sql, $binds = FALSE, $return_object = TRUE) + public function query($sql, $binds = FALSE, $return_object = TRUE) { if ($sql == '') { log_message('error', 'Invalid query: '.$sql); - if ($this->db_debug) - { - return $this->display_error('db_invalid_query'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE; } // Verify table prefix and replace if necessary - if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) + if ( ($this->dbprefix != '' && $this->swap_pre != '') && ($this->dbprefix != $this->swap_pre) ) { - $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); + $sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql); } - // Is query caching enabled? If the query is a "read type" + // Is query caching enabled? If the query is a "read type" // we will load the caching class and return the previously // cached query if it exists - if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) + if ($this->cache_on == TRUE && stripos($sql, 'SELECT') !== FALSE && $this->_cache_init()) { - if ($this->_cache_init()) + $this->load_rdriver(); + if (FALSE !== ($cache = $this->CACHE->read($sql))) { - $this->load_rdriver(); - if (FALSE !== ($cache = $this->CACHE->read($sql))) - { - return $cache; - } + return $cache; } } @@ -326,7 +309,7 @@ class CI_DB_driver { $sql = $this->compile_binds($sql, $binds); } - // Save the query for debugging + // Save the query for debugging if ($this->save_queries == TRUE) { $this->queries[] = $sql; @@ -357,19 +340,13 @@ class CI_DB_driver { if ($this->db_debug) { // We call this function in order to roll-back queries - // if transactions are enabled. If we don't call this here + // if transactions are enabled. If we don't call this here // the error message will trigger an exit, causing the // transactions to remain in limbo. $this->trans_complete(); // Display errors - return $this->display_error( - array( - 'Error Number: '.$error_no, - $error_msg, - $sql - ) - ); + return $this->display_error(array('Error Number: '.$error_no, $error_msg, $sql)); } return FALSE; @@ -393,7 +370,7 @@ class CI_DB_driver { { // If caching is enabled we'll auto-cleanup any // existing files related to this particular URI - if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) + if ($this->cache_on == TRUE && $this->cache_autodel == TRUE && $this->_cache_init()) { $this->CACHE->delete(); } @@ -410,13 +387,12 @@ class CI_DB_driver { } // Load and instantiate the result driver - - $driver = $this->load_rdriver(); - $RES = new $driver(); + $driver = $this->load_rdriver(); + $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->result_id = $this->result_id; - if ($this->dbdriver == 'oci8') + if ($this->dbdriver === 'oci8') { $RES->stmt_id = $this->stmt_id; $RES->curs_id = NULL; @@ -427,9 +403,9 @@ class CI_DB_driver { // oci8 vars must be set before calling this $RES->num_rows = $RES->num_rows(); - // Is query caching enabled? If so, we'll serialize the + // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. - if ($this->cache_on == TRUE AND $this->_cache_init()) + if ($this->cache_on == TRUE && $this->_cache_init()) { // We'll create a new instance of the result object // only without the platform specific driver since @@ -438,9 +414,9 @@ class CI_DB_driver { // result object, so we'll have to compile the data // and save it) $CR = new CI_DB_result(); - $CR->num_rows = $RES->num_rows(); $CR->result_object = $RES->result_object(); $CR->result_array = $RES->result_array(); + $CR->num_rows = $RES->num_rows(); // Reset these since cached objects can not utilize resource IDs. $CR->conn_id = NULL; @@ -457,10 +433,9 @@ class CI_DB_driver { /** * Load the result drivers * - * @access public * @return string the name of the result class */ - function load_rdriver() + public function load_rdriver() { $driver = 'CI_DB_'.$this->dbdriver.'_result'; @@ -477,15 +452,14 @@ class CI_DB_driver { /** * Simple Query - * This is a simplified version of the query() function. Internally + * This is a simplified version of the query() function. Internally * we only use it when running transaction commands since they do * not require all the features of the main query() function. * - * @access public * @param string the sql query * @return mixed */ - function simple_query($sql) + public function simple_query($sql) { if ( ! $this->conn_id) { @@ -501,10 +475,9 @@ class CI_DB_driver { * Disable Transactions * This permits transactions to be disabled at run-time. * - * @access public * @return void */ - function trans_off() + public function trans_off() { $this->trans_enabled = FALSE; } @@ -518,10 +491,9 @@ class CI_DB_driver { * If strict mode is disabled, each group is treated autonomously, meaning * a failure of one group will not affect any others * - * @access public * @return void */ - function trans_strict($mode = TRUE) + public function trans_strict($mode = TRUE) { $this->trans_strict = is_bool($mode) ? $mode : TRUE; } @@ -531,10 +503,9 @@ class CI_DB_driver { /** * Start Transaction * - * @access public * @return void */ - function trans_start($test_mode = FALSE) + public function trans_start($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -557,10 +528,9 @@ class CI_DB_driver { /** * Complete Transaction * - * @access public * @return bool */ - function trans_complete() + public function trans_complete() { if ( ! $this->trans_enabled) { @@ -604,10 +574,9 @@ class CI_DB_driver { /** * Lets you retrieve the transaction flag to determine if it has failed * - * @access public * @return bool */ - function trans_status() + public function trans_status() { return $this->_trans_status; } @@ -617,12 +586,11 @@ class CI_DB_driver { /** * Compile Bindings * - * @access public * @param string the sql statement * @param array an array of bind data * @return string */ - function compile_binds($sql, $binds) + public function compile_binds($sql, $binds) { if (strpos($sql, $this->bind_marker) === FALSE) { @@ -639,7 +607,8 @@ class CI_DB_driver { // The count of bind should be 1 less then the count of segments // If there are more bind arguments trim it down - if (count($binds) >= count($segments)) { + if (count($binds) >= count($segments)) + { $binds = array_slice($binds, 0, count($segments)-1); } @@ -648,8 +617,7 @@ class CI_DB_driver { $i = 0; foreach ($binds as $bind) { - $result .= $this->escape($bind); - $result .= $segments[++$i]; + $result .= $this->escape($bind).$segments[++$i]; } return $result; @@ -660,17 +628,12 @@ class CI_DB_driver { /** * Determines if a query is a "write" type. * - * @access public * @param string An SQL query string - * @return boolean + * @return bool */ - function is_write_type($sql) + public function is_write_type($sql) { - if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) - { - return FALSE; - } - return TRUE; + return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql); } // -------------------------------------------------------------------- @@ -678,11 +641,10 @@ class CI_DB_driver { /** * Calculate the aggregate query elapsed time * - * @access public - * @param integer The number of decimal places - * @return integer + * @param int The number of decimal places + * @return int */ - function elapsed_time($decimals = 6) + public function elapsed_time($decimals = 6) { return number_format($this->benchmark, $decimals); } @@ -692,10 +654,9 @@ class CI_DB_driver { /** * Returns the total number of queries * - * @access public - * @return integer + * @return int */ - function total_queries() + public function total_queries() { return $this->query_count; } @@ -705,10 +666,9 @@ class CI_DB_driver { /** * Returns the last query that was executed * - * @access public - * @return void + * @return string */ - function last_query() + public function last_query() { return end($this->queries); } @@ -721,23 +681,22 @@ class CI_DB_driver { * Escapes data based on type * Sets boolean and null types * - * @access public * @param string * @return mixed */ - function escape($str) + public function escape($str) { if (is_string($str)) { - $str = "'".$this->escape_str($str)."'"; + return "'".$this->escape_str($str)."'"; } elseif (is_bool($str)) { - $str = ($str === FALSE) ? 0 : 1; + return ($str === FALSE) ? 0 : 1; } elseif (is_null($str)) { - $str = 'NULL'; + return 'NULL'; } return $str; @@ -751,11 +710,10 @@ class CI_DB_driver { * Calls the individual driver for platform * specific escaping for LIKE conditions * - * @access public * @param string * @return mixed */ - function escape_like_str($str) + public function escape_like_str($str) { return $this->escape_str($str, TRUE); } @@ -765,23 +723,16 @@ class CI_DB_driver { /** * Primary * - * Retrieves the primary key. It assumes that the row in the first + * Retrieves the primary key. It assumes that the row in the first * position is the primary key * - * @access public * @param string the table name * @return string */ - function primary($table = '') + public function primary($table = '') { $fields = $this->list_fields($table); - - if ( ! is_array($fields)) - { - return FALSE; - } - - return current($fields); + return is_array($fields) ? current($fields) : FALSE; } // -------------------------------------------------------------------- @@ -789,10 +740,9 @@ class CI_DB_driver { /** * Returns an array of table names * - * @access public * @return array */ - function list_tables($constrain_by_prefix = FALSE) + public function list_tables($constrain_by_prefix = FALSE) { // Is there a cached result? if (isset($this->data_cache['table_names'])) @@ -802,32 +752,17 @@ class CI_DB_driver { if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; } - $retval = array(); + $this->data_cache['table_names'] = array(); $query = $this->query($sql); - if ($query->num_rows() > 0) + foreach ($query->result_array() as $row) { - foreach ($query->result_array() as $row) - { - if (isset($row['TABLE_NAME'])) - { - $retval[] = $row['TABLE_NAME']; - } - else - { - $retval[] = array_shift($row); - } - } + $this->data_cache['table_names'][] = isset($row['TABLE_NAME']) ? $row['TABLE_NAME'] : array_shift($row); } - $this->data_cache['table_names'] = $retval; return $this->data_cache['table_names']; } @@ -835,12 +770,12 @@ class CI_DB_driver { /** * Determine if a particular table exists - * @access public - * @return boolean + * + * @return bool */ - function table_exists($table_name) + public function table_exists($table_name) { - return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE; + return in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables()); } // -------------------------------------------------------------------- @@ -848,11 +783,10 @@ class CI_DB_driver { /** * Fetch MySQL Field Names * - * @access public * @param string the table name * @return array */ - function list_fields($table = '') + public function list_fields($table = '') { // Is there a cached result? if (isset($this->data_cache['field_names'][$table])) @@ -862,38 +796,22 @@ class CI_DB_driver { if ($table == '') { - if ($this->db_debug) - { - return $this->display_error('db_field_param_missing'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; } if (FALSE === ($sql = $this->_list_columns($table))) { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; } $query = $this->query($sql); + $this->data_cache['field_names'][$table] = array(); - $retval = array(); foreach ($query->result_array() as $row) { - if (isset($row['COLUMN_NAME'])) - { - $retval[] = $row['COLUMN_NAME']; - } - else - { - $retval[] = current($row); - } + $this->data_cache['field_names'][$table][] = isset($row['COLUMN_NAME']) ? $row['COLUMN_NAME'] : current($row); } - $this->data_cache['field_names'][$table] = $retval; return $this->data_cache['field_names'][$table]; } @@ -901,14 +819,14 @@ class CI_DB_driver { /** * Determine if a particular field exists - * @access public + * * @param string * @param string - * @return boolean + * @return bool */ - function field_exists($field_name, $table_name) + public function field_exists($field_name, $table_name) { - return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; + return in_array($field_name, $this->list_fields($table_name)); } // -------------------------------------------------------------------- @@ -916,23 +834,17 @@ class CI_DB_driver { /** * Returns an object with field data * - * @access public * @param string the table name - * @return object + * @return mixed */ - function field_data($table = '') + public function field_data($table = '') { if ($table == '') { - if ($this->db_debug) - { - return $this->display_error('db_field_param_missing'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; } $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE))); - return $query->field_data(); } @@ -941,15 +853,13 @@ class CI_DB_driver { /** * Generate an insert string * - * @access public * @param string the table upon which the query will be performed * @param array an associative array data of key/values * @return string */ - function insert_string($table, $data) + public function insert_string($table, $data) { - $fields = array(); - $values = array(); + $fields = $values = array(); foreach ($data as $key => $val) { @@ -965,17 +875,16 @@ class CI_DB_driver { /** * Generate an update string * - * @access public * @param string the table upon which the query will be performed * @param array an associative array data of key/values * @param mixed the "where" statement * @return string */ - function update_string($table, $data, $where) + public function update_string($table, $data, $where) { if ($where == '') { - return false; + return FALSE; } $fields = array(); @@ -993,7 +902,7 @@ class CI_DB_driver { $dest = array(); foreach ($where as $key => $val) { - $prefix = (count($dest) == 0) ? '' : ' AND '; + $prefix = (count($dest) === 0) ? '' : ' AND '; $key = $this->_protect_identifiers($key); if ($val !== '') @@ -1018,19 +927,12 @@ class CI_DB_driver { /** * Tests whether the string has an SQL operator * - * @access private * @param string * @return bool */ - function _has_operator($str) + protected function _has_operator($str) { - $str = trim($str); - if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) - { - return FALSE; - } - - return TRUE; + return (bool) preg_match('/(\s|<|>|!|=|is null|is not null)/i', trim($str)); } // -------------------------------------------------------------------- @@ -1038,12 +940,11 @@ class CI_DB_driver { /** * Enables a native PHP function to be run, using a platform agnostic wrapper. * - * @access public * @param string the function name * @param mixed any parameters needed by the function * @return mixed */ - function call_function($function) + public function call_function($function) { $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; @@ -1054,25 +955,12 @@ class CI_DB_driver { if ( ! function_exists($function)) { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; } - else - { - $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; - if (is_null($args)) - { - return call_user_func($function); - } - else - { - return call_user_func_array($function, $args); - } - } + return (func_num_args() > 1) + ? call_user_func_array($function, array_splice(func_get_args(), 1)) + : call_user_func($function); } // -------------------------------------------------------------------- @@ -1080,11 +968,10 @@ class CI_DB_driver { /** * Set Cache Directory Path * - * @access public * @param string the path to the cache directory * @return void */ - function cache_set_path($path = '') + public function cache_set_path($path = '') { $this->cachedir = $path; } @@ -1094,13 +981,11 @@ class CI_DB_driver { /** * Enable Query Caching * - * @access public - * @return void + * @return bool cache_on value */ - function cache_on() + public function cache_on() { - $this->cache_on = TRUE; - return TRUE; + return $this->cache_on = TRUE; } // -------------------------------------------------------------------- @@ -1108,13 +993,11 @@ class CI_DB_driver { /** * Disable Query Caching * - * @access public - * @return void + * @return bool cache_on value */ - function cache_off() + public function cache_off() { - $this->cache_on = FALSE; - return FALSE; + return $this->cache_on = FALSE; } @@ -1123,15 +1006,15 @@ class CI_DB_driver { /** * Delete the cache files associated with a particular URI * - * @access public - * @return void + * @return bool */ - function cache_delete($segment_one = '', $segment_two = '') + public function cache_delete($segment_one = '', $segment_two = '') { if ( ! $this->_cache_init()) { return FALSE; } + return $this->CACHE->delete($segment_one, $segment_two); } @@ -1140,10 +1023,9 @@ class CI_DB_driver { /** * Delete All cache files * - * @access public - * @return void + * @return bool */ - function cache_delete_all() + public function cache_delete_all() { if ( ! $this->_cache_init()) { @@ -1158,23 +1040,21 @@ class CI_DB_driver { /** * Initialize the Cache Class * - * @access private * @return void */ - function _cache_init() + protected function _cache_init() { - if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) + if (class_exists('CI_DB_Cache')) { - return TRUE; - } - - if ( ! class_exists('CI_DB_Cache')) - { - if ( ! @include(BASEPATH.'database/DB_cache.php')) + if (is_object($this->CACHE)) { - return $this->cache_off(); + return TRUE; } } + elseif ( ! @include_once(BASEPATH.'database/DB_cache.php')) + { + return $this->cache_off(); + } $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects return TRUE; @@ -1185,16 +1065,15 @@ class CI_DB_driver { /** * Close DB Connection * - * @access public * @return void */ - function close() + public function close() { - if (is_resource($this->conn_id) OR is_object($this->conn_id)) + if ($this->conn_id) { $this->_close($this->conn_id); + $this->conn_id = FALSE; } - $this->conn_id = FALSE; } // -------------------------------------------------------------------- @@ -1202,13 +1081,12 @@ class CI_DB_driver { /** * Display an error message * - * @access public * @param string the error message * @param string any "swap" values - * @param boolean whether to localize the message + * @param bool whether to localize the message * @return string sends the application/error_db.php template */ - function display_error($error = '', $swap = '', $native = FALSE) + public function display_error($error = '', $swap = '', $native = FALSE) { $LANG =& load_class('Lang', 'core'); $LANG->load('db'); @@ -1227,9 +1105,7 @@ class CI_DB_driver { // Find the most likely culprit of the error by going through // the backtrace until the source file is no longer in the // database folder. - $trace = debug_backtrace(); - foreach ($trace as $call) { if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE) @@ -1237,7 +1113,6 @@ class CI_DB_driver { // Found it - use a relative path for safety $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']); $message[] = 'Line Number: '.$call['line']; - break; } } @@ -1254,11 +1129,10 @@ class CI_DB_driver { * * This function adds backticks if appropriate based on db type * - * @access private * @param mixed the item to escape * @return mixed the item with backticks */ - function protect_identifiers($item, $prefix_single = FALSE) + public function protect_identifiers($item, $prefix_single = FALSE) { return $this->_protect_identifiers($item, $prefix_single); } @@ -1271,8 +1145,8 @@ class CI_DB_driver { * This function is used extensively by the Active Record 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 - * column names that include the path. Consider a query like this: + * the table prefix onto it. Some logic is necessary in order to deal with + * column names that include the path. Consider a query like this: * * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table * @@ -1285,14 +1159,16 @@ class CI_DB_driver { * insert the table prefix (if it exists) in the proper position, and escape only * the correct identifiers. * - * @access private + * NOTE: This is used by DB_forge drivers and therefore needs to be public. + * (until a better solution is implemented) + * * @param string * @param bool * @param mixed * @param bool * @return string */ - function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) + public function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) { if ( ! is_bool($protect_identifiers)) { @@ -1302,7 +1178,6 @@ class CI_DB_driver { if (is_array($item)) { $escaped_array = array(); - foreach ($item as $k => $v) { $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v); @@ -1316,16 +1191,19 @@ class CI_DB_driver { // If the item has an alias declaration we remove it and set it aside. // Basically we remove everything to the right of the first space - $alias = ''; if (strpos($item, ' ') !== FALSE) { - $alias = strstr($item, " "); + $alias = strstr($item, ' '); $item = substr($item, 0, - strlen($alias)); } + else + { + $alias = ''; + } // This is basically a bug fix for queries that use MAX, MIN, etc. // If a parenthesis is found we know that we do not need to - // escape the data or add a prefix. There's probably a more graceful + // escape the data or add a prefix. There's probably a more graceful // way to deal with this, but I'm not thinking of it -- Rick if (strpos($item, '(') !== FALSE) { @@ -1340,7 +1218,7 @@ class CI_DB_driver { $parts = explode('.', $item); // Does the first segment of the exploded item match - // one of the aliases previously identified? If so, + // 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)) { @@ -1356,10 +1234,11 @@ class CI_DB_driver { $item = implode('.', $parts); } + return $item.$alias; } - // Is there a table prefix defined in the config file? If not, no need to do anything + // Is there a table prefix defined in the config file? If not, no need to do anything if ($this->dbprefix != '') { // We now add the table prefix based on some logic. @@ -1390,13 +1269,12 @@ class CI_DB_driver { } // Verify table prefix and replace if necessary - if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0) + if ($this->swap_pre != '' && strpos($parts[$i], $this->swap_pre) === 0) { - $parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]); + $parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]); } - // We only add the table prefix if it does not already exist - if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix) + elseif (strpos($parts[$i], $this->dbprefix) !== 0) { $parts[$i] = $this->dbprefix.$parts[$i]; } @@ -1417,19 +1295,18 @@ class CI_DB_driver { if ($this->dbprefix != '') { // Verify table prefix and replace if necessary - if ($this->swap_pre != '' && strncmp($item, $this->swap_pre, strlen($this->swap_pre)) === 0) + if ($this->swap_pre != '' && strpos($item, $this->swap_pre) === 0) { - $item = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $item); + $item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item); } - // Do we prefix an item with no segments? - if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) + elseif ($prefix_single == TRUE && strpos($item, $this->dbprefix) !== 0) { $item = $this->dbprefix.$item; } } - if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) + if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers)) { $item = $this->_escape_identifiers($item); } @@ -1440,6 +1317,5 @@ class CI_DB_driver { } - /* End of file DB_driver.php */ /* Location: ./system/database/DB_driver.php */ -- cgit v1.2.3-24-g4f1b From a5f2f694c6fb0cf3286a4ae44af47ac77684a36a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 25 Jan 2012 21:44:56 +0200 Subject: Pass CI_DB_driver::curs_id to CI_DB_oci8_result ... --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index d9d83d55d..117db68e8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -395,7 +395,7 @@ class CI_DB_driver { if ($this->dbdriver === 'oci8') { $RES->stmt_id = $this->stmt_id; - $RES->curs_id = NULL; + $RES->curs_id = $this->curs_id; $RES->limit_used = $this->limit_used; $this->stmt_id = FALSE; } -- cgit v1.2.3-24-g4f1b From 12567e8263be2d007dc50fc94e7456c7183f8098 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 25 Jan 2012 22:50:33 +0200 Subject: Add better key/index detection for list_tables() and list_fields() --- system/database/DB_driver.php | 50 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 117db68e8..eb6ab7430 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -760,7 +760,30 @@ class CI_DB_driver { foreach ($query->result_array() as $row) { - $this->data_cache['table_names'][] = isset($row['TABLE_NAME']) ? $row['TABLE_NAME'] : array_shift($row); + // Do we know from which column to get the table name? + if ( ! isset($key)) + { + if (array_key_exists('table_name', $row)) + { + $key = 'table_name'; + } + elseif (array_key_exists('TABLE_NAME', $row)) + { + $key = 'TABLE_NAME'; + } + else + { + /* We have no other choice but to just get the first element's key. + * Due to array_shift() accepting it's argument by reference, if + * E_STRICT is on, this would trigger a warning. So we'll have to + * assign it first. + */ + $key = array_keys($row); + $key = array_shift($key); + } + } + + $this->data_cache['table_names'][] = $row[$key]; } return $this->data_cache['table_names']; @@ -809,7 +832,30 @@ class CI_DB_driver { foreach ($query->result_array() as $row) { - $this->data_cache['field_names'][$table][] = isset($row['COLUMN_NAME']) ? $row['COLUMN_NAME'] : current($row); + // Do we know from where to get the column's name? + if ( ! isset($key)) + { + if (array_key_exists('column_name', $row)) + { + $key = 'column_name'; + } + elseif (array_key_exists('COLUMN_NAME', $row)) + { + $key = 'COLUMN_NAME'; + } + else + { + /* We have no other choice but to just get the first element's key. + * Due to array_shift() accepting it's argument by reference, if + * E_STRICT is on, this would trigger a warning. So we'll have to + * assign it first. + */ + $key = array_keys($row); + $key = array_shift($key); + } + } + + $this->data_cache['field_names'][$table][] = $row[$key]; } return $this->data_cache['field_names'][$table]; -- cgit v1.2.3-24-g4f1b From 4a31568b2eb410dd153a3636da13d62e9cbfd41a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 26 Jan 2012 02:03:10 +0200 Subject: DB forge escaping related --- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_forge.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 58d9b9ba3..9fce18674 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -568,7 +568,7 @@ class CI_DB_oci8_driver extends CI_DB { * @param string * @return string */ - protected function _escape_identifiers($item) + public function _escape_identifiers($item) { if ($this->_escape_char == '') { diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 35587a9cc..661ec3a40 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -97,7 +97,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { { $attributes = array_change_key_case($attributes, CASE_UPPER); - $sql .= "\n\t".$this->db->_protect_identifiers($field).' '.$attributes['TYPE'] + $sql .= "\n\t".$this->db->protect_identifiers($field).' '.$attributes['TYPE'] .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '') .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '') @@ -113,7 +113,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $primary_keys = $this->db->_protect_identifiers($primary_keys); + $primary_keys = $this->db->protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')'; } @@ -123,11 +123,11 @@ class CI_DB_oci8_forge extends CI_DB_forge { { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->protect_identifiers($key); } else { - $key = array($this->db->_protect_identifiers($key)); + $key = array($this->db->protect_identifiers($key)); } $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).')'; @@ -146,7 +146,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { */ public function _drop_table($table) { - return 'DROP TABLE '.$this->db->_protect_identifiers($table); + return 'DROP TABLE '.$this->db->protect_identifiers($table); } // -------------------------------------------------------------------- @@ -168,7 +168,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { */ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table).' '.$alter_type.' '.$this->db->_protect_identifiers($column_name); + $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name); // DROP has everything it needs now. if ($alter_type === 'DROP') @@ -179,7 +179,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { return $sql.' '.$column_definition .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '') .($null === NULL ? ' NULL' : ' NOT NULL') - .($after_field != '' ? ' AFTER '.$this->db->_protect_identifiers($after_field) : ''); + .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : ''); } @@ -196,7 +196,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { */ public function _rename_table($table_name, $new_table_name) { - return 'ALTER TABLE '.$this->db->_protect_identifiers($table_name).' RENAME TO '.$this->db->_protect_identifiers($new_table_name); + return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name); } } -- cgit v1.2.3-24-g4f1b From cb9f361feb5f60191fc14a19f23aa0ba2bf91c37 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 26 Jan 2012 02:06:48 +0200 Subject: DB forge escaping related --- system/database/drivers/sqlite3/sqlite3_driver.php | 12 ++++++------ system/database/drivers/sqlite3/sqlite3_forge.php | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index 2e6589b52..eb9a8f526 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -43,19 +43,19 @@ class CI_DB_sqlite3_driver extends CI_DB { public $dbdriver = 'sqlite3'; // The character used for escaping - public $_escape_char = '"'; + protected $_escape_char = '"'; // clause and character used for LIKE escape sequences - public $_like_escape_str = ' ESCAPE \'%s\' '; - public $_like_escape_chr = '!'; + protected $_like_escape_str = ' ESCAPE \'%s\' '; + protected $_like_escape_chr = '!'; /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - public $_count_string = 'SELECT COUNT(*) AS '; - public $_random_keyword = ' RANDOM()'; + protected $_count_string = 'SELECT COUNT(*) AS '; + protected $_random_keyword = ' RANDOM()'; /** * Non-persistent database connection @@ -403,7 +403,7 @@ class CI_DB_sqlite3_driver extends CI_DB { * @param string * @return string */ - protected function _escape_identifiers($item) + public function _escape_identifiers($item) { if ($this->_escape_char == '') { diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php index a94970180..6398e48cd 100644 --- a/system/database/drivers/sqlite3/sqlite3_forge.php +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -111,7 +111,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { { $attributes = array_change_key_case($attributes, CASE_UPPER); - $sql .= "\n\t".$this->db->_protect_identifiers($field) + $sql .= "\n\t".$this->db->protect_identifiers($field) .' '.$attributes['TYPE'] .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '') .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') @@ -129,7 +129,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $primary_keys = $this->db->_protect_identifiers($primary_keys); + $primary_keys = $this->db->protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')'; } @@ -139,11 +139,11 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->protect_identifiers($key); } else { - $key = array($this->db->_protect_identifiers($key)); + $key = array($this->db->protect_identifiers($key)); } $sql .= ",\n\tUNIQUE (".implode(', ', $key).')'; @@ -195,7 +195,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { return FALSE; } - return 'ALTER TABLE '.$this->db->_protect_identifiers($table).' '.$alter_type.' '.$this->db->_protect_identifiers($column_name) + return 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name) .' '.$column_definition .($default_value != '' ? ' DEFAULT '.$default_value : '') // If NOT NULL is specified, the field must have a DEFAULT value other than NULL @@ -215,7 +215,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { */ public function _rename_table($table_name, $new_table_name) { - return 'ALTER TABLE '.$this->db->_protect_identifiers($table_name).' RENAME TO '.$this->db->_protect_identifiers($new_table_name); + return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name); } } -- cgit v1.2.3-24-g4f1b From f32110a952f8e1f58c4c0f13715681c248bc8ace Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 26 Jan 2012 11:04:11 +0200 Subject: Fix a comment typo --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index eb6ab7430..113c3d3fe 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -74,7 +74,7 @@ class CI_DB_driver { protected $_protect_identifiers = TRUE; protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped - // These are use with Oracle + // These are used with Oracle public $stmt_id; public $curs_id; public $limit_used; -- cgit v1.2.3-24-g4f1b From 85facfa42793cce480d2f49696c2d3e3096763f0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 26 Jan 2012 14:12:14 +0200 Subject: Replace array_key_exists() with isset() and ! empty() --- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_forge.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 9fce18674..700cde4b8 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -255,7 +255,7 @@ class CI_DB_oci8_driver extends CI_DB { { $sql .= $param['name'].','; - if (array_key_exists('type', $param) && ($param['type'] === OCI_B_CURSOR)) + if (isset($param['type']) && $param['type'] === OCI_B_CURSOR) { $have_cursor = TRUE; } diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 661ec3a40..1dcc346d2 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -98,10 +98,10 @@ class CI_DB_oci8_forge extends CI_DB_forge { $attributes = array_change_key_case($attributes, CASE_UPPER); $sql .= "\n\t".$this->db->protect_identifiers($field).' '.$attributes['TYPE'] - .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '') - .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') - .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '') - .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'); + .(isset($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '') + .((isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') + .(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '') + .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'); } // don't add a comma on the end of the last field -- cgit v1.2.3-24-g4f1b From 79f675446b29a0006ea090ed03ed721fb18c5dc5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 26 Jan 2012 14:15:53 +0200 Subject: Replace array_key_exists() with isset() --- system/database/drivers/sqlite3/sqlite3_forge.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php index 6398e48cd..43f08ed7a 100644 --- a/system/database/drivers/sqlite3/sqlite3_forge.php +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -113,11 +113,11 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { $sql .= "\n\t".$this->db->protect_identifiers($field) .' '.$attributes['TYPE'] - .(array_key_exists('CONSTRAINT', $attributes) ? '('.$attributes['CONSTRAINT'].')' : '') - .((array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') - .(array_key_exists('DEFAULT', $attributes) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '') - .((array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') - .((array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : ''); + .(isset($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '') + .((isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') + .(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '') + .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') + .((isset($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : ''); } // don't add a comma on the end of the last field -- cgit v1.2.3-24-g4f1b From fe3428ae6c3a563e2ada653e3d099231827c2c3d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 26 Jan 2012 14:47:29 +0200 Subject: Another minor improvement --- system/database/drivers/sqlite3/sqlite3_forge.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php index 43f08ed7a..68da7627e 100644 --- a/system/database/drivers/sqlite3/sqlite3_forge.php +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -113,11 +113,11 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { $sql .= "\n\t".$this->db->protect_identifiers($field) .' '.$attributes['TYPE'] - .(isset($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '') - .((isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') + .( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '') + .(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') .(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '') - .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') - .((isset($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : ''); + .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') + .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : ''); } // don't add a comma on the end of the last field -- cgit v1.2.3-24-g4f1b From a7c0656a530ca405d2ed18b8e9bd252975bb8505 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jan 2012 21:18:48 +0200 Subject: Removed a few more unnecessary lines --- system/database/DB_driver.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 03fc8a698..39eb1cc8a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -180,12 +180,7 @@ class CI_DB_driver { else { // We've selected the DB. Now we set the character set - if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) - { - return FALSE; - } - - return TRUE; + return $this->db_set_charset($this->char_set, $this->dbcollat); } } @@ -247,9 +242,7 @@ class CI_DB_driver { // Some DBs have functions that return the version, and don't run special // SQL queries per se. In these instances, just return the result. - $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo', 'mysqli'); - - if (in_array($this->dbdriver, $driver_version_exceptions)) + if (in_array($this->dbdriver, array('oci8', 'sqlite', 'cubrid', 'pdo', 'mysqli')) { return $sql; } -- cgit v1.2.3-24-g4f1b From 569091cf6ad7101059e6a4ffbd93f227aad9937f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 9 Feb 2012 00:16:17 +0200 Subject: Revert CI_DB_driver changes (see #971) --- system/database/DB_driver.php | 287 +++++++++++++++++++++++++----------------- 1 file changed, 171 insertions(+), 116 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a30c8226d..daca08f0f 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,13 +1,13 @@ -_db_set_charset($this->char_set, $this->dbcollat)) { @@ -222,9 +227,10 @@ class CI_DB_driver { /** * The name of the platform in use (mysql, mssql, etc...) * + * @access public * @return string */ - public function platform() + function platform() { return $this->dbdriver; } @@ -235,9 +241,10 @@ class CI_DB_driver { * Database Version Number. Returns a string containing the * version of the database being used * + * @access public * @return string */ - public function version() + function version() { if (FALSE === ($sql = $this->_version())) { @@ -274,11 +281,12 @@ class CI_DB_driver { * FALSE upon failure, and if the $db_debug variable is set to TRUE * will raise an error. * + * @access public * @param string An SQL query string * @param array An array of binding data * @return mixed */ - public function query($sql, $binds = FALSE, $return_object = TRUE) + function query($sql, $binds = FALSE, $return_object = TRUE) { if ($sql == '') { @@ -292,15 +300,15 @@ class CI_DB_driver { } // Verify table prefix and replace if necessary - if (($this->dbprefix != '' && $this->swap_pre != '') && ($this->dbprefix != $this->swap_pre)) + if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) { - $sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql); + $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); } // Is query caching enabled? If the query is a "read type" // we will load the caching class and return the previously // cached query if it exists - if ($this->cache_on == TRUE && stristr($sql, 'SELECT')) + if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) { if ($this->_cache_init()) { @@ -385,7 +393,7 @@ class CI_DB_driver { { // If caching is enabled we'll auto-cleanup any // existing files related to this particular URI - if ($this->cache_on == TRUE && $this->cache_autodel == TRUE && $this->_cache_init()) + if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) { $this->CACHE->delete(); } @@ -404,10 +412,10 @@ class CI_DB_driver { // Load and instantiate the result driver $driver = $this->load_rdriver(); $RES = new $driver(); - $RES->conn_id = $this->conn_id; - $RES->result_id = $this->result_id; + $RES->conn_id = $this->conn_id; + $RES->result_id = $this->result_id; - if ($this->dbdriver == 'oci8') + if ($this->dbdriver === 'oci8') { $RES->stmt_id = $this->stmt_id; $RES->curs_id = $this->curs_id; @@ -419,7 +427,7 @@ class CI_DB_driver { // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. - if ($this->cache_on == TRUE && $this->_cache_init()) + if ($this->cache_on == TRUE AND $this->_cache_init()) { // We'll create a new instance of the result object // only without the platform specific driver since @@ -447,9 +455,10 @@ class CI_DB_driver { /** * Load the result drivers * + * @access public * @return string the name of the result class */ - public function load_rdriver() + function load_rdriver() { $driver = 'CI_DB_'.$this->dbdriver.'_result'; @@ -470,10 +479,11 @@ class CI_DB_driver { * we only use it when running transaction commands since they do * not require all the features of the main query() function. * + * @access public * @param string the sql query * @return mixed */ - public function simple_query($sql) + function simple_query($sql) { if ( ! $this->conn_id) { @@ -489,9 +499,10 @@ class CI_DB_driver { * Disable Transactions * This permits transactions to be disabled at run-time. * + * @access public * @return void */ - public function trans_off() + function trans_off() { $this->trans_enabled = FALSE; } @@ -500,15 +511,15 @@ class CI_DB_driver { /** * Enable/disable Transaction Strict Mode - * * When strict mode is enabled, if you are running multiple groups of * transactions, if one group fails all groups will be rolled back. * If strict mode is disabled, each group is treated autonomously, meaning * a failure of one group will not affect any others * + * @access public * @return void */ - public function trans_strict($mode = TRUE) + function trans_strict($mode = TRUE) { $this->trans_strict = is_bool($mode) ? $mode : TRUE; } @@ -518,9 +529,10 @@ class CI_DB_driver { /** * Start Transaction * + * @access public * @return void */ - public function trans_start($test_mode = FALSE) + function trans_start($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -543,9 +555,10 @@ class CI_DB_driver { /** * Complete Transaction * + * @access public * @return bool */ - public function trans_complete() + function trans_complete() { if ( ! $this->trans_enabled) { @@ -589,9 +602,10 @@ class CI_DB_driver { /** * Lets you retrieve the transaction flag to determine if it has failed * + * @access public * @return bool */ - public function trans_status() + function trans_status() { return $this->_trans_status; } @@ -601,11 +615,12 @@ class CI_DB_driver { /** * Compile Bindings * + * @access public * @param string the sql statement * @param array an array of bind data * @return string */ - public function compile_binds($sql, $binds) + function compile_binds($sql, $binds) { if (strpos($sql, $this->bind_marker) === FALSE) { @@ -643,12 +658,17 @@ class CI_DB_driver { /** * Determines if a query is a "write" type. * + * @access public * @param string An SQL query string - * @return bool + * @return boolean */ - public function is_write_type($sql) + function is_write_type($sql) { - return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql); + if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + { + return FALSE; + } + return TRUE; } // -------------------------------------------------------------------- @@ -656,10 +676,11 @@ class CI_DB_driver { /** * Calculate the aggregate query elapsed time * - * @param int The number of decimal places - * @return string + * @access public + * @param integer The number of decimal places + * @return integer */ - public function elapsed_time($decimals = 6) + function elapsed_time($decimals = 6) { return number_format($this->benchmark, $decimals); } @@ -669,9 +690,10 @@ class CI_DB_driver { /** * Returns the total number of queries * + * @access public * @return integer */ - public function total_queries() + function total_queries() { return $this->query_count; } @@ -681,9 +703,10 @@ class CI_DB_driver { /** * Returns the last query that was executed * + * @access public * @return void */ - public function last_query() + function last_query() { return end($this->queries); } @@ -696,10 +719,11 @@ class CI_DB_driver { * Escapes data based on type * Sets boolean and null types * + * @access public * @param string * @return mixed */ - public function escape($str) + function escape($str) { if (is_string($str)) { @@ -725,10 +749,11 @@ class CI_DB_driver { * Calls the individual driver for platform * specific escaping for LIKE conditions * + * @access public * @param string * @return mixed */ - public function escape_like_str($str) + function escape_like_str($str) { return $this->escape_str($str, TRUE); } @@ -738,13 +763,14 @@ class CI_DB_driver { /** * Primary * - * Retrieves the primary key. It assumes that the row in the first + * Retrieves the primary key. It assumes that the row in the first * position is the primary key * + * @access public * @param string the table name * @return string */ - public function primary($table = '') + function primary($table = '') { $fields = $this->list_fields($table); @@ -761,9 +787,10 @@ class CI_DB_driver { /** * Returns an array of table names * + * @access public * @return array */ - public function list_tables($constrain_by_prefix = FALSE) + function list_tables($constrain_by_prefix = FALSE) { // Is there a cached result? if (isset($this->data_cache['table_names'])) @@ -806,23 +833,24 @@ class CI_DB_driver { /** * Determine if a particular table exists - * + * @access public * @return boolean */ - public function table_exists($table_name) + function table_exists($table_name) { - return in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables()); + return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- /** - * Fetch Field Names + * Fetch MySQL Field Names * + * @access public * @param string the table name * @return array */ - public function list_fields($table = '') + function list_fields($table = '') { // Is there a cached result? if (isset($this->data_cache['field_names'][$table])) @@ -871,14 +899,14 @@ class CI_DB_driver { /** * Determine if a particular field exists - * + * @access public * @param string * @param string * @return boolean */ - public function field_exists($field_name, $table_name) + function field_exists($field_name, $table_name) { - return in_array($field_name, $this->list_fields($table_name)); + return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -886,10 +914,11 @@ class CI_DB_driver { /** * Returns an object with field data * + * @access public * @param string the table name * @return object */ - public function field_data($table = '') + function field_data($table = '') { if ($table == '') { @@ -901,6 +930,7 @@ class CI_DB_driver { } $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE))); + return $query->field_data(); } @@ -909,11 +939,12 @@ class CI_DB_driver { /** * Generate an insert string * + * @access public * @param string the table upon which the query will be performed * @param array an associative array data of key/values * @return string */ - public function insert_string($table, $data) + function insert_string($table, $data) { $fields = array(); $values = array(); @@ -932,16 +963,17 @@ class CI_DB_driver { /** * Generate an update string * + * @access public * @param string the table upon which the query will be performed * @param array an associative array data of key/values * @param mixed the "where" statement * @return string */ - public function update_string($table, $data, $where) + function update_string($table, $data, $where) { if ($where == '') { - return FALSE; + return false; } $fields = array(); @@ -984,12 +1016,19 @@ class CI_DB_driver { /** * Tests whether the string has an SQL operator * + * @access private * @param string * @return bool */ - protected function _has_operator($str) + function _has_operator($str) { - return (bool) preg_match('/(\s|<|>|!|=|is null|is not null)/i', trim($str)); + $str = trim($str); + if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) + { + return FALSE; + } + + return TRUE; } // -------------------------------------------------------------------- @@ -997,11 +1036,12 @@ class CI_DB_driver { /** * Enables a native PHP function to be run, using a platform agnostic wrapper. * + * @access public * @param string the function name * @param mixed any parameters needed by the function * @return mixed */ - public function call_function($function) + function call_function($function) { $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; @@ -1038,10 +1078,11 @@ class CI_DB_driver { /** * Set Cache Directory Path * + * @access public * @param string the path to the cache directory * @return void */ - public function cache_set_path($path = '') + function cache_set_path($path = '') { $this->cachedir = $path; } @@ -1051,11 +1092,13 @@ class CI_DB_driver { /** * Enable Query Caching * + * @access public * @return void */ - public function cache_on() + function cache_on() { - return $this->cache_on = TRUE; + $this->cache_on = TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -1063,11 +1106,13 @@ class CI_DB_driver { /** * Disable Query Caching * + * @access public * @return void */ - public function cache_off() + function cache_off() { - return $this->cache_on = FALSE; + $this->cache_on = FALSE; + return FALSE; } @@ -1076,9 +1121,10 @@ class CI_DB_driver { /** * Delete the cache files associated with a particular URI * + * @access public * @return void */ - public function cache_delete($segment_one = '', $segment_two = '') + function cache_delete($segment_one = '', $segment_two = '') { if ( ! $this->_cache_init()) { @@ -1092,9 +1138,10 @@ class CI_DB_driver { /** * Delete All cache files * + * @access public * @return void */ - public function cache_delete_all() + function cache_delete_all() { if ( ! $this->_cache_init()) { @@ -1109,18 +1156,22 @@ class CI_DB_driver { /** * Initialize the Cache Class * + * @access private * @return void */ - private function _cache_init() + function _cache_init() { - if (is_object($this->CACHE) && class_exists('CI_DB_Cache')) + if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) { return TRUE; } - if ( ! class_exists('CI_DB_Cache') && ! @include(BASEPATH.'database/DB_cache.php')) + if ( ! class_exists('CI_DB_Cache')) { - return $this->cache_off(); + if ( ! @include(BASEPATH.'database/DB_cache.php')) + { + return $this->cache_off(); + } } $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects @@ -1132,9 +1183,10 @@ class CI_DB_driver { /** * Close DB Connection * + * @access public * @return void */ - public function close() + function close() { if (is_resource($this->conn_id) OR is_object($this->conn_id)) { @@ -1148,12 +1200,13 @@ class CI_DB_driver { /** * Display an error message * + * @access public * @param string the error message * @param string any "swap" values * @param boolean whether to localize the message * @return string sends the application/error_db.php template */ - public function display_error($error = '', $swap = '', $native = FALSE) + function display_error($error = '', $swap = '', $native = FALSE) { $LANG =& load_class('Lang', 'core'); $LANG->load('db'); @@ -1199,10 +1252,11 @@ class CI_DB_driver { * * This function adds backticks if appropriate based on db type * + * @access private * @param mixed the item to escape * @return mixed the item with backticks */ - public function protect_identifiers($item, $prefix_single = FALSE) + function protect_identifiers($item, $prefix_single = FALSE) { return $this->_protect_identifiers($item, $prefix_single); } @@ -1216,7 +1270,7 @@ class CI_DB_driver { * 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 - * column names that include the path. Consider a query like this: + * column names that include the path. Consider a query like this: * * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table * @@ -1229,14 +1283,14 @@ class CI_DB_driver { * insert the table prefix (if it exists) in the proper position, and escape only * the correct identifiers. * - * @access public (DB Forge needs it to be public!) + * @access private * @param string * @param bool * @param mixed * @param bool * @return string */ - public function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) + function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) { if ( ! is_bool($protect_identifiers)) { @@ -1284,7 +1338,7 @@ class CI_DB_driver { $parts = explode('.', $item); // Does the first segment of the exploded item match - // one of the aliases previously identified? If so, + // 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)) { @@ -1303,7 +1357,7 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix defined in the config file? If not, no need to do anything + // Is there a table prefix defined in the config file? If not, no need to do anything if ($this->dbprefix != '') { // We now add the table prefix based on some logic. @@ -1336,7 +1390,7 @@ class CI_DB_driver { // Verify table prefix and replace if necessary if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0) { - $parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]); + $parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]); } // We only add the table prefix if it does not already exist @@ -1357,23 +1411,23 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix? If not, no need to insert it + // Is there a table prefix? If not, no need to insert it if ($this->dbprefix != '') { // Verify table prefix and replace if necessary if ($this->swap_pre != '' && strncmp($item, $this->swap_pre, strlen($this->swap_pre)) === 0) { - $item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item); + $item = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $item); } // Do we prefix an item with no segments? - if ($prefix_single == TRUE && substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) + if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) { $item = $this->dbprefix.$item; } } - if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers)) + if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) { $item = $this->_escape_identifiers($item); } @@ -1384,5 +1438,6 @@ class CI_DB_driver { } + /* End of file DB_driver.php */ /* Location: ./system/database/DB_driver.php */ -- cgit v1.2.3-24-g4f1b From 574c85df35b68251c178510649b88b61eb84a43d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 12 Feb 2012 20:40:53 +0200 Subject: Improve custom_result_object() method --- system/database/drivers/oci8/oci8_result.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 7781b5bbd..ce6aa996f 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -306,7 +306,7 @@ class CI_DB_oci8_result extends CI_DB_result { */ public function custom_result_object($class_name) { - if (array_key_exists($class_name, $this->custom_result_object)) + if (isset($this->custom_result_object[$class_name])) { return $this->custom_result_object[$class_name]; } @@ -332,18 +332,17 @@ class CI_DB_oci8_result extends CI_DB_result { $data = &$this->result_object; } - $result_object = array(); + $this->custom_result_object[$class_name] = array(); for ($i = 0, $c = count($data); $i < $c; $i++) { - $result_object[$i] = new $class_name(); + $this->custom_result_object[$class_name][$i] = new $class_name(); foreach ($data[$i] as $key => $value) { - $result_object[$i]->$key = $value; + $this->custom_result_object[$class_name][$i]->$key = $value; } } - // Cache and return the array - return $this->custom_result_object[$class_name] = $result_object; + return $this->custom_result_object[$class_name]; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 74e5098bfb433b013bd4e3c95a23f5df43351469 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 12 Feb 2012 20:46:10 +0200 Subject: Replace a few spaces with a tab --- system/database/drivers/oci8/oci8_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index ce6aa996f..ff6f7a405 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -343,7 +343,7 @@ class CI_DB_oci8_result extends CI_DB_result { } return $this->custom_result_object[$class_name]; - } + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From dad61c273c1ce3553196883bf10633fcab868b17 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 13 Feb 2012 01:08:06 +0200 Subject: Add DSN string support --- system/database/drivers/oci8/oci8_driver.php | 87 +++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 700cde4b8..06acbbb67 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -78,6 +78,85 @@ class CI_DB_oci8_driver extends CI_DB { // throw off num_fields later public $limit_used; + public function __construct($params) + { + parent::__construct($params); + + $valid_dsns = array( + // Easy Connect string - Oracle 10g+ + 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^/])?(\/[a-z0-9$_]+)?$/i', + 'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS + '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 * @@ -85,7 +164,9 @@ class CI_DB_oci8_driver extends CI_DB { */ public function db_connect() { - return @oci_connect($this->username, $this->password, $this->hostname, $this->char_set); + return ( ! empty($this->char_set)) + ? @oci_connect($this->username, $this->password, $this->dsn, $this->char_set) + : @oci_connect($this->username, $this->password, $this->dsn); } // -------------------------------------------------------------------- @@ -97,7 +178,9 @@ class CI_DB_oci8_driver extends CI_DB { */ public function db_pconnect() { - return @oci_pconnect($this->username, $this->password, $this->hostname, $this->char_set); + return ( ! empty($this->char_set)) + ? @oci_pconnect($this->username, $this->password, $this->dsn, $this->char_set) + : @oci_pconnect($this->username, $this->password, $this->dsn); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 45ba4f73a13660fa05f30d2ec21965620b0e5be5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 13 Feb 2012 01:24:39 +0200 Subject: Fix a possible bug in DB() and renamed a variable --- system/database/DB.php | 23 +++++++++++++---------- system/database/DB_driver.php | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index d06ffb40e..8f9cb3743 100755 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -74,24 +74,24 @@ function &DB($params = '', $active_record_override = NULL) * parameter. DSNs must have this prototype: * $dsn = 'driver://username:password@hostname/database'; */ - if (($dns = @parse_url($params)) === FALSE) + if (($dsn = @parse_url($params)) === FALSE) { show_error('Invalid DB Connection String'); } $params = array( - 'dbdriver' => $dns['scheme'], - 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', - 'port' => (isset($dns['port'])) ? rawurldecode($dns['port']) : '', - 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '', - 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', - 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : '' + '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($dns['query'])) + if (isset($dsn['query'])) { - parse_str($dns['query'], $extra); + parse_str($dsn['query'], $extra); foreach ($extra as $key => $val) { // booleans please @@ -104,7 +104,10 @@ function &DB($params = '', $active_record_override = NULL) $val = FALSE; } - $params[$key] = $val; + if ( ! isset($params[$key])) + { + $params[$key] = $val; + } } } } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index c4aa0beaf..30149193a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -40,6 +40,7 @@ */ class CI_DB_driver { + public $dsn; public $username; public $password; public $hostname; -- cgit v1.2.3-24-g4f1b From fcd1f474a253cbe6e764a5c39cf5e58493670f60 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 13 Feb 2012 09:30:16 +0200 Subject: Fix Easy Connect string regexp and give TNS priority over it --- system/database/drivers/oci8/oci8_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 06acbbb67..3c70ccd9f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -83,9 +83,9 @@ class CI_DB_oci8_driver extends CI_DB { parent::__construct($params); $valid_dsns = array( - // Easy Connect string - Oracle 10g+ - 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^/])?(\/[a-z0-9$_]+)?$/i', '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) ); -- cgit v1.2.3-24-g4f1b From 8ad2ec7b0a8e6ea385b13ad2fd782fe775ef92db Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 13 Feb 2012 12:25:42 +0200 Subject: Fix issue #1036 --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 30149193a..a3171e395 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -627,7 +627,7 @@ class CI_DB_driver { */ public function is_write_type($sql) { - return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql); + return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 08c7c62b57b0d6d8f126e8629b8e8da71bd9636f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Feb 2012 13:23:38 +0200 Subject: Fix escape_like_str() --- system/database/drivers/oci8/oci8_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 3c70ccd9f..007e56a0b 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -477,8 +477,8 @@ class CI_DB_oci8_driver extends CI_DB { // escape LIKE condition wildcards if ($like === TRUE) { - return str_replace(array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + return str_replace(array($this->_like_escape_chr.$this->_like_escape_chr, '%', '_'), + array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), $str); } -- cgit v1.2.3-24-g4f1b From 927e950cb9e01d02415e13a8fb13eb95ce4a31c6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 19:50:26 +0200 Subject: Remove SQLite3 db_set_charset() - no longer needed --- system/database/drivers/sqlite3/sqlite3_driver.php | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index eb9a8f526..1f2d8f0a0 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -119,21 +119,6 @@ class CI_DB_sqlite3_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Set client character set - * - * @param string - * @param string - * @return bool - */ - public function db_set_charset($charset, $collation) - { - // Not (natively) supported - return TRUE; - } - - // -------------------------------------------------------------------- - /** * Version number query string * -- cgit v1.2.3-24-g4f1b From a92c7cdeddd9f1b46a6c8f254b2949ad047bbc21 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Mar 2012 13:51:22 +0200 Subject: Change SQLite3 _execute to use is_write_type() --- system/database/drivers/sqlite3/sqlite3_driver.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index 1f2d8f0a0..2af973875 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -139,14 +139,12 @@ class CI_DB_sqlite3_driver extends CI_DB { */ protected function _execute($sql) { - if ( ! preg_match('/^(SELECT|EXPLAIN).+$/i', ltrim($sql))) - { - return $this->conn_id->exec($sql); - } - // TODO: Implement use of SQLite3::querySingle(), if needed // TODO: Use $this->_prep_query(), if needed - return $this->conn_id->query($sql); + + return $this->is_write_type($sql) + ? $this->conn_id->exec($sql) + : $this->conn_id->query($sql); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5d93e13326b86344610cf13008726e40bef0a5b8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Mar 2012 20:36:21 +0200 Subject: Revert a comment change --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 1dc80a104..482a6c8f3 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -854,7 +854,7 @@ class CI_DB_driver { * Returns an object with field data * * @param string the table name - * @return mixed + * @return object */ public function field_data($table = '') { -- cgit v1.2.3-24-g4f1b From 0aa9f2e86124194cd64fde098ba7a4169625d353 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Mar 2012 14:55:20 +0200 Subject: _protect_identifiers() to protect_identifier() --- system/database/drivers/sqlite3/sqlite3_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index 0db366eb3..6affb8745 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -303,8 +303,8 @@ class CI_DB_sqlite3_driver extends CI_DB { return 0; } - $result = $this->conn_id->querySingle($this->_count_string.$this->_protect_identifiers('numrows') - .' FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE)); + $result = $this->conn_id->querySingle($this->_count_string.$this->protect_identifiers('numrows') + .' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE)); return empty($result) ? 0 : (int) $result; } -- cgit v1.2.3-24-g4f1b From 20bd7bc3f9e3c370954a0abead4f87043b99e040 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Mar 2012 09:26:40 +0200 Subject: Fix _limit() --- system/database/drivers/sqlite3/sqlite3_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index 6affb8745..ae0091cea 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -544,7 +544,7 @@ class CI_DB_sqlite3_driver extends CI_DB { */ protected function _limit($sql, $limit, $offset) { - return $sql.($offset ? $offset.',' : '').$limit; + return $sql.' LIMIT '.($offset ? $offset.',' : '').$limit; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From dc3de15b02eb768cf9e0a410b0d914523d019a67 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Mar 2012 15:41:49 +0200 Subject: Fix escape_str() and change _prep_query() to just return the query --- system/database/drivers/sqlite3/sqlite3_driver.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index ae0091cea..ed081102b 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -146,7 +146,6 @@ class CI_DB_sqlite3_driver extends CI_DB { protected function _execute($sql) { // TODO: Implement use of SQLite3::querySingle(), if needed - // TODO: Use $this->_prep_query(), if needed return $this->is_write_type($sql) ? $this->conn_id->exec($sql) @@ -165,7 +164,7 @@ class CI_DB_sqlite3_driver extends CI_DB { */ protected function _prep_query($sql) { - return $this->conn_id->prepare($sql); + return $sql; } // -------------------------------------------------------------------- @@ -253,8 +252,8 @@ class CI_DB_sqlite3_driver extends CI_DB { // escape LIKE condition wildcards if ($like === TRUE) { - return str_replace(array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + return str_replace(array($this->_like_escape_chr, '%', '_'), + array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), $str); } -- cgit v1.2.3-24-g4f1b From 1b5a85671bb28cdf87ef1c32c3d926a14a9409de Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 13 Mar 2012 13:13:43 +0200 Subject: Swtich _bind_params() from private to protected --- system/database/drivers/oci8/oci8_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 8e9ba9e5a..6842ec650 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -345,7 +345,7 @@ class CI_DB_oci8_driver extends CI_DB { * * @return void */ - private function _bind_params($params) + protected function _bind_params($params) { if ( ! is_array($params) OR ! is_resource($this->stmt_id)) { -- cgit v1.2.3-24-g4f1b From 5688d58688318cecaf9decdde014635f3a27760f Mon Sep 17 00:00:00 2001 From: Matteo Mattei Date: Tue, 13 Mar 2012 19:29:29 +0100 Subject: Add support for buffer string email attachment. --- system/libraries/Email.php | 58 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index f30fe40b6..aec4957de 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -83,6 +83,8 @@ class CI_Email { protected $_attach_name = array(); protected $_attach_type = array(); protected $_attach_disp = array(); + protected $_attach_source = array(); + protected $_attach_content = array(); protected $_protocols = array('mail', 'sendmail', 'smtp'); protected $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix) protected $_bit_depths = array('7bit', '8bit'); @@ -171,6 +173,8 @@ class CI_Email { $this->_attach_name = array(); $this->_attach_type = array(); $this->_attach_disp = array(); + $this->_attach_source = array(); + $this->_attach_content = array(); } return $this; @@ -411,6 +415,23 @@ class CI_Email { $this->_attach_name[] = array($filename, $newname); $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters + $this->_attach_source[] = 'file'; + return $this; + } + + /** + * Assign string attachments + * + * @param string + * @return object + */ + public function string_attach($str, $filename, $mime, $disposition = 'attachment') + { + $this->_attach_name[] = $filename; + $this->_attach_type[] = $mime; + $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters + $this->_attach_source[] = 'string'; + $this->_attach_content[] = $str; return $this; } @@ -1048,29 +1069,38 @@ class CI_Email { $filename = $this->_attach_name[$i][0]; $basename = (is_null($this->_attach_name[$i][1])) ? basename($filename) : $this->_attach_name[$i][1]; $ctype = $this->_attach_type[$i]; + $file_content = ''; - if ( ! file_exists($filename)) + if($this->_attach_source[$i] == 'file') { - $this->_set_error_message('lang:email_attachment_missing', $filename); - return FALSE; - } + if ( ! file_exists($filename)) + { + $this->_set_error_message('lang:email_attachment_missing', $filename); + return FALSE; + } + $file = filesize($filename) +1; + + if ( ! $fp = fopen($filename, FOPEN_READ)) + { + $this->_set_error_message('lang:email_attachment_unreadable', $filename); + return FALSE; + } + + $file_content = fread($fp, $file); + fclose($fp); + } + else + { + $file_content =& $this->_attach_content[$i]; + } $attachment[$z++] = "--".$this->_atc_boundary.$this->newline . "Content-type: ".$ctype."; " . "name=\"".$basename."\"".$this->newline . "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline . "Content-Transfer-Encoding: base64".$this->newline; - $file = filesize($filename) +1; - - if ( ! $fp = fopen($filename, FOPEN_READ)) - { - $this->_set_error_message('lang:email_attachment_unreadable', $filename); - return FALSE; - } - - $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file))); - fclose($fp); + $attachment[$z++] = chunk_split(base64_encode($file_content)); } $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; -- cgit v1.2.3-24-g4f1b From 5a98a3dda56f6167f8241a7bc7d1c8784d98ccf9 Mon Sep 17 00:00:00 2001 From: Matteo Mattei Date: Thu, 15 Mar 2012 12:00:44 +0100 Subject: Email class: move string_attach() to attach() and add documentation --- system/libraries/Email.php | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index aec4957de..df03eaaf6 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -83,7 +83,6 @@ class CI_Email { protected $_attach_name = array(); protected $_attach_type = array(); protected $_attach_disp = array(); - protected $_attach_source = array(); protected $_attach_content = array(); protected $_protocols = array('mail', 'sendmail', 'smtp'); protected $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix) @@ -173,7 +172,6 @@ class CI_Email { $this->_attach_name = array(); $this->_attach_type = array(); $this->_attach_disp = array(); - $this->_attach_source = array(); $this->_attach_content = array(); } @@ -410,27 +408,11 @@ class CI_Email { * @param string * @return object */ - public function attach($filename, $disposition = '', $newname = NULL) + public function attach($filename, $str = '', $mime = '', $disposition = '', $newname = NULL) { $this->_attach_name[] = array($filename, $newname); - $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); + $this->_attach_type[] = ($mime === '') ? $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)) : $mime; $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters - $this->_attach_source[] = 'file'; - return $this; - } - - /** - * Assign string attachments - * - * @param string - * @return object - */ - public function string_attach($str, $filename, $mime, $disposition = 'attachment') - { - $this->_attach_name[] = $filename; - $this->_attach_type[] = $mime; - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters - $this->_attach_source[] = 'string'; $this->_attach_content[] = $str; return $this; } @@ -1071,7 +1053,7 @@ class CI_Email { $ctype = $this->_attach_type[$i]; $file_content = ''; - if($this->_attach_source[$i] == 'file') + if ($this->_attach_content[$i] === '') { if ( ! file_exists($filename)) { -- cgit v1.2.3-24-g4f1b From df59c687a2243142e6da9d7b904523a1b91ca09b Mon Sep 17 00:00:00 2001 From: Matteo Mattei Date: Thu, 15 Mar 2012 16:03:58 +0100 Subject: Email class: adjust documentation and make the code backward compatible --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index df03eaaf6..7320ea566 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -408,10 +408,10 @@ class CI_Email { * @param string * @return object */ - public function attach($filename, $str = '', $mime = '', $disposition = '', $newname = NULL) + public function attach($filename, $disposition = '', $str = '', $mime = '', $newname = NULL) { $this->_attach_name[] = array($filename, $newname); - $this->_attach_type[] = ($mime === '') ? $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)) : $mime; + $this->_attach_type[] = ($mime == '') ? $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)) : $mime; $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters $this->_attach_content[] = $str; return $this; -- cgit v1.2.3-24-g4f1b From 65b568fcd444fbeaf6fa9130289c254e34e5bbbd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Mar 2012 15:33:15 +0200 Subject: Remove EOF newlines --- system/database/DB.php | 2 +- system/database/DB_driver.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index 8f9cb3743..e9d70ccc2 100755 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -161,4 +161,4 @@ function &DB($params = '', $active_record_override = NULL) } /* End of file DB.php */ -/* Location: ./system/database/DB.php */ +/* Location: ./system/database/DB.php */ \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 73f3e44d7..7fc569e9a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1327,4 +1327,4 @@ class CI_DB_driver { } /* End of file DB_driver.php */ -/* Location: ./system/database/DB_driver.php */ +/* Location: ./system/database/DB_driver.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 35bbb1ab4f7ee09d75fb407c6d9d9637b4404698 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Mar 2012 15:33:55 +0200 Subject: Remove EOF newlines --- system/database/DB.php | 2 +- system/database/DB_driver.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index be6ee9c2f..7c12e562b 100755 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -161,4 +161,4 @@ function &DB($params = '', $active_record_override = NULL) } /* End of file DB.php */ -/* Location: ./system/database/DB.php */ +/* Location: ./system/database/DB.php */ \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 162d3bbb2..1fce76cb5 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1327,4 +1327,4 @@ class CI_DB_driver { } /* End of file DB_driver.php */ -/* Location: ./system/database/DB_driver.php */ +/* Location: ./system/database/DB_driver.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f944d3b50ad589aeb78fe04ceef9ebfe4c3bd692 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Mar 2012 22:12:55 +0200 Subject: Remove unused _prep_query() method --- system/database/drivers/sqlite3/sqlite3_driver.php | 17 +---------------- system/database/drivers/sqlite3/sqlite3_forge.php | 2 +- system/database/drivers/sqlite3/sqlite3_result.php | 4 ++-- system/database/drivers/sqlite3/sqlite3_utility.php | 3 ++- 4 files changed, 6 insertions(+), 20 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index ed081102b..a3f5191b4 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -154,21 +154,6 @@ class CI_DB_sqlite3_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @param string an SQL query - * @return string - */ - protected function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - /** * Begin Transaction * @@ -561,4 +546,4 @@ class CI_DB_sqlite3_driver extends CI_DB { } /* End of file sqlite3_driver.php */ -/* Location: ./system/database/drivers/sqlite3/sqlite3_driver.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php index 68da7627e..254db21d8 100644 --- a/system/database/drivers/sqlite3/sqlite3_forge.php +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -220,4 +220,4 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { } /* End of file sqlite3_forge.php */ -/* Location: ./system/database/drivers/sqlite3/sqlite3_forge.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php index c88696328..ddf59dbd0 100644 --- a/system/database/drivers/sqlite3/sqlite3_result.php +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -607,7 +607,7 @@ class CI_DB_sqlite3_result extends CI_DB_result { * * @return array */ - public function _data_seek($n = 0) + protected function _data_seek($n = 0) { // Only resetting to the start of the result set is supported return $this->result_id->reset(); @@ -616,4 +616,4 @@ class CI_DB_sqlite3_result extends CI_DB_result { } /* End of file sqlite3_result.php */ -/* Location: ./system/database/drivers/sqlite3/sqlite3_result.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_result.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite3/sqlite3_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php index bc9898ee4..a4dc875e1 100644 --- a/system/database/drivers/sqlite3/sqlite3_utility.php +++ b/system/database/drivers/sqlite3/sqlite3_utility.php @@ -96,7 +96,8 @@ class CI_DB_sqlite3_utility extends CI_DB_utility { // Not supported return $this->db->display_error('db_unsuported_feature'); } + } /* End of file sqlite3_utility.php */ -/* Location: ./system/database/drivers/sqlite3/sqlite3_utility.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_utility.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0fd760e9765ea6785b4bd59d65365a079717ca6a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 23 Mar 2012 16:10:01 +0200 Subject: Remove no longer needed reconnect() method --- system/database/drivers/sqlite3/sqlite3_driver.php | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index a3f5191b4..39d1e2141 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -91,21 +91,6 @@ class CI_DB_sqlite3_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * 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() - { - // Not supported - } - - // -------------------------------------------------------------------- - /** * Select the database * -- cgit v1.2.3-24-g4f1b From c3b36f4c6b8e8b15c96d6653ebdf07c76eb57d9e Mon Sep 17 00:00:00 2001 From: Matteo Mattei Date: Mon, 26 Mar 2012 10:27:17 +0200 Subject: Centralize handling of attach() function for both real file and buffer string. Update documentation. --- system/libraries/Email.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 7320ea566..7429035f8 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -83,7 +83,6 @@ class CI_Email { protected $_attach_name = array(); protected $_attach_type = array(); protected $_attach_disp = array(); - protected $_attach_content = array(); protected $_protocols = array('mail', 'sendmail', 'smtp'); protected $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix) protected $_bit_depths = array('7bit', '8bit'); @@ -172,7 +171,6 @@ class CI_Email { $this->_attach_name = array(); $this->_attach_type = array(); $this->_attach_disp = array(); - $this->_attach_content = array(); } return $this; @@ -408,12 +406,11 @@ class CI_Email { * @param string * @return object */ - public function attach($filename, $disposition = '', $str = '', $mime = '', $newname = NULL) + public function attach($filename, $disposition = '', $newname = NULL, $mime = '') { $this->_attach_name[] = array($filename, $newname); - $this->_attach_type[] = ($mime == '') ? $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)) : $mime; $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters - $this->_attach_content[] = $str; + $this->_attach_type[] = $mime; return $this; } @@ -1053,7 +1050,7 @@ class CI_Email { $ctype = $this->_attach_type[$i]; $file_content = ''; - if ($this->_attach_content[$i] === '') + if ($this->_attach_type[$i] == '') { if ( ! file_exists($filename)) { @@ -1069,6 +1066,7 @@ class CI_Email { return FALSE; } + $ctype = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); $file_content = fread($fp, $file); fclose($fp); } -- cgit v1.2.3-24-g4f1b From 8f50b6b36cb743be8b70809279e501c20b8e38e2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 28 Mar 2012 14:12:09 +0300 Subject: Some minor style changes in the XMLRPC class --- system/libraries/Xmlrpc.php | 57 +++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) (limited to 'system') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 32e2e523b..b6e6c810d 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -136,10 +136,9 @@ class CI_Xmlrpc { $this->initialize($config); - log_message('debug', "XML-RPC Class Initialized"); + log_message('debug', 'XML-RPC Class Initialized'); } - //------------------------------------- // Initialize Prefs //------------------------------------- @@ -163,7 +162,7 @@ class CI_Xmlrpc { // Take URL and parse it //------------------------------------- - public function server($url, $port=80) + public function server($url, $port = 80) { if (strpos($url, 'http') !== 0) { @@ -172,9 +171,9 @@ class CI_Xmlrpc { $parts = parse_url($url); - $path = ( ! isset($parts['path'])) ? '/' : $parts['path']; + $path = isset($parts['path']) ? $parts['path'] : '/'; - if (isset($parts['query']) && $parts['query'] != '') + if ( ! empty($parts['query'])) { $path .= '?'.$parts['query']; } @@ -244,7 +243,7 @@ class CI_Xmlrpc { { if (is_array($value) && array_key_exists(0, $value)) { - if ( ! isset($value[1]) OR ( ! isset($this->xmlrpcTypes[$value[1]]))) + if ( ! isset($value[1], $this->xmlrpcTypes[$value[1]])) { $temp = new XML_RPC_Values($value[0], (is_array($value[0]) ? 'array' : 'string')); } @@ -337,7 +336,6 @@ class CI_Xmlrpc { } // END XML_RPC Class - /** * XML-RPC Client class * @@ -355,7 +353,7 @@ class XML_RPC_Client extends CI_Xmlrpc public $timeout = 5; public $no_multicall = FALSE; - public function __construct($path, $server, $port=80) + public function __construct($path, $server, $port = 80) { parent::__construct(); @@ -383,7 +381,7 @@ class XML_RPC_Client extends CI_Xmlrpc if ( ! is_resource($fp)) { error_log($this->xmlrpcstr['http_error']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); return $r; } @@ -394,12 +392,12 @@ class XML_RPC_Client extends CI_Xmlrpc } $r = "\r\n"; - $op = "POST {$this->path} HTTP/1.0$r" - . "Host: {$this->server}$r" - . "Content-Type: text/xml$r" - . "User-Agent: {$this->xmlrpcName}$r" - . "Content-Length: ".strlen($msg->payload)."$r$r" - . $msg->payload; + $op = 'POST '.$this->path.' HTTP/1.0'.$r + .'Host: '.$this->server.$r + .'Content-Type: text/xml'.$r + .'User-Agent: '.$this->xmlrpcName.$r + .'Content-Length: '.strlen($msg->payload).$r.$r + .$msg->payload; if ( ! fputs($fp, $op, strlen($op))) @@ -446,10 +444,10 @@ class XML_RPC_Response $this->errstr = htmlspecialchars($fstr, ENT_XML1 | ENT_NOQUOTES, 'UTF-8'); } } - else if ( ! is_object($val)) + elseif ( ! is_object($val)) { // programmer error, not an object - error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); + error_log("Invalid type '".gettype($val)."' (value: ".$val.') passed to XML_RPC_Response. Defaulting to empty value.'); $this->val = new XML_RPC_Values(); } else @@ -532,8 +530,6 @@ class XML_RPC_Response return $result; } - - //------------------------------------- // XML-RPC Object to PHP Types //------------------------------------- @@ -571,7 +567,6 @@ class XML_RPC_Response } } - //------------------------------------- // ISO-8601 time to server or UTC time //------------------------------------- @@ -605,7 +600,7 @@ class XML_RPC_Message extends CI_Xmlrpc public $params = array(); public $xh = array(); - public function __construct($method, $pars=0) + public function __construct($method, $pars = 0) { parent::__construct(); @@ -681,7 +676,7 @@ class XML_RPC_Message extends CI_Xmlrpc if (strncmp($data, 'HTTP', 4) === 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) { $errstr= substr($data, 0, strpos($data, "\n")-1); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')'); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error'].' (' . $errstr . ')'); return $r; } @@ -706,7 +701,6 @@ class XML_RPC_Message extends CI_Xmlrpc xml_set_character_data_handler($parser, 'character_data'); //xml_set_default_handler($parser, 'default_handler'); - //------------------------------------- // GET HEADERS //------------------------------------- @@ -765,14 +759,14 @@ class XML_RPC_Message extends CI_Xmlrpc if ($this->debug === TRUE) { - echo "
";
+			echo '
';
 
 			if (count($this->xh[$parser]['headers'] > 0))
 			{
 				echo "---HEADERS---\n";
 				foreach ($this->xh[$parser]['headers'] as $header)
 				{
-					echo "$header\n";
+					echo $header."\n";
 				}
 				echo "---END HEADERS---\n\n";
 			}
@@ -850,7 +844,7 @@ class XML_RPC_Message extends CI_Xmlrpc
 			if ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE))
 			{
 				$this->xh[$the_parser]['isf'] = 2;
-				$this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0];
+				$this->xh[$the_parser]['isf_reason'] = 'XML-RPC element $name cannot be child of '.$this->xh[$the_parser]['stack'][0];
 				return;
 			}
 		}
@@ -861,8 +855,7 @@ class XML_RPC_Message extends CI_Xmlrpc
 			case 'ARRAY':
 				// Creates array for child elements
 
-				$cur_val = array('value' => array(),
-								 'type'	 => $name);
+				$cur_val = array('value' => array(), 'type' => $name);
 
 				array_unshift($this->xh[$the_parser]['valuestack'], $cur_val);
 			break;
@@ -925,7 +918,6 @@ class XML_RPC_Message extends CI_Xmlrpc
 	}
 	// END
 
-
 	//-------------------------------------
 	//  End Element Handler
 	//-------------------------------------
@@ -996,7 +988,7 @@ class XML_RPC_Message extends CI_Xmlrpc
 					}
 					else
 					{
-						$this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac'];
+						$this->xh[$the_parser]['value'] = (float) $this->xh[$the_parser]['ac'];
 					}
 				}
 				else
@@ -1145,7 +1137,6 @@ class XML_RPC_Message extends CI_Xmlrpc
 		return $parameters;
 	}
 
-
 	public function decode_message($param)
 	{
 		$kind = $param->kindOf();
@@ -1237,7 +1228,7 @@ class XML_RPC_Values extends CI_Xmlrpc
 
 		if ($type == $this->xmlrpcBoolean)
 		{
-			$val = (strcasecmp($val,'true') === 0 OR $val == 1 OR ($val == true && strcasecmp($val, 'false'))) ? 1 : 0;
+			$val = (strcasecmp($val,'true') === 0 OR $val == 1 OR ($val == TRUE && strcasecmp($val, 'false'))) ? 1 : 0;
 		}
 
 		if ($this->mytype == 2)
@@ -1383,4 +1374,4 @@ class XML_RPC_Values extends CI_Xmlrpc
 // END XML_RPC_Values Class
 
 /* End of file Xmlrpc.php */
-/* Location: ./system/libraries/Xmlrpc.php */
+/* Location: ./system/libraries/Xmlrpc.php */
\ No newline at end of file
-- 
cgit v1.2.3-24-g4f1b


From 6202a3c822a7b68040de2c5e0528bc1ec1c50758 Mon Sep 17 00:00:00 2001
From: Andrey Andreev 
Date: Wed, 28 Mar 2012 14:46:24 +0300
Subject: Some more unneeded brackets removed

---
 system/database/DB_driver.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'system')

diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index f0b8e7789..553f70c45 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -291,7 +291,7 @@ abstract class CI_DB_driver {
 		}
 
 		// Verify table prefix and replace if necessary
-		if ( ($this->dbprefix != '' && $this->swap_pre != '') && ($this->dbprefix != $this->swap_pre) )
+		if ($this->dbprefix != '' && $this->swap_pre != '' && $this->dbprefix != $this->swap_pre)
 		{
 			$sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql);
 		}
-- 
cgit v1.2.3-24-g4f1b


From 6781a5f64dc0c75110f3100eb281276f00fe9dbf Mon Sep 17 00:00:00 2001
From: Andrey Andreev 
Date: Wed, 28 Mar 2012 14:50:51 +0300
Subject: A replace array_key_exists() with isset()

---
 system/database/DB_driver.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'system')

diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 553f70c45..d3359e13e 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -755,11 +755,11 @@ abstract class CI_DB_driver {
 			// Do we know from which column to get the table name?
 			if ( ! isset($key))
 			{
-				if (array_key_exists('table_name', $row))
+				if (isset($row['table_name']))
 				{
 					$key = 'table_name';
 				}
-				elseif (array_key_exists('TABLE_NAME', $row))
+				elseif (isset($row['TABLE_NAME']))
 				{
 					$key = 'TABLE_NAME';
 				}
@@ -827,11 +827,11 @@ abstract class CI_DB_driver {
 			// Do we know from where to get the column's name?
 			if ( ! isset($key))
 			{
-				if (array_key_exists('column_name', $row))
+				if (isset($row['column_name']))
 				{
 					$key = 'column_name';
 				}
-				elseif (array_key_exists('COLUMN_NAME', $row))
+				elseif (isset($row['COLUMN_NAME']))
 				{
 					$key = 'COLUMN_NAME';
 				}
-- 
cgit v1.2.3-24-g4f1b


From bee6644ce280d8e72cc2db23c86d5f5f6973acf3 Mon Sep 17 00:00:00 2001
From: Andrey Andreev 
Date: Wed, 28 Mar 2012 15:28:19 +0300
Subject: Add a dummy db_select() method to CI_DB_driver and remove it from
 drivers that don't have such functionality

---
 system/database/DB_driver.php                          | 16 +++++++++++++++-
 system/database/drivers/cubrid/cubrid_driver.php       | 16 ----------------
 system/database/drivers/interbase/interbase_driver.php | 13 -------------
 system/database/drivers/oci8/oci8_driver.php           | 13 -------------
 system/database/drivers/odbc/odbc_driver.php           | 13 -------------
 system/database/drivers/pdo/pdo_driver.php             | 13 -------------
 system/database/drivers/postgre/postgre_driver.php     | 13 -------------
 system/database/drivers/sqlite/sqlite_driver.php       | 12 ------------
 8 files changed, 15 insertions(+), 94 deletions(-)

(limited to 'system')

diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index d3359e13e..594fcced9 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -191,11 +191,25 @@ abstract class CI_DB_driver {
 
 	// --------------------------------------------------------------------
 
+	/**
+	 * Select database
+	 *
+	 * This is just a dummy method to allow drivers without such
+	 * functionality to not declare it, while others will override it.
+	 *
+	 * @return      bool
+	 */
+	public function db_select()
+	{
+		return TRUE;
+	}
+
+	// --------------------------------------------------------------------
+
 	/**
 	 * Set client character set
 	 *
 	 * @param	string
-	 * @param	string
 	 * @return	bool
 	 */
 	public function db_set_charset($charset)
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index bed3d8685..0f9c427e6 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -158,22 +158,6 @@ class CI_DB_cubrid_driver extends CI_DB {
 
 	// --------------------------------------------------------------------
 
-	/**
-	 * Select the database
-	 *
-	 * @return	resource
-	 */
-	public function db_select()
-	{
-		// In CUBRID there is no need to select a database as the database
-		// is chosen at the connection time.
-		// So, to determine if the database is "selected", all we have to
-		// do is ping the server and return that value.
-		return cubrid_ping($this->conn_id);
-	}
-
-	// --------------------------------------------------------------------
-
 	/**
 	 * Database version number
 	 *
diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php
index d8b6ae571..6d3346292 100644
--- a/system/database/drivers/interbase/interbase_driver.php
+++ b/system/database/drivers/interbase/interbase_driver.php
@@ -84,19 +84,6 @@ class CI_DB_interbase_driver extends CI_DB {
 
 	// --------------------------------------------------------------------
 
-	/**
-	 * Select the database
-	 *
-	 * @return	bool
-	 */
-	public function db_select()
-	{
-		// Connection selects the database
-		return TRUE;
-	}
-
-	// --------------------------------------------------------------------
-
 	/**
 	 * Database version number
 	 *
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 3bc8c114c..45b0198eb 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -185,19 +185,6 @@ class CI_DB_oci8_driver extends CI_DB {
 
 	// --------------------------------------------------------------------
 
-	/**
-	 * Select the database
-	 *
-	 * @return	resource
-	 */
-	public function db_select()
-	{
-		// Not in Oracle - schemas are actually usernames
-		return TRUE;
-	}
-
-	// --------------------------------------------------------------------
-
 	/**
 	 * Database version number
 	 *
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index ad773117f..ed901bd81 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -94,19 +94,6 @@ class CI_DB_odbc_driver extends CI_DB {
 
 	// --------------------------------------------------------------------
 
-	/**
-	 * Select the database
-	 *
-	 * @return	resource
-	 */
-	public function db_select()
-	{
-		// Not needed for ODBC
-		return TRUE;
-	}
-
-	// --------------------------------------------------------------------
-
 	/**
 	 * Execute the query
 	 *
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index f336eb0ab..a9bed367e 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -246,19 +246,6 @@ class CI_DB_pdo_driver extends CI_DB {
 
 	// --------------------------------------------------------------------
 
-	/**
-	 * Select the database
-	 *
-	 * @return	resource
-	 */
-	public function db_select()
-	{
-		// Not needed for PDO
-		return TRUE;
-	}
-
-	// --------------------------------------------------------------------
-
 	/**
 	 * Database version number
 	 *
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 3e2d05ce8..a033d74f3 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -161,19 +161,6 @@ class CI_DB_postgre_driver extends CI_DB {
 
 	// --------------------------------------------------------------------
 
-	/**
-	 * Select the database
-	 *
-	 * @return	resource
-	 */
-	public function db_select()
-	{
-		// Not needed for Postgre so we'll return TRUE
-		return TRUE;
-	}
-
-	// --------------------------------------------------------------------
-
 	/**
 	 * Set client character set
 	 *
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index 102c79bb3..ef543c9b5 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -105,18 +105,6 @@ class CI_DB_sqlite_driver extends CI_DB {
 
 	// --------------------------------------------------------------------
 
-	/**
-	 * Select the database
-	 *
-	 * @return	resource
-	 */
-	public function db_select()
-	{
-		return TRUE;
-	}
-
-	// --------------------------------------------------------------------
-
 	/**
 	 * Database version number
 	 *
-- 
cgit v1.2.3-24-g4f1b


From da44bacbad76b9a898accdd533b48c04c6b0b12f Mon Sep 17 00:00:00 2001
From: Andrey Andreev 
Date: Wed, 28 Mar 2012 15:45:18 +0300
Subject: Revert CI_DB_driver::_reset_select() to a regular method instead of
 abstract.abstract methods are required to be implemented by their child
 classes and this is not what's intended in our case.

---
 system/database/DB_driver.php | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

(limited to 'system')

diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 594fcced9..45f17e8ec 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1351,7 +1351,9 @@ abstract class CI_DB_driver {
 	 *
 	 * @return	void
 	 */
-	abstract protected function _reset_select();
+	protected function _reset_select()
+	{
+	}
 
 }
 
-- 
cgit v1.2.3-24-g4f1b


From a8a2e3325c128ccdc941daba3bba10b78bf2d098 Mon Sep 17 00:00:00 2001
From: Taufan Aditya 
Date: Thu, 29 Mar 2012 03:56:46 +0700
Subject: Travis setup and minor cleanup

---
 system/database/DB.php | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'system')

diff --git a/system/database/DB.php b/system/database/DB.php
index 96e495515..e9434231c 100755
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -138,7 +138,12 @@ function &DB($params = '', $active_record_override = NULL)
 		class CI_DB extends CI_DB_driver { }
 	}
 
-	require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php');
+	// Load the DB driver
+	$driver_file = BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php';
+
+	if ( ! file_exists($driver_file)) show_error('Invalid DB driver');
+
+	require_once($driver_file);
 
 	// Instantiate the DB adapter
 	$driver = 'CI_DB_'.$params['dbdriver'].'_driver';
-- 
cgit v1.2.3-24-g4f1b


From 22b9e5f5a2a95b5ab0e77423c8807318b8c4b030 Mon Sep 17 00:00:00 2001
From: Andrey Andreev 
Date: Thu, 29 Mar 2012 11:30:33 +0300
Subject: Minor improvements to PostgreSQL and SQLite result classes

---
 system/database/drivers/postgre/postgre_result.php | 18 ++++-----
 system/database/drivers/sqlite/sqlite_result.php   | 46 ++++++----------------
 2 files changed, 20 insertions(+), 44 deletions(-)

(limited to 'system')

diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php
index 8b22564b3..394b8b6fd 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -70,7 +70,7 @@ class CI_DB_postgre_result extends CI_DB_result {
 	public function list_fields()
 	{
 		$field_names = array();
-		for ($i = 0; $i < $this->num_fields(); $i++)
+		for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
 		{
 			$field_names[] = pg_field_name($this->result_id, $i);
 		}
@@ -90,16 +90,14 @@ class CI_DB_postgre_result extends CI_DB_result {
 	public function field_data()
 	{
 		$retval = array();
-		for ($i = 0; $i < $this->num_fields(); $i++)
+		for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
 		{
-			$F				= new stdClass();
-			$F->name		= pg_field_name($this->result_id, $i);
-			$F->type		= pg_field_type($this->result_id, $i);
-			$F->max_length	= pg_field_size($this->result_id, $i);
-			$F->primary_key = 0;
-			$F->default		= '';
-
-			$retval[] = $F;
+			$retval[$i]			= new stdClass();
+			$retval[$i]->name		= pg_field_name($this->result_id, $i);
+			$retval[$i]->type		= pg_field_type($this->result_id, $i);
+			$retval[$i]->max_length		= pg_field_size($this->result_id, $i);
+			$retval[$i]->primary_key	= 0;
+			$retval[$i]->default		= '';
 		}
 
 		return $retval;
diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php
index b002aeff1..4af80abf7 100644
--- a/system/database/drivers/sqlite/sqlite_result.php
+++ b/system/database/drivers/sqlite/sqlite_result.php
@@ -70,9 +70,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
 	public function list_fields()
 	{
 		$field_names = array();
-		for ($i = 0; $i < $this->num_fields(); $i++)
+		for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
 		{
-			$field_names[] = sqlite_field_name($this->result_id, $i);
+			$field_names[$i] = sqlite_field_name($this->result_id, $i);
 		}
 
 		return $field_names;
@@ -90,16 +90,14 @@ class CI_DB_sqlite_result extends CI_DB_result {
 	public function field_data()
 	{
 		$retval = array();
-		for ($i = 0; $i < $this->num_fields(); $i++)
+		for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
 		{
-			$F				= new stdClass();
-			$F->name		= sqlite_field_name($this->result_id, $i);
-			$F->type		= 'varchar';
-			$F->max_length	= 0;
-			$F->primary_key = 0;
-			$F->default		= '';
-
-			$retval[] = $F;
+			$retval[$i]			= new stdClass();
+			$retval[$i]->name		= sqlite_field_name($this->result_id, $i);
+			$retval[$i]->type		= 'varchar';
+			$retval[$i]->max_length		= 0;
+			$retval[$i]->primary_key	= 0;
+			$retval[$i]->default		= '';
 		}
 
 		return $retval;
@@ -107,18 +105,6 @@ class CI_DB_sqlite_result extends CI_DB_result {
 
 	// --------------------------------------------------------------------
 
-	/**
-	 * Free the result
-	 *
-	 * @return	void
-	 */
-	public function free_result()
-	{
-		// Not implemented in SQLite
-	}
-
-	// --------------------------------------------------------------------
-
 	/**
 	 * Data Seek
 	 *
@@ -162,17 +148,9 @@ class CI_DB_sqlite_result extends CI_DB_result {
 		{
 			return sqlite_fetch_object($this->result_id);
 		}
-		else
-		{
-			$arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC);
-			if (is_array($arr))
-			{
-				$obj = (object) $arr;
-				return $obj;
-			} else {
-				return NULL;
-			}
-		}
+
+		$arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC);
+		return is_array($arr) ? (object) $arr : FALSE;
 	}
 
 }
-- 
cgit v1.2.3-24-g4f1b


From 38b2a256758ee8184d354cbdb0eac467118af36b Mon Sep 17 00:00:00 2001
From: Andrey Andreev 
Date: Thu, 29 Mar 2012 11:35:32 +0300
Subject: Changed the dummy DB free_result() method to void (that's how it's
 implemented by all drivers) and some style/comment changes in DB_result

---
 system/database/DB_result.php | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

(limited to 'system')

diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index 04f964fb1..bb09c014c 100644
--- a/system/database/DB_result.php
+++ b/system/database/DB_result.php
@@ -57,7 +57,7 @@ class CI_DB_result {
 	 * Query result.  Acts as a wrapper function for the following functions.
 	 *
 	 * @param	string	can be "object" or "array"
-	 * @return	mixed	either a result object or array
+	 * @return	object
 	 */
 	public function result($type = 'object')
 	{
@@ -108,9 +108,9 @@ class CI_DB_result {
 	// --------------------------------------------------------------------
 
 	/**
-	 * Query result.  "object" version.
+	 * Query result. "object" version.
 	 *
-	 * @return	object
+	 * @return	array
 	 */
 	public function result_object()
 	{
@@ -224,7 +224,7 @@ class CI_DB_result {
 			return;
 		}
 
-		if ($key != '' AND ! is_null($value))
+		if ($key != '' && ! is_null($value))
 		{
 			$this->row_data[$key] = $value;
 		}
@@ -245,7 +245,7 @@ class CI_DB_result {
 			return $result;
 		}
 
-		if ($n != $this->current_row AND isset($result[$n]))
+		if ($n != $this->current_row && isset($result[$n]))
 		{
 			$this->current_row = $n;
 		}
@@ -266,7 +266,7 @@ class CI_DB_result {
 			return $result;
 		}
 
-		if ($n != $this->current_row AND isset($result[$n]))
+		if ($n != $this->current_row && isset($result[$n]))
 		{
 			$this->current_row = $n;
 		}
@@ -289,7 +289,7 @@ class CI_DB_result {
 			return $result;
 		}
 
-		if ($n != $this->current_row AND isset($result[$n]))
+		if ($n != $this->current_row && isset($result[$n]))
 		{
 			$this->current_row = $n;
 		}
@@ -297,7 +297,6 @@ class CI_DB_result {
 		return $result[$this->current_row];
 	}
 
-
 	// --------------------------------------------------------------------
 
 	/**
@@ -374,9 +373,9 @@ class CI_DB_result {
 	/**
 	 * The following functions 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.
+	 * 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
+	 * 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.
 	 */
@@ -384,7 +383,7 @@ class CI_DB_result {
 	public function num_fields() { return 0; }
 	public function list_fields() { return array(); }
 	public function field_data() { return array(); }
-	public function free_result() { return TRUE; }
+	public function free_result() { $this->result_id = FALSE; }
 	protected function _data_seek() { return TRUE; }
 	protected function _fetch_assoc() { return array(); }
 	protected function _fetch_object() { return array(); }
-- 
cgit v1.2.3-24-g4f1b


From f1bbb17cd8c12680a3f95b1dbdc8979246796684 Mon Sep 17 00:00:00 2001
From: Ryan Neufeld 
Date: Thu, 29 Mar 2012 08:24:01 -0700
Subject: Fix for Issue 88. _default_options does not exist in the
 Cache_memcahe driver

---
 system/libraries/Cache/drivers/Cache_memcached.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'system')

diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index 1028c8fd5..4cd5f3d6f 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.php
@@ -189,17 +189,17 @@ class CI_Cache_memcached extends CI_Driver {
 		{
 			if ( ! array_key_exists('hostname', $cache_server))
 			{
-				$cache_server['hostname'] = $this->_default_options['default_host'];
+				$cache_server['hostname'] = $this->_memcache_conf['default']['default_host'];
 			}
 
 			if ( ! array_key_exists('port', $cache_server))
 			{
-				$cache_server['port'] = $this->_default_options['default_port'];
+				$cache_server['port'] = $this->_memcache_conf['default']['default_port'];
 			}
 
 			if ( ! array_key_exists('weight', $cache_server))
 			{
-				$cache_server['weight'] = $this->_default_options['default_weight'];
+				$cache_server['weight'] = $this->_memcache_conf['default']['default_weight'];
 			}
 
 			if (get_class($this->_memcached) == 'Memcache')
-- 
cgit v1.2.3-24-g4f1b


From ee2f5d08c64d96b7abc7195bcd1b6a3fd67b5b42 Mon Sep 17 00:00:00 2001
From: Taufan Aditya 
Date: Fri, 30 Mar 2012 06:29:11 +0700
Subject: Multi database setup

---
 system/database/DB.php | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

(limited to 'system')

diff --git a/system/database/DB.php b/system/database/DB.php
index e9434231c..0d81e40d3 100755
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -92,16 +92,12 @@ function &DB($params = '', $active_record_override = NULL)
 		if (isset($dsn['query']))
 		{
 			parse_str($dsn['query'], $extra);
+
 			foreach ($extra as $key => $val)
 			{
-				// booleans please
-				if (strtoupper($val) === 'TRUE')
-				{
-					$val = TRUE;
-				}
-				elseif (strtoupper($val) === 'FALSE')
+				if (is_string($val) && in_array(strtoupper($val), array('TRUE', 'FALSE', 'NULL')))
 				{
-					$val = FALSE;
+					$val = var_export($val);
 				}
 
 				$params[$key] = $val;
-- 
cgit v1.2.3-24-g4f1b


From 52fe7bb68f9961cdd765dd38e54779ae3b66e586 Mon Sep 17 00:00:00 2001
From: Songpol Sripaoeiam 
Date: Sun, 1 Apr 2012 11:43:20 +0700
Subject: add function get_current_content_type to output class and user manual
 library

---
 system/core/Output.php | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

(limited to 'system')

diff --git a/system/core/Output.php b/system/core/Output.php
index 9bf818e88..673ceb0ee 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -220,6 +220,24 @@ class CI_Output {
 		$this->headers[] = array($header, TRUE);
 		return $this;
 	}
+	
+	// --------------------------------------------------------------------
+	
+	/**
+	 * Get Current Content Type Header
+	 * Return text/html if Content-Type is not set
+	 *
+	 * @return	string
+	 */
+	public function get_current_content_type()
+	{
+			foreach($this->headers as $header){
+				if(preg_match('/^Content-Type/', $header[0])){
+					return str_replace('Content-Type: ', '', $header[0]);
+				}
+			}
+			return 'text/html';
+	}
 
 	// --------------------------------------------------------------------
 
-- 
cgit v1.2.3-24-g4f1b


From b966701fad01c094199a89f7e4df72d981e5cf48 Mon Sep 17 00:00:00 2001
From: Songpol Sripaoeiam 
Date: Sun, 1 Apr 2012 17:13:44 +0700
Subject: bracket on a new line

Also add space after foreach

bracket on a new line... Also add a space after if

Follow up from https://github.com/EllisLab/CodeIgniter/pull/1234/files#r630522
---
 system/core/Output.php | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

(limited to 'system')

diff --git a/system/core/Output.php b/system/core/Output.php
index 673ceb0ee..c0de24bb9 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -231,12 +231,13 @@ class CI_Output {
 	 */
 	public function get_current_content_type()
 	{
-			foreach($this->headers as $header){
-				if(preg_match('/^Content-Type/', $header[0])){
-					return str_replace('Content-Type: ', '', $header[0]);
-				}
+		foreach ($this->headers as $header){
+			if (preg_match('/^Content-Type/', $header[0]))
+			{
+				return str_replace('Content-Type: ', '', $header[0]);
 			}
-			return 'text/html';
+		}
+		return 'text/html';
 	}
 
 	// --------------------------------------------------------------------
-- 
cgit v1.2.3-24-g4f1b


From 38c0a72169ffbf002c7f3c7fd3b4fd41f0d75f09 Mon Sep 17 00:00:00 2001
From: Songpol Sripao-eiam 
Date: Sun, 1 Apr 2012 20:10:35 +0700
Subject: Fix style coding

---
 system/core/Output.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'system')

diff --git a/system/core/Output.php b/system/core/Output.php
index c0de24bb9..ea39b0223 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -231,7 +231,8 @@ class CI_Output {
 	 */
 	public function get_current_content_type()
 	{
-		foreach ($this->headers as $header){
+		foreach ($this->headers as $header)
+		{
 			if (preg_match('/^Content-Type/', $header[0]))
 			{
 				return str_replace('Content-Type: ', '', $header[0]);
-- 
cgit v1.2.3-24-g4f1b


From 614db07c77e341bfe4bf92d7576f01a6cabd43ff Mon Sep 17 00:00:00 2001
From: Songpol Sripaoeiam 
Date: Tue, 3 Apr 2012 01:29:28 +0700
Subject: The current name is too wide change to get_content_type()consistent
 with set_content_type()

---
 system/core/Output.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'system')

diff --git a/system/core/Output.php b/system/core/Output.php
index ea39b0223..09d74f0c0 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -229,7 +229,7 @@ class CI_Output {
 	 *
 	 * @return	string
 	 */
-	public function get_current_content_type()
+	public function get_content_type()
 	{
 		foreach ($this->headers as $header)
 		{
-- 
cgit v1.2.3-24-g4f1b


From 00adf1d480f94692a625ec2165e0fcc9171c6e2f Mon Sep 17 00:00:00 2001
From: Andrey Andreev 
Date: Tue, 3 Apr 2012 12:30:50 +0300
Subject: Some improvements to the additions from pull #1234

---
 system/core/Output.php | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

(limited to 'system')

diff --git a/system/core/Output.php b/system/core/Output.php
index 09d74f0c0..01fd1d867 100755
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -220,24 +220,24 @@ class CI_Output {
 		$this->headers[] = array($header, TRUE);
 		return $this;
 	}
-	
+
 	// --------------------------------------------------------------------
-	
+
 	/**
 	 * Get Current Content Type Header
-	 * Return text/html if Content-Type is not set
 	 *
-	 * @return	string
+	 * @return	string	'text/html', if not already set
 	 */
 	public function get_content_type()
 	{
-		foreach ($this->headers as $header)
+		for ($i = 0, $c = count($this->headers); $i < $c; $i++)
 		{
-			if (preg_match('/^Content-Type/', $header[0]))
+			if (preg_match('/^Content-Type:\s(.+)$/', $this->headers[$i][0], $matches))
 			{
-				return str_replace('Content-Type: ', '', $header[0]);
+				return $matches[1];
 			}
 		}
+
 		return 'text/html';
 	}
 
-- 
cgit v1.2.3-24-g4f1b


From d6057485408fab0caaca75ef78434d8077eaadd9 Mon Sep 17 00:00:00 2001
From: Andrey Andreev 
Date: Tue, 3 Apr 2012 14:07:31 +0300
Subject: Fix issue #14

---
 system/database/drivers/mysql/mysql_forge.php   | 2 +-
 system/database/drivers/mysqli/mysqli_forge.php | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

(limited to 'system')

diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index 11172b41b..9e19de1bb 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -42,7 +42,7 @@ class CI_DB_mysql_forge extends CI_DB_forge {
 	 */
 	public function _create_database($name)
 	{
-		return 'CREATE DATABASE '.$name;
+		return 'CREATE DATABASE '.$name.' CHARACTER SET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat;
 	}
 
 	// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php
index 8cf0ae1fd..a1caf5cfb 100644
--- a/system/database/drivers/mysqli/mysqli_forge.php
+++ b/system/database/drivers/mysqli/mysqli_forge.php
@@ -42,7 +42,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge {
 	 */
 	public function _create_database($name)
 	{
-		return 'CREATE DATABASE '.$name;
+		return 'CREATE DATABASE '.$name.' CHARACTER SET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat;
 	}
 
 	// --------------------------------------------------------------------
-- 
cgit v1.2.3-24-g4f1b


From 443bbd96382552e8a7aea0f9dc7f1c90efc9b4e8 Mon Sep 17 00:00:00 2001
From: Andrey Andreev 
Date: Tue, 3 Apr 2012 15:49:11 +0300
Subject: Minor cleanup and style fixes in the Log and Javascript libraries

---
 system/libraries/Javascript.php | 41 +++++++++++++++--------------------------
 system/libraries/Log.php        | 17 ++++++-----------
 2 files changed, 21 insertions(+), 37 deletions(-)

(limited to 'system')

diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php
index 9ba93000b..baa044117 100644
--- a/system/libraries/Javascript.php
+++ b/system/libraries/Javascript.php
@@ -25,8 +25,6 @@
  * @filesource
  */
 
-// ------------------------------------------------------------------------
-
 /**
  * Javascript Class
  *
@@ -46,7 +44,7 @@ class CI_Javascript {
 
 		foreach ($defaults as $key => $val)
 		{
-			if (isset($params[$key]) && $params[$key] !== "")
+			if (isset($params[$key]) && $params[$key] !== '')
 			{
 				$defaults[$key] = $params[$key];
 			}
@@ -61,7 +59,7 @@ class CI_Javascript {
 		// make js to refer to current library
 		$this->js =& $this->CI->$js_library_driver;
 
-		log_message('debug', "Javascript Class Initialized and loaded.  Driver used: $js_library_driver");
+		log_message('debug', 'Javascript Class Initialized and loaded. Driver used: '.$js_library_driver);
 	}
 
 	// --------------------------------------------------------------------
@@ -375,7 +373,6 @@ class CI_Javascript {
 	// Effects
 	// --------------------------------------------------------------------
 
-
 	/**
 	 * Add Class
 	 *
@@ -618,12 +615,9 @@ class CI_Javascript {
 		{
 			$this->_javascript_location = $external_file;
 		}
-		else
+		elseif ($this->CI->config->item('javascript_location') != '')
 		{
-			if ($this->CI->config->item('javascript_location') != '')
-			{
-				$this->_javascript_location = $this->CI->config->item('javascript_location');
-			}
+			$this->_javascript_location = $this->CI->config->item('javascript_location');
 		}
 
 		if ($relative === TRUE OR strncmp($external_file, 'http://', 7) === 0 OR strncmp($external_file, 'https://', 8) === 0)
@@ -656,7 +650,7 @@ class CI_Javascript {
 	public function inline($script, $cdata = TRUE)
 	{
 		return $this->_open_script()
-			. ($cdata ? "\n// \n" : "\n{$script}\n")
+			. ($cdata ? "\n// \n" : "\n".$script."\n")
 			. $this->_close_script();
 	}
 
@@ -673,7 +667,7 @@ class CI_Javascript {
 	protected function _open_script($src = '')
 	{
 		return '$extra";
+		return ''.$extra;
 	}
 
-
-	// --------------------------------------------------------------------
 	// --------------------------------------------------------------------
 	// AJAX-Y STUFF - still a testbed
 	// --------------------------------------------------------------------
-	// --------------------------------------------------------------------
 
 	/**
 	 * Update
@@ -751,9 +742,9 @@ class CI_Javascript {
 		$json = array();
 		$_is_assoc = TRUE;
 
-		if ( ! is_array($json_result) AND empty($json_result))
+		if ( ! is_array($json_result) && empty($json_result))
 		{
-			show_error("Generate JSON Failed - Illegal key, value pair.");
+			show_error('Generate JSON Failed - Illegal key, value pair.');
 		}
 		elseif ($match_array_type)
 		{
@@ -774,7 +765,7 @@ class CI_Javascript {
 
 		$json = implode(',', $json);
 
-		return $_is_assoc ? "{".$json."}" : "[".$json."]";
+		return $_is_assoc ? '{'.$json.'}' : '['.$json.']';
 
 	}
 
@@ -785,8 +776,8 @@ class CI_Javascript {
 	 *
 	 * Checks for an associative array
 	 *
-	 * @param	type
-	 * @return	type
+	 * @param	array
+	 * @return	bool
 	 */
 	protected function _is_associative_array($arr)
 	{
@@ -808,8 +799,8 @@ class CI_Javascript {
 	 *
 	 * Ensures a standard json value and escapes values
 	 *
-	 * @param	type
-	 * @return	type
+	 * @param	mixed
+	 * @return	string
 	 */
 	protected function _prep_args($result, $is_key = FALSE)
 	{
@@ -831,9 +822,7 @@ class CI_Javascript {
 		}
 	}
 
-	// --------------------------------------------------------------------
 }
-// END Javascript Class
 
 /* End of file Javascript.php */
-/* Location: ./system/libraries/Javascript.php */
+/* Location: ./system/libraries/Javascript.php */
\ No newline at end of file
diff --git a/system/libraries/Log.php b/system/libraries/Log.php
index 955277acc..66f9ebff9 100644
--- a/system/libraries/Log.php
+++ b/system/libraries/Log.php
@@ -25,8 +25,6 @@
  * @filesource
  */
 
-// ------------------------------------------------------------------------
-
 /**
  * Logging Class
  *
@@ -43,12 +41,9 @@ class CI_Log {
 	protected $_threshold_max	= 0;
 	protected $_threshold_array	= array();
 	protected $_date_fmt		= 'Y-m-d H:i:s';
-	protected $_enabled			= TRUE;
-	protected $_levels			= array('ERROR' => 1, 'DEBUG' => 2,  'INFO' => 3, 'ALL' => 4);
+	protected $_enabled		= TRUE;
+	protected $_levels		= array('ERROR' => 1, 'DEBUG' => 2,  'INFO' => 3, 'ALL' => 4);
 
-	/**
-	 * Constructor
-	 */
 	public function __construct()
 	{
 		$config =& get_config();
@@ -98,7 +93,7 @@ class CI_Log {
 		$level = strtoupper($level);
 
 		if (( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
-			AND ! isset($this->_threshold_array[$this->_levels[$level]]))
+			&& ! isset($this->_threshold_array[$this->_levels[$level]]))
 		{
 			return FALSE;
 		}
@@ -125,15 +120,15 @@ class CI_Log {
 		flock($fp, LOCK_UN);
 		fclose($fp);
 
-		if (isset($newfile) AND $newfile === TRUE)
+		if (isset($newfile) && $newfile === TRUE)
 		{
 			@chmod($filepath, FILE_WRITE_MODE);
 		}
+
 		return TRUE;
 	}
 
 }
-// END Log Class
 
 /* End of file Log.php */
-/* Location: ./system/libraries/Log.php */
+/* Location: ./system/libraries/Log.php */
\ No newline at end of file
-- 
cgit v1.2.3-24-g4f1b


From 1b815532378bd444347d1bc741771e13108147b6 Mon Sep 17 00:00:00 2001
From: Andrey Andreev 
Date: Tue, 3 Apr 2012 16:06:03 +0300
Subject: Minor cleanup and style fixes in the Unit_test and Image_lib
 libraries

---
 system/libraries/Image_lib.php  |  4 ++--
 system/libraries/Javascript.php |  4 ++--
 system/libraries/Unit_test.php  | 28 ++++++++++++----------------
 3 files changed, 16 insertions(+), 20 deletions(-)

(limited to 'system')

diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index 86b77bf07..1ab8b23e0 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.php
@@ -251,7 +251,7 @@ class CI_Image_lib {
 		}
 		else
 		{
-			if (strpos($this->new_image, '/') === FALSE AND strpos($this->new_image, '\\') === FALSE)
+			if (strpos($this->new_image, '/') === FALSE && strpos($this->new_image, '\\') === FALSE)
 			{
 				$full_dest_path = str_replace('\\', '/', realpath($this->new_image));
 			}
@@ -1462,4 +1462,4 @@ class CI_Image_lib {
 }
 
 /* End of file Image_lib.php */
-/* Location: ./system/libraries/Image_lib.php */
+/* Location: ./system/libraries/Image_lib.php */
\ No newline at end of file
diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php
index baa044117..629a3adfe 100644
--- a/system/libraries/Javascript.php
+++ b/system/libraries/Javascript.php
@@ -105,7 +105,7 @@ class CI_Javascript {
 	 *
 	 * @param	string	The element to attach the event to
 	 * @param	string	The code to execute
-	 * @param	boolean	whether or not to return false
+	 * @param	bool	whether or not to return false
 	 * @return	string
 	 */
 	public function click($element = 'this', $js = '', $ret_false = TRUE)
@@ -644,7 +644,7 @@ class CI_Javascript {
 	 * Outputs a