From 80ab8160e82c4b87d53916a3920d85a7e689c7e4 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 22 Aug 2011 18:26:12 -0400 Subject: Started PDO db driver --- system/database/drivers/pdo/pdo_result.php | 228 +++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 system/database/drivers/pdo/pdo_result.php (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 new file mode 100644 index 000000000..161a77bf8 --- /dev/null +++ b/system/database/drivers/pdo/pdo_result.php @@ -0,0 +1,228 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @pdo_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $field_names[] = pdo_field_name($this->result_id, $i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = pdo_field_name($this->result_id, $i); + $F->type = pdo_field_type($this->result_id, $i); + $F->max_length = pdo_field_len($this->result_id, $i); + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + pdo_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + if (function_exists('pdo_fetch_object')) + { + return pdo_fetch_array($this->result_id); + } + else + { + return $this->_pdo_fetch_array($this->result_id); + } + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + if (function_exists('pdo_fetch_object')) + { + return pdo_fetch_object($this->result_id); + } + else + { + return $this->_pdo_fetch_object($this->result_id); + } + } + + + /** + * Result - object + * + * subsititutes the pdo_fetch_object function when + * not available (pdo_fetch_object requires unixPDO) + * + * @access private + * @return object + */ + function _pdo_fetch_object(& $pdo_result) { + $rs = array(); + $rs_obj = FALSE; + if (pdo_fetch_into($pdo_result, $rs)) { + foreach ($rs as $k=>$v) { + $field_name= pdo_field_name($pdo_result, $k+1); + $rs_obj->$field_name = $v; + } + } + return $rs_obj; + } + + + /** + * Result - array + * + * subsititutes the pdo_fetch_array function when + * not available (pdo_fetch_array requires unixPDO) + * + * @access private + * @return array + */ + function _pdo_fetch_array(& $pdo_result) { + $rs = array(); + $rs_assoc = FALSE; + if (pdo_fetch_into($pdo_result, $rs)) { + $rs_assoc=array(); + foreach ($rs as $k=>$v) { + $field_name= pdo_field_name($pdo_result, $k+1); + $rs_assoc[$field_name] = $v; + } + } + return $rs_assoc; + } + +} + + +/* End of file pdo_result.php */ +/* Location: ./system/database/drivers/pdo/pdo_result.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ab347586ef289e960ab7cfad32574e526cdcce0b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 23 Aug 2011 12:29:29 -0400 Subject: Got PDO working --- system/database/drivers/pdo/pdo_result.php | 106 +++++++---------------------- 1 file changed, 25 insertions(+), 81 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 161a77bf8..c38658626 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -34,7 +34,7 @@ class CI_DB_pdo_result extends CI_DB_result { */ function num_rows() { - return @pdo_num_rows($this->result_id); + return $this->result_id->rowCount(); } // -------------------------------------------------------------------- @@ -47,7 +47,7 @@ class CI_DB_pdo_result extends CI_DB_result { */ function num_fields() { - return @pdo_num_fields($this->result_id); + return $this->result_id->columnCount(); } // -------------------------------------------------------------------- @@ -62,13 +62,11 @@ class CI_DB_pdo_result extends CI_DB_result { */ function list_fields() { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) + if ($this->db->db_debug) { - $field_names[] = pdo_field_name($this->result_id, $i); + return $this->db->display_error('db_unsuported_feature'); } - - return $field_names; + return FALSE; } // -------------------------------------------------------------------- @@ -83,20 +81,25 @@ class CI_DB_pdo_result extends CI_DB_result { */ function field_data() { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) + $data = array(); + + try { - $F = new stdClass(); - $F->name = pdo_field_name($this->result_id, $i); - $F->type = pdo_field_type($this->result_id, $i); - $F->max_length = pdo_field_len($this->result_id, $i); - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; + for($i = 0; $i < $this->num_fields(); $i++) + { + $data[] = $this->result_id->getColumnMeta($i); + } + + return $data; + } + catch (Exception $e) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; } - - return $retval; } // -------------------------------------------------------------------- @@ -144,14 +147,7 @@ class CI_DB_pdo_result extends CI_DB_result { */ function _fetch_assoc() { - if (function_exists('pdo_fetch_object')) - { - return pdo_fetch_array($this->result_id); - } - else - { - return $this->_pdo_fetch_array($this->result_id); - } + return $this->result_id->fetch(PDO::FETCH_ASSOC); } // -------------------------------------------------------------------- @@ -165,60 +161,8 @@ class CI_DB_pdo_result extends CI_DB_result { * @return object */ function _fetch_object() - { - if (function_exists('pdo_fetch_object')) - { - return pdo_fetch_object($this->result_id); - } - else - { - return $this->_pdo_fetch_object($this->result_id); - } - } - - - /** - * Result - object - * - * subsititutes the pdo_fetch_object function when - * not available (pdo_fetch_object requires unixPDO) - * - * @access private - * @return object - */ - function _pdo_fetch_object(& $pdo_result) { - $rs = array(); - $rs_obj = FALSE; - if (pdo_fetch_into($pdo_result, $rs)) { - foreach ($rs as $k=>$v) { - $field_name= pdo_field_name($pdo_result, $k+1); - $rs_obj->$field_name = $v; - } - } - return $rs_obj; - } - - - /** - * Result - array - * - * subsititutes the pdo_fetch_array function when - * not available (pdo_fetch_array requires unixPDO) - * - * @access private - * @return array - */ - function _pdo_fetch_array(& $pdo_result) { - $rs = array(); - $rs_assoc = FALSE; - if (pdo_fetch_into($pdo_result, $rs)) { - $rs_assoc=array(); - foreach ($rs as $k=>$v) { - $field_name= pdo_field_name($pdo_result, $k+1); - $rs_assoc[$field_name] = $v; - } - } - return $rs_assoc; + { + return $this->result_id->fetchObject(); } } -- cgit v1.2.3-24-g4f1b From 6a450cf1b6440543b14379abacd6308fe51ea4f3 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 23 Aug 2011 12:46:11 -0400 Subject: Fixed db->close() and db->free_result() functions --- system/database/drivers/pdo/pdo_result.php | 3 +-- 1 file changed, 1 insertion(+), 2 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 c38658626..5e136f581 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -111,9 +111,8 @@ class CI_DB_pdo_result extends CI_DB_result { */ function free_result() { - if (is_resource($this->result_id)) + if (is_object($this->result_id)) { - pdo_free_result($this->result_id); $this->result_id = FALSE; } } -- cgit v1.2.3-24-g4f1b From 018af7a82749cb5c6d224940ab5f08d801f54988 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 7 Sep 2011 12:07:35 -0400 Subject: Added changelog item, updated since version file headers --- system/database/drivers/pdo/pdo_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 5e136f581..e3ae0da4b 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -9,7 +9,7 @@ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com - * @since Version 1.0 + * @since Version 2.1.0 * @filesource */ -- cgit v1.2.3-24-g4f1b From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/database/drivers/pdo/pdo_result.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 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 e3ae0da4b..559c2edb3 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * 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 + * 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 + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2011, 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 * @filesource @@ -21,7 +33,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_pdo_result extends CI_DB_result { -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/database/drivers/pdo/pdo_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 559c2edb3..6b523b001 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @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 -- cgit v1.2.3-24-g4f1b From 1820933505d6aa8def25d0e74344f878c3ec76ad Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 9 Feb 2012 16:07:27 +0700 Subject: Fixed PDO --- system/database/drivers/pdo/pdo_result.php | 67 +++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 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 6b523b001..c333abc40 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -38,6 +38,16 @@ */ 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 * @@ -46,7 +56,59 @@ class CI_DB_pdo_result extends CI_DB_result { */ function num_rows() { - return $this->result_id->rowCount(); + if (empty($this->result_id) OR ! is_object($this->result_id)) + { + // invalid result handler + return 0; + } + elseif (($num_rows = $this->result_id->rowCount()) && $num_rows > 0) + { + // If rowCount return something, we're done. + return $num_rows; + } + + // 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 + * + * @access public + * @return mixed + */ + function result_assoc() + { + // If the result already fetched before, use that one + if (count($this->result_array) > 0 OR $this->is_fetched) + { + return $this->result_array(); + } + + // Define the output + $output = array('assoc', 'object'); + + // Fetch the result + foreach ($output as $type) + { + // Define the method and handler + $res_method = '_fetch_'.$type; + $res_handler = 'result_'.$type; + + $this->$res_handler = array(); + $this->_data_seek(0); + + while ($row = $this->$res_method()) + { + $this->{$res_handler}[] = $row; + } + } + + // Save this as buffer and marked the fetch flag + $this->result_array = $this->result_assoc; + $this->is_fetched = TRUE; + + return $this->result_assoc; } // -------------------------------------------------------------------- @@ -78,6 +140,7 @@ class CI_DB_pdo_result extends CI_DB_result { { return $this->db->display_error('db_unsuported_feature'); } + return FALSE; } @@ -110,6 +173,7 @@ class CI_DB_pdo_result extends CI_DB_result { { return $this->db->display_error('db_unsuported_feature'); } + return FALSE; } } @@ -178,6 +242,5 @@ class CI_DB_pdo_result extends CI_DB_result { } - /* End of file pdo_result.php */ /* Location: ./system/database/drivers/pdo/pdo_result.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4e44b344d79b52c7b79489b7e3d137d5ed66ab21 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 18 Feb 2012 22:47:36 +0700 Subject: Fixed meta table method(s) for PDO --- system/database/drivers/pdo/pdo_result.php | 43 ++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 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 c333abc40..213b5d670 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -160,9 +160,48 @@ class CI_DB_pdo_result extends CI_DB_result { try { - for($i = 0; $i < $this->num_fields(); $i++) + if (strpos($this->result_id->queryString, 'PRAGMA') !== FALSE) { - $data[] = $this->result_id->getColumnMeta($i); + foreach($this->result_array() as $field) + { + preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field['type'], $matches); + + $F = new stdClass(); + $F->name = $field['name']; + $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL; + $F->default = NULL; + $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; + $F->primary_key = (int) $field['pk']; + $F->pdo_type = NULL; + + $data[] = $F; + } + } + else + { + for($i = 0, $max = $this->num_fields(); $i < $max; $i++) + { + $field = $this->result_id->getColumnMeta($i); + + $F = new stdClass(); + $F->name = $field['name']; + $F->type = $field['native_type']; + $F->default = NULL; + $F->pdo_type = $field['pdo_type']; + + if ($field['precision'] < 0) + { + $F->max_length = NULL; + $F->primary_key = 0; + } + else + { + $F->max_length = ($field['len'] > 255) ? NULL : (string) $field['len']; + $F->primary_key = (int) (array_key_exists('flags', $field) && in_array('primary_key', $field['flags'])); + } + + $data[] = $F; + } } return $data; -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/database/drivers/pdo/pdo_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 c333abc40..309f1947d 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 865ce1e3a2466259996e52d764650e2144ae10c9 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 17 Mar 2012 02:19:42 +0700 Subject: Spacing and replace array_key_exists --- system/database/drivers/pdo/pdo_result.php | 4 ++-- 1 file changed, 2 insertions(+), 2 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 213b5d670..6bc923e38 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -162,7 +162,7 @@ class CI_DB_pdo_result extends CI_DB_result { { if (strpos($this->result_id->queryString, 'PRAGMA') !== FALSE) { - foreach($this->result_array() as $field) + foreach ($this->result_array() as $field) { preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field['type'], $matches); @@ -197,7 +197,7 @@ class CI_DB_pdo_result extends CI_DB_result { else { $F->max_length = ($field['len'] > 255) ? NULL : (string) $field['len']; - $F->primary_key = (int) (array_key_exists('flags', $field) && in_array('primary_key', $field['flags'])); + $F->primary_key = (int) ( ! empty($field['flags']) && in_array('primary_key', $field['flags'])); } $data[] = $F; -- cgit v1.2.3-24-g4f1b From 4a80154b0bb28df04d407d3d3d83e112808b25d4 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sun, 18 Mar 2012 01:00:36 +0700 Subject: Remove type casting --- system/database/drivers/pdo/pdo_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 6bc923e38..1c72216b1 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -196,7 +196,7 @@ class CI_DB_pdo_result extends CI_DB_result { } else { - $F->max_length = ($field['len'] > 255) ? NULL : (string) $field['len']; + $F->max_length = ($field['len'] > 255) ? 0 : $field['len']; $F->primary_key = (int) ( ! empty($field['flags']) && in_array('primary_key', $field['flags'])); } -- cgit v1.2.3-24-g4f1b From be22c5bcbea252da8133f5e3a2403f2e6bfcf90a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Mar 2012 23:01:53 +0200 Subject: Visibility declarations and cleanup for CI_DB_pdo_result --- system/database/drivers/pdo/pdo_result.php | 60 +++++++++++++----------------- 1 file changed, 25 insertions(+), 35 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 384b753da..5bbd85d75 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -1,13 +1,13 @@ -result_id) OR ! is_object($this->result_id)) { @@ -74,10 +71,9 @@ class CI_DB_pdo_result extends CI_DB_result { /** * Fetch the result handler * - * @access public * @return mixed */ - function result_assoc() + public function result_assoc() { // If the result already fetched before, use that one if (count($this->result_array) > 0 OR $this->is_fetched) @@ -94,7 +90,7 @@ class CI_DB_pdo_result extends CI_DB_result { // Define the method and handler $res_method = '_fetch_'.$type; $res_handler = 'result_'.$type; - + $this->$res_handler = array(); $this->_data_seek(0); @@ -116,10 +112,9 @@ class CI_DB_pdo_result extends CI_DB_result { /** * Number of fields in the result set * - * @access public - * @return integer + * @return int */ - function num_fields() + public function num_fields() { return $this->result_id->columnCount(); } @@ -131,16 +126,15 @@ class CI_DB_pdo_result extends CI_DB_result { * * Generates an array of column names * - * @access public - * @return array + * @return bool */ - function list_fields() + public function list_fields() { if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); } - + return FALSE; } @@ -151,13 +145,12 @@ class CI_DB_pdo_result extends CI_DB_result { * * Generates an array of objects containing field meta-data * - * @access public * @return array */ - function field_data() + public function field_data() { $data = array(); - + try { if (strpos($this->result_id->queryString, 'PRAGMA') !== FALSE) @@ -173,7 +166,7 @@ class CI_DB_pdo_result extends CI_DB_result { $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; $F->primary_key = (int) $field['pk']; $F->pdo_type = NULL; - + $data[] = $F; } } @@ -188,7 +181,7 @@ class CI_DB_pdo_result extends CI_DB_result { $F->type = $field['native_type']; $F->default = NULL; $F->pdo_type = $field['pdo_type']; - + if ($field['precision'] < 0) { $F->max_length = NULL; @@ -203,7 +196,7 @@ class CI_DB_pdo_result extends CI_DB_result { $data[] = $F; } } - + return $data; } catch (Exception $e) @@ -222,9 +215,9 @@ class CI_DB_pdo_result extends CI_DB_result { /** * Free the result * - * @return null + * @return void */ - function free_result() + public function free_result() { if (is_object($this->result_id)) { @@ -237,14 +230,13 @@ class CI_DB_pdo_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 * - * @access private - * @return array + * @return bool */ - function _data_seek($n = 0) + protected function _data_seek($n = 0) { return FALSE; } @@ -256,10 +248,9 @@ class CI_DB_pdo_result extends CI_DB_result { * * Returns the result set as an array * - * @access private * @return array */ - function _fetch_assoc() + protected function _fetch_assoc() { return $this->result_id->fetch(PDO::FETCH_ASSOC); } @@ -271,11 +262,10 @@ class CI_DB_pdo_result extends CI_DB_result { * * Returns the result set as an object * - * @access private * @return object */ - function _fetch_object() - { + protected function _fetch_object() + { return $this->result_id->fetchObject(); } -- cgit v1.2.3-24-g4f1b From 8f3566fffcb9015ba53dbf52922fc5724ffa6045 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 12 Apr 2012 14:30:05 +0300 Subject: Changed default CI_DB_result::_data_seek() return value to FALSE and removed the method from drivers that don't support it --- system/database/drivers/pdo/pdo_result.php | 17 ----------------- 1 file changed, 17 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 5bbd85d75..19aee1dfc 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -92,7 +92,6 @@ class CI_DB_pdo_result extends CI_DB_result { $res_handler = 'result_'.$type; $this->$res_handler = array(); - $this->_data_seek(0); while ($row = $this->$res_method()) { @@ -227,22 +226,6 @@ class CI_DB_pdo_result extends CI_DB_result { // -------------------------------------------------------------------- - /** - * 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 bool - */ - protected function _data_seek($n = 0) - { - return FALSE; - } - - // -------------------------------------------------------------------- - /** * Result - associative array * -- cgit v1.2.3-24-g4f1b From 8ca31f34c855c783689198f0d352e6efec352b4d Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 23:57:46 +0700 Subject: PDO SQLite bug fixed, for result_object --- system/database/drivers/pdo/pdo_result.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 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 19aee1dfc..0b8937cc5 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -84,19 +84,14 @@ class CI_DB_pdo_result extends CI_DB_result { // Define the output $output = array('assoc', 'object'); + // Initial value + $this->result_assoc = array() and $this->result_object = array(); + // Fetch the result - foreach ($output as $type) + while ($row = $this->_fetch_assoc()) { - // Define the method and handler - $res_method = '_fetch_'.$type; - $res_handler = 'result_'.$type; - - $this->$res_handler = array(); - - while ($row = $this->$res_method()) - { - $this->{$res_handler}[] = $row; - } + $this->result_assoc[] = $row; + $this->result_object[] = (object) $row; } // Save this as buffer and marked the fetch flag @@ -249,7 +244,7 @@ class CI_DB_pdo_result extends CI_DB_result { */ protected function _fetch_object() { - return $this->result_id->fetchObject(); + return $this->result_id->fetch(PDO::FETCH_OBJ); } } -- cgit v1.2.3-24-g4f1b From 626f1a657206a8b33a59c20388d0ec4de4593487 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 4 Jul 2012 22:38:52 +0300 Subject: Add PDO support for list_fields() Signed-off-by: Andrey Andreev --- system/database/drivers/pdo/pdo_result.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 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 0b8937cc5..867105605 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -124,12 +124,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; } // -------------------------------------------------------------------- -- 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/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 From 014a4d23c4805d5aa81b2feb0f9694611a372a9f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jul 2012 15:14:58 +0300 Subject: Fix a typo --- system/database/drivers/pdo/pdo_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 8dc16b1df..322da8d37 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -56,7 +56,7 @@ class CI_DB_pdo_result extends CI_DB_result { { return $this->num_rows = count($this->result_object); } - elseif (($this->num_rows = $this->restul_id->rowCount()) > 0) + elseif (($this->num_rows = $this->result_id->rowCount()) > 0) { return $this->num_rows; } -- cgit v1.2.3-24-g4f1b From 7ca36131d881d3f83a86d824263d4abd65439e12 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 5 Jul 2012 16:20:15 +0300 Subject: Fix pdo_result num_rows() for subdrivers that don't support rowCount() --- system/database/drivers/pdo/pdo_result.php | 4 ++-- 1 file changed, 2 insertions(+), 2 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 322da8d37..b45e74195 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -56,9 +56,9 @@ class CI_DB_pdo_result extends CI_DB_result { { return $this->num_rows = count($this->result_object); } - elseif (($this->num_rows = $this->result_id->rowCount()) > 0) + elseif (($num_rows = $this->result_id->rowCount()) > 0) { - return $this->num_rows; + return $this->num_rows = $num_rows; } return $this->num_rows = count($this->result_array()); -- 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/pdo/pdo_result.php | 5 +++-- 1 file changed, 3 insertions(+), 2 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 b45e74195..444406986 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -205,11 +205,12 @@ class CI_DB_pdo_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') { - return $this->result_id->fetch(PDO::FETCH_OBJ); + return $this->result_id->fetchObject($class_name); } } -- cgit v1.2.3-24-g4f1b