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