blob: fb7a686479a66c26118199cb157fe8ec11c556e7 [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 *
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
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
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030024 * @since Version 1.0
Alex Bilbie84445d02011-03-10 16:43:39 +000025 * @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/
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030036 * @since 2.0.3
Alex Bilbie84445d02011-03-10 16:43:39 +000037 */
Alex Bilbie01ab0042011-03-18 19:24:30 +000038class CI_DB_sqlsrv_result extends CI_DB_result {
Alex Bilbie84445d02011-03-10 16:43:39 +000039
40 /**
41 * Number of rows in the result set
42 *
Andrey Andreev0e8968a2012-01-26 02:04:37 +020043 * @return int
Alex Bilbie84445d02011-03-10 16:43:39 +000044 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020045 public function num_rows()
Alex Bilbie84445d02011-03-10 16:43:39 +000046 {
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030047 return is_int($this->num_rows)
48 ? $this->num_rows
49 : $this->num_rows = @sqlsrv_num_rows($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +000050 }
51
52 // --------------------------------------------------------------------
53
54 /**
55 * Number of fields in the result set
56 *
Andrey Andreev0e8968a2012-01-26 02:04:37 +020057 * @return int
Alex Bilbie84445d02011-03-10 16:43:39 +000058 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020059 public function num_fields()
Alex Bilbie84445d02011-03-10 16:43:39 +000060 {
Alex Bilbie079069c2011-03-10 19:36:58 +000061 return @sqlsrv_num_fields($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +000062 }
63
64 // --------------------------------------------------------------------
65
66 /**
67 * Fetch Field Names
68 *
69 * Generates an array of column names
70 *
Alex Bilbie84445d02011-03-10 16:43:39 +000071 * @return array
72 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020073 public function list_fields()
Alex Bilbie84445d02011-03-10 16:43:39 +000074 {
75 $field_names = array();
Andrey Andreev0e8968a2012-01-26 02:04:37 +020076 foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
Alex Bilbie84445d02011-03-10 16:43:39 +000077 {
Alex Bilbie3a43c7a2011-03-18 19:48:04 +000078 $field_names[] = $field['Name'];
Alex Bilbie84445d02011-03-10 16:43:39 +000079 }
Andrey Andreev0e8968a2012-01-26 02:04:37 +020080
Alex Bilbie84445d02011-03-10 16:43:39 +000081 return $field_names;
82 }
83
84 // --------------------------------------------------------------------
85
86 /**
87 * Field data
88 *
89 * Generates an array of objects containing field meta-data
90 *
Alex Bilbie84445d02011-03-10 16:43:39 +000091 * @return array
92 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020093 public function field_data()
Alex Bilbie84445d02011-03-10 16:43:39 +000094 {
95 $retval = array();
Andrey Andreev0e8968a2012-01-26 02:04:37 +020096 foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
Alex Bilbie84445d02011-03-10 16:43:39 +000097 {
Andrey Andreev0e8968a2012-01-26 02:04:37 +020098 $F = new stdClass();
99 $F->name = $field['Name'];
100 $F->type = $field['Type'];
Alex Bilbie3a43c7a2011-03-18 19:48:04 +0000101 $F->max_length = $field['Size'];
Alex Bilbie84445d02011-03-10 16:43:39 +0000102 $F->primary_key = 0;
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200103 $F->default = '';
104
Alex Bilbie84445d02011-03-10 16:43:39 +0000105 $retval[] = $F;
106 }
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200107
Alex Bilbie84445d02011-03-10 16:43:39 +0000108 return $retval;
109 }
110
111 // --------------------------------------------------------------------
112
113 /**
114 * Free the result
115 *
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200116 * @return void
Alex Bilbie84445d02011-03-10 16:43:39 +0000117 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200118 public function free_result()
Alex Bilbie84445d02011-03-10 16:43:39 +0000119 {
120 if (is_resource($this->result_id))
121 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000122 sqlsrv_free_stmt($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +0000123 $this->result_id = FALSE;
124 }
125 }
126
127 // --------------------------------------------------------------------
128
129 /**
Alex Bilbie84445d02011-03-10 16:43:39 +0000130 * Result - associative array
131 *
132 * Returns the result set as an array
133 *
Alex Bilbie84445d02011-03-10 16:43:39 +0000134 * @return array
135 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200136 protected function _fetch_assoc()
Alex Bilbie84445d02011-03-10 16:43:39 +0000137 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000138 return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC);
Alex Bilbie84445d02011-03-10 16:43:39 +0000139 }
140
141 // --------------------------------------------------------------------
142
143 /**
144 * Result - object
145 *
146 * Returns the result set as an object
147 *
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300148 * @param string
Alex Bilbie84445d02011-03-10 16:43:39 +0000149 * @return object
150 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300151 protected function _fetch_object($class_name = 'stdClass')
Alex Bilbie84445d02011-03-10 16:43:39 +0000152 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300153 return sqlsrv_fetch_object($this->result_id, $class_name);
Alex Bilbie84445d02011-03-10 16:43:39 +0000154 }
155
156}
157
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200158/* End of file sqlsrv_result.php */
Andrey Andreev9659bd52012-03-20 16:27:47 +0200159/* Location: ./system/database/drivers/sqlsrv/sqlsrv_result.php */