blob: 8e1f4164cfaf76f9f3cadbf81733a14fe0182b14 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02005 * An open source application development framework for PHP
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02007 * This content is released under the MIT License (MIT)
Andrey Andreev4da24f82012-01-25 21:54:23 +02008 *
Andrey Andreevcce6bd12018-01-09 11:32:02 +02009 * Copyright (c) 2014 - 2018, British Columbia Institute of Technology
Andrey Andreev4da24f82012-01-25 21:54:23 +020010 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020011 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
Derek Jonesf4a4bd82011-10-20 12:18:42 -050017 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020018 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 *
29 * @package CodeIgniter
30 * @author EllisLab Dev Team
Andrey Andreev1924e872016-01-11 12:55:34 +020031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
Andrey Andreevcce6bd12018-01-09 11:32:02 +020032 * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020033 * @license http://opensource.org/licenses/MIT MIT License
Andrey Andreevbd202c92016-01-11 12:50:18 +020034 * @link https://codeigniter.com
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020035 * @since Version 1.3.0
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @filesource
37 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020038defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000039
Derek Allard2067d1a2008-11-13 22:59:24 +000040/**
Andrey Andreev9a4f3562012-07-06 11:57:37 +030041 * MSSQL Result Class
Derek Allard2067d1a2008-11-13 22:59:24 +000042 *
43 * This class extends the parent result class: CI_DB_result
44 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020045 * @package CodeIgniter
46 * @subpackage Drivers
Derek Allard2067d1a2008-11-13 22:59:24 +000047 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050048 * @author EllisLab Dev Team
Andrey Andreevbd202c92016-01-11 12:50:18 +020049 * @link https://codeigniter.com/user_guide/database/
Derek Allard2067d1a2008-11-13 22:59:24 +000050 */
51class CI_DB_mssql_result extends CI_DB_result {
Barry Mienydd671972010-10-04 16:33:58 +020052
Derek Allard2067d1a2008-11-13 22:59:24 +000053 /**
54 * Number of rows in the result set
55 *
Andrey Andreev4da24f82012-01-25 21:54:23 +020056 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000057 */
Andrey Andreev4da24f82012-01-25 21:54:23 +020058 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000059 {
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030060 return is_int($this->num_rows)
61 ? $this->num_rows
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +030062 : $this->num_rows = mssql_num_rows($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +000063 }
Barry Mienydd671972010-10-04 16:33:58 +020064
Derek Allard2067d1a2008-11-13 22:59:24 +000065 // --------------------------------------------------------------------
66
67 /**
68 * Number of fields in the result set
69 *
Andrey Andreev4da24f82012-01-25 21:54:23 +020070 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000071 */
Andrey Andreev4da24f82012-01-25 21:54:23 +020072 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000073 {
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +030074 return mssql_num_fields($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +000075 }
76
77 // --------------------------------------------------------------------
78
79 /**
80 * Fetch Field Names
81 *
82 * Generates an array of column names
83 *
Derek Allard2067d1a2008-11-13 22:59:24 +000084 * @return array
85 */
Andrey Andreev4da24f82012-01-25 21:54:23 +020086 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000087 {
88 $field_names = array();
Chris Buckleyb835a4f2013-01-28 23:35:13 +000089 mssql_field_seek($this->result_id, 0);
Derek Allard2067d1a2008-11-13 22:59:24 +000090 while ($field = mssql_fetch_field($this->result_id))
91 {
92 $field_names[] = $field->name;
93 }
Barry Mienydd671972010-10-04 16:33:58 +020094
Derek Allard2067d1a2008-11-13 22:59:24 +000095 return $field_names;
96 }
97
98 // --------------------------------------------------------------------
99
100 /**
101 * Field data
102 *
103 * Generates an array of objects containing field meta-data
104 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 * @return array
106 */
Andrey Andreev4da24f82012-01-25 21:54:23 +0200107 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 {
109 $retval = array();
Gabriel Potkány8194ce52015-02-04 10:34:24 +0100110 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Barry Mienydd671972010-10-04 16:33:58 +0200111 {
Andrey Andreevf1e1b772012-11-16 01:27:00 +0200112 $field = mssql_fetch_field($this->result_id, $i);
Barry Mienydd671972010-10-04 16:33:58 +0200113
Andrey Andreevf1e1b772012-11-16 01:27:00 +0200114 $retval[$i] = new stdClass();
115 $retval[$i]->name = $field->name;
116 $retval[$i]->type = $field->type;
117 $retval[$i]->max_length = $field->max_length;
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 }
Barry Mienydd671972010-10-04 16:33:58 +0200119
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 return $retval;
121 }
122
123 // --------------------------------------------------------------------
124
125 /**
126 * Free the result
127 *
Andrey Andreev4da24f82012-01-25 21:54:23 +0200128 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200129 */
Andrey Andreev4da24f82012-01-25 21:54:23 +0200130 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000131 {
132 if (is_resource($this->result_id))
133 {
134 mssql_free_result($this->result_id);
135 $this->result_id = FALSE;
136 }
137 }
138
139 // --------------------------------------------------------------------
140
141 /**
142 * Data Seek
143 *
Andrey Andreev4da24f82012-01-25 21:54:23 +0200144 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 * this internally before fetching results to make sure the
Andrey Andreev8463b912012-11-02 02:16:28 +0200146 * result set starts at zero.
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200148 * @param int $n
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300149 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000150 */
Andrey Andreev69edc432012-12-04 13:32:16 +0200151 public function data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 {
153 return mssql_data_seek($this->result_id, $n);
154 }
Barry Mienydd671972010-10-04 16:33:58 +0200155
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 // --------------------------------------------------------------------
157
158 /**
159 * Result - associative array
160 *
161 * Returns the result set as an array
162 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 * @return array
164 */
Andrey Andreev4da24f82012-01-25 21:54:23 +0200165 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 {
167 return mssql_fetch_assoc($this->result_id);
168 }
Barry Mienydd671972010-10-04 16:33:58 +0200169
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 // --------------------------------------------------------------------
171
172 /**
173 * Result - object
174 *
175 * Returns the result set as an object
176 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200177 * @param string $class_name
Derek Allard2067d1a2008-11-13 22:59:24 +0000178 * @return object
179 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300180 protected function _fetch_object($class_name = 'stdClass')
Derek Allard2067d1a2008-11-13 22:59:24 +0000181 {
Andrey Andreev2bbbd1a2014-05-09 10:24:14 +0300182 $row = mssql_fetch_object($this->result_id);
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300183
184 if ($class_name === 'stdClass' OR ! $row)
185 {
186 return $row;
187 }
188
189 $class_name = new $class_name();
190 foreach ($row as $key => $value)
191 {
192 $class_name->$key = $value;
193 }
194
195 return $class_name;
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 }
197
198}