Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [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 |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 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 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 28 | /** |
| 29 | * CUBRID Result Class |
| 30 | * |
| 31 | * This class extends the parent result class: CI_DB_result |
| 32 | * |
| 33 | * @category Database |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 34 | * @author Esen Sagynov |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/database/ |
| 36 | */ |
| 37 | class CI_DB_cubrid_result extends CI_DB_result { |
| 38 | |
| 39 | /** |
| 40 | * Number of rows in the result set |
| 41 | * |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 42 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 43 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 44 | public function num_rows() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 45 | { |
| 46 | return @cubrid_num_rows($this->result_id); |
| 47 | } |
| 48 | |
| 49 | // -------------------------------------------------------------------- |
| 50 | |
| 51 | /** |
| 52 | * Number of fields in the result set |
| 53 | * |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 54 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 55 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 56 | public function num_fields() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 57 | { |
| 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 Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 68 | * @return array |
| 69 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 70 | public function list_fields() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 71 | { |
| 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 Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 82 | * @return array |
| 83 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 84 | public function field_data() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 85 | { |
| 86 | $retval = array(); |
| 87 | |
| 88 | $tablePrimaryKeys = array(); |
| 89 | |
| 90 | while ($field = cubrid_fetch_field($this->result_id)) |
| 91 | { |
| 92 | $F = new stdClass(); |
| 93 | $F->name = $field->name; |
| 94 | $F->type = $field->type; |
| 95 | $F->default = $field->def; |
| 96 | $F->max_length = $field->max_length; |
| 97 | |
| 98 | // At this moment primary_key property is not returned when |
| 99 | // cubrid_fetch_field is called. The following code will |
| 100 | // provide a patch for it. primary_key property will be added |
| 101 | // in the next release. |
| 102 | |
| 103 | // TODO: later version of CUBRID will provide primary_key |
| 104 | // property. |
| 105 | // When PK is defined in CUBRID, an index is automatically |
| 106 | // created in the db_index system table in the form of |
| 107 | // pk_tblname_fieldname. So the following will count how many |
| 108 | // columns are there which satisfy this format. |
| 109 | // The query will search for exact single columns, thus |
| 110 | // compound PK is not supported. |
| 111 | $res = cubrid_query($this->conn_id, |
| 112 | "SELECT COUNT(*) FROM db_index WHERE class_name = '" . $field->table . |
| 113 | "' AND is_primary_key = 'YES' AND index_name = 'pk_" . |
| 114 | $field->table . "_" . $field->name . "'" |
| 115 | ); |
| 116 | |
| 117 | if ($res) |
| 118 | { |
| 119 | $row = cubrid_fetch_array($res, CUBRID_NUM); |
| 120 | $F->primary_key = ($row[0] > 0 ? 1 : null); |
| 121 | } |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 122 | else |
| 123 | { |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 124 | $F->primary_key = null; |
| 125 | } |
| 126 | |
| 127 | if (is_resource($res)) |
| 128 | { |
| 129 | cubrid_close_request($res); |
| 130 | $this->result_id = FALSE; |
| 131 | } |
| 132 | |
| 133 | $retval[] = $F; |
| 134 | } |
| 135 | |
| 136 | return $retval; |
| 137 | } |
| 138 | |
| 139 | // -------------------------------------------------------------------- |
| 140 | |
| 141 | /** |
| 142 | * Free the result |
| 143 | * |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 144 | * @return void |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 145 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 146 | public function free_result() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 147 | { |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 148 | if(is_resource($this->result_id) || |
| 149 | get_resource_type($this->result_id) == "Unknown" && |
| 150 | preg_match('/Resource id #/', strval($this->result_id))) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 151 | { |
| 152 | cubrid_close_request($this->result_id); |
| 153 | $this->result_id = FALSE; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // -------------------------------------------------------------------- |
| 158 | |
| 159 | /** |
| 160 | * Data Seek |
| 161 | * |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 162 | * Moves the internal pointer to the desired offset. We call |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 163 | * this internally before fetching results to make sure the |
| 164 | * result set starts at zero |
| 165 | * |
Andrey Andreev | 8f3566f | 2012-04-12 14:30:05 +0300 | [diff] [blame^] | 166 | * @return bool |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 167 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 168 | protected function _data_seek($n = 0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 169 | { |
| 170 | return cubrid_data_seek($this->result_id, $n); |
| 171 | } |
| 172 | |
| 173 | // -------------------------------------------------------------------- |
| 174 | |
| 175 | /** |
| 176 | * Result - associative array |
| 177 | * |
| 178 | * Returns the result set as an array |
| 179 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 180 | * @return array |
| 181 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 182 | protected function _fetch_assoc() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 183 | { |
| 184 | return cubrid_fetch_assoc($this->result_id); |
| 185 | } |
| 186 | |
| 187 | // -------------------------------------------------------------------- |
| 188 | |
| 189 | /** |
| 190 | * Result - object |
| 191 | * |
| 192 | * Returns the result set as an object |
| 193 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 194 | * @return object |
| 195 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 196 | protected function _fetch_object() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 197 | { |
| 198 | return cubrid_fetch_object($this->result_id); |
| 199 | } |
| 200 | |
| 201 | } |
| 202 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 203 | /* End of file cubrid_result.php */ |
| 204 | /* Location: ./system/database/drivers/cubrid/cubrid_result.php */ |