00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 require_once 'creole/ResultSet.php';
00023 require_once 'creole/common/ResultSetCommon.php';
00024
00036 class MSSQLResultSet extends ResultSetCommon implements ResultSet {
00037
00042 private $offset = 0;
00043
00048 private $limit = 0;
00049
00057 public function _setOffset($offset)
00058 {
00059 $this->offset = $offset;
00060 if ($offset > 0) {
00061 $this->seek(0);
00062 }
00063 }
00064
00072 public function _setLimit($limit)
00073 {
00074 $this->limit = $limit;
00075 }
00076
00080 function seek($rownum)
00081 {
00082
00083 $actual = $rownum + $this->offset;
00084
00085 if (($this->limit > 0 && $rownum >= $this->limit) || $rownum < 0) {
00086
00087
00088 return false;
00089 }
00090
00091
00092
00093 if (!@mssql_data_seek($this->result, $actual)) {
00094 return false;
00095 }
00096
00097 $this->cursorPos = $rownum;
00098 return true;
00099 }
00100
00104 function next()
00105 {
00106
00107 if ( $this->limit > 0 && ($this->cursorPos >= $this->limit) ) {
00108 $this->afterLast();
00109 return false;
00110 }
00111
00112 $this->fields = mssql_fetch_array($this->result, $this->fetchmode);
00113
00114 if (!$this->fields) {
00115 if ($errmsg = mssql_get_last_message()) {
00116 throw new SQLException("Error fetching result", $errmsg);
00117 } else {
00118
00119 $this->afterLast();
00120 return false;
00121 }
00122 }
00123
00124 if ($this->fetchmode === ResultSet::FETCHMODE_ASSOC && $this->lowerAssocCase) {
00125 $this->fields = array_change_key_case($this->fields, CASE_LOWER);
00126 }
00127
00128
00129 $this->cursorPos++;
00130 return true;
00131 }
00132
00136 function getRecordCount()
00137 {
00138 $rows = @mssql_num_rows($this->result);
00139 if ($rows === null) {
00140 throw new SQLException('Error getting record count', mssql_get_last_message());
00141 }
00142
00143 $rows -= $this->offset;
00144 return ($this->limit > 0 && $rows > $this->limit ? $this->limit : $rows);
00145 }
00146
00150 function close()
00151 {
00152 $ret = @mssql_free_result($this->result);
00153 $this->result = false;
00154 $this->fields = array();
00155 $this->limit = 0;
00156 $this->offset = 0;
00157 }
00158
00159 }