diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-07-05 15:31:12 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-07-05 15:31:12 +0200 |
commit | 92d18a7b6c46eadc9db58ca60ffce3980e2313ff (patch) | |
tree | b0a869a5312279d65c3e920ffbf0b32344ab1d0f /system/database/drivers/pdo/pdo_result.php | |
parent | d66872ae5d7cd4d2b531251a9c63528e81af3322 (diff) | |
parent | 7ca36131d881d3f83a86d824263d4abd65439e12 (diff) |
Merge upstream branch
Diffstat (limited to 'system/database/drivers/pdo/pdo_result.php')
-rw-r--r-- | system/database/drivers/pdo/pdo_result.php | 67 |
1 files changed, 16 insertions, 51 deletions
diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php index 0b8937cc5..b45e74195 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,72 +33,35 @@ * @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 * * @return int */ 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 (($num_rows = $this->result_id->rowCount()) > 0) { - $this->result_assoc[] = $row; - $this->result_object[] = (object) $row; + return $this->num_rows = $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()); } // -------------------------------------------------------------------- @@ -124,12 +87,14 @@ class CI_DB_pdo_result extends CI_DB_result { */ public function list_fields() { - if ($this->db->db_debug) + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) { - return $this->db->display_error('db_unsuported_feature'); + $field_names[$i] = @$this->result_id->getColumnMeta(); + $field_names[$i] = $field_names[$i]['name']; } - return FALSE; + return $field_names; } // -------------------------------------------------------------------- |