blob: b27afaedbaec68497c2683b4715c7319c103b5e1 [file] [log] [blame]
Derek Jones37f4b9c2011-07-01 17:56:50 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
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 Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Postgres Result Class
32 *
33 * This class extends the parent result class: CI_DB_result
34 *
35 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/database/
38 */
39class CI_DB_postgre_result extends CI_DB_result {
40
41 /**
42 * Number of rows in the result set
43 *
Derek Allard2067d1a2008-11-13 22:59:24 +000044 * @return integer
45 */
Timothy Warren7a3f8972012-03-19 18:18:27 -040046 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000047 {
48 return @pg_num_rows($this->result_id);
49 }
Barry Mienydd671972010-10-04 16:33:58 +020050
Derek Allard2067d1a2008-11-13 22:59:24 +000051 // --------------------------------------------------------------------
52
53 /**
54 * Number of fields in the result set
55 *
Derek Allard2067d1a2008-11-13 22:59:24 +000056 * @return integer
57 */
Timothy Warren7a3f8972012-03-19 18:18:27 -040058 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000059 {
60 return @pg_num_fields($this->result_id);
61 }
62
63 // --------------------------------------------------------------------
64
65 /**
66 * Fetch Field Names
67 *
68 * Generates an array of column names
69 *
Derek Allard2067d1a2008-11-13 22:59:24 +000070 * @return array
71 */
Timothy Warren7a3f8972012-03-19 18:18:27 -040072 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000073 {
74 $field_names = array();
75 for ($i = 0; $i < $this->num_fields(); $i++)
76 {
77 $field_names[] = pg_field_name($this->result_id, $i);
78 }
Barry Mienydd671972010-10-04 16:33:58 +020079
Derek Allard2067d1a2008-11-13 22:59:24 +000080 return $field_names;
81 }
82
83 // --------------------------------------------------------------------
84
85 /**
86 * Field data
87 *
88 * Generates an array of objects containing field meta-data
89 *
Derek Allard2067d1a2008-11-13 22:59:24 +000090 * @return array
91 */
Timothy Warren7a3f8972012-03-19 18:18:27 -040092 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +000093 {
94 $retval = array();
95 for ($i = 0; $i < $this->num_fields(); $i++)
96 {
Barry Mienydd671972010-10-04 16:33:58 +020097 $F = new stdClass();
98 $F->name = pg_field_name($this->result_id, $i);
99 $F->type = pg_field_type($this->result_id, $i);
Derek Allard2067d1a2008-11-13 22:59:24 +0000100 $F->max_length = pg_field_size($this->result_id, $i);
101 $F->primary_key = 0;
102 $F->default = '';
103
104 $retval[] = $F;
105 }
Barry Mienydd671972010-10-04 16:33:58 +0200106
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 return $retval;
108 }
109
110 // --------------------------------------------------------------------
111
112 /**
113 * Free the result
114 *
115 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200116 */
Timothy Warren7a3f8972012-03-19 18:18:27 -0400117 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 {
119 if (is_resource($this->result_id))
120 {
121 pg_free_result($this->result_id);
122 $this->result_id = FALSE;
123 }
124 }
125
126 // --------------------------------------------------------------------
127
128 /**
129 * Data Seek
130 *
Derek Jones37f4b9c2011-07-01 17:56:50 -0500131 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 * this internally before fetching results to make sure the
133 * result set starts at zero
134 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 * @return array
136 */
Timothy Warren7a3f8972012-03-19 18:18:27 -0400137 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 {
139 return pg_result_seek($this->result_id, $n);
140 }
141
142 // --------------------------------------------------------------------
143
144 /**
145 * Result - associative array
146 *
147 * Returns the result set as an array
148 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000149 * @return array
150 */
Timothy Warren7a3f8972012-03-19 18:18:27 -0400151 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 {
153 return pg_fetch_assoc($this->result_id);
154 }
Barry Mienydd671972010-10-04 16:33:58 +0200155
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 // --------------------------------------------------------------------
157
158 /**
159 * Result - object
160 *
161 * Returns the result set as an object
162 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 * @return object
164 */
Timothy Warren7a3f8972012-03-19 18:18:27 -0400165 protected function _fetch_object()
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 {
167 return pg_fetch_object($this->result_id);
168 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000169}
170
Derek Allard2067d1a2008-11-13 22:59:24 +0000171/* End of file postgre_result.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000172/* Location: ./system/database/drivers/postgre/postgre_result.php */