blob: 6a61a213d0bd1beb34b6472361ce1fef23597034 [file] [log] [blame]
Andrey Andreev32ed1cc2012-03-20 15:11:50 +02001<?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
Andrey Andreev32ed1cc2012-03-20 15:11:50 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev32ed1cc2012-03-20 15:11:50 +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 *
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
Esen Sagynov2e087942011-08-09 23:35:01 -070028/**
29 * CUBRID Result Class
30 *
31 * This class extends the parent result class: CI_DB_result
32 *
33 * @category Database
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -070034 * @author Esen Sagynov
Esen Sagynov2e087942011-08-09 23:35:01 -070035 * @link http://codeigniter.com/user_guide/database/
36 */
37class CI_DB_cubrid_result extends CI_DB_result {
38
39 /**
40 * Number of rows in the result set
41 *
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020042 * @return int
Esen Sagynov2e087942011-08-09 23:35:01 -070043 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020044 public function num_rows()
Esen Sagynov2e087942011-08-09 23:35:01 -070045 {
46 return @cubrid_num_rows($this->result_id);
47 }
48
49 // --------------------------------------------------------------------
50
51 /**
52 * Number of fields in the result set
53 *
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020054 * @return int
Esen Sagynov2e087942011-08-09 23:35:01 -070055 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020056 public function num_fields()
Esen Sagynov2e087942011-08-09 23:35:01 -070057 {
58 return @cubrid_num_fields($this->result_id);
59 }
60
61 // --------------------------------------------------------------------
62
63 /**
64 * Fetch Field Names
65 *
66 * Generates an array of column names
67 *
Esen Sagynov2e087942011-08-09 23:35:01 -070068 * @return array
69 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020070 public function list_fields()
Esen Sagynov2e087942011-08-09 23:35:01 -070071 {
72 return cubrid_column_names($this->result_id);
73 }
74
75 // --------------------------------------------------------------------
76
77 /**
78 * Field data
79 *
80 * Generates an array of objects containing field meta-data
81 *
Esen Sagynov2e087942011-08-09 23:35:01 -070082 * @return array
83 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020084 public function field_data()
Esen Sagynov2e087942011-08-09 23:35:01 -070085 {
86 $retval = array();
87
88 $tablePrimaryKeys = array();
89
90 while ($field = cubrid_fetch_field($this->result_id))
91 {
92 $F = new stdClass();
93 $F->name = $field->name;
94 $F->type = $field->type;
95 $F->default = $field->def;
96 $F->max_length = $field->max_length;
97
98 // At this moment primary_key property is not returned when
99 // cubrid_fetch_field is called. The following code will
100 // provide a patch for it. primary_key property will be added
101 // in the next release.
102
103 // TODO: later version of CUBRID will provide primary_key
104 // property.
105 // When PK is defined in CUBRID, an index is automatically
106 // created in the db_index system table in the form of
107 // pk_tblname_fieldname. So the following will count how many
108 // columns are there which satisfy this format.
109 // The query will search for exact single columns, thus
110 // compound PK is not supported.
111 $res = cubrid_query($this->conn_id,
112 "SELECT COUNT(*) FROM db_index WHERE class_name = '" . $field->table .
113 "' AND is_primary_key = 'YES' AND index_name = 'pk_" .
114 $field->table . "_" . $field->name . "'"
115 );
116
117 if ($res)
118 {
119 $row = cubrid_fetch_array($res, CUBRID_NUM);
120 $F->primary_key = ($row[0] > 0 ? 1 : null);
121 }
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700122 else
123 {
Esen Sagynov2e087942011-08-09 23:35:01 -0700124 $F->primary_key = null;
125 }
126
127 if (is_resource($res))
128 {
129 cubrid_close_request($res);
130 $this->result_id = FALSE;
131 }
132
133 $retval[] = $F;
134 }
135
136 return $retval;
137 }
138
139 // --------------------------------------------------------------------
140
141 /**
142 * Free the result
143 *
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200144 * @return void
Esen Sagynov2e087942011-08-09 23:35:01 -0700145 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200146 public function free_result()
Esen Sagynov2e087942011-08-09 23:35:01 -0700147 {
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700148 if(is_resource($this->result_id) ||
149 get_resource_type($this->result_id) == "Unknown" &&
150 preg_match('/Resource id #/', strval($this->result_id)))
Esen Sagynov2e087942011-08-09 23:35:01 -0700151 {
152 cubrid_close_request($this->result_id);
153 $this->result_id = FALSE;
154 }
155 }
156
157 // --------------------------------------------------------------------
158
159 /**
160 * Data Seek
161 *
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700162 * Moves the internal pointer to the desired offset. We call
Esen Sagynov2e087942011-08-09 23:35:01 -0700163 * this internally before fetching results to make sure the
164 * result set starts at zero
165 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700166 * @return array
167 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200168 protected function _data_seek($n = 0)
Esen Sagynov2e087942011-08-09 23:35:01 -0700169 {
170 return cubrid_data_seek($this->result_id, $n);
171 }
172
173 // --------------------------------------------------------------------
174
175 /**
176 * Result - associative array
177 *
178 * Returns the result set as an array
179 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700180 * @return array
181 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200182 protected function _fetch_assoc()
Esen Sagynov2e087942011-08-09 23:35:01 -0700183 {
184 return cubrid_fetch_assoc($this->result_id);
185 }
186
187 // --------------------------------------------------------------------
188
189 /**
190 * Result - object
191 *
192 * Returns the result set as an object
193 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700194 * @return object
195 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200196 protected function _fetch_object()
Esen Sagynov2e087942011-08-09 23:35:01 -0700197 {
198 return cubrid_fetch_object($this->result_id);
199 }
200
201}
202
Esen Sagynov2e087942011-08-09 23:35:01 -0700203/* End of file cubrid_result.php */
204/* Location: ./system/database/drivers/cubrid/cubrid_result.php */