Merge "Add CollationFa"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / resultwrapper / MssqlResultWrapper.php
1 <?php
2 class MssqlResultWrapper extends ResultWrapper {
3 /** @var integer|null */
4 private $mSeekTo = null;
5
6 /**
7 * @return stdClass|bool
8 */
9 public function fetchObject() {
10 $res = $this->result;
11
12 if ( $this->mSeekTo !== null ) {
13 $result = sqlsrv_fetch_object( $res, 'stdClass', [],
14 SQLSRV_SCROLL_ABSOLUTE, $this->mSeekTo );
15 $this->mSeekTo = null;
16 } else {
17 $result = sqlsrv_fetch_object( $res );
18 }
19
20 // Return boolean false when there are no more rows instead of null
21 if ( $result === null ) {
22 return false;
23 }
24
25 return $result;
26 }
27
28 /**
29 * @return array|bool
30 */
31 public function fetchRow() {
32 $res = $this->result;
33
34 if ( $this->mSeekTo !== null ) {
35 $result = sqlsrv_fetch_array( $res, SQLSRV_FETCH_BOTH,
36 SQLSRV_SCROLL_ABSOLUTE, $this->mSeekTo );
37 $this->mSeekTo = null;
38 } else {
39 $result = sqlsrv_fetch_array( $res );
40 }
41
42 // Return boolean false when there are no more rows instead of null
43 if ( $result === null ) {
44 return false;
45 }
46
47 return $result;
48 }
49
50 /**
51 * @param int $row
52 * @return bool
53 */
54 public function seek( $row ) {
55 $res = $this->result;
56
57 // check bounds
58 $numRows = $this->db->numRows( $res );
59 $row = intval( $row );
60
61 if ( $numRows === 0 ) {
62 return false;
63 } elseif ( $row < 0 || $row > $numRows - 1 ) {
64 return false;
65 }
66
67 // Unlike MySQL, the seek actually happens on the next access
68 $this->mSeekTo = $row;
69 return true;
70 }
71 }