blob: c5f9093dbef61b4130662d619a8ed62d158f5c88 [file] [log] [blame]
Andrey Andreev0e8968a2012-01-26 02:04:37 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Alex Bilbie84445d02011-03-10 16:43:39 +00002/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev0e8968a2012-01-26 02:04:37 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev0e8968a2012-01-26 02:04:37 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -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 *
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
Alex Bilbie84445d02011-03-10 16:43:39 +000028/**
Alex Bilbie01ab0042011-03-18 19:24:30 +000029 * SQLSRV Result Class
Alex Bilbie84445d02011-03-10 16:43:39 +000030 *
31 * This class extends the parent result class: CI_DB_result
32 *
33 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Alex Bilbie84445d02011-03-10 16:43:39 +000035 * @link http://codeigniter.com/user_guide/database/
36 */
Alex Bilbie01ab0042011-03-18 19:24:30 +000037class CI_DB_sqlsrv_result extends CI_DB_result {
Alex Bilbie84445d02011-03-10 16:43:39 +000038
39 /**
40 * Number of rows in the result set
41 *
Andrey Andreev0e8968a2012-01-26 02:04:37 +020042 * @return int
Alex Bilbie84445d02011-03-10 16:43:39 +000043 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020044 public function num_rows()
Alex Bilbie84445d02011-03-10 16:43:39 +000045 {
Alex Bilbie079069c2011-03-10 19:36:58 +000046 return @sqlsrv_num_rows($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +000047 }
48
49 // --------------------------------------------------------------------
50
51 /**
52 * Number of fields in the result set
53 *
Andrey Andreev0e8968a2012-01-26 02:04:37 +020054 * @return int
Alex Bilbie84445d02011-03-10 16:43:39 +000055 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020056 public function num_fields()
Alex Bilbie84445d02011-03-10 16:43:39 +000057 {
Alex Bilbie079069c2011-03-10 19:36:58 +000058 return @sqlsrv_num_fields($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +000059 }
60
61 // --------------------------------------------------------------------
62
63 /**
64 * Fetch Field Names
65 *
66 * Generates an array of column names
67 *
Alex Bilbie84445d02011-03-10 16:43:39 +000068 * @return array
69 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020070 public function list_fields()
Alex Bilbie84445d02011-03-10 16:43:39 +000071 {
72 $field_names = array();
Andrey Andreev0e8968a2012-01-26 02:04:37 +020073 foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
Alex Bilbie84445d02011-03-10 16:43:39 +000074 {
Alex Bilbie3a43c7a2011-03-18 19:48:04 +000075 $field_names[] = $field['Name'];
Alex Bilbie84445d02011-03-10 16:43:39 +000076 }
Andrey Andreev0e8968a2012-01-26 02:04:37 +020077
Alex Bilbie84445d02011-03-10 16:43:39 +000078 return $field_names;
79 }
80
81 // --------------------------------------------------------------------
82
83 /**
84 * Field data
85 *
86 * Generates an array of objects containing field meta-data
87 *
Alex Bilbie84445d02011-03-10 16:43:39 +000088 * @return array
89 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020090 public function field_data()
Alex Bilbie84445d02011-03-10 16:43:39 +000091 {
92 $retval = array();
Andrey Andreev0e8968a2012-01-26 02:04:37 +020093 foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
Alex Bilbie84445d02011-03-10 16:43:39 +000094 {
Andrey Andreev0e8968a2012-01-26 02:04:37 +020095 $F = new stdClass();
96 $F->name = $field['Name'];
97 $F->type = $field['Type'];
Alex Bilbie3a43c7a2011-03-18 19:48:04 +000098 $F->max_length = $field['Size'];
Alex Bilbie84445d02011-03-10 16:43:39 +000099 $F->primary_key = 0;
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200100 $F->default = '';
101
Alex Bilbie84445d02011-03-10 16:43:39 +0000102 $retval[] = $F;
103 }
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200104
Alex Bilbie84445d02011-03-10 16:43:39 +0000105 return $retval;
106 }
107
108 // --------------------------------------------------------------------
109
110 /**
111 * Free the result
112 *
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200113 * @return void
Alex Bilbie84445d02011-03-10 16:43:39 +0000114 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200115 public function free_result()
Alex Bilbie84445d02011-03-10 16:43:39 +0000116 {
117 if (is_resource($this->result_id))
118 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000119 sqlsrv_free_stmt($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +0000120 $this->result_id = FALSE;
121 }
122 }
123
124 // --------------------------------------------------------------------
125
126 /**
127 * Data Seek
128 *
129 * Moves the internal pointer to the desired offset. We call
130 * this internally before fetching results to make sure the
131 * result set starts at zero
132 *
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200133 * @return void
Alex Bilbie84445d02011-03-10 16:43:39 +0000134 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200135 protected function _data_seek($n = 0)
Alex Bilbie84445d02011-03-10 16:43:39 +0000136 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000137 // Not implemented
Alex Bilbie84445d02011-03-10 16:43:39 +0000138 }
139
140 // --------------------------------------------------------------------
141
142 /**
143 * Result - associative array
144 *
145 * Returns the result set as an array
146 *
Alex Bilbie84445d02011-03-10 16:43:39 +0000147 * @return array
148 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200149 protected function _fetch_assoc()
Alex Bilbie84445d02011-03-10 16:43:39 +0000150 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000151 return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC);
Alex Bilbie84445d02011-03-10 16:43:39 +0000152 }
153
154 // --------------------------------------------------------------------
155
156 /**
157 * Result - object
158 *
159 * Returns the result set as an object
160 *
Alex Bilbie84445d02011-03-10 16:43:39 +0000161 * @return object
162 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200163 protected function _fetch_object()
Alex Bilbie84445d02011-03-10 16:43:39 +0000164 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000165 return sqlsrv_fetch_object($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +0000166 }
167
168}
169
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200170/* End of file sqlsrv_result.php */
171/* Location: ./system/database/drivers/sqlsrv/sqlsrv_result.php */