Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * 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 Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 2.0.2 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
| 28 | // -------------------------------------------------------------------- |
| 29 | |
| 30 | /** |
| 31 | * CUBRID Result Class |
| 32 | * |
| 33 | * This class extends the parent result class: CI_DB_result |
| 34 | * |
| 35 | * @category Database |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 36 | * @author Esen Sagynov |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/database/ |
| 38 | */ |
| 39 | class CI_DB_cubrid_result extends CI_DB_result { |
| 40 | |
| 41 | /** |
| 42 | * Number of rows in the result set |
| 43 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 44 | * @return integer |
| 45 | */ |
Timothy Warren | f83f0d5 | 2012-03-19 17:38:30 -0400 | [diff] [blame] | 46 | public function num_rows() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 47 | { |
| 48 | return @cubrid_num_rows($this->result_id); |
| 49 | } |
| 50 | |
| 51 | // -------------------------------------------------------------------- |
| 52 | |
| 53 | /** |
| 54 | * Number of fields in the result set |
| 55 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 56 | * @return integer |
| 57 | */ |
Timothy Warren | f83f0d5 | 2012-03-19 17:38:30 -0400 | [diff] [blame] | 58 | public function num_fields() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 59 | { |
| 60 | return @cubrid_num_fields($this->result_id); |
| 61 | } |
| 62 | |
| 63 | // -------------------------------------------------------------------- |
| 64 | |
| 65 | /** |
| 66 | * Fetch Field Names |
| 67 | * |
| 68 | * Generates an array of column names |
| 69 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 70 | * @return array |
| 71 | */ |
Timothy Warren | f83f0d5 | 2012-03-19 17:38:30 -0400 | [diff] [blame] | 72 | public function list_fields() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 73 | { |
| 74 | return cubrid_column_names($this->result_id); |
| 75 | } |
| 76 | |
| 77 | // -------------------------------------------------------------------- |
| 78 | |
| 79 | /** |
| 80 | * Field data |
| 81 | * |
| 82 | * Generates an array of objects containing field meta-data |
| 83 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 84 | * @return array |
| 85 | */ |
Timothy Warren | f83f0d5 | 2012-03-19 17:38:30 -0400 | [diff] [blame] | 86 | public function field_data() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 87 | { |
| 88 | $retval = array(); |
| 89 | |
| 90 | $tablePrimaryKeys = array(); |
| 91 | |
| 92 | while ($field = cubrid_fetch_field($this->result_id)) |
| 93 | { |
| 94 | $F = new stdClass(); |
| 95 | $F->name = $field->name; |
| 96 | $F->type = $field->type; |
| 97 | $F->default = $field->def; |
| 98 | $F->max_length = $field->max_length; |
| 99 | |
| 100 | // At this moment primary_key property is not returned when |
| 101 | // cubrid_fetch_field is called. The following code will |
| 102 | // provide a patch for it. primary_key property will be added |
| 103 | // in the next release. |
| 104 | |
| 105 | // TODO: later version of CUBRID will provide primary_key |
| 106 | // property. |
| 107 | // When PK is defined in CUBRID, an index is automatically |
| 108 | // created in the db_index system table in the form of |
| 109 | // pk_tblname_fieldname. So the following will count how many |
| 110 | // columns are there which satisfy this format. |
| 111 | // The query will search for exact single columns, thus |
| 112 | // compound PK is not supported. |
| 113 | $res = cubrid_query($this->conn_id, |
| 114 | "SELECT COUNT(*) FROM db_index WHERE class_name = '" . $field->table . |
| 115 | "' AND is_primary_key = 'YES' AND index_name = 'pk_" . |
| 116 | $field->table . "_" . $field->name . "'" |
| 117 | ); |
| 118 | |
| 119 | if ($res) |
| 120 | { |
| 121 | $row = cubrid_fetch_array($res, CUBRID_NUM); |
| 122 | $F->primary_key = ($row[0] > 0 ? 1 : null); |
| 123 | } |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 124 | else |
| 125 | { |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 126 | $F->primary_key = null; |
| 127 | } |
| 128 | |
| 129 | if (is_resource($res)) |
| 130 | { |
| 131 | cubrid_close_request($res); |
| 132 | $this->result_id = FALSE; |
| 133 | } |
| 134 | |
| 135 | $retval[] = $F; |
| 136 | } |
| 137 | |
| 138 | return $retval; |
| 139 | } |
| 140 | |
| 141 | // -------------------------------------------------------------------- |
| 142 | |
| 143 | /** |
| 144 | * Free the result |
| 145 | * |
| 146 | * @return null |
| 147 | */ |
Timothy Warren | f83f0d5 | 2012-03-19 17:38:30 -0400 | [diff] [blame] | 148 | public function free_result() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 149 | { |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 150 | if(is_resource($this->result_id) || |
| 151 | get_resource_type($this->result_id) == "Unknown" && |
| 152 | preg_match('/Resource id #/', strval($this->result_id))) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 153 | { |
| 154 | cubrid_close_request($this->result_id); |
| 155 | $this->result_id = FALSE; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // -------------------------------------------------------------------- |
| 160 | |
| 161 | /** |
| 162 | * Data Seek |
| 163 | * |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 164 | * Moves the internal pointer to the desired offset. We call |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 165 | * this internally before fetching results to make sure the |
| 166 | * result set starts at zero |
| 167 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 168 | * @return array |
| 169 | */ |
Timothy Warren | f83f0d5 | 2012-03-19 17:38:30 -0400 | [diff] [blame] | 170 | protected function _data_seek($n = 0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 171 | { |
| 172 | return cubrid_data_seek($this->result_id, $n); |
| 173 | } |
| 174 | |
| 175 | // -------------------------------------------------------------------- |
| 176 | |
| 177 | /** |
| 178 | * Result - associative array |
| 179 | * |
| 180 | * Returns the result set as an array |
| 181 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 182 | * @return array |
| 183 | */ |
Timothy Warren | f83f0d5 | 2012-03-19 17:38:30 -0400 | [diff] [blame] | 184 | protected function _fetch_assoc() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 185 | { |
| 186 | return cubrid_fetch_assoc($this->result_id); |
| 187 | } |
| 188 | |
| 189 | // -------------------------------------------------------------------- |
| 190 | |
| 191 | /** |
| 192 | * Result - object |
| 193 | * |
| 194 | * Returns the result set as an object |
| 195 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 196 | * @return object |
| 197 | */ |
Timothy Warren | f83f0d5 | 2012-03-19 17:38:30 -0400 | [diff] [blame] | 198 | protected function _fetch_object() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 199 | { |
| 200 | return cubrid_fetch_object($this->result_id); |
| 201 | } |
| 202 | |
| 203 | } |
| 204 | |
| 205 | |
| 206 | /* End of file cubrid_result.php */ |
| 207 | /* Location: ./system/database/drivers/cubrid/cubrid_result.php */ |