blob: b2f1bcf71c73817256fe1f75fa2ea44632271eb9 [file] [log] [blame]
Derek Jonesf4a4bd82011-10-20 12:18:42 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Esen Sagynov2e087942011-08-09 23:35:01 -07002/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
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 *
Esen Sagynov2e087942011-08-09 23:35:01 -070019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Esen Sagynov2e087942011-08-09 23:35:01 -070023 * @link http://codeigniter.com
24 * @since Version 2.0.2
25 * @filesource
26 */
27
28// --------------------------------------------------------------------
29
30/**
31 * CUBRID Result Class
32 *
33 * This class extends the parent result class: CI_DB_result
34 *
35 * @category Database
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -070036 * @author Esen Sagynov
Esen Sagynov2e087942011-08-09 23:35:01 -070037 * @link http://codeigniter.com/user_guide/database/
38 */
39class CI_DB_cubrid_result extends CI_DB_result {
40
41 /**
42 * Number of rows in the result set
43 *
44 * @access public
45 * @return integer
46 */
47 function num_rows()
48 {
49 return @cubrid_num_rows($this->result_id);
50 }
51
52 // --------------------------------------------------------------------
53
54 /**
55 * Number of fields in the result set
56 *
57 * @access public
58 * @return integer
59 */
60 function num_fields()
61 {
62 return @cubrid_num_fields($this->result_id);
63 }
64
65 // --------------------------------------------------------------------
66
67 /**
68 * Fetch Field Names
69 *
70 * Generates an array of column names
71 *
72 * @access public
73 * @return array
74 */
75 function list_fields()
76 {
77 return cubrid_column_names($this->result_id);
78 }
79
80 // --------------------------------------------------------------------
81
82 /**
83 * Field data
84 *
85 * Generates an array of objects containing field meta-data
86 *
87 * @access public
88 * @return array
89 */
90 function field_data()
91 {
92 $retval = array();
93
94 $tablePrimaryKeys = array();
95
96 while ($field = cubrid_fetch_field($this->result_id))
97 {
98 $F = new stdClass();
99 $F->name = $field->name;
100 $F->type = $field->type;
101 $F->default = $field->def;
102 $F->max_length = $field->max_length;
103
104 // At this moment primary_key property is not returned when
105 // cubrid_fetch_field is called. The following code will
106 // provide a patch for it. primary_key property will be added
107 // in the next release.
108
109 // TODO: later version of CUBRID will provide primary_key
110 // property.
111 // When PK is defined in CUBRID, an index is automatically
112 // created in the db_index system table in the form of
113 // pk_tblname_fieldname. So the following will count how many
114 // columns are there which satisfy this format.
115 // The query will search for exact single columns, thus
116 // compound PK is not supported.
117 $res = cubrid_query($this->conn_id,
118 "SELECT COUNT(*) FROM db_index WHERE class_name = '" . $field->table .
119 "' AND is_primary_key = 'YES' AND index_name = 'pk_" .
120 $field->table . "_" . $field->name . "'"
121 );
122
123 if ($res)
124 {
125 $row = cubrid_fetch_array($res, CUBRID_NUM);
126 $F->primary_key = ($row[0] > 0 ? 1 : null);
127 }
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700128 else
129 {
Esen Sagynov2e087942011-08-09 23:35:01 -0700130 $F->primary_key = null;
131 }
132
133 if (is_resource($res))
134 {
135 cubrid_close_request($res);
136 $this->result_id = FALSE;
137 }
138
139 $retval[] = $F;
140 }
141
142 return $retval;
143 }
144
145 // --------------------------------------------------------------------
146
147 /**
148 * Free the result
149 *
150 * @return null
151 */
152 function free_result()
153 {
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700154 if(is_resource($this->result_id) ||
155 get_resource_type($this->result_id) == "Unknown" &&
156 preg_match('/Resource id #/', strval($this->result_id)))
Esen Sagynov2e087942011-08-09 23:35:01 -0700157 {
158 cubrid_close_request($this->result_id);
159 $this->result_id = FALSE;
160 }
161 }
162
163 // --------------------------------------------------------------------
164
165 /**
166 * Data Seek
167 *
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700168 * Moves the internal pointer to the desired offset. We call
Esen Sagynov2e087942011-08-09 23:35:01 -0700169 * this internally before fetching results to make sure the
170 * result set starts at zero
171 *
172 * @access private
173 * @return array
174 */
175 function _data_seek($n = 0)
176 {
177 return cubrid_data_seek($this->result_id, $n);
178 }
179
180 // --------------------------------------------------------------------
181
182 /**
183 * Result - associative array
184 *
185 * Returns the result set as an array
186 *
187 * @access private
188 * @return array
189 */
190 function _fetch_assoc()
191 {
192 return cubrid_fetch_assoc($this->result_id);
193 }
194
195 // --------------------------------------------------------------------
196
197 /**
198 * Result - object
199 *
200 * Returns the result set as an object
201 *
202 * @access private
203 * @return object
204 */
205 function _fetch_object()
206 {
207 return cubrid_fetch_object($this->result_id);
208 }
209
210}
211
212
213/* End of file cubrid_result.php */
214/* Location: ./system/database/drivers/cubrid/cubrid_result.php */