[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: ResultSetIterator.php,v 1.3 2004/03/15 17:47:45 hlellelid Exp $ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information please see 19 * <http://creole.phpdb.org>. 20 */ 21 22 /** 23 * Basic ResultSet Iterator. 24 * 25 * This can be returned by your class's getIterator() method, but of course 26 * you can also implement your own (e.g. to get better performance, by using direct 27 * driver calls and avoiding other side-effects inherent in ResultSet scrolling 28 * functions -- e.g. beforeFirst() / afterLast(), etc.). 29 * 30 * Important: ResultSet iteration does rewind the resultset if it is not at the 31 * start. Not all drivers support reverse scrolling, so this may result in an 32 * exception in some cases (Oracle). 33 * 34 * Developer note: 35 * The implementation of this class is a little weird because it fetches the 36 * array _early_ in order to answer valid() w/o needing to know total num 37 * of fields. Remember the way iterators work: 38 * <code> 39 * $it = $obj->getIterator(); 40 * for($it->rewind(); $it->valid(); $it->next()) { 41 * $key = $it->current(); 42 * $val = $it->key(); 43 * echo "$key = $val\n"; 44 * } 45 * unset($it); 46 * </code> 47 * 48 * @author Hans Lellelid <hans@xmpl.org> 49 * @version $Revision: 1.3 $ 50 * @package creole 51 */ 52 class ResultSetIterator implements Iterator { 53 54 private $rs; 55 56 /** 57 * Construct the iterator. 58 * @param ResultSet $rs 59 */ 60 public function __construct(ResultSet $rs) 61 { 62 $this->rs = $rs; 63 } 64 65 /** 66 * If not at start of resultset, this method will call seek(0). 67 * @see ResultSet::seek() 68 */ 69 function rewind() 70 { 71 if (!$this->rs->isBeforeFirst()) { 72 $this->rs->seek(0); 73 } 74 } 75 76 /** 77 * This method checks to see whether there are more results 78 * by advancing the cursor position. 79 * @see ResultSet::next() 80 */ 81 function valid() 82 { 83 return $this->rs->next(); 84 } 85 86 /** 87 * Returns the cursor position. 88 * @return int 89 */ 90 function key() 91 { 92 return $this->rs->getCursorPos(); 93 } 94 95 /** 96 * Returns the row (assoc array) at current cursor pos. 97 * @return array 98 */ 99 function current() 100 { 101 return $this->rs->getRow(); 102 } 103 104 /** 105 * This method does not actually do anything since we have already advanced 106 * the cursor pos in valid(). 107 * @see valid() 108 */ 109 function next() 110 { 111 } 112 113 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |