blob: fc66d9d8aad93826824a0534c31695b001a98b59 [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 Andreev0e8968a2012-01-26 02:04:37 +020097 foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
Alex Bilbie84445d02011-03-10 16:43:39 +000098 {
Andrey Andreev0e8968a2012-01-26 02:04:37 +020099 $F = new stdClass();
100 $F->name = $field['Name'];
101 $F->type = $field['Type'];
Alex Bilbie3a43c7a2011-03-18 19:48:04 +0000102 $F->max_length = $field['Size'];
Alex Bilbie84445d02011-03-10 16:43:39 +0000103 $F->primary_key = 0;
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200104 $F->default = '';
105
Alex Bilbie84445d02011-03-10 16:43:39 +0000106 $retval[] = $F;
107 }
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200108
Alex Bilbie84445d02011-03-10 16:43:39 +0000109 return $retval;
110 }
111
112 // --------------------------------------------------------------------
113
114 /**
115 * Free the result
116 *
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200117 * @return void
Alex Bilbie84445d02011-03-10 16:43:39 +0000118 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200119 public function free_result()
Alex Bilbie84445d02011-03-10 16:43:39 +0000120 {
121 if (is_resource($this->result_id))
122 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000123 sqlsrv_free_stmt($this->result_id);
Alex Bilbie84445d02011-03-10 16:43:39 +0000124 $this->result_id = FALSE;
125 }
126 }
127
128 // --------------------------------------------------------------------
129
130 /**
Alex Bilbie84445d02011-03-10 16:43:39 +0000131 * Result - associative array
132 *
133 * Returns the result set as an array
134 *
Alex Bilbie84445d02011-03-10 16:43:39 +0000135 * @return array
136 */
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200137 protected function _fetch_assoc()
Alex Bilbie84445d02011-03-10 16:43:39 +0000138 {
Alex Bilbie079069c2011-03-10 19:36:58 +0000139 return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC);
Alex Bilbie84445d02011-03-10 16:43:39 +0000140 }
141
142 // --------------------------------------------------------------------
143
144 /**
145 * Result - object
146 *
147 * Returns the result set as an object
148 *
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300149 * @param string
Alex Bilbie84445d02011-03-10 16:43:39 +0000150 * @return object
151 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300152 protected function _fetch_object($class_name = 'stdClass')
Alex Bilbie84445d02011-03-10 16:43:39 +0000153 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300154 return sqlsrv_fetch_object($this->result_id, $class_name);
Alex Bilbie84445d02011-03-10 16:43:39 +0000155 }
156
157}
158
Andrey Andreev0e8968a2012-01-26 02:04:37 +0200159/* End of file sqlsrv_result.php */
Andrey Andreev9659bd52012-03-20 16:27:47 +0200160/* Location: ./system/database/drivers/sqlsrv/sqlsrv_result.php */