Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 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 |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 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 | |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 28 | /** |
Alex Bilbie | 01ab004 | 2011-03-18 19:24:30 +0000 | [diff] [blame] | 29 | * SQLSRV Result Class |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 30 | * |
| 31 | * This class extends the parent result class: CI_DB_result |
| 32 | * |
| 33 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 34 | * @author EllisLab Dev Team |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/database/ |
| 36 | */ |
Alex Bilbie | 01ab004 | 2011-03-18 19:24:30 +0000 | [diff] [blame] | 37 | class CI_DB_sqlsrv_result extends CI_DB_result { |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Number of rows in the result set |
| 41 | * |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 42 | * @return int |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 43 | */ |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 44 | public function num_rows() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 45 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 46 | return @sqlsrv_num_rows($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | // -------------------------------------------------------------------- |
| 50 | |
| 51 | /** |
| 52 | * Number of fields in the result set |
| 53 | * |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 54 | * @return int |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 55 | */ |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 56 | public function num_fields() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 57 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 58 | return @sqlsrv_num_fields($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | // -------------------------------------------------------------------- |
| 62 | |
| 63 | /** |
| 64 | * Fetch Field Names |
| 65 | * |
| 66 | * Generates an array of column names |
| 67 | * |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 68 | * @return array |
| 69 | */ |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 70 | public function list_fields() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 71 | { |
| 72 | $field_names = array(); |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 73 | foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field) |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 74 | { |
Alex Bilbie | 3a43c7a | 2011-03-18 19:48:04 +0000 | [diff] [blame] | 75 | $field_names[] = $field['Name']; |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 76 | } |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 77 | |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 78 | return $field_names; |
| 79 | } |
| 80 | |
| 81 | // -------------------------------------------------------------------- |
| 82 | |
| 83 | /** |
| 84 | * Field data |
| 85 | * |
| 86 | * Generates an array of objects containing field meta-data |
| 87 | * |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 88 | * @return array |
| 89 | */ |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 90 | public function field_data() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 91 | { |
| 92 | $retval = array(); |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 93 | foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field) |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 94 | { |
Alex Bilbie | 3a43c7a | 2011-03-18 19:48:04 +0000 | [diff] [blame] | 95 | $F = new stdClass(); |
| 96 | $F->name = $field['Name']; |
| 97 | $F->type = $field['Type']; |
| 98 | $F->max_length = $field['Size']; |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 99 | $F->primary_key = 0; |
| 100 | $F->default = ''; |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 101 | |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 102 | $retval[] = $F; |
| 103 | } |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 104 | |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 105 | return $retval; |
| 106 | } |
| 107 | |
| 108 | // -------------------------------------------------------------------- |
| 109 | |
| 110 | /** |
| 111 | * Free the result |
| 112 | * |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 113 | * @return void |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 114 | */ |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 115 | public function free_result() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 116 | { |
| 117 | if (is_resource($this->result_id)) |
| 118 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 119 | sqlsrv_free_stmt($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 120 | $this->result_id = FALSE; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // -------------------------------------------------------------------- |
| 125 | |
| 126 | /** |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 127 | * Result - associative array |
| 128 | * |
| 129 | * Returns the result set as an array |
| 130 | * |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 131 | * @return array |
| 132 | */ |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 133 | protected function _fetch_assoc() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 134 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 135 | return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // -------------------------------------------------------------------- |
| 139 | |
| 140 | /** |
| 141 | * Result - object |
| 142 | * |
| 143 | * Returns the result set as an object |
| 144 | * |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 145 | * @return object |
| 146 | */ |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 147 | protected function _fetch_object() |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 148 | { |
Alex Bilbie | 079069c | 2011-03-10 19:36:58 +0000 | [diff] [blame] | 149 | return sqlsrv_fetch_object($this->result_id); |
Alex Bilbie | 84445d0 | 2011-03-10 16:43:39 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | } |
| 153 | |
Andrey Andreev | 9659bd5 | 2012-03-20 16:27:47 +0200 | [diff] [blame] | 154 | /* End of file sqlsrv_result.php */ |
| 155 | /* Location: ./system/database/drivers/sqlsrv/sqlsrv_result.php */ |