Index: trunk/phase3/includes/Database.php |
— | — | @@ -2084,8 +2084,7 @@ |
2085 | 2085 | */ |
2086 | 2086 | function getLag() { |
2087 | 2087 | $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 |
2090 | 2089 | while ( $row = $this->fetchObject( $res ) ) { |
2091 | 2090 | /* This should work for most situations - when default db |
2092 | 2091 | * for thread is not specified, it had no events executed, |
— | — | @@ -2282,8 +2281,8 @@ |
2283 | 2282 | * Result wrapper for grabbing data queried by someone else |
2284 | 2283 | * @addtogroup Database |
2285 | 2284 | */ |
2286 | | -class ResultWrapper { |
2287 | | - var $db, $result; |
| 2285 | +class ResultWrapper implements Iterator { |
| 2286 | + var $db, $result, $pos = 0, $currentRow = null; |
2288 | 2287 | |
2289 | 2288 | /** |
2290 | 2289 | * Create a new result object from a result resource and a Database object |
— | — | @@ -2345,16 +2344,41 @@ |
2346 | 2345 | function seek( $row ) { |
2347 | 2346 | $this->db->dataSeek( $this->result, $row ); |
2348 | 2347 | } |
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. |
2352 | 2353 | */ |
| 2354 | + |
2353 | 2355 | function rewind() { |
2354 | 2356 | if ($this->numRows()) { |
2355 | 2357 | $this->db->dataSeek($this->result, 0); |
2356 | 2358 | } |
| 2359 | + $this->pos = 0; |
| 2360 | + $this->currentRow = null; |
2357 | 2361 | } |
2358 | 2362 | |
| 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 | + } |
2359 | 2383 | } |
2360 | 2384 | |
2361 | 2385 | |