[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/creole/drivers/pgsql/ -> PgSQLResultSetIterator.php (source)

   1  <?php
   2  /*
   3   *  $Id: PgSQLResultSetIterator.php,v 1.1 2004/12/04 05:58:53 gamr 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   * Optimized iterator for PostgreSQL, based off of SQLite iterator.
  24   * Testing with SeekableIterator, no idea if it will keep this
  25   * functionality or what uses it or even how to use it as yet.
  26   * 
  27   * @author    Cameron Brunner <webmaster@animetorrents.com>
  28   * @version   $Revision: 1.1 $
  29   * @package   creole.drivers.pgsql
  30   */
  31  class PgSQLResultSetIterator implements SeekableIterator, Countable {
  32  
  33      private $result;
  34      private $pos = 0;
  35      private $fetchmode;
  36      private $row_count;
  37      private $rs;
  38      
  39      /**
  40       * Construct the iterator.
  41       * @param PgSQLResultSet $rs
  42       */
  43      public function __construct(PgSQLResultSet $rs)
  44      {
  45          $this->result = $rs->getResource();
  46          $this->fetchmode = $rs->getFetchmode();
  47          $this->row_count = $rs->getRecordCount();
  48          $this->rs = $rs; // This is to address reference count bug: http://creole.phpdb.org/trac/ticket/6
  49      }
  50      
  51      /**
  52       * This method actually has no effect, since we do not rewind ResultSet for iteration.
  53       */
  54      function rewind()
  55      {        
  56          $this->pos = 0;
  57      }
  58      
  59      function valid()
  60      {
  61          return ( $this->pos < $this->row_count );
  62      }
  63      
  64      /**
  65       * Returns the cursor position.  Note that this will not necessarily
  66       * be 1 for the first row, since no rewind is performed at beginning
  67       * of iteration.
  68       * @return int
  69       */
  70      function key()
  71      {
  72          return $this->pos;
  73      }
  74      
  75      /**
  76       * Returns the row (assoc array) at current cursor pos.
  77       * @return array
  78       */
  79      function current()
  80      {
  81         return pg_fetch_array($this->result, $this->pos, $this->fetchmode);
  82      }
  83      
  84      /**
  85       * Advances internal cursor pos.
  86       */
  87      function next()
  88      {
  89          $this->pos++;
  90      }
  91  
  92      /**
  93       * Sets cursor to specific value.
  94       */
  95      function seek ( $index )
  96      {
  97          if ( ! is_int ( $index ) ) {
  98              throw new InvalidArgumentException ( 'Invalid arguement to seek' );
  99          }
 100          if ( $index < 0 || $index > $this->row_count ) {
 101              throw new OutOfBoundsException ( 'Invalid seek position' );
 102          }
 103          $this->pos = $index;
 104      }
 105  
 106      function count ( ) {
 107          return $this->row_count;
 108      }
 109  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7