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