From 79922c0d963de9728315db02deaf4d2516c94d5b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 23 May 2012 12:27:17 +0300 Subject: Removed the parameter use in database drivers' _close() and added a default _close() method in CI_DB_driver + some changelog fixes --- system/database/drivers/oci8/oci8_driver.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 33a89df94..e2fa51349 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -671,15 +671,14 @@ class CI_DB_oci8_driver extends CI_DB { /** * Close DB Connection * - * @param resource * @return void */ - protected function _close($conn_id) + protected function _close() { - @oci_close($conn_id); + @oci_close($this->conn_id); } } /* End of file oci8_driver.php */ -/* Location: ./system/database/drivers/oci8/oci8_driver.php */ +/* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 55d3ad4faf2727b900832884e7c219076a255b66 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 24 May 2012 22:13:06 +0300 Subject: Fix issue #121 --- system/database/drivers/oci8/oci8_result.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 7b05e0a43..6fb6c81f1 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -419,7 +419,7 @@ class CI_DB_oci8_result extends CI_DB_result { OR $n < $this->current_row) { // No such row exists - return array(); + return NULL; } // Get the next row index that would actually need to be fetched @@ -460,7 +460,7 @@ class CI_DB_oci8_result extends CI_DB_result { $this->num_rows = 0; } - return array(); + return NULL; } $this->current_row = $n; @@ -507,7 +507,7 @@ class CI_DB_oci8_result extends CI_DB_result { return (object) $row; } - return array(); + return NULL; } // -------------------------------------------------------------------- @@ -539,19 +539,19 @@ class CI_DB_oci8_result extends CI_DB_result { } else { - return array(); + return NULL; } } elseif ( ! class_exists($class_name)) // No such class exists { - return array(); + return NULL; } $row = $this->row_array($n); - // An array would mean that the row doesn't exist - if (is_array($row)) + // A non-array would mean that the row doesn't exist + if ( ! is_array($row)) { - return $row; + return NULL; } // Convert to the desired class and return -- cgit v1.2.3-24-g4f1b From 16bb9bd93698335fc1692adcfbd20d8e4fda6268 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 26 May 2012 18:21:14 +0300 Subject: Move count_all() from the drivers to CI_DB_driver --- system/database/drivers/oci8/oci8_driver.php | 29 ---------------------------- 1 file changed, 29 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index e2fa51349..b979c8a17 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -454,35 +454,6 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * "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; - } - - $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE)); - if ($query == FALSE) - { - return 0; - } - - $row = $query->row(); - $this->_reset_select(); - return (int) $row->numrows; - } - - // -------------------------------------------------------------------- - /** * Show table query * -- cgit v1.2.3-24-g4f1b From 48a2baf0e288accd206f5da5031d29076e130792 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:09:54 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/database --- system/database/drivers/oci8/oci8_driver.php | 6 +++--- system/database/drivers/oci8/oci8_forge.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index b979c8a17..e78091614 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -262,7 +262,7 @@ class CI_DB_oci8_driver extends CI_DB { */ public function stored_procedure($package, $procedure, $params) { - if ($package == '' OR $procedure == '' OR ! is_array($params)) + if ($package === '' OR $procedure === '' OR ! is_array($params)) { if ($this->db_debug) { @@ -466,7 +466,7 @@ class CI_DB_oci8_driver extends CI_DB { { $sql = 'SELECT TABLE_NAME FROM ALL_TABLES'; - if ($prefix_limit !== FALSE && $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); } @@ -634,7 +634,7 @@ class CI_DB_oci8_driver extends CI_DB { { $this->limit_used = TRUE; return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit).')' - .($offset != 0 ? ' WHERE rnum >= '.$offset : ''); + .($offset !== 0 ? ' WHERE rnum >= '.$offset : ''); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index bd265b6e0..837e7eaad 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -141,9 +141,9 @@ class CI_DB_oci8_forge extends CI_DB_forge { } return $sql.' '.$column_definition - .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '') + .($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) : ''); } -- cgit v1.2.3-24-g4f1b From 5ef194df98294d5427c0e7582ca88b1fc06e1d72 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Jun 2012 01:12:54 +0300 Subject: Resolve formatting differences between DB forge drivers --- system/database/drivers/oci8/oci8_forge.php | 38 +++++++++++++++++------------ 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 837e7eaad..4fd3dc4a5 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -73,11 +73,22 @@ 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'] - .((isset($attributes['UNSINGED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') - .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '') - .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? '' : ' NOT NULL') - .(isset($attributes['CONSTRAINT']) ? ' CONSTRAINT '.$attributes['CONSTRAINT'] : ''); + $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE']; + + if (isset($attributes['UNSINGED']) && $attributes['UNSIGNED'] === TRUE) + { + $sql .= ' UNSIGNED'; + } + + if (isset($attributes['DEFAULT'])) + { + $sql .= " DEFAULT '".$attributes['DEFAULT']."'"; + } + + $sql .= (isset($attributes['NULL']) && $attributes['NULL'] === TRUE) + ? '' : ' NOT NULL'; + + empty($attributes['CONSTRAINT']) OR ' CONSTRAINT '.$attributes['CONSTRAINT']; } // don't add a comma on the end of the last field @@ -89,7 +100,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->escape_identifiers($primary_keys); $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $primary_keys).')'; } @@ -97,14 +108,9 @@ class CI_DB_oci8_forge extends CI_DB_forge { { foreach ($keys as $key) { - if (is_array($key)) - { - $key = $this->db->protect_identifiers($key); - } - else - { - $key = array($this->db->protect_identifiers($key)); - } + $key = is_array($key) + ? $this->db->escape_identifiers($key) + : array($this->db->escape_identifiers($key)); $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).')'; } @@ -132,7 +138,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { */ protected 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->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name); // DROP has everything it needs now. if ($alter_type === 'DROP') @@ -143,7 +149,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->escape_identifiers($after_field) : ''); } -- cgit v1.2.3-24-g4f1b From caa04f15096590261093dff2a8b59f266a1dcaf5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Jun 2012 01:39:20 +0300 Subject: Revert back some escape_identifiers() to proect_identifiers() as the first one can't handle arrays --- system/database/drivers/oci8/oci8_forge.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 4fd3dc4a5..be093750b 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -100,8 +100,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $primary_keys = $this->db->escape_identifiers($primary_keys); - $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $primary_keys).')'; + $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')'; } if (is_array($keys) && count($keys) > 0) @@ -109,7 +108,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { foreach ($keys as $key) { $key = is_array($key) - ? $this->db->escape_identifiers($key) + ? $this->db->protect_identifiers($key) : array($this->db->escape_identifiers($key)); $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).')'; -- cgit v1.2.3-24-g4f1b From 9637b40ca9e9ac1cdce2b895d3db09848a6eef76 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Jun 2012 15:39:24 +0300 Subject: escape_identifiers() to accept arrays as well --- system/database/drivers/oci8/oci8_forge.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index be093750b..92e8c02ed 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -100,7 +100,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')'; + $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $this->db->escape_identifiers($primary_keys)).')'; } if (is_array($keys) && count($keys) > 0) @@ -108,7 +108,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { foreach ($keys as $key) { $key = is_array($key) - ? $this->db->protect_identifiers($key) + ? $this->db->escape_identifiers($key) : array($this->db->escape_identifiers($key)); $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).')'; -- cgit v1.2.3-24-g4f1b From 2c35b64fc2b072ce873c56dde0f4bb1e5f404450 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 24 Jun 2012 03:05:26 +0300 Subject: Add a default _limit() method to the Query Builder class --- system/database/drivers/oci8/oci8_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index e78091614..1f571e586 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -634,7 +634,7 @@ class CI_DB_oci8_driver extends CI_DB { { $this->limit_used = TRUE; return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit).')' - .($offset !== 0 ? ' WHERE rnum >= '.$offset : ''); + .($offset ? ' WHERE rnum >= '.$offset : ''); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d3f13670cb79e2225ee871c0a7c78b65ead2f26b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 24 Jun 2012 22:13:21 +0300 Subject: Some changes to the OCI8 (Oracle) driver --- system/database/drivers/oci8/oci8_driver.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 1f571e586..67bb0403b 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -66,6 +66,8 @@ class CI_DB_oci8_driver extends CI_DB { protected $_count_string = 'SELECT COUNT(1) AS '; protected $_random_keyword = ' ASC'; // not currently supported + protected $_reserved_identifiers = array('*', 'rownum'); + // Set "auto commit" by default public $commit_mode = OCI_COMMIT_ON_SUCCESS; @@ -464,11 +466,12 @@ class CI_DB_oci8_driver extends CI_DB { */ 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 && $this->dbprefix !== '') { - return $sql." WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); + return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " + .sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; @@ -486,7 +489,7 @@ class CI_DB_oci8_driver extends CI_DB { */ 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" = '.$this->escape($table); } // -------------------------------------------------------------------- @@ -501,7 +504,7 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _field_data($table) { - return 'SELECT * FROM '.$table.' WHERE rownum = 1'; + return 'SELECT * FROM '.$this->protect_identifiers($table).' WHERE rownum = 1'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d580999cead0aa37d705c2f32e02712a2d522deb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 28 Jun 2012 14:06:54 +0300 Subject: Fix issue #1545 --- system/database/drivers/oci8/oci8_driver.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 67bb0403b..691247fee 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -158,6 +158,8 @@ class CI_DB_oci8_driver extends CI_DB { $this->dsn = ''; } + // -------------------------------------------------------------------- + /** * Non-persistent database connection * @@ -179,9 +181,9 @@ class CI_DB_oci8_driver extends CI_DB { */ public function db_pconnect() { - return ( ! empty($this->char_set)) - ? @oci_pconnect($this->username, $this->password, $this->dsn, $this->char_set) - : @oci_pconnect($this->username, $this->password, $this->dsn); + return empty($this->char_set) + ? @oci_pconnect($this->username, $this->password, $this->dsn) + : @oci_pconnect($this->username, $this->password, $this->dsn, $this->char_set); } // -------------------------------------------------------------------- @@ -217,6 +219,8 @@ class CI_DB_oci8_driver extends CI_DB { return @oci_execute($this->stmt_id, $this->commit_mode); } + // -------------------------------------------------------------------- + /** * Generate a statement ID * @@ -236,7 +240,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Get cursor. Returns a cursor from the database * - * @return cursor id + * @return resource */ public function get_cursor() { @@ -300,6 +304,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Bind parameters * + * @param array * @return void */ protected function _bind_params($params) @@ -328,6 +333,7 @@ class CI_DB_oci8_driver extends CI_DB { /** * Begin Transaction * + * @param bool * @return bool */ public function trans_begin($test_mode = FALSE) @@ -636,8 +642,8 @@ class CI_DB_oci8_driver extends CI_DB { protected function _limit($sql, $limit, $offset) { $this->limit_used = TRUE; - return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit).')' - .($offset ? ' WHERE rnum >= '.$offset : ''); + return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit + 1).')' + .($offset ? ' WHERE rnum >= '.($offset + 1): ''); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5ca0513e1af6c2498f6f28b769c30d762495389f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jul 2012 12:06:34 +0300 Subject: Change DB_result::num_rows default value to NULL --- system/database/drivers/oci8/oci8_result.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 6fb6c81f1..f168131e6 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -33,6 +33,7 @@ * @category Database * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/database/ + * @since 1.4.1 */ class CI_DB_oci8_result extends CI_DB_result { @@ -41,14 +42,16 @@ class CI_DB_oci8_result extends CI_DB_result { public $limit_used; public $commit_mode; - /* Overwriting the parent here, so we have a way to know if it's - * already called or not: + /** + * Constructor + * + * @param object + * @return void */ - public $num_rows; - public function __construct(&$driver_object) { parent::__construct($driver_object); + $this->stmt_id = $driver_object->stmt_id; $this->curs_id = $driver_object->curs_id; $this->limit_used = $driver_object->limit_used; @@ -56,6 +59,8 @@ class CI_DB_oci8_result extends CI_DB_result { $driver_object->stmt_id = FALSE; } + // -------------------------------------------------------------------- + /** * Number of rows in the result set. * -- cgit v1.2.3-24-g4f1b From c7db6bb9b64c8322af4d727bcb71122cd7f09dbf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jul 2012 15:11:20 +0300 Subject: Clean-up the separate drivers' DB result classes from no longer needed methods --- system/database/drivers/oci8/oci8_result.php | 467 --------------------------- 1 file changed, 467 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index f168131e6..faa295e2a 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -61,35 +61,6 @@ class CI_DB_oci8_result extends CI_DB_result { // -------------------------------------------------------------------- - /** - * Number of rows in the result set. - * - * Oracle doesn't have a graceful way to return the number of rows - * so we have to use what amounts to a hack. - * - * @return int - */ - public function num_rows() - { - if ( ! is_int($this->num_rows)) - { - if (count($this->result_array) > 0) - { - return $this->num_rows = count($this->result_array); - } - elseif (count($this->result_object) > 0) - { - return $this->num_rows = count($this->result_object); - } - - return $this->num_rows = count($this->result_array()); - } - - return $this->num_rows; - } - - // -------------------------------------------------------------------- - /** * Number of fields in the result set * @@ -206,444 +177,6 @@ class CI_DB_oci8_result extends CI_DB_result { // -------------------------------------------------------------------- - /** - * Query result. Array version. - * - * @return array - */ - public function result_array() - { - if (count($this->result_array) > 0) - { - 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->row_data[$row_index++] = $row; - } - - 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; - } - - 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 (isset($this->custom_result_object[$class_name])) - { - return $this->custom_result_object[$class_name]; - } - - if ( ! class_exists($class_name) OR $this->result_id === FALSE OR $this->num_rows() === 0) - { - return array(); - } - - /* 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. - */ - if (count($this->result_array) > 0) - { - $data = &$this->result_array; - } - elseif (count($this->result_object) > 0) - { - $data = &$this->result_object; - } - - $this->custom_result_object[$class_name] = array(); - for ($i = 0, $c = count($data); $i < $c; $i++) - { - $this->custom_result_object[$class_name][$i] = new $class_name(); - foreach ($data[$i] as $key => $value) - { - $this->custom_result_object[$class_name][$i]->$key = $value; - } - } - - return $this->custom_result_object[$class_name]; - } - - // -------------------------------------------------------------------- - - /* 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, 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 NULL; - } - - // 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 NULL; - } - - $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 NULL; - } - - // -------------------------------------------------------------------- - - /* 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 NULL; - } - } - elseif ( ! class_exists($class_name)) // No such class exists - { - return NULL; - } - - $row = $this->row_array($n); - // A non-array would mean that the row doesn't exist - if ( ! is_array($row)) - { - return NULL; - } - - // 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); - } - - // -------------------------------------------------------------------- - /** * Data Seek * -- cgit v1.2.3-24-g4f1b From 9a4f356846daa078c077cbadb227524c857b8f97 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Jul 2012 11:57:37 +0300 Subject: _fetch_object(), custom_result_object() to utilize PHP's native capability to directly return custom class results --- system/database/drivers/oci8/oci8_result.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index faa295e2a..a2b600e6c 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -167,12 +167,27 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an object * + * @param string * @return object */ - protected function _fetch_object() + protected function _fetch_object($class_name = 'stdClass') { - $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - return oci_fetch_object($id); + $row = ($this->curs_id) + ? oci_fetch_object($this->curs_id) + : oci_fetch_object($this->stmt_id); + + if ($class_name === 'stdClass' OR ! $row) + { + return $row; + } + + $class_name = new $class_name(); + foreach ($row as $key => $value) + { + $class_name->$key = $value; + } + + return $class_name; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2ea33c37e9bfa3ff0e029c18a0d2c9ef05016bf0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 4 Oct 2012 12:37:51 +0300 Subject: Fix issue #1789 Signed-off-by: Andrey Andreev --- system/database/drivers/oci8/oci8_driver.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'system/database/drivers/oci8') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 691247fee..7bf18949b 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -54,10 +54,6 @@ class CI_DB_oci8_driver extends CI_DB { // The character used for excaping protected $_escape_char = '"'; - // clause and character used for LIKE escape sequences - 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 -- cgit v1.2.3-24-g4f1b