Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * Postgres Result Class |
| 30 | * |
| 31 | * This class extends the parent result class: CI_DB_result |
| 32 | * |
| 33 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 34 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/database/ |
| 36 | */ |
| 37 | class CI_DB_postgre_result extends CI_DB_result { |
| 38 | |
| 39 | /** |
| 40 | * Number of rows in the result set |
| 41 | * |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 42 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 43 | */ |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 44 | public function num_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 45 | { |
| 46 | return @pg_num_rows($this->result_id); |
| 47 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 48 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 49 | // -------------------------------------------------------------------- |
| 50 | |
| 51 | /** |
| 52 | * Number of fields in the result set |
| 53 | * |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 54 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 55 | */ |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 56 | public function num_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 57 | { |
| 58 | return @pg_num_fields($this->result_id); |
| 59 | } |
| 60 | |
| 61 | // -------------------------------------------------------------------- |
| 62 | |
| 63 | /** |
| 64 | * Fetch Field Names |
| 65 | * |
| 66 | * Generates an array of column names |
| 67 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 68 | * @return array |
| 69 | */ |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 70 | public function list_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | { |
| 72 | $field_names = array(); |
Andrey Andreev | 22b9e5f | 2012-03-29 11:30:33 +0300 | [diff] [blame] | 73 | for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 74 | { |
| 75 | $field_names[] = pg_field_name($this->result_id, $i); |
| 76 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 77 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 78 | return $field_names; |
| 79 | } |
| 80 | |
| 81 | // -------------------------------------------------------------------- |
| 82 | |
| 83 | /** |
| 84 | * Field data |
| 85 | * |
| 86 | * Generates an array of objects containing field meta-data |
| 87 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 88 | * @return array |
| 89 | */ |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 90 | public function field_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 91 | { |
| 92 | $retval = array(); |
Andrey Andreev | 22b9e5f | 2012-03-29 11:30:33 +0300 | [diff] [blame] | 93 | for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 94 | { |
Andrey Andreev | 22b9e5f | 2012-03-29 11:30:33 +0300 | [diff] [blame] | 95 | $retval[$i] = new stdClass(); |
| 96 | $retval[$i]->name = pg_field_name($this->result_id, $i); |
| 97 | $retval[$i]->type = pg_field_type($this->result_id, $i); |
| 98 | $retval[$i]->max_length = pg_field_size($this->result_id, $i); |
| 99 | $retval[$i]->primary_key = 0; |
| 100 | $retval[$i]->default = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 101 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 102 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 103 | return $retval; |
| 104 | } |
| 105 | |
| 106 | // -------------------------------------------------------------------- |
| 107 | |
| 108 | /** |
| 109 | * Free the result |
| 110 | * |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 111 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 112 | */ |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 113 | public function free_result() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 114 | { |
| 115 | if (is_resource($this->result_id)) |
| 116 | { |
| 117 | pg_free_result($this->result_id); |
| 118 | $this->result_id = FALSE; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // -------------------------------------------------------------------- |
| 123 | |
| 124 | /** |
| 125 | * Data Seek |
| 126 | * |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 127 | * Moves the internal pointer to the desired offset. We call |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 128 | * this internally before fetching results to make sure the |
| 129 | * result set starts at zero |
| 130 | * |
Andrey Andreev | 8f3566f | 2012-04-12 14:30:05 +0300 | [diff] [blame^] | 131 | * @return bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 132 | */ |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 133 | protected function _data_seek($n = 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 134 | { |
| 135 | return pg_result_seek($this->result_id, $n); |
| 136 | } |
| 137 | |
| 138 | // -------------------------------------------------------------------- |
| 139 | |
| 140 | /** |
| 141 | * Result - associative array |
| 142 | * |
| 143 | * Returns the result set as an array |
| 144 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 145 | * @return array |
| 146 | */ |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 147 | protected function _fetch_assoc() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 148 | { |
| 149 | return pg_fetch_assoc($this->result_id); |
| 150 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 151 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 152 | // -------------------------------------------------------------------- |
| 153 | |
| 154 | /** |
| 155 | * Result - object |
| 156 | * |
| 157 | * Returns the result set as an object |
| 158 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 159 | * @return object |
| 160 | */ |
Andrey Andreev | 02878c2 | 2012-03-20 14:16:53 +0200 | [diff] [blame] | 161 | protected function _fetch_object() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 162 | { |
| 163 | return pg_fetch_object($this->result_id); |
| 164 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 165 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | /* End of file postgre_result.php */ |
Timothy Warren | 215890b | 2012-03-20 09:38:16 -0400 | [diff] [blame] | 169 | /* Location: ./system/database/drivers/postgre/postgre_result.php */ |