X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/libs/rdbms/database/resultwrapper/MssqlResultWrapper.php diff --git a/includes/libs/rdbms/database/resultwrapper/MssqlResultWrapper.php b/includes/libs/rdbms/database/resultwrapper/MssqlResultWrapper.php new file mode 100644 index 00000000..298ec619 --- /dev/null +++ b/includes/libs/rdbms/database/resultwrapper/MssqlResultWrapper.php @@ -0,0 +1,76 @@ +result; + + if ( $this->mSeekTo !== null ) { + $result = sqlsrv_fetch_object( $res, 'stdClass', [], + SQLSRV_SCROLL_ABSOLUTE, $this->mSeekTo ); + $this->mSeekTo = null; + } else { + $result = sqlsrv_fetch_object( $res ); + } + + // Return boolean false when there are no more rows instead of null + if ( $result === null ) { + return false; + } + + return $result; + } + + /** + * @return array|bool + */ + public function fetchRow() { + $res = $this->result; + + if ( $this->mSeekTo !== null ) { + $result = sqlsrv_fetch_array( $res, SQLSRV_FETCH_BOTH, + SQLSRV_SCROLL_ABSOLUTE, $this->mSeekTo ); + $this->mSeekTo = null; + } else { + $result = sqlsrv_fetch_array( $res ); + } + + // Return boolean false when there are no more rows instead of null + if ( $result === null ) { + return false; + } + + return $result; + } + + /** + * @param int $row + * @return bool + */ + public function seek( $row ) { + $res = $this->result; + + // check bounds + $numRows = $this->db->numRows( $res ); + $row = intval( $row ); + + if ( $numRows === 0 ) { + return false; + } elseif ( $row < 0 || $row > $numRows - 1 ) { + return false; + } + + // Unlike MySQL, the seek actually happens on the next access + $this->mSeekTo = $row; + return true; + } +}