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