blob: 4b51b355a6ce55e7f6c18a6b373de9230e0c1720 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Esen Sagynov2e087942011-08-09 23:35:01 -070028
Esen Sagynov2e087942011-08-09 23:35:01 -070029/**
30 * CUBRID Result Class
31 *
32 * This class extends the parent result class: CI_DB_result
33 *
34 * @category Database
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -070035 * @author Esen Sagynov
Esen Sagynov2e087942011-08-09 23:35:01 -070036 * @link http://codeigniter.com/user_guide/database/
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030037 * @since 2.1
Esen Sagynov2e087942011-08-09 23:35:01 -070038 */
39class CI_DB_cubrid_result extends CI_DB_result {
40
41 /**
42 * Number of rows in the result set
43 *
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020044 * @return int
Esen Sagynov2e087942011-08-09 23:35:01 -070045 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020046 public function num_rows()
Esen Sagynov2e087942011-08-09 23:35:01 -070047 {
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030048 return is_int($this->num_rows)
49 ? $this->num_rows
50 : $this->num_rows = @cubrid_num_rows($this->result_id);
Esen Sagynov2e087942011-08-09 23:35:01 -070051 }
52
53 // --------------------------------------------------------------------
54
55 /**
56 * Number of fields in the result set
57 *
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020058 * @return int
Esen Sagynov2e087942011-08-09 23:35:01 -070059 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020060 public function num_fields()
Esen Sagynov2e087942011-08-09 23:35:01 -070061 {
62 return @cubrid_num_fields($this->result_id);
63 }
64
65 // --------------------------------------------------------------------
66
67 /**
68 * Fetch Field Names
69 *
70 * Generates an array of column names
71 *
Esen Sagynov2e087942011-08-09 23:35:01 -070072 * @return array
73 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020074 public function list_fields()
Esen Sagynov2e087942011-08-09 23:35:01 -070075 {
76 return cubrid_column_names($this->result_id);
77 }
78
79 // --------------------------------------------------------------------
80
81 /**
82 * Field data
83 *
84 * Generates an array of objects containing field meta-data
85 *
Esen Sagynov2e087942011-08-09 23:35:01 -070086 * @return array
87 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +020088 public function field_data()
Esen Sagynov2e087942011-08-09 23:35:01 -070089 {
90 $retval = array();
Andrey Andreev394a3f12012-02-15 14:35:11 +020091 $i = 0;
Esen Sagynov2e087942011-08-09 23:35:01 -070092
93 while ($field = cubrid_fetch_field($this->result_id))
94 {
Andrey Andreev394a3f12012-02-15 14:35:11 +020095 $retval[$i] = new stdClass();
96 $retval[$i]->name = $field->name;
97 // CUBRID returns type as e.g. varchar(100),
98 // so we need to remove all digits and brackets.
99 $retval[$i]->type = preg_replace('/[\d()]/', '', $field->type);
100 $retval[$i]->default = $field->def;
101 // Use CUBRID's native API to obtain column's max_length,
102 // otherwise $field->max_length has incorrect info
103 $retval[$i]->max_length = cubrid_field_len($this->result_id, $i);
104 $retval[$i++]->primary_key = $field->primary_key;
Esen Sagynov2e087942011-08-09 23:35:01 -0700105 }
106
107 return $retval;
108 }
109
110 // --------------------------------------------------------------------
111
112 /**
113 * Free the result
114 *
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200115 * @return void
Esen Sagynov2e087942011-08-09 23:35:01 -0700116 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200117 public function free_result()
Esen Sagynov2e087942011-08-09 23:35:01 -0700118 {
Andrey Andreev7f55d612012-01-26 13:44:28 +0200119 if (is_resource($this->result_id) OR
120 (get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id))))
Esen Sagynov2e087942011-08-09 23:35:01 -0700121 {
122 cubrid_close_request($this->result_id);
123 $this->result_id = FALSE;
124 }
125 }
126
127 // --------------------------------------------------------------------
128
129 /**
130 * Data Seek
131 *
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700132 * Moves the internal pointer to the desired offset. We call
Esen Sagynov2e087942011-08-09 23:35:01 -0700133 * this internally before fetching results to make sure the
134 * result set starts at zero
135 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300136 * @param int $n = 0
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300137 * @return bool
Esen Sagynov2e087942011-08-09 23:35:01 -0700138 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200139 protected function _data_seek($n = 0)
Esen Sagynov2e087942011-08-09 23:35:01 -0700140 {
141 return cubrid_data_seek($this->result_id, $n);
142 }
143
144 // --------------------------------------------------------------------
145
146 /**
147 * Result - associative array
148 *
149 * Returns the result set as an array
150 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700151 * @return array
152 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200153 protected function _fetch_assoc()
Esen Sagynov2e087942011-08-09 23:35:01 -0700154 {
155 return cubrid_fetch_assoc($this->result_id);
156 }
157
158 // --------------------------------------------------------------------
159
160 /**
161 * Result - object
162 *
163 * Returns the result set as an object
164 *
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300165 * @param string
Esen Sagynov2e087942011-08-09 23:35:01 -0700166 * @return object
167 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300168 protected function _fetch_object($class_name = 'stdClass')
Esen Sagynov2e087942011-08-09 23:35:01 -0700169 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300170 return cubrid_fetch_object($this->result_id, $class_name);
Esen Sagynov2e087942011-08-09 23:35:01 -0700171 }
172
173}
174
Esen Sagynov2e087942011-08-09 23:35:01 -0700175/* End of file cubrid_result.php */
176/* Location: ./system/database/drivers/cubrid/cubrid_result.php */