blob: 3351b34309438622be6d2f26a15aa4f8bc7b706b [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 Andreev394a3f12012-02-15 14:35:11 +020086 $retval = array();
87 $i = 0;
Esen Sagynov2e087942011-08-09 23:35:01 -070088
89 while ($field = cubrid_fetch_field($this->result_id))
90 {
Andrey Andreev394a3f12012-02-15 14:35:11 +020091 $retval[$i] = new stdClass();
92 $retval[$i]->name = $field->name;
93 // CUBRID returns type as e.g. varchar(100),
94 // so we need to remove all digits and brackets.
95 $retval[$i]->type = preg_replace('/[\d()]/', '', $field->type);
96 $retval[$i]->default = $field->def;
97 // Use CUBRID's native API to obtain column's max_length,
98 // otherwise $field->max_length has incorrect info
99 $retval[$i]->max_length = cubrid_field_len($this->result_id, $i);
100 $retval[$i++]->primary_key = $field->primary_key;
Esen Sagynov2e087942011-08-09 23:35:01 -0700101 }
102
103 return $retval;
104 }
105
106 // --------------------------------------------------------------------
107
108 /**
109 * Free the result
110 *
Andrey Andreev7f55d612012-01-26 13:44:28 +0200111 * @return void
Esen Sagynov2e087942011-08-09 23:35:01 -0700112 */
Andrey Andreev7f55d612012-01-26 13:44:28 +0200113 public function free_result()
Esen Sagynov2e087942011-08-09 23:35:01 -0700114 {
Andrey Andreev7f55d612012-01-26 13:44:28 +0200115 if (is_resource($this->result_id) OR
116 (get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id))))
Esen Sagynov2e087942011-08-09 23:35:01 -0700117 {
118 cubrid_close_request($this->result_id);
119 $this->result_id = FALSE;
120 }
121 }
122
123 // --------------------------------------------------------------------
124
125 /**
126 * Data Seek
127 *
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700128 * Moves the internal pointer to the desired offset. We call
Esen Sagynov2e087942011-08-09 23:35:01 -0700129 * this internally before fetching results to make sure the
130 * result set starts at zero
131 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700132 * @return array
133 */
Andrey Andreev7f55d612012-01-26 13:44:28 +0200134 protected function _data_seek($n = 0)
Esen Sagynov2e087942011-08-09 23:35:01 -0700135 {
136 return cubrid_data_seek($this->result_id, $n);
137 }
138
139 // --------------------------------------------------------------------
140
141 /**
142 * Result - associative array
143 *
144 * Returns the result set as an array
145 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700146 * @return array
147 */
Andrey Andreev7f55d612012-01-26 13:44:28 +0200148 protected function _fetch_assoc()
Esen Sagynov2e087942011-08-09 23:35:01 -0700149 {
150 return cubrid_fetch_assoc($this->result_id);
151 }
152
153 // --------------------------------------------------------------------
154
155 /**
156 * Result - object
157 *
158 * Returns the result set as an object
159 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700160 * @return object
161 */
Andrey Andreev7f55d612012-01-26 13:44:28 +0200162 protected function _fetch_object()
Esen Sagynov2e087942011-08-09 23:35:01 -0700163 {
164 return cubrid_fetch_object($this->result_id);
165 }
166
167}
168
Esen Sagynov2e087942011-08-09 23:35:01 -0700169/* End of file cubrid_result.php */
Andrey Andreev7f55d612012-01-26 13:44:28 +0200170/* Location: ./system/database/drivers/cubrid/cubrid_result.php */