blob: c7a7632aadd19b8a336fade15b30ebb1669a62a4 [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 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Esen Sagynov2e087942011-08-09 23:35:01 -07006 *
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
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)
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 *
Esen Sagynov2e087942011-08-09 23:35:01 -070044 * @return integer
45 */
Timothy Warrenf83f0d52012-03-19 17:38:30 -040046 public function num_rows()
Esen Sagynov2e087942011-08-09 23:35:01 -070047 {
48 return @cubrid_num_rows($this->result_id);
49 }
50
51 // --------------------------------------------------------------------
52
53 /**
54 * Number of fields in the result set
55 *
Esen Sagynov2e087942011-08-09 23:35:01 -070056 * @return integer
57 */
Timothy Warrenf83f0d52012-03-19 17:38:30 -040058 public function num_fields()
Esen Sagynov2e087942011-08-09 23:35:01 -070059 {
60 return @cubrid_num_fields($this->result_id);
61 }
62
63 // --------------------------------------------------------------------
64
65 /**
66 * Fetch Field Names
67 *
68 * Generates an array of column names
69 *
Esen Sagynov2e087942011-08-09 23:35:01 -070070 * @return array
71 */
Timothy Warrenf83f0d52012-03-19 17:38:30 -040072 public function list_fields()
Esen Sagynov2e087942011-08-09 23:35:01 -070073 {
74 return cubrid_column_names($this->result_id);
75 }
76
77 // --------------------------------------------------------------------
78
79 /**
80 * Field data
81 *
82 * Generates an array of objects containing field meta-data
83 *
Esen Sagynov2e087942011-08-09 23:35:01 -070084 * @return array
85 */
Timothy Warrenf83f0d52012-03-19 17:38:30 -040086 public function field_data()
Esen Sagynov2e087942011-08-09 23:35:01 -070087 {
88 $retval = array();
89
90 $tablePrimaryKeys = array();
91
92 while ($field = cubrid_fetch_field($this->result_id))
93 {
94 $F = new stdClass();
95 $F->name = $field->name;
96 $F->type = $field->type;
97 $F->default = $field->def;
98 $F->max_length = $field->max_length;
99
100 // At this moment primary_key property is not returned when
101 // cubrid_fetch_field is called. The following code will
102 // provide a patch for it. primary_key property will be added
103 // in the next release.
104
105 // TODO: later version of CUBRID will provide primary_key
106 // property.
107 // When PK is defined in CUBRID, an index is automatically
108 // created in the db_index system table in the form of
109 // pk_tblname_fieldname. So the following will count how many
110 // columns are there which satisfy this format.
111 // The query will search for exact single columns, thus
112 // compound PK is not supported.
113 $res = cubrid_query($this->conn_id,
114 "SELECT COUNT(*) FROM db_index WHERE class_name = '" . $field->table .
115 "' AND is_primary_key = 'YES' AND index_name = 'pk_" .
116 $field->table . "_" . $field->name . "'"
117 );
118
119 if ($res)
120 {
121 $row = cubrid_fetch_array($res, CUBRID_NUM);
122 $F->primary_key = ($row[0] > 0 ? 1 : null);
123 }
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700124 else
125 {
Esen Sagynov2e087942011-08-09 23:35:01 -0700126 $F->primary_key = null;
127 }
128
129 if (is_resource($res))
130 {
131 cubrid_close_request($res);
132 $this->result_id = FALSE;
133 }
134
135 $retval[] = $F;
136 }
137
138 return $retval;
139 }
140
141 // --------------------------------------------------------------------
142
143 /**
144 * Free the result
145 *
146 * @return null
147 */
Timothy Warrenf83f0d52012-03-19 17:38:30 -0400148 public function free_result()
Esen Sagynov2e087942011-08-09 23:35:01 -0700149 {
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700150 if(is_resource($this->result_id) ||
151 get_resource_type($this->result_id) == "Unknown" &&
152 preg_match('/Resource id #/', strval($this->result_id)))
Esen Sagynov2e087942011-08-09 23:35:01 -0700153 {
154 cubrid_close_request($this->result_id);
155 $this->result_id = FALSE;
156 }
157 }
158
159 // --------------------------------------------------------------------
160
161 /**
162 * Data Seek
163 *
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700164 * Moves the internal pointer to the desired offset. We call
Esen Sagynov2e087942011-08-09 23:35:01 -0700165 * this internally before fetching results to make sure the
166 * result set starts at zero
167 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700168 * @return array
169 */
Timothy Warrenf83f0d52012-03-19 17:38:30 -0400170 protected function _data_seek($n = 0)
Esen Sagynov2e087942011-08-09 23:35:01 -0700171 {
172 return cubrid_data_seek($this->result_id, $n);
173 }
174
175 // --------------------------------------------------------------------
176
177 /**
178 * Result - associative array
179 *
180 * Returns the result set as an array
181 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700182 * @return array
183 */
Timothy Warrenf83f0d52012-03-19 17:38:30 -0400184 protected function _fetch_assoc()
Esen Sagynov2e087942011-08-09 23:35:01 -0700185 {
186 return cubrid_fetch_assoc($this->result_id);
187 }
188
189 // --------------------------------------------------------------------
190
191 /**
192 * Result - object
193 *
194 * Returns the result set as an object
195 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700196 * @return object
197 */
Timothy Warrenf83f0d52012-03-19 17:38:30 -0400198 protected function _fetch_object()
Esen Sagynov2e087942011-08-09 23:35:01 -0700199 {
200 return cubrid_fetch_object($this->result_id);
201 }
202
203}
204
205
206/* End of file cubrid_result.php */
207/* Location: ./system/database/drivers/cubrid/cubrid_result.php */