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/pdo/pdo_result.php | 59 ++++++------------------------ 1 file changed, 11 insertions(+), 48 deletions(-) (limited to 'system/database/drivers/pdo/pdo_result.php') diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php index 867105605..8dc16b1df 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -21,7 +21,7 @@ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com - * @since Version 2.1.0 + * @since Version 1.0 * @filesource */ @@ -33,19 +33,10 @@ * @category Database * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/database/ + * @since 2.1 */ class CI_DB_pdo_result extends CI_DB_result { - /** - * @var bool Hold the flag whether a result handler already fetched before - */ - protected $is_fetched = FALSE; - - /** - * @var mixed Hold the fetched assoc array of a result handler - */ - protected $result_assoc; - /** * Number of rows in the result set * @@ -53,52 +44,24 @@ class CI_DB_pdo_result extends CI_DB_result { */ public function num_rows() { - if (empty($this->result_id) OR ! is_object($this->result_id)) + if (is_int($this->num_rows)) { - // invalid result handler - return 0; + return $this->num_rows; } - elseif (($num_rows = $this->result_id->rowCount()) && $num_rows > 0) + elseif (count($this->result_array) > 0) { - // If rowCount return something, we're done. - return $num_rows; + return $this->num_rows = count($this->result_array); } - - // Fetch the result, instead perform another extra query - return ($this->is_fetched && is_array($this->result_assoc)) ? count($this->result_assoc) : count($this->result_assoc()); - } - - /** - * Fetch the result handler - * - * @return mixed - */ - public function result_assoc() - { - // If the result already fetched before, use that one - if (count($this->result_array) > 0 OR $this->is_fetched) + elseif (count($this->result_object) > 0) { - return $this->result_array(); + return $this->num_rows = count($this->result_object); } - - // Define the output - $output = array('assoc', 'object'); - - // Initial value - $this->result_assoc = array() and $this->result_object = array(); - - // Fetch the result - while ($row = $this->_fetch_assoc()) + elseif (($this->num_rows = $this->restul_id->rowCount()) > 0) { - $this->result_assoc[] = $row; - $this->result_object[] = (object) $row; + return $this->num_rows; } - // Save this as buffer and marked the fetch flag - $this->result_array = $this->result_assoc; - $this->is_fetched = TRUE; - - return $this->result_assoc; + return $this->num_rows = count($this->result_array()); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b