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-2006 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 327310 2012-08-27 15:16:18Z danielc $
  46.  
  47. /**
  48.  * PHP5 Iterator
  49.  *
  50.  * @package  MDB2
  51.  * @category Database
  52.  * @author   Lukas Smith <smith@pooteeweet.org>
  53.  */
  54. class MDB2_Iterator implements Iterator
  55. {
  56.     protected $fetchmode;
  57.     /**
  58.      * @var MDB2_Result_Common 
  59.      */
  60.     protected $result;
  61.     protected $row;
  62.  
  63.     // {{{ constructor
  64.  
  65.     /**
  66.      * Constructor
  67.      */
  68.     public function __construct(MDB2_Result_Common $result$fetchmode = MDB2_FETCHMODE_DEFAULT)
  69.     {
  70.         $this->result = $result;
  71.         $this->fetchmode = $fetchmode;
  72.     }
  73.     // }}}
  74.  
  75.     // {{{ seek()
  76.  
  77.     /**
  78.      * Seek forward to a specific row in a result set
  79.      *
  80.      * @param int number of the row where the data can be found
  81.      *
  82.      * @return void 
  83.      * @access public
  84.      */
  85.     public function seek($rownum)
  86.     {
  87.         $this->row = null;
  88.         if ($this->result{
  89.             $this->result->seek($rownum);
  90.         }
  91.     }
  92.     // }}}
  93.  
  94.     // {{{ next()
  95.  
  96.     /**
  97.      * Fetch next row of data
  98.      *
  99.      * @return void 
  100.      * @access public
  101.      */
  102.     public function next()
  103.     {
  104.         $this->row = null;
  105.     }
  106.     // }}}
  107.  
  108.     // {{{ current()
  109.  
  110.     /**
  111.      * return a row of data
  112.      *
  113.      * @return void 
  114.      * @access public
  115.      */
  116.     public function current()
  117.     {
  118.         if (null === $this->row{
  119.             $row $this->result->fetchRow($this->fetchmode);
  120.             if (MDB2::isError($row)) {
  121.                 $row = false;
  122.             }
  123.             $this->row = $row;
  124.         }
  125.         return $this->row;
  126.     }
  127.     // }}}
  128.  
  129.     // {{{ valid()
  130.  
  131.     /**
  132.      * Check if the end of the result set has been reached
  133.      *
  134.      * @return bool true/false, false is also returned on failure
  135.      * @access public
  136.      */
  137.     public function valid()
  138.     {
  139.         return (bool)$this->current();
  140.     }
  141.     // }}}
  142.  
  143.     // {{{ free()
  144.  
  145.     /**
  146.      * Free the internal resources associated with result.
  147.      *
  148.      * @return bool|MDB2_Errortrue on success, false|MDB2_Error if result is invalid
  149.      * @access public
  150.      */
  151.     public function free()
  152.     {
  153.         if ($this->result{
  154.             return $this->result->free();
  155.         }
  156.         $this->result = false;
  157.         $this->row = null;
  158.         return false;
  159.     }
  160.     // }}}
  161.  
  162.     // {{{ key()
  163.  
  164.     /**
  165.      * Returns the row number
  166.      *
  167.      * @return int|bool|MDB2_Errortrue on success, false|MDB2_Error if result is invalid
  168.      * @access public
  169.      */
  170.     public function key()
  171.     {
  172.         if ($this->result{
  173.             return $this->result->rowCount();
  174.         }
  175.         return false;
  176.     }
  177.     // }}}
  178.  
  179.     // {{{ rewind()
  180.  
  181.     /**
  182.      * Seek to the first row in a result set
  183.      *
  184.      * @return void 
  185.      * @access public
  186.      */
  187.     public function rewind()
  188.     {
  189.     }
  190.     // }}}
  191.  
  192.     // {{{ destructor
  193.  
  194.     /**
  195.      * Destructor
  196.      */
  197.     public function __destruct()
  198.     {
  199.         $this->free();
  200.     }
  201.     // }}}
  202. }
  203.  
  204. /**
  205.  * PHP5 buffered Iterator
  206.  *
  207.  * @package  MDB2
  208.  * @category Database
  209.  * @author   Lukas Smith <smith@pooteeweet.org>
  210.  */
  211. class MDB2_BufferedIterator extends MDB2_Iterator implements SeekableIterator
  212. {
  213.     // {{{ valid()
  214.  
  215.     /**
  216.      * Check if the end of the result set has been reached
  217.      *
  218.      * @return bool|MDB2_Errortrue on success, false|MDB2_Error if result is invalid
  219.      * @access public
  220.      */
  221.     public function valid()
  222.     {
  223.         if ($this->result{
  224.             return $this->result->valid();
  225.         }
  226.         return false;
  227.     }
  228.     // }}}
  229.  
  230.     // {{{count()
  231.  
  232.     /**
  233.      * Returns the number of rows in a result object
  234.      *
  235.      * @return int|MDB2_Errornumber of rows, false|MDB2_Error if result is invalid
  236.      * @access public
  237.      */
  238.     public function count()
  239.     {
  240.         if ($this->result{
  241.             return $this->result->numRows();
  242.         }
  243.         return false;
  244.     }
  245.     // }}}
  246.  
  247.     // {{{ rewind()
  248.  
  249.     /**
  250.      * Seek to the first row in a result set
  251.      *
  252.      * @return void 
  253.      * @access public
  254.      */
  255.     public function rewind()
  256.     {
  257.         $this->seek(0);
  258.     }
  259.     // }}}
  260. }
  261.  
  262. ?>

Documentation generated on Mon, 11 Mar 2019 15:51:34 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.