From 08364ea08c53bd872504d5d6c20110540df5e81f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 4 Jul 2012 23:10:46 +0300 Subject: Create aliases for odbc_fetch_array() and odbc_fetch_object() instead of using custom methods Signed-off-by: Andrey Andreev --- system/database/drivers/odbc/odbc_result.php | 130 ++++++++++++++------------- 1 file changed, 68 insertions(+), 62 deletions(-) (limited to 'system/database/drivers/odbc/odbc_result.php') diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 227fe4fac..af532110a 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -146,9 +146,7 @@ class CI_DB_odbc_result extends CI_DB_result { */ protected function _fetch_assoc() { - return function_exists('odbc_fetch_array') - ? odbc_fetch_array($this->result_id) - : $this->_odbc_fetch_array($this->result_id); + return odbc_fetch_array($this->result_id); } // -------------------------------------------------------------------- @@ -162,65 +160,7 @@ class CI_DB_odbc_result extends CI_DB_result { */ protected function _fetch_object() { - return function_exists('odbc_fetch_object') - ? odbc_fetch_object($this->result_id) - : $this->_odbc_fetch_object($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * subsititutes the odbc_fetch_object function when - * not available (odbc_fetch_object requires unixODBC) - * - * @return object - */ - protected function _odbc_fetch_object(& $odbc_result) - { - $rs = array(); - if ( ! odbc_fetch_into($odbc_result, $rs)) - { - return FALSE; - } - - $rs_obj = new stdClass(); - foreach ($rs as $k => $v) - { - $field_name = odbc_field_name($odbc_result, $k+1); - $rs_obj->$field_name = $v; - } - - return $rs_obj; - } - - // -------------------------------------------------------------------- - - /** - * Result - array - * - * subsititutes the odbc_fetch_array function when - * not available (odbc_fetch_array requires unixODBC) - * - * @return array - */ - protected function _odbc_fetch_array(& $odbc_result) - { - $rs = array(); - if ( ! odbc_fetch_into($odbc_result, $rs)) - { - return FALSE; - } - - $rs_assoc = array(); - foreach ($rs as $k => $v) - { - $field_name = odbc_field_name($odbc_result, $k+1); - $rs_assoc[$field_name] = $v; - } - - return $rs_assoc; + return odbc_fetch_object($this->result_id); } // -------------------------------------------------------------------- @@ -295,5 +235,71 @@ class CI_DB_odbc_result extends CI_DB_result { } +// -------------------------------------------------------------------- + +if ( ! function_exists('odbc_fetch_array')) +{ + /** + * ODBC Fetch array + * + * Emulates the native odbc_fetch_array() function when + * it is not available (odbc_fetch_array() requires unixODBC) + * + * @param resource + * @param int + * @return array + */ + function odbc_fetch_array(& $result, $rownumber = 1) + { + $rs = array(); + if ( ! odbc_fetch_into($result, $rs, $rownumber)) + { + return FALSE; + } + + $rs_assoc = array(); + foreach ($rs as $k => $v) + { + $field_name = odbc_field_name($result, $k+1); + $rs_assoc[$field_name] = $v; + } + + return $rs_assoc; + } +} + +// -------------------------------------------------------------------- + +if ( ! function_exists('odbc_fetch_object')) +{ + /** + * ODBC Fetch object + * + * Emulates the native odbc_fetch_object() function when + * it is not available. + * + * @param resource + * @param int + * @return object + */ + function odbc_fetch_object(& $result, $rownumber = 1) + { + $rs = array(); + if ( ! odbc_fetch_into($result, $rs, $rownumber)) + { + return FALSE; + } + + $rs_object = new stdClass(); + foreach ($rs as $k => $v) + { + $field_name = odbc_field_name($result, $k+1); + $rs_object->$field_name = $v; + } + + return $rs_object; + } +} + /* End of file odbc_result.php */ /* Location: ./system/database/drivers/odbc/odbc_result.php */ \ No newline at end of file -- 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/odbc/odbc_result.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/odbc/odbc_result.php') diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index af532110a..0085ef664 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -33,11 +33,10 @@ * @category Database * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/database/ + * @since 1.3 */ class CI_DB_odbc_result extends CI_DB_result { - public $num_rows; - /** * Number of rows in the result set * @@ -59,6 +58,8 @@ class CI_DB_odbc_result extends CI_DB_result { return $this->num_rows; } + // -------------------------------------------------------------------- + /** * Number of fields 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/odbc/odbc_result.php | 84 ++++------------------------ 1 file changed, 11 insertions(+), 73 deletions(-) (limited to 'system/database/drivers/odbc/odbc_result.php') diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 0085ef664..1d998bea8 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -48,14 +48,22 @@ class CI_DB_odbc_result extends CI_DB_result { { return $this->num_rows; } + elseif (($this->num_rows = @odbc_num_rows($this->result_id)) !== -1) + { + return $this->num_rows; + } // Work-around for ODBC subdrivers that don't support num_rows() - if (($this->num_rows = @odbc_num_rows($this->result_id)) === -1) + if (count($this->result_array) > 0) { - $this->num_rows = count($this->result_array()); + 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; + return $this->num_rows = count($this->result_array()); } // -------------------------------------------------------------------- @@ -164,76 +172,6 @@ class CI_DB_odbc_result extends CI_DB_result { return odbc_fetch_object($this->result_id); } - // -------------------------------------------------------------------- - - /** - * Query result. Array version. - * - * @return array - */ - public function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - elseif (($c = count($this->result_object)) > 0) - { - for ($i = 0; $i < $c; $i++) - { - $this->result_array[$i] = (array) $this->result_object[$i]; - } - } - elseif ($this->result_id === FALSE) - { - return array(); - } - else - { - while ($row = $this->_fetch_assoc()) - { - $this->result_array[] = $row; - } - } - - return $this->result_array; - } - - // -------------------------------------------------------------------- - - /** - * Query result. Object version. - * - * @return array - */ - public function result_object() - { - if (count($this->result_object) > 0) - { - return $this->result_object; - } - elseif (($c = count($this->result_array)) > 0) - { - for ($i = 0; $i < $c; $i++) - { - $this->result_object[$i] = (object) $this->result_array[$i]; - } - } - elseif ($this->result_id === FALSE) - { - return array(); - } - else - { - while ($row = $this->_fetch_object()) - { - $this->result_object[] = $row; - } - } - - return $this->result_object; - } - } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b