blob: b084b84cd1f55ac27e8403439c8392770deac8e3 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Alex Bilbie84445d02011-03-10 16:43:39 +000028
Alex Bilbie84445d02011-03-10 16:43:39 +000029/**
Alex Bilbie01ab0042011-03-18 19:24:30 +000030 * SQLSRV Result Class
Alex Bilbie84445d02011-03-10 16:43:39 +000031 *
32 * This class extends the parent result class: CI_DB_result
33 *
34 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
Alex Bilbie84445d02011-03-10 16:43:39 +000036 * @link http://codeigniter.com/user_guide/database/
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030037 * @since 2.0.3
Alex Bilbie84445d02011-03-10 16:43:39 +000038 */
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 *
Andrey Andreev0e8968a2012-01-26 02:04:37 +020044 * @return int
Alex Bilbie84445d02011-03-10 16:43:39 +000045 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020046 public function num_rows()
Alex Bilbie84445d02011-03-10 16:43:39 +000047 {
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030048 return is_int($this->num_rows)
49 ? $this->num_rows
50 : $this->num_rows = @sqlsrv_num_rows($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +000051 }
52
53 // --------------------------------------------------------------------
54
55 /**
56 * Number of fields in the result set
57 *
Andrey Andreev0e8968a2012-01-26 02:04:37 +020058 * @return int
Alex Bilbie84445d02011-03-10 16:43:39 +000059 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020060 public function num_fields()
Alex Bilbie84445d02011-03-10 16:43:39 +000061 {
Alex Bilbie079069c2011-03-10 19:36:58 +000062 return @sqlsrv_num_fields($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +000063 }
64
65 // --------------------------------------------------------------------
66
67 /**
68 * Fetch Field Names
69 *
70 * Generates an array of column names
71 *
Alex Bilbie84445d02011-03-10 16:43:39 +000072 * @return array
73 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020074 public function list_fields()
Alex Bilbie84445d02011-03-10 16:43:39 +000075 {
76 $field_names = array();
Andrey Andreev0e8968a2012-01-26 02:04:37 +020077 foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
Alex Bilbie84445d02011-03-10 16:43:39 +000078 {
Alex Bilbie3a43c7a2011-03-18 19:48:04 +000079 $field_names[] = $field['Name'];
Alex Bilbie84445d02011-03-10 16:43:39 +000080 }
Andrey Andreev0e8968a2012-01-26 02:04:37 +020081
Alex Bilbie84445d02011-03-10 16:43:39 +000082 return $field_names;
83 }
84
85 // --------------------------------------------------------------------
86
87 /**
88 * Field data
89 *
90 * Generates an array of objects containing field meta-data
91 *
Alex Bilbie84445d02011-03-10 16:43:39 +000092 * @return array
93 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +020094 public function field_data()
Alex Bilbie84445d02011-03-10 16:43:39 +000095 {
96 $retval = array();
Andrey Andreevf1e1b772012-11-16 01:27:00 +020097 foreach (sqlsrv_field_metadata($this->result_id) as $i => $field)
Alex Bilbie84445d02011-03-10 16:43:39 +000098 {
Andrey Andreevf1e1b772012-11-16 01:27:00 +020099 $retval[$i] = new stdClass();
100 $retval[$i]->name = $field['Name'];
101 $retval[$i]->type = $field['Type'];
102 $retval[$i]->max_length = $field['Size'];
Alex Bilbie84445d02011-03-10 16:43:39 +0000103 }
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 /**
Alex Bilbie84445d02011-03-10 16:43:39 +0000127 * Result - associative array
128 *
129 * Returns the result set as an array
130 *
Alex Bilbie84445d02011-03-10 16:43:39 +0000131 * @return array
132 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200133 protected function _fetch_assoc()
Alex Bilbie84445d02011-03-10 16:43:39 +0000134 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000135 return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC);
Alex Bilbie84445d02011-03-10 16:43:39 +0000136 }
137
138 // --------------------------------------------------------------------
139
140 /**
141 * Result - object
142 *
143 * Returns the result set as an object
144 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200145 * @param string $class_name
Alex Bilbie84445d02011-03-10 16:43:39 +0000146 * @return object
147 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300148 protected function _fetch_object($class_name = 'stdClass')
Alex Bilbie84445d02011-03-10 16:43:39 +0000149 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300150 return sqlsrv_fetch_object($this->result_id, $class_name);
Alex Bilbie84445d02011-03-10 16:43:39 +0000151 }
152
153}
154
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200155/* End of file sqlsrv_result.php */
Andrey Andreev9659bd52012-03-20 16:27:47 +0200156/* Location: ./system/database/drivers/sqlsrv/sqlsrv_result.php */