blob: b3eafb8f79827b4ca9d533080e7cb909a417b55b [file] [log] [blame]
Andrey Andreev02878c22012-03-20 14:16:53 +02001<?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
Andrey Andreev02878c22012-03-20 14:16:53 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev02878c22012-03-20 14:16:53 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * Postgres Result Class
30 *
31 * This class extends the parent result class: CI_DB_result
32 *
33 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/database/
36 */
37class CI_DB_postgre_result extends CI_DB_result {
38
39 /**
40 * Number of rows in the result set
41 *
Andrey Andreev02878c22012-03-20 14:16:53 +020042 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000043 */
Andrey Andreev02878c22012-03-20 14:16:53 +020044 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000045 {
46 return @pg_num_rows($this->result_id);
47 }
Barry Mienydd671972010-10-04 16:33:58 +020048
Derek Allard2067d1a2008-11-13 22:59:24 +000049 // --------------------------------------------------------------------
50
51 /**
52 * Number of fields in the result set
53 *
Andrey Andreev02878c22012-03-20 14:16:53 +020054 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000055 */
Andrey Andreev02878c22012-03-20 14:16:53 +020056 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000057 {
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 Allard2067d1a2008-11-13 22:59:24 +000068 * @return array
69 */
Andrey Andreev02878c22012-03-20 14:16:53 +020070 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000071 {
72 $field_names = array();
73 for ($i = 0; $i < $this->num_fields(); $i++)
74 {
75 $field_names[] = pg_field_name($this->result_id, $i);
76 }
Barry Mienydd671972010-10-04 16:33:58 +020077
Derek Allard2067d1a2008-11-13 22:59:24 +000078 return $field_names;
79 }
80
81 // --------------------------------------------------------------------
82
83 /**
84 * Field data
85 *
86 * Generates an array of objects containing field meta-data
87 *
Derek Allard2067d1a2008-11-13 22:59:24 +000088 * @return array
89 */
Andrey Andreev02878c22012-03-20 14:16:53 +020090 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
92 $retval = array();
93 for ($i = 0; $i < $this->num_fields(); $i++)
94 {
Barry Mienydd671972010-10-04 16:33:58 +020095 $F = new stdClass();
96 $F->name = pg_field_name($this->result_id, $i);
97 $F->type = pg_field_type($this->result_id, $i);
Derek Allard2067d1a2008-11-13 22:59:24 +000098 $F->max_length = pg_field_size($this->result_id, $i);
99 $F->primary_key = 0;
100 $F->default = '';
101
102 $retval[] = $F;
103 }
Barry Mienydd671972010-10-04 16:33:58 +0200104
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 return $retval;
106 }
107
108 // --------------------------------------------------------------------
109
110 /**
111 * Free the result
112 *
Andrey Andreev02878c22012-03-20 14:16:53 +0200113 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200114 */
Andrey Andreev02878c22012-03-20 14:16:53 +0200115 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 {
117 if (is_resource($this->result_id))
118 {
119 pg_free_result($this->result_id);
120 $this->result_id = FALSE;
121 }
122 }
123
124 // --------------------------------------------------------------------
125
126 /**
127 * Data Seek
128 *
Andrey Andreev02878c22012-03-20 14:16:53 +0200129 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000130 * this internally before fetching results to make sure the
131 * result set starts at zero
132 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 * @return array
134 */
Andrey Andreev02878c22012-03-20 14:16:53 +0200135 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 {
137 return pg_result_seek($this->result_id, $n);
138 }
139
140 // --------------------------------------------------------------------
141
142 /**
143 * Result - associative array
144 *
145 * Returns the result set as an array
146 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 * @return array
148 */
Andrey Andreev02878c22012-03-20 14:16:53 +0200149 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000150 {
151 return pg_fetch_assoc($this->result_id);
152 }
Barry Mienydd671972010-10-04 16:33:58 +0200153
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 // --------------------------------------------------------------------
155
156 /**
157 * Result - object
158 *
159 * Returns the result set as an object
160 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 * @return object
162 */
Andrey Andreev02878c22012-03-20 14:16:53 +0200163 protected function _fetch_object()
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 {
165 return pg_fetch_object($this->result_id);
166 }
Barry Mienydd671972010-10-04 16:33:58 +0200167
Derek Allard2067d1a2008-11-13 22:59:24 +0000168}
169
Derek Allard2067d1a2008-11-13 22:59:24 +0000170/* End of file postgre_result.php */
Andrey Andreev02878c22012-03-20 14:16:53 +0200171/* Location: ./system/database/drivers/postgre/postgre_result.php */