blob: 4a06a2d39d046174f825423c270decbcaca64d42 [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
Andrey Andreevcf631202012-02-16 11:36:28 +020024 * @since Version 2.1
Esen Sagynov2e087942011-08-09 23:35:01 -070025 * @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/
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030036 * @since 2.1
Esen Sagynov2e087942011-08-09 23:35:01 -070037 */
38class CI_DB_cubrid_result extends CI_DB_result {
39
40 /**
41 * Number of rows in the result set
42 *
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020043 * @return int
Esen Sagynov2e087942011-08-09 23:35:01 -070044 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020045 public function num_rows()
Esen Sagynov2e087942011-08-09 23:35:01 -070046 {
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030047 return is_int($this->num_rows)
48 ? $this->num_rows
49 : $this->num_rows = @cubrid_num_rows($this->result_id);
Esen Sagynov2e087942011-08-09 23:35:01 -070050 }
51
52 // --------------------------------------------------------------------
53
54 /**
55 * Number of fields in the result set
56 *
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020057 * @return int
Esen Sagynov2e087942011-08-09 23:35:01 -070058 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020059 public function num_fields()
Esen Sagynov2e087942011-08-09 23:35:01 -070060 {
61 return @cubrid_num_fields($this->result_id);
62 }
63
64 // --------------------------------------------------------------------
65
66 /**
67 * Fetch Field Names
68 *
69 * Generates an array of column names
70 *
Esen Sagynov2e087942011-08-09 23:35:01 -070071 * @return array
72 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020073 public function list_fields()
Esen Sagynov2e087942011-08-09 23:35:01 -070074 {
75 return cubrid_column_names($this->result_id);
76 }
77
78 // --------------------------------------------------------------------
79
80 /**
81 * Field data
82 *
83 * Generates an array of objects containing field meta-data
84 *
Esen Sagynov2e087942011-08-09 23:35:01 -070085 * @return array
86 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020087 public function field_data()
Esen Sagynov2e087942011-08-09 23:35:01 -070088 {
89 $retval = array();
Andrey Andreev394a3f12012-02-15 14:35:11 +020090 $i = 0;
Esen Sagynov2e087942011-08-09 23:35:01 -070091
92 while ($field = cubrid_fetch_field($this->result_id))
93 {
Andrey Andreev394a3f12012-02-15 14:35:11 +020094 $retval[$i] = new stdClass();
95 $retval[$i]->name = $field->name;
96 // CUBRID returns type as e.g. varchar(100),
97 // so we need to remove all digits and brackets.
98 $retval[$i]->type = preg_replace('/[\d()]/', '', $field->type);
99 $retval[$i]->default = $field->def;
100 // Use CUBRID's native API to obtain column's max_length,
101 // otherwise $field->max_length has incorrect info
102 $retval[$i]->max_length = cubrid_field_len($this->result_id, $i);
103 $retval[$i++]->primary_key = $field->primary_key;
Esen Sagynov2e087942011-08-09 23:35:01 -0700104 }
105
106 return $retval;
107 }
108
109 // --------------------------------------------------------------------
110
111 /**
112 * Free the result
113 *
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200114 * @return void
Esen Sagynov2e087942011-08-09 23:35:01 -0700115 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200116 public function free_result()
Esen Sagynov2e087942011-08-09 23:35:01 -0700117 {
Andrey Andreev7f55d612012-01-26 13:44:28 +0200118 if (is_resource($this->result_id) OR
119 (get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id))))
Esen Sagynov2e087942011-08-09 23:35:01 -0700120 {
121 cubrid_close_request($this->result_id);
122 $this->result_id = FALSE;
123 }
124 }
125
126 // --------------------------------------------------------------------
127
128 /**
129 * Data Seek
130 *
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700131 * Moves the internal pointer to the desired offset. We call
Esen Sagynov2e087942011-08-09 23:35:01 -0700132 * this internally before fetching results to make sure the
133 * result set starts at zero
134 *
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300135 * @return bool
Esen Sagynov2e087942011-08-09 23:35:01 -0700136 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200137 protected function _data_seek($n = 0)
Esen Sagynov2e087942011-08-09 23:35:01 -0700138 {
139 return cubrid_data_seek($this->result_id, $n);
140 }
141
142 // --------------------------------------------------------------------
143
144 /**
145 * Result - associative array
146 *
147 * Returns the result set as an array
148 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700149 * @return array
150 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200151 protected function _fetch_assoc()
Esen Sagynov2e087942011-08-09 23:35:01 -0700152 {
153 return cubrid_fetch_assoc($this->result_id);
154 }
155
156 // --------------------------------------------------------------------
157
158 /**
159 * Result - object
160 *
161 * Returns the result set as an object
162 *
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300163 * @param string
Esen Sagynov2e087942011-08-09 23:35:01 -0700164 * @return object
165 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300166 protected function _fetch_object($class_name = 'stdClass')
Esen Sagynov2e087942011-08-09 23:35:01 -0700167 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300168 return cubrid_fetch_object($this->result_id, $class_name);
Esen Sagynov2e087942011-08-09 23:35:01 -0700169 }
170
171}
172
Esen Sagynov2e087942011-08-09 23:35:01 -0700173/* End of file cubrid_result.php */
174/* Location: ./system/database/drivers/cubrid/cubrid_result.php */