MDB2
[ class tree: MDB2 ] [ index: MDB2 ] [ all elements ]

Source for file Iterator.php

Documentation is available at Iterator.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP version 5                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox,                 |
  6. // | Stig. S. Bakken, Lukas Smith                                         |
  7. // | All rights reserved.                                                 |
  8. // +----------------------------------------------------------------------+
  9. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
  10. // | API as well as database abstraction for PHP applications.            |
  11. // | This LICENSE is in the BSD license style.                            |
  12. // |                                                                      |
  13. // | Redistribution and use in source and binary forms, with or without   |
  14. // | modification, are permitted provided that the following conditions   |
  15. // | are met:                                                             |
  16. // |                                                                      |
  17. // | Redistributions of source code must retain the above copyright       |
  18. // | notice, this list of conditions and the following disclaimer.        |
  19. // |                                                                      |
  20. // | Redistributions in binary form must reproduce the above copyright    |
  21. // | notice, this list of conditions and the following disclaimer in the  |
  22. // | documentation and/or other materials provided with the distribution. |
  23. // |                                                                      |
  24. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  25. // | Lukas Smith nor the names of his contributors may be used to endorse |
  26. // | or promote products derived from this software without specific prior|
  27. // | written permission.                                                  |
  28. // |                                                                      |
  29. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  30. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  31. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  32. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  33. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  34. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  35. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  36. // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  37. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  38. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  39. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  40. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  41. // +----------------------------------------------------------------------+
  42. // | Author: Lukas Smith <smith@pooteeweet.org>                           |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: Iterator.php,v 1.19 2006/02/08 15:42:04 lsmith Exp $
  46.  
  47. /**
  48.  * @package  MDB2
  49.  * @category Database
  50.  * @author   Lukas Smith <smith@pooteeweet.org>
  51.  */
  52. class MDB2_Iterator implements Iterator
  53. {
  54.     protected $fetchmode;
  55.     protected $result;
  56.     protected $row;
  57.  
  58.     // {{{ constructor
  59.  
  60.     /**
  61.      * Constructor
  62.      */
  63.     public function __construct($result$fetchmode = MDB2_FETCHMODE_DEFAULT)
  64.     {
  65.         $this->result = $result;
  66.         $this->fetchmode = $fetchmode;
  67.     }
  68.     // }}}
  69.  
  70.     // {{{ seek()
  71.  
  72.     /**
  73.      * seek forward to a specific row in a result set
  74.      *
  75.      * @param int number of the row where the data can be found
  76.      *
  77.      * @return void 
  78.      * @access public
  79.      */
  80.     public function seek($rownum)
  81.     {
  82.         $this->row = null;
  83.         if ($this->result{
  84.             $this->result->seek($rownum);
  85.         }
  86.     }
  87.     // }}}
  88.  
  89.     // {{{ next()
  90.  
  91.     /**
  92.      * Fetch next row of data
  93.      *
  94.      * @return void 
  95.      * @access public
  96.      */
  97.     public function next()
  98.     {
  99.         $this->row = null;
  100.     }
  101.     // }}}
  102.  
  103.     // {{{ current()
  104.  
  105.     /**
  106.      * return a row of data
  107.      *
  108.      * @return void 
  109.      * @access public
  110.      */
  111.     public function current()
  112.     {
  113.         if (is_null($this->row)) {
  114.             $row $this->result->fetchRow($this->fetchmode);
  115.             if (PEAR::isError($row)) {
  116.                 $row = false;
  117.             }
  118.             $this->row = $row;
  119.         }
  120.         return $this->row;
  121.     }
  122.     // }}}
  123.  
  124.     // {{{ valid()
  125.  
  126.     /**
  127.      * check if the end of the result set has been reached
  128.      *
  129.      * @return bool true/false, false is also returned on failure
  130.      * @access public
  131.      */
  132.     public function valid()
  133.     {
  134.         return (bool)$this->current();
  135.     }
  136.     // }}}
  137.  
  138.     // {{{ free()
  139.  
  140.     /**
  141.      * Free the internal resources associated with result.
  142.      *
  143.      * @return bool|MDB2_Errortrue on success, false|MDB2_Error if result is invalid
  144.      * @access public
  145.      */
  146.     public function free()
  147.     {
  148.         if ($this->result{
  149.             return $this->result->free();
  150.         }
  151.         $this->result = false;
  152.         $this->row = null;
  153.         return false;
  154.     }
  155.     // }}}
  156.  
  157.     // {{{ key()
  158.  
  159.     /**
  160.      * returns the row number
  161.      *
  162.      * @return int|bool|MDB2_Errortrue on success, false|MDB2_Error if result is invalid
  163.      * @access public
  164.      */
  165.     public function key()
  166.     {
  167.         if ($this->result{
  168.             return $this->result->rowCount();
  169.         }
  170.         return false;
  171.     }
  172.     // }}}
  173.  
  174.     // {{{ rewind()
  175.  
  176.     /**
  177.      * seek to the first row in a result set
  178.      *
  179.      * @return void 
  180.      * @access public
  181.      */
  182.     public function rewind()
  183.     {
  184.     }
  185.     // }}}
  186.  
  187.     // {{{ destructor
  188.  
  189.     /**
  190.      * Destructor
  191.      */
  192.     public function __destruct()
  193.     {
  194.         $this->free();
  195.     }
  196.     // }}}
  197. }
  198.  
  199. class MDB2_BufferedIterator extends MDB2_Iterator implements SeekableIterator
  200. {
  201.     // {{{ valid()
  202.  
  203.     /**
  204.      * check if the end of the result set has been reached
  205.      *
  206.      * @return bool|MDB2_Errortrue on success, false|MDB2_Error if result is invalid
  207.      * @access public
  208.      */
  209.     public function valid()
  210.     {
  211.         if ($this->result{
  212.             return $this->result->valid();
  213.         }
  214.         return false;
  215.     }
  216.     // }}}
  217.  
  218.     // {{{count()
  219.  
  220.     /**
  221.      * returns the number of rows in a result object
  222.      *
  223.      * @return int|MDB2_Errornumber of rows, false|MDB2_Error if result is invalid
  224.      * @access public
  225.      */
  226.     public function count()
  227.     {
  228.         if ($this->result{
  229.             return $this->result->numRows();
  230.         }
  231.         return false;
  232.     }
  233.     // }}}
  234.  
  235.     // {{{ rewind()
  236.  
  237.     /**
  238.      * seek to the first row in a result set
  239.      *
  240.      * @return void 
  241.      * @access public
  242.      */
  243.     public function rewind()
  244.     {
  245.         $this->seek(0);
  246.     }
  247.     // }}}
  248. }
  249.  
  250. ?>

Documentation generated on Mon, 11 Mar 2019 14:36:21 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.