blob: 95e55710bc605250158c28dbaa07ac04c76e002b [file] [log] [blame]
Timothy Warren817af192012-02-16 08:28:00 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Timothy Warren76e04352012-02-14 11:55:17 -05002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Timothy Warren76e04352012-02-14 11:55:17 -05006 *
7 * NOTICE OF LICENSE
Timothy Warren817af192012-02-16 08:28:00 -05008 *
Timothy Warren76e04352012-02-14 11:55:17 -05009 * Licensed under the Open Software License version 3.0
Timothy Warren817af192012-02-16 08:28:00 -050010 *
Timothy Warren76e04352012-02-14 11:55:17 -050011 * 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
21 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
23 * @link http://codeigniter.com
Andrey Andreev5ca05132012-07-05 12:06:34 +030024 * @since Version 1.0
Timothy Warren76e04352012-02-14 11:55:17 -050025 * @filesource
26 */
27
Timothy Warren76e04352012-02-14 11:55:17 -050028/**
29 * Interbase/Firebird Result Class
30 *
31 * This class extends the parent result class: CI_DB_result
32 *
33 * @category Database
34 * @author EllisLab Dev Team
35 * @link http://codeigniter.com/user_guide/database/
Andrey Andreev5ca05132012-07-05 12:06:34 +030036 * @since 3.0
Timothy Warren76e04352012-02-14 11:55:17 -050037 */
Andrey Andreev26086872012-07-05 11:21:58 +030038class CI_DB_ibase_result extends CI_DB_result {
Timothy Warren76e04352012-02-14 11:55:17 -050039
40 /**
Timothy Warren76e04352012-02-14 11:55:17 -050041 * Number of fields in the result set
42 *
Andrey Andreev60c9c992012-03-20 23:46:09 +020043 * @return int
Timothy Warren76e04352012-02-14 11:55:17 -050044 */
Timothy Warren4be822b2012-02-14 12:07:34 -050045 public function num_fields()
Timothy Warren76e04352012-02-14 11:55:17 -050046 {
47 return @ibase_num_fields($this->result_id);
48 }
49
50 // --------------------------------------------------------------------
51
52 /**
53 * Fetch Field Names
54 *
55 * Generates an array of column names
56 *
Timothy Warren76e04352012-02-14 11:55:17 -050057 * @return array
58 */
Timothy Warren4be822b2012-02-14 12:07:34 -050059 public function list_fields()
Timothy Warren76e04352012-02-14 11:55:17 -050060 {
61 $field_names = array();
Timothy Warren2da66ed2012-02-20 17:54:39 -050062 for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++)
Timothy Warren76e04352012-02-14 11:55:17 -050063 {
64 $info = ibase_field_info($this->result_id, $i);
65 $field_names[] = $info['name'];
66 }
67
68 return $field_names;
69 }
70
71 // --------------------------------------------------------------------
72
73 /**
74 * Field data
75 *
76 * Generates an array of objects containing field meta-data
77 *
Timothy Warren76e04352012-02-14 11:55:17 -050078 * @return array
79 */
Timothy Warren4be822b2012-02-14 12:07:34 -050080 public function field_data()
Timothy Warren76e04352012-02-14 11:55:17 -050081 {
Timothy Warren76e04352012-02-14 11:55:17 -050082 $retval = array();
Andrey Andreev60c9c992012-03-20 23:46:09 +020083 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Timothy Warren76e04352012-02-14 11:55:17 -050084 {
85 $info = ibase_field_info($this->result_id, $i);
Timothy Warren76e04352012-02-14 11:55:17 -050086
Andrey Andreev60c9c992012-03-20 23:46:09 +020087 $retval[$i] = new stdClass();
88 $retval[$i]->name = $info['name'];
89 $retval[$i]->type = $info['type'];
90 $retval[$i]->max_length = $info['length'];
91 $retval[$i]->primary_key = 0;
92 $retval[$i]->default = '';
Timothy Warren76e04352012-02-14 11:55:17 -050093 }
94
95 return $retval;
96 }
97
98 // --------------------------------------------------------------------
99
100 /**
101 * Free the result
102 *
Andrey Andreev60c9c992012-03-20 23:46:09 +0200103 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500104 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500105 public function free_result()
Timothy Warren76e04352012-02-14 11:55:17 -0500106 {
107 @ibase_free_result($this->result_id);
108 }
109
110 // --------------------------------------------------------------------
111
112 /**
Timothy Warren76e04352012-02-14 11:55:17 -0500113 * Result - associative array
114 *
115 * Returns the result set as an array
116 *
Timothy Warren76e04352012-02-14 11:55:17 -0500117 * @return array
118 */
Timothy Warren95562142012-02-20 17:37:21 -0500119 protected function _fetch_assoc()
Timothy Warren76e04352012-02-14 11:55:17 -0500120 {
Andrey Andreevc7db6bb2012-07-05 15:11:20 +0300121 return @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS);
Timothy Warren76e04352012-02-14 11:55:17 -0500122 }
123
124 // --------------------------------------------------------------------
125
126 /**
127 * Result - object
128 *
129 * Returns the result set as an object
130 *
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300131 * @param string
Timothy Warren76e04352012-02-14 11:55:17 -0500132 * @return object
133 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300134 protected function _fetch_object($class_name = 'stdClass')
Timothy Warren76e04352012-02-14 11:55:17 -0500135 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300136 $row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS);
137
138 if ($class_name === 'stdClass' OR ! $row)
139 {
140 return $row;
141 }
142
143 $class_name = new $class_name();
144 foreach ($row as $key => $value)
145 {
146 $class_name->$key = $value;
147 }
148
149 return $class_name;
Timothy Warren3a4cdc62012-02-17 13:59:44 -0500150 }
Timothy Warren76e04352012-02-14 11:55:17 -0500151
152}
153
Andrey Andreev26086872012-07-05 11:21:58 +0300154/* End of file ibase_result.php */
155/* Location: ./system/database/drivers/ibase/ibase_result.php */