r23879 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23878‎ | r23879 | r23880 >
Date:00:48, 9 July 2007
Author:tstarling
Status:old
Tags:
Comment:
Added iterator interface to ResultWrapper. No support in Oracle yet. Updated documentation for Database::getLag().
Modified paths:
  • /trunk/phase3/includes/Database.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Database.php
@@ -2084,8 +2084,7 @@
20852085 */
20862086 function getLag() {
20872087 $res = $this->query( 'SHOW PROCESSLIST' );
2088 - # Find slave SQL thread. Assumed to be the second one running, which is a bit
2089 - # dubious, but unfortunately there's no easy rigorous way
 2088+ # Find slave SQL thread
20902089 while ( $row = $this->fetchObject( $res ) ) {
20912090 /* This should work for most situations - when default db
20922091 * for thread is not specified, it had no events executed,
@@ -2282,8 +2281,8 @@
22832282 * Result wrapper for grabbing data queried by someone else
22842283 * @addtogroup Database
22852284 */
2286 -class ResultWrapper {
2287 - var $db, $result;
 2285+class ResultWrapper implements Iterator {
 2286+ var $db, $result, $pos = 0, $currentRow = null;
22882287
22892288 /**
22902289 * Create a new result object from a result resource and a Database object
@@ -2345,16 +2344,41 @@
23462345 function seek( $row ) {
23472346 $this->db->dataSeek( $this->result, $row );
23482347 }
2349 -
2350 - /**
2351 - * Reset the cursor to the start of the result set
 2348+
 2349+ /*********************
 2350+ * Iterator functions
 2351+ * Note that using these in combination with the non-iterator functions
 2352+ * above may cause rows to be skipped or repeated.
23522353 */
 2354+
23532355 function rewind() {
23542356 if ($this->numRows()) {
23552357 $this->db->dataSeek($this->result, 0);
23562358 }
 2359+ $this->pos = 0;
 2360+ $this->currentRow = null;
23572361 }
23582362
 2363+ function current() {
 2364+ if ( is_null( $this->currentRow ) ) {
 2365+ $this->next();
 2366+ }
 2367+ return $this->currentRow;
 2368+ }
 2369+
 2370+ function key() {
 2371+ return $this->pos;
 2372+ }
 2373+
 2374+ function next() {
 2375+ $this->pos++;
 2376+ $this->currentRow = $this->fetchObject();
 2377+ return $this->currentRow;
 2378+ }
 2379+
 2380+ function valid() {
 2381+ return $this->current() !== false;
 2382+ }
23592383 }
23602384
23612385

Follow-up revisions

RevisionCommit summaryAuthorDate
r23912Merged revisions 23662-23909 via svnmerge from...david18:11, 9 July 2007

Status & tagging log