blob: 095e3440a6482b84d643f89e73a7f905eaf54eb4 [file] [log] [blame]
Alex Bilbie84445d02011-03-10 16:43:39 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Alex Bilbie84445d02011-03-10 16:43:39 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
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 *
Alex Bilbie84445d02011-03-10 16:43:39 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Alex Bilbie84445d02011-03-10 16:43:39 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
Alex Bilbie01ab0042011-03-18 19:24:30 +000031 * SQLSRV Result Class
Alex Bilbie84445d02011-03-10 16:43:39 +000032 *
33 * This class extends the parent result class: CI_DB_result
34 *
35 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Alex Bilbie84445d02011-03-10 16:43:39 +000037 * @link http://codeigniter.com/user_guide/database/
38 */
Alex Bilbie01ab0042011-03-18 19:24:30 +000039class CI_DB_sqlsrv_result extends CI_DB_result {
Alex Bilbie84445d02011-03-10 16:43:39 +000040
41 /**
42 * Number of rows in the result set
43 *
Alex Bilbie84445d02011-03-10 16:43:39 +000044 * @return integer
45 */
Timothy Warrenb4172692012-03-19 18:34:11 -040046 public function num_rows()
Alex Bilbie84445d02011-03-10 16:43:39 +000047 {
Alex Bilbie079069c2011-03-10 19:36:58 +000048 return @sqlsrv_num_rows($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +000049 }
50
51 // --------------------------------------------------------------------
52
53 /**
54 * Number of fields in the result set
55 *
Alex Bilbie84445d02011-03-10 16:43:39 +000056 * @return integer
57 */
Timothy Warrenb4172692012-03-19 18:34:11 -040058 pubilc function num_fields()
Alex Bilbie84445d02011-03-10 16:43:39 +000059 {
Alex Bilbie079069c2011-03-10 19:36:58 +000060 return @sqlsrv_num_fields($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +000061 }
62
63 // --------------------------------------------------------------------
64
65 /**
66 * Fetch Field Names
67 *
68 * Generates an array of column names
69 *
Alex Bilbie84445d02011-03-10 16:43:39 +000070 * @return array
71 */
Timothy Warrenb4172692012-03-19 18:34:11 -040072 public function list_fields()
Alex Bilbie84445d02011-03-10 16:43:39 +000073 {
74 $field_names = array();
Alex Bilbie3a43c7a2011-03-18 19:48:04 +000075 foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field)
Alex Bilbie84445d02011-03-10 16:43:39 +000076 {
Alex Bilbie3a43c7a2011-03-18 19:48:04 +000077 $field_names[] = $field['Name'];
Alex Bilbie84445d02011-03-10 16:43:39 +000078 }
Alex Bilbie3a43c7a2011-03-18 19:48:04 +000079
Alex Bilbie84445d02011-03-10 16:43:39 +000080 return $field_names;
81 }
82
83 // --------------------------------------------------------------------
84
85 /**
86 * Field data
87 *
88 * Generates an array of objects containing field meta-data
89 *
Alex Bilbie84445d02011-03-10 16:43:39 +000090 * @return array
91 */
Timothy Warrenb4172692012-03-19 18:34:11 -040092 public function field_data()
Alex Bilbie84445d02011-03-10 16:43:39 +000093 {
94 $retval = array();
Alex Bilbie3a43c7a2011-03-18 19:48:04 +000095 foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field)
Alex Bilbie84445d02011-03-10 16:43:39 +000096 {
Alex Bilbie3a43c7a2011-03-18 19:48:04 +000097 $F = new stdClass();
98 $F->name = $field['Name'];
99 $F->type = $field['Type'];
100 $F->max_length = $field['Size'];
Alex Bilbie84445d02011-03-10 16:43:39 +0000101 $F->primary_key = 0;
102 $F->default = '';
Alex Bilbie3a43c7a2011-03-18 19:48:04 +0000103
Alex Bilbie84445d02011-03-10 16:43:39 +0000104 $retval[] = $F;
105 }
Alex Bilbie3a43c7a2011-03-18 19:48:04 +0000106
Alex Bilbie84445d02011-03-10 16:43:39 +0000107 return $retval;
108 }
109
110 // --------------------------------------------------------------------
111
112 /**
113 * Free the result
114 *
115 * @return null
116 */
Timothy Warrenb4172692012-03-19 18:34:11 -0400117 public function free_result()
Alex Bilbie84445d02011-03-10 16:43:39 +0000118 {
119 if (is_resource($this->result_id))
120 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000121 sqlsrv_free_stmt($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +0000122 $this->result_id = FALSE;
123 }
124 }
125
126 // --------------------------------------------------------------------
127
128 /**
129 * Data Seek
130 *
131 * Moves the internal pointer to the desired offset. We call
132 * this internally before fetching results to make sure the
133 * result set starts at zero
134 *
Alex Bilbie84445d02011-03-10 16:43:39 +0000135 * @return array
136 */
Timothy Warrenb4172692012-03-19 18:34:11 -0400137 protected function _data_seek($n = 0)
Alex Bilbie84445d02011-03-10 16:43:39 +0000138 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000139 // Not implemented
Alex Bilbie84445d02011-03-10 16:43:39 +0000140 }
141
142 // --------------------------------------------------------------------
143
144 /**
145 * Result - associative array
146 *
147 * Returns the result set as an array
148 *
Alex Bilbie84445d02011-03-10 16:43:39 +0000149 * @return array
150 */
Timothy Warrenb4172692012-03-19 18:34:11 -0400151 protected function _fetch_assoc()
Alex Bilbie84445d02011-03-10 16:43:39 +0000152 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000153 return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC);
Alex Bilbie84445d02011-03-10 16:43:39 +0000154 }
155
156 // --------------------------------------------------------------------
157
158 /**
159 * Result - object
160 *
161 * Returns the result set as an object
162 *
Alex Bilbie84445d02011-03-10 16:43:39 +0000163 * @return object
164 */
Timothy Warrenb4172692012-03-19 18:34:11 -0400165 protected function _fetch_object()
Alex Bilbie84445d02011-03-10 16:43:39 +0000166 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000167 return sqlsrv_fetch_object($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +0000168 }
169
170}
171
Alex Bilbie84445d02011-03-10 16:43:39 +0000172/* End of file mssql_result.php */
173/* Location: ./system/database/drivers/mssql/mssql_result.php */