blob: 7a72cdde4e28ba6629333dd634dca1f0e498115d [file] [log] [blame]
Andrey Andreev7f55d612012-01-26 13:44:28 +02001<?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
Andrey Andreev7f55d612012-01-26 13:44:28 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev7f55d612012-01-26 13:44:28 +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 Andreev7f55d612012-01-26 13:44:28 +020042 * @return int
Esen Sagynov2e087942011-08-09 23:35:01 -070043 */
Andrey Andreev7f55d612012-01-26 13:44:28 +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 Andreev7f55d612012-01-26 13:44:28 +020054 * @return int
Esen Sagynov2e087942011-08-09 23:35:01 -070055 */
Andrey Andreev7f55d612012-01-26 13:44:28 +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 Andreev7f55d612012-01-26 13:44:28 +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 Andreev7f55d612012-01-26 13:44:28 +020084 public function field_data()
Esen Sagynov2e087942011-08-09 23:35:01 -070085 {
Andrey Andreev7f55d612012-01-26 13:44:28 +020086 $retval = $tablePrimaryKeys = array();
Esen Sagynov2e087942011-08-09 23:35:01 -070087
88 while ($field = cubrid_fetch_field($this->result_id))
89 {
Andrey Andreev7f55d612012-01-26 13:44:28 +020090 $F = new stdClass();
91 $F->name = $field->name;
92 $F->type = $field->type;
93 $F->default = $field->def;
Esen Sagynov2e087942011-08-09 23:35:01 -070094 $F->max_length = $field->max_length;
95
96 // At this moment primary_key property is not returned when
97 // cubrid_fetch_field is called. The following code will
98 // provide a patch for it. primary_key property will be added
99 // in the next release.
100
101 // TODO: later version of CUBRID will provide primary_key
102 // property.
103 // When PK is defined in CUBRID, an index is automatically
104 // created in the db_index system table in the form of
105 // pk_tblname_fieldname. So the following will count how many
106 // columns are there which satisfy this format.
107 // The query will search for exact single columns, thus
108 // compound PK is not supported.
109 $res = cubrid_query($this->conn_id,
Andrey Andreev7f55d612012-01-26 13:44:28 +0200110 "SELECT COUNT(*) FROM db_index WHERE class_name = '".$field->table
111 ."' AND is_primary_key = 'YES' AND index_name = 'pk_".$field->table.'_'.$field->name."'"
112 );
Esen Sagynov2e087942011-08-09 23:35:01 -0700113
114 if ($res)
115 {
116 $row = cubrid_fetch_array($res, CUBRID_NUM);
Andrey Andreev7f55d612012-01-26 13:44:28 +0200117 $F->primary_key = ($row[0] > 0 ? 1 : NULL);
Esen Sagynov2e087942011-08-09 23:35:01 -0700118 }
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700119 else
120 {
Andrey Andreev7f55d612012-01-26 13:44:28 +0200121 $F->primary_key = NULL;
Esen Sagynov2e087942011-08-09 23:35:01 -0700122 }
123
124 if (is_resource($res))
125 {
126 cubrid_close_request($res);
127 $this->result_id = FALSE;
128 }
129
130 $retval[] = $F;
131 }
132
133 return $retval;
134 }
135
136 // --------------------------------------------------------------------
137
138 /**
139 * Free the result
140 *
Andrey Andreev7f55d612012-01-26 13:44:28 +0200141 * @return void
Esen Sagynov2e087942011-08-09 23:35:01 -0700142 */
Andrey Andreev7f55d612012-01-26 13:44:28 +0200143 public function free_result()
Esen Sagynov2e087942011-08-09 23:35:01 -0700144 {
Andrey Andreev7f55d612012-01-26 13:44:28 +0200145 if (is_resource($this->result_id) OR
146 (get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id))))
Esen Sagynov2e087942011-08-09 23:35:01 -0700147 {
148 cubrid_close_request($this->result_id);
149 $this->result_id = FALSE;
150 }
151 }
152
153 // --------------------------------------------------------------------
154
155 /**
156 * Data Seek
157 *
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700158 * Moves the internal pointer to the desired offset. We call
Esen Sagynov2e087942011-08-09 23:35:01 -0700159 * this internally before fetching results to make sure the
160 * result set starts at zero
161 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700162 * @return array
163 */
Andrey Andreev7f55d612012-01-26 13:44:28 +0200164 protected function _data_seek($n = 0)
Esen Sagynov2e087942011-08-09 23:35:01 -0700165 {
166 return cubrid_data_seek($this->result_id, $n);
167 }
168
169 // --------------------------------------------------------------------
170
171 /**
172 * Result - associative array
173 *
174 * Returns the result set as an array
175 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700176 * @return array
177 */
Andrey Andreev7f55d612012-01-26 13:44:28 +0200178 protected function _fetch_assoc()
Esen Sagynov2e087942011-08-09 23:35:01 -0700179 {
180 return cubrid_fetch_assoc($this->result_id);
181 }
182
183 // --------------------------------------------------------------------
184
185 /**
186 * Result - object
187 *
188 * Returns the result set as an object
189 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700190 * @return object
191 */
Andrey Andreev7f55d612012-01-26 13:44:28 +0200192 protected function _fetch_object()
Esen Sagynov2e087942011-08-09 23:35:01 -0700193 {
194 return cubrid_fetch_object($this->result_id);
195 }
196
197}
198
Esen Sagynov2e087942011-08-09 23:35:01 -0700199/* End of file cubrid_result.php */
Andrey Andreev7f55d612012-01-26 13:44:28 +0200200/* Location: ./system/database/drivers/cubrid/cubrid_result.php */