Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame^] | 1 | <?php |
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 |
Andrey Andreev | cf63120 | 2012-02-16 11:36:28 +0200 | [diff] [blame] | 24 | * @since Version 2.1 |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame^] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 28 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 29 | /** |
| 30 | * CUBRID Result Class |
| 31 | * |
| 32 | * This class extends the parent result class: CI_DB_result |
| 33 | * |
| 34 | * @category Database |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 35 | * @author Esen Sagynov |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 36 | * @link http://codeigniter.com/user_guide/database/ |
Andrey Andreev | c7db6bb | 2012-07-05 15:11:20 +0300 | [diff] [blame] | 37 | * @since 2.1 |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 38 | */ |
| 39 | class CI_DB_cubrid_result extends CI_DB_result { |
| 40 | |
| 41 | /** |
| 42 | * Number of rows in the result set |
| 43 | * |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 44 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 45 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 46 | public function num_rows() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 47 | { |
Andrey Andreev | c7db6bb | 2012-07-05 15:11:20 +0300 | [diff] [blame] | 48 | return is_int($this->num_rows) |
| 49 | ? $this->num_rows |
| 50 | : $this->num_rows = @cubrid_num_rows($this->result_id); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // -------------------------------------------------------------------- |
| 54 | |
| 55 | /** |
| 56 | * Number of fields in the result set |
| 57 | * |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 58 | * @return int |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 59 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 60 | public function num_fields() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 61 | { |
| 62 | return @cubrid_num_fields($this->result_id); |
| 63 | } |
| 64 | |
| 65 | // -------------------------------------------------------------------- |
| 66 | |
| 67 | /** |
| 68 | * Fetch Field Names |
| 69 | * |
| 70 | * Generates an array of column names |
| 71 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 72 | * @return array |
| 73 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 74 | public function list_fields() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 75 | { |
| 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 Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 86 | * @return array |
| 87 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 88 | public function field_data() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 89 | { |
| 90 | $retval = array(); |
Andrey Andreev | 394a3f1 | 2012-02-15 14:35:11 +0200 | [diff] [blame] | 91 | $i = 0; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 92 | |
| 93 | while ($field = cubrid_fetch_field($this->result_id)) |
| 94 | { |
Andrey Andreev | 394a3f1 | 2012-02-15 14:35:11 +0200 | [diff] [blame] | 95 | $retval[$i] = new stdClass(); |
| 96 | $retval[$i]->name = $field->name; |
| 97 | // CUBRID returns type as e.g. varchar(100), |
| 98 | // so we need to remove all digits and brackets. |
| 99 | $retval[$i]->type = preg_replace('/[\d()]/', '', $field->type); |
| 100 | $retval[$i]->default = $field->def; |
| 101 | // Use CUBRID's native API to obtain column's max_length, |
| 102 | // otherwise $field->max_length has incorrect info |
| 103 | $retval[$i]->max_length = cubrid_field_len($this->result_id, $i); |
| 104 | $retval[$i++]->primary_key = $field->primary_key; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | return $retval; |
| 108 | } |
| 109 | |
| 110 | // -------------------------------------------------------------------- |
| 111 | |
| 112 | /** |
| 113 | * Free the result |
| 114 | * |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 115 | * @return void |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 116 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 117 | public function free_result() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 118 | { |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 119 | if (is_resource($this->result_id) OR |
| 120 | (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] | 121 | { |
| 122 | cubrid_close_request($this->result_id); |
| 123 | $this->result_id = FALSE; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // -------------------------------------------------------------------- |
| 128 | |
| 129 | /** |
| 130 | * Data Seek |
| 131 | * |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 132 | * Moves the internal pointer to the desired offset. We call |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 133 | * this internally before fetching results to make sure the |
| 134 | * result set starts at zero |
| 135 | * |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 136 | * @param int $n = 0 |
Andrey Andreev | 8f3566f | 2012-04-12 14:30:05 +0300 | [diff] [blame] | 137 | * @return bool |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 138 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 139 | protected function _data_seek($n = 0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 140 | { |
| 141 | return cubrid_data_seek($this->result_id, $n); |
| 142 | } |
| 143 | |
| 144 | // -------------------------------------------------------------------- |
| 145 | |
| 146 | /** |
| 147 | * Result - associative array |
| 148 | * |
| 149 | * Returns the result set as an array |
| 150 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 151 | * @return array |
| 152 | */ |
Andrey Andreev | 32ed1cc | 2012-03-20 15:11:50 +0200 | [diff] [blame] | 153 | protected function _fetch_assoc() |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 154 | { |
| 155 | return cubrid_fetch_assoc($this->result_id); |
| 156 | } |
| 157 | |
| 158 | // -------------------------------------------------------------------- |
| 159 | |
| 160 | /** |
| 161 | * Result - object |
| 162 | * |
| 163 | * Returns the result set as an object |
| 164 | * |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 165 | * @param string |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 166 | * @return object |
| 167 | */ |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 168 | protected function _fetch_object($class_name = 'stdClass') |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 169 | { |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 170 | return cubrid_fetch_object($this->result_id, $class_name); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | } |
| 174 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 175 | /* End of file cubrid_result.php */ |
| 176 | /* Location: ./system/database/drivers/cubrid/cubrid_result.php */ |