blob: d2bdeb0f5ef32c3e1fea533260a45af0c3476b45 [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
darwinel871754a2014-02-11 17:34:57 +010021 * @copyright Copyright (c) 2008 - 2014, 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
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +030050 : $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 {
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +030062 return cubrid_num_fields($this->result_id);
Esen Sagynov2e087942011-08-09 23:35:01 -070063 }
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();
Esen Sagynov2e087942011-08-09 23:35:01 -070091
Andrey Andreev10ecc842012-11-16 01:06:20 +020092 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Esen Sagynov2e087942011-08-09 23:35:01 -070093 {
Andrey Andreev394a3f12012-02-15 14:35:11 +020094 $retval[$i] = new stdClass();
Andrey Andreev10ecc842012-11-16 01:06:20 +020095 $retval[$i]->name = cubrid_field_name($this->result_id, $i);
96 $retval[$i]->type = cubrid_field_type($this->result_id, $i);
Andrey Andreev394a3f12012-02-15 14:35:11 +020097 $retval[$i]->max_length = cubrid_field_len($this->result_id, $i);
Andrey Andreev10ecc842012-11-16 01:06:20 +020098 $retval[$i]->primary_key = (int) (strpos(cubrid_field_flags($this->result_id, $i), 'primary_key') !== FALSE);
Esen Sagynov2e087942011-08-09 23:35:01 -070099 }
100
101 return $retval;
102 }
103
104 // --------------------------------------------------------------------
105
106 /**
107 * Free the result
108 *
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200109 * @return void
Esen Sagynov2e087942011-08-09 23:35:01 -0700110 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200111 public function free_result()
Esen Sagynov2e087942011-08-09 23:35:01 -0700112 {
Andrey Andreev7f55d612012-01-26 13:44:28 +0200113 if (is_resource($this->result_id) OR
114 (get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id))))
Esen Sagynov2e087942011-08-09 23:35:01 -0700115 {
116 cubrid_close_request($this->result_id);
117 $this->result_id = FALSE;
118 }
119 }
120
121 // --------------------------------------------------------------------
122
123 /**
124 * Data Seek
125 *
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -0700126 * Moves the internal pointer to the desired offset. We call
Esen Sagynov2e087942011-08-09 23:35:01 -0700127 * this internally before fetching results to make sure the
Andrey Andreev8463b912012-11-02 02:16:28 +0200128 * result set starts at zero.
Esen Sagynov2e087942011-08-09 23:35:01 -0700129 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200130 * @param int $n
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300131 * @return bool
Esen Sagynov2e087942011-08-09 23:35:01 -0700132 */
Andrey Andreev69edc432012-12-04 13:32:16 +0200133 public function data_seek($n = 0)
Esen Sagynov2e087942011-08-09 23:35:01 -0700134 {
135 return cubrid_data_seek($this->result_id, $n);
136 }
137
138 // --------------------------------------------------------------------
139
140 /**
141 * Result - associative array
142 *
143 * Returns the result set as an array
144 *
Esen Sagynov2e087942011-08-09 23:35:01 -0700145 * @return array
146 */
Andrey Andreev32ed1cc2012-03-20 15:11:50 +0200147 protected function _fetch_assoc()
Esen Sagynov2e087942011-08-09 23:35:01 -0700148 {
149 return cubrid_fetch_assoc($this->result_id);
150 }
151
152 // --------------------------------------------------------------------
153
154 /**
155 * Result - object
156 *
157 * Returns the result set as an object
158 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200159 * @param string $class_name
Esen Sagynov2e087942011-08-09 23:35:01 -0700160 * @return object
161 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300162 protected function _fetch_object($class_name = 'stdClass')
Esen Sagynov2e087942011-08-09 23:35:01 -0700163 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300164 return cubrid_fetch_object($this->result_id, $class_name);
Esen Sagynov2e087942011-08-09 23:35:01 -0700165 }
166
167}
168
Esen Sagynov2e087942011-08-09 23:35:01 -0700169/* End of file cubrid_result.php */
170/* Location: ./system/database/drivers/cubrid/cubrid_result.php */