Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 5.1.6 or newer |
| 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 7 | * 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 Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
Alex Bilbie | 01ab004 | 2011-03-18 19:24:30 +0000 | [diff] [blame] | 31 | * SQLSRV Result Class |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 32 | * |
| 33 | * This class extends the parent result class: CI_DB_result |
| 34 | * |
| 35 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 36 | * @author EllisLab Dev Team |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/database/ |
| 38 | */ |
Alex Bilbie | 01ab004 | 2011-03-18 19:24:30 +0000 | [diff] [blame] | 39 | class CI_DB_sqlsrv_result extends CI_DB_result { |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Number of rows in the result set |
| 43 | * |
| 44 | * @access public |
| 45 | * @return integer |
| 46 | */ |
| 47 | function num_rows() |
| 48 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 49 | return @sqlsrv_num_rows($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | // -------------------------------------------------------------------- |
| 53 | |
| 54 | /** |
| 55 | * Number of fields in the result set |
| 56 | * |
| 57 | * @access public |
| 58 | * @return integer |
| 59 | */ |
| 60 | function num_fields() |
| 61 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 62 | return @sqlsrv_num_fields($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // -------------------------------------------------------------------- |
| 66 | |
| 67 | /** |
| 68 | * Fetch Field Names |
| 69 | * |
| 70 | * Generates an array of column names |
| 71 | * |
| 72 | * @access public |
| 73 | * @return array |
| 74 | */ |
| 75 | function list_fields() |
| 76 | { |
| 77 | $field_names = array(); |
Alex Bilbie | 3a43c7a | 2011-03-18 19:48:04 +0000 | [diff] [blame] | 78 | foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field) |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 79 | { |
Alex Bilbie | 3a43c7a | 2011-03-18 19:48:04 +0000 | [diff] [blame] | 80 | $field_names[] = $field['Name']; |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 81 | } |
Alex Bilbie | 3a43c7a | 2011-03-18 19:48:04 +0000 | [diff] [blame] | 82 | |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 83 | return $field_names; |
| 84 | } |
| 85 | |
| 86 | // -------------------------------------------------------------------- |
| 87 | |
| 88 | /** |
| 89 | * Field data |
| 90 | * |
| 91 | * Generates an array of objects containing field meta-data |
| 92 | * |
| 93 | * @access public |
| 94 | * @return array |
| 95 | */ |
| 96 | function field_data() |
| 97 | { |
| 98 | $retval = array(); |
Alex Bilbie | 3a43c7a | 2011-03-18 19:48:04 +0000 | [diff] [blame] | 99 | foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field) |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 100 | { |
Alex Bilbie | 3a43c7a | 2011-03-18 19:48:04 +0000 | [diff] [blame] | 101 | $F = new stdClass(); |
| 102 | $F->name = $field['Name']; |
| 103 | $F->type = $field['Type']; |
| 104 | $F->max_length = $field['Size']; |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 105 | $F->primary_key = 0; |
| 106 | $F->default = ''; |
Alex Bilbie | 3a43c7a | 2011-03-18 19:48:04 +0000 | [diff] [blame] | 107 | |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 108 | $retval[] = $F; |
| 109 | } |
Alex Bilbie | 3a43c7a | 2011-03-18 19:48:04 +0000 | [diff] [blame] | 110 | |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 111 | return $retval; |
| 112 | } |
| 113 | |
| 114 | // -------------------------------------------------------------------- |
| 115 | |
| 116 | /** |
| 117 | * Free the result |
| 118 | * |
| 119 | * @return null |
| 120 | */ |
| 121 | function free_result() |
| 122 | { |
| 123 | if (is_resource($this->result_id)) |
| 124 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 125 | sqlsrv_free_stmt($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 126 | $this->result_id = FALSE; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // -------------------------------------------------------------------- |
| 131 | |
| 132 | /** |
| 133 | * Data Seek |
| 134 | * |
| 135 | * Moves the internal pointer to the desired offset. We call |
| 136 | * this internally before fetching results to make sure the |
| 137 | * result set starts at zero |
| 138 | * |
| 139 | * @access private |
| 140 | * @return array |
| 141 | */ |
| 142 | function _data_seek($n = 0) |
| 143 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 144 | // Not implemented |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | // -------------------------------------------------------------------- |
| 148 | |
| 149 | /** |
| 150 | * Result - associative array |
| 151 | * |
| 152 | * Returns the result set as an array |
| 153 | * |
| 154 | * @access private |
| 155 | * @return array |
| 156 | */ |
| 157 | function _fetch_assoc() |
| 158 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 159 | return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | // -------------------------------------------------------------------- |
| 163 | |
| 164 | /** |
| 165 | * Result - object |
| 166 | * |
| 167 | * Returns the result set as an object |
| 168 | * |
| 169 | * @access private |
| 170 | * @return object |
| 171 | */ |
| 172 | function _fetch_object() |
| 173 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 174 | return sqlsrv_fetch_object($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | } |
| 178 | |
| 179 | |
| 180 | /* End of file mssql_result.php */ |
| 181 | /* Location: ./system/database/drivers/mssql/mssql_result.php */ |