Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +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 | * |
| 5 | * An open source application development framework for PHP 5.1.6 or newer |
| 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +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 | 7f55d61 | 2012-01-26 13:44:28 +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 | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 42 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 43 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +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 | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 54 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 55 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +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 | 7f55d61 | 2012-01-26 13:44:28 +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 | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 84 | public function field_data() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 85 | { |
Andrey Andreev | 394a3f1 | 2012-02-15 14:35:11 +0200 | [diff] [blame^] | 86 | $retval = array(); |
| 87 | $i = 0; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 88 | |
| 89 | while ($field = cubrid_fetch_field($this->result_id)) |
| 90 | { |
Andrey Andreev | 394a3f1 | 2012-02-15 14:35:11 +0200 | [diff] [blame^] | 91 | $retval[$i] = new stdClass(); |
| 92 | $retval[$i]->name = $field->name; |
| 93 | // CUBRID returns type as e.g. varchar(100), |
| 94 | // so we need to remove all digits and brackets. |
| 95 | $retval[$i]->type = preg_replace('/[\d()]/', '', $field->type); |
| 96 | $retval[$i]->default = $field->def; |
| 97 | // Use CUBRID's native API to obtain column's max_length, |
| 98 | // otherwise $field->max_length has incorrect info |
| 99 | $retval[$i]->max_length = cubrid_field_len($this->result_id, $i); |
| 100 | $retval[$i++]->primary_key = $field->primary_key; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | return $retval; |
| 104 | } |
| 105 | |
| 106 | // -------------------------------------------------------------------- |
| 107 | |
| 108 | /** |
| 109 | * Free the result |
| 110 | * |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 111 | * @return void |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 112 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 113 | public function free_result() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 114 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 115 | if (is_resource($this->result_id) OR |
| 116 | (get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id)))) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 117 | { |
| 118 | cubrid_close_request($this->result_id); |
| 119 | $this->result_id = FALSE; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // -------------------------------------------------------------------- |
| 124 | |
| 125 | /** |
| 126 | * Data Seek |
| 127 | * |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 128 | * Moves the internal pointer to the desired offset. We call |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 129 | * this internally before fetching results to make sure the |
| 130 | * result set starts at zero |
| 131 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 132 | * @return array |
| 133 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 134 | protected function _data_seek($n = 0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 135 | { |
| 136 | return cubrid_data_seek($this->result_id, $n); |
| 137 | } |
| 138 | |
| 139 | // -------------------------------------------------------------------- |
| 140 | |
| 141 | /** |
| 142 | * Result - associative array |
| 143 | * |
| 144 | * Returns the result set as an array |
| 145 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 146 | * @return array |
| 147 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 148 | protected function _fetch_assoc() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 149 | { |
| 150 | return cubrid_fetch_assoc($this->result_id); |
| 151 | } |
| 152 | |
| 153 | // -------------------------------------------------------------------- |
| 154 | |
| 155 | /** |
| 156 | * Result - object |
| 157 | * |
| 158 | * Returns the result set as an object |
| 159 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 160 | * @return object |
| 161 | */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 162 | protected function _fetch_object() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 163 | { |
| 164 | return cubrid_fetch_object($this->result_id); |
| 165 | } |
| 166 | |
| 167 | } |
| 168 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 169 | /* End of file cubrid_result.php */ |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 170 | /* Location: ./system/database/drivers/cubrid/cubrid_result.php */ |