blob: cb2c7f4a6d788b0633d4075f62d2d700fc294a46 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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
darwinel871754a2014-02-11 17:34:57 +010021 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
Timothy Warren76e04352012-02-14 11:55:17 -050022 * @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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Timothy Warren76e04352012-02-14 11:55:17 -050028
Timothy Warren76e04352012-02-14 11:55:17 -050029/**
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 Andreev5ca05132012-07-05 12:06:34 +030037 * @since 3.0
Timothy Warren76e04352012-02-14 11:55:17 -050038 */
Andrey Andreev26086872012-07-05 11:21:58 +030039class CI_DB_ibase_result extends CI_DB_result {
Timothy Warren76e04352012-02-14 11:55:17 -050040
41 /**
Timothy Warren76e04352012-02-14 11:55:17 -050042 * Number of fields in the result set
43 *
Andrey Andreev60c9c992012-03-20 23:46:09 +020044 * @return int
Timothy Warren76e04352012-02-14 11:55:17 -050045 */
Timothy Warren4be822b2012-02-14 12:07:34 -050046 public function num_fields()
Timothy Warren76e04352012-02-14 11:55:17 -050047 {
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +030048 return ibase_num_fields($this->result_id);
Timothy Warren76e04352012-02-14 11:55:17 -050049 }
50
51 // --------------------------------------------------------------------
52
53 /**
54 * Fetch Field Names
55 *
56 * Generates an array of column names
57 *
Timothy Warren76e04352012-02-14 11:55:17 -050058 * @return array
59 */
Timothy Warren4be822b2012-02-14 12:07:34 -050060 public function list_fields()
Timothy Warren76e04352012-02-14 11:55:17 -050061 {
62 $field_names = array();
Timothy Warren2da66ed2012-02-20 17:54:39 -050063 for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++)
Timothy Warren76e04352012-02-14 11:55:17 -050064 {
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 Warren76e04352012-02-14 11:55:17 -050079 * @return array
80 */
Timothy Warren4be822b2012-02-14 12:07:34 -050081 public function field_data()
Timothy Warren76e04352012-02-14 11:55:17 -050082 {
Timothy Warren76e04352012-02-14 11:55:17 -050083 $retval = array();
Andrey Andreev60c9c992012-03-20 23:46:09 +020084 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Timothy Warren76e04352012-02-14 11:55:17 -050085 {
86 $info = ibase_field_info($this->result_id, $i);
Timothy Warren76e04352012-02-14 11:55:17 -050087
Andrey Andreev60c9c992012-03-20 23:46:09 +020088 $retval[$i] = new stdClass();
89 $retval[$i]->name = $info['name'];
90 $retval[$i]->type = $info['type'];
91 $retval[$i]->max_length = $info['length'];
Timothy Warren76e04352012-02-14 11:55:17 -050092 }
93
94 return $retval;
95 }
96
97 // --------------------------------------------------------------------
98
99 /**
100 * Free the result
101 *
Andrey Andreev60c9c992012-03-20 23:46:09 +0200102 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500103 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500104 public function free_result()
Timothy Warren76e04352012-02-14 11:55:17 -0500105 {
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +0300106 ibase_free_result($this->result_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500107 }
108
109 // --------------------------------------------------------------------
110
111 /**
Timothy Warren76e04352012-02-14 11:55:17 -0500112 * Result - associative array
113 *
114 * Returns the result set as an array
115 *
Timothy Warren76e04352012-02-14 11:55:17 -0500116 * @return array
117 */
Timothy Warren95562142012-02-20 17:37:21 -0500118 protected function _fetch_assoc()
Timothy Warren76e04352012-02-14 11:55:17 -0500119 {
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +0300120 return ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS);
Timothy Warren76e04352012-02-14 11:55:17 -0500121 }
122
123 // --------------------------------------------------------------------
124
125 /**
126 * Result - object
127 *
128 * Returns the result set as an object
129 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200130 * @param string $class_name
Timothy Warren76e04352012-02-14 11:55:17 -0500131 * @return object
132 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300133 protected function _fetch_object($class_name = 'stdClass')
Timothy Warren76e04352012-02-14 11:55:17 -0500134 {
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +0300135 $row = ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS);
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300136
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 Warren3a4cdc62012-02-17 13:59:44 -0500149 }
Timothy Warren76e04352012-02-14 11:55:17 -0500150
151}
152
Andrey Andreev26086872012-07-05 11:21:58 +0300153/* End of file ibase_result.php */
154/* Location: ./system/database/drivers/ibase/ibase_result.php */