MSSQLResultSet.php

Go to the documentation of this file.
00001 <?php 00002 /* 00003 * $Id: MSSQLResultSet.php,v 1.1 2004/05/03 16:19:39 micha Exp $ 00004 * 00005 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00006 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00007 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00008 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00009 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00010 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00011 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00012 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00013 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00014 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00015 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00016 * 00017 * This software consists of voluntary contributions made by many individuals 00018 * and is licensed under the LGPL. For more information please see 00019 * <http://creole.phpdb.org>. 00020 */ 00021 00022 require_once 'creole/ResultSet.php'; 00023 require_once 'creole/common/ResultSetCommon.php'; 00024 00037 class MSSQLResultSet extends ResultSetCommon 00038 { 00043 var $offset = 0; 00044 00049 var $limit = 0; 00050 00058 function _setOffset($offset) 00059 { 00060 $this->offset = $offset; 00061 if ($offset > 0) { 00062 $this->seek(0); // 0 becomes $offset by seek() method 00063 } 00064 } 00065 00073 function _setLimit($limit) 00074 { 00075 $this->limit = $limit; 00076 } 00077 00082 function seek($rownum) 00083 { 00084 // support emulated OFFSET 00085 $actual = $rownum + $this->offset; 00086 00087 if (($this->limit > 0 && $rownum >= $this->limit) || $rownum < 0) { 00088 // have to check for rownum < 0, because mssql_seek() won't 00089 // complain if the $actual is valid. 00090 return false; 00091 } 00092 00093 // MSSQL rows start w/ 0, but this works, because we are 00094 // looking to move the position _before_ the next desired position 00095 if (!@mssql_data_seek($this->result, $actual)) { 00096 return false; 00097 } 00098 00099 $this->cursorPos = $rownum; 00100 return true; 00101 } 00102 00107 function next() 00108 { 00109 // support emulated LIMIT 00110 if ( $this->limit > 0 && ($this->cursorPos >= $this->limit) ) { 00111 if (($e = $this->afterLast()) !== true) { 00112 return $e; 00113 } 00114 return false; 00115 } 00116 00117 $this->fields = mssql_fetch_array($this->result, $this->fetchmode); 00118 00119 if (!$this->fields) { 00120 if ($errmsg = mssql_get_last_message()) { 00121 return new SQLException(CREOLE_ERROR, "Error fetching result", $errmsg); 00122 } else { 00123 // We've advanced beyond end of recordset. 00124 if (($e = $this->afterLast()) !== true) { 00125 return $e; 00126 } 00127 return false; 00128 } 00129 } 00130 00131 if (!$this->ignoreAssocCase) { 00132 $this->fields = array_change_key_case($this->fields, CASE_LOWER); 00133 } 00134 00135 // Advance cursor position 00136 $this->cursorPos++; 00137 return true; 00138 } 00139 00143 function getRecordCount() 00144 { 00145 $rows = @mssql_num_rows($this->result); 00146 if ($rows === null) { 00147 return new SQLException(CREOLE_ERROR, 'Error getting record count', mssql_get_last_message()); 00148 } 00149 // adjust count based on emulated LIMIT/OFFSET 00150 $rows -= $this->offset; 00151 return ($this->limit > 0 && $rows > $this->limit ? $this->limit : $rows); 00152 } 00153 00157 function close() 00158 { 00159 $ret = @mssql_free_result($this->result); 00160 $this->result = false; 00161 $this->fields = array(); 00162 $this->limit = 0; 00163 $this->offset = 0; 00164 } 00165 00166 }

This file is part of the Creole[php4] library.


Copyright © 2004 Hans Lellelid  
Creole[php4] CVS