Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [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 |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 6 | * |
| 7 | * NOTICE OF LICENSE |
Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 8 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 10 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -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 | * |
| 19 | * @package CodeIgniter |
| 20 | * @author EllisLab Dev Team |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
| 23 | * @link http://codeigniter.com |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 24 | * @since Version 1.0 |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [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'); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 28 | |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 29 | /** |
| 30 | * Interbase/Firebird Result Class |
| 31 | * |
| 32 | * This class extends the parent result class: CI_DB_result |
| 33 | * |
| 34 | * @category Database |
| 35 | * @author EllisLab Dev Team |
| 36 | * @link http://codeigniter.com/user_guide/database/ |
Andrey Andreev | 5ca0513 | 2012-07-05 12:06:34 +0300 | [diff] [blame] | 37 | * @since 3.0 |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 38 | */ |
Andrey Andreev | 2608687 | 2012-07-05 11:21:58 +0300 | [diff] [blame] | 39 | class CI_DB_ibase_result extends CI_DB_result { |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 40 | |
| 41 | /** |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 42 | * Number of fields in the result set |
| 43 | * |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 44 | * @return int |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 45 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 46 | public function num_fields() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 47 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame^] | 48 | return ibase_num_fields($this->result_id); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | // -------------------------------------------------------------------- |
| 52 | |
| 53 | /** |
| 54 | * Fetch Field Names |
| 55 | * |
| 56 | * Generates an array of column names |
| 57 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 58 | * @return array |
| 59 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 60 | public function list_fields() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 61 | { |
| 62 | $field_names = array(); |
Timothy Warren | 2da66ed | 2012-02-20 17:54:39 -0500 | [diff] [blame] | 63 | for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 64 | { |
| 65 | $info = ibase_field_info($this->result_id, $i); |
| 66 | $field_names[] = $info['name']; |
| 67 | } |
| 68 | |
| 69 | return $field_names; |
| 70 | } |
| 71 | |
| 72 | // -------------------------------------------------------------------- |
| 73 | |
| 74 | /** |
| 75 | * Field data |
| 76 | * |
| 77 | * Generates an array of objects containing field meta-data |
| 78 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 79 | * @return array |
| 80 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 81 | public function field_data() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 82 | { |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 83 | $retval = array(); |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 84 | for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 85 | { |
| 86 | $info = ibase_field_info($this->result_id, $i); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 87 | |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 88 | $retval[$i] = new stdClass(); |
| 89 | $retval[$i]->name = $info['name']; |
| 90 | $retval[$i]->type = $info['type']; |
| 91 | $retval[$i]->max_length = $info['length']; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | return $retval; |
| 95 | } |
| 96 | |
| 97 | // -------------------------------------------------------------------- |
| 98 | |
| 99 | /** |
| 100 | * Free the result |
| 101 | * |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 102 | * @return void |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 103 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 104 | public function free_result() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 105 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame^] | 106 | ibase_free_result($this->result_id); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | // -------------------------------------------------------------------- |
| 110 | |
| 111 | /** |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 112 | * Result - associative array |
| 113 | * |
| 114 | * Returns the result set as an array |
| 115 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 116 | * @return array |
| 117 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 118 | protected function _fetch_assoc() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 119 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame^] | 120 | return ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | // -------------------------------------------------------------------- |
| 124 | |
| 125 | /** |
| 126 | * Result - object |
| 127 | * |
| 128 | * Returns the result set as an object |
| 129 | * |
Andrey Andreev | 8463b91 | 2012-11-02 02:16:28 +0200 | [diff] [blame] | 130 | * @param string $class_name |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 131 | * @return object |
| 132 | */ |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 133 | protected function _fetch_object($class_name = 'stdClass') |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 134 | { |
Andrey Andreev | 2bbbd1a | 2014-05-09 10:24:14 +0300 | [diff] [blame^] | 135 | $row = ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS); |
Andrey Andreev | 9a4f356 | 2012-07-06 11:57:37 +0300 | [diff] [blame] | 136 | |
| 137 | if ($class_name === 'stdClass' OR ! $row) |
| 138 | { |
| 139 | return $row; |
| 140 | } |
| 141 | |
| 142 | $class_name = new $class_name(); |
| 143 | foreach ($row as $key => $value) |
| 144 | { |
| 145 | $class_name->$key = $value; |
| 146 | } |
| 147 | |
| 148 | return $class_name; |
Timothy Warren | 3a4cdc6 | 2012-02-17 13:59:44 -0500 | [diff] [blame] | 149 | } |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 150 | |
| 151 | } |
| 152 | |
Andrey Andreev | 2608687 | 2012-07-05 11:21:58 +0300 | [diff] [blame] | 153 | /* End of file ibase_result.php */ |
| 154 | /* Location: ./system/database/drivers/ibase/ibase_result.php */ |