/** * Start iteration. This must be called before current() or next(). * @return Revision First list item */ public function reset() { if (!$this->res) { $this->res = $this->doQuery(wfGetDB(DB_SLAVE)); } else { $this->res->rewind(); } $this->initCurrent(); return $this->current; }
/** * Do the query, using information from the object context. This function * has been kept minimal to make it overridable if necessary, to allow for * result sets formed from multiple DB queries. */ public function doQuery() { # Use the child class name for profiling $fname = __METHOD__ . ' (' . get_class( $this ) . ')'; wfProfileIn( $fname ); $descending = ( $this->mIsBackwards == $this->mDefaultDirection ); # Plus an extra row so that we can tell the "next" link should be shown $queryLimit = $this->mLimit + 1; if ( $this->mOffset == '' ) { $isFirst = true; } else { // If there's an offset, we may or may not be at the first entry. // The only way to tell is to run the query in the opposite // direction see if we get a row. $oldIncludeOffset = $this->mIncludeOffset; $this->mIncludeOffset = !$this->mIncludeOffset; $isFirst = !$this->reallyDoQuery( $this->mOffset, 1, !$descending )->numRows(); $this->mIncludeOffset = $oldIncludeOffset; } $this->mResult = $this->reallyDoQuery( $this->mOffset, $queryLimit, $descending ); $this->extractResultInfo( $isFirst, $queryLimit, $this->mResult ); $this->mQueryDone = true; $this->preprocessResults( $this->mResult ); $this->mResult->rewind(); // Paranoia wfProfileOut( $fname ); }
/** * Combine results from 2 tables. * * Note: This will throw away some results * * @param ResultWrapper $res1 * @param ResultWrapper $res2 * @param int $limit * @param bool $ascending See note about $asc in $this->reallyDoQuery * @return FakeResultWrapper $res1 and $res2 combined */ protected function combineResult($res1, $res2, $limit, $ascending) { $res1->rewind(); $res2->rewind(); $topRes1 = $res1->next(); $topRes2 = $res2->next(); $resultArray = array(); for ($i = 0; $i < $limit && $topRes1 && $topRes2; $i++) { if (strcmp($topRes1->{$this->mIndexField}, $topRes2->{$this->mIndexField}) > 0) { if (!$ascending) { $resultArray[] = $topRes1; $topRes1 = $res1->next(); } else { $resultArray[] = $topRes2; $topRes2 = $res2->next(); } } else { if (!$ascending) { $resultArray[] = $topRes2; $topRes2 = $res2->next(); } else { $resultArray[] = $topRes1; $topRes1 = $res1->next(); } } } // @codingStandardsIgnoreStart Squiz.WhiteSpace.SemicolonSpacing.Incorrect for (; $i < $limit && $topRes1; $i++) { // @codingStandardsIgnoreEnd $resultArray[] = $topRes1; $topRes1 = $res1->next(); } // @codingStandardsIgnoreStart Squiz.WhiteSpace.SemicolonSpacing.Incorrect for (; $i < $limit && $topRes2; $i++) { // @codingStandardsIgnoreEnd $resultArray[] = $topRes2; $topRes2 = $res2->next(); } return new FakeResultWrapper($resultArray); }
/** * Do the query, using information from the object context. This function * has been kept minimal to make it overridable if necessary, to allow for * result sets formed from multiple DB queries. */ public function doQuery() { # Use the child class name for profiling $fname = __METHOD__ . ' (' . get_class($this) . ')'; wfProfileIn($fname); $descending = $this->mIsBackwards == $this->mDefaultDirection; # Plus an extra row so that we can tell the "next" link should be shown $queryLimit = $this->mLimit + 1; $this->mResult = $this->reallyDoQuery($this->mOffset, $queryLimit, $descending); $this->extractResultInfo($this->mOffset, $queryLimit, $this->mResult); $this->mQueryDone = true; $this->preprocessResults($this->mResult); $this->mResult->rewind(); // Paranoia wfProfileOut($fname); }
function rewind() { $this->res->rewind(); $this->key = 0; $this->setCurrent($this->res->current()); }