[ 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/sqlite/ -> SQLiteResultSet.php (source)

   1  <?php
   2  /*
   3   *  $Id: SQLiteResultSet.php,v 1.9 2004/11/29 13:41:24 micha 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  require_once 'creole/ResultSet.php';
  23  require_once 'creole/common/ResultSetCommon.php';
  24  
  25  /**
  26   * SQLite implementation of ResultSet class.
  27   *
  28   * SQLite supports OFFSET / LIMIT natively; this means that no adjustments or checking
  29   * are performed.  We will assume that if the lmitSQL() operation failed that an
  30   * exception was thrown, and that OFFSET/LIMIT will never be emulated for SQLite.
  31   * 
  32   * @author    Hans Lellelid <hans@xmpl.org>
  33   * @version   $Revision: 1.9 $
  34   * @package   creole.drivers.sqlite
  35   */
  36  class SQLiteResultSet extends ResultSetCommon implements ResultSet {
  37      
  38      /**
  39       * Gets optimized SQLiteResultSetIterator.
  40       * @return SQLiteResultSetIterator
  41       */
  42      public function getIterator()
  43      {
  44          require_once 'creole/drivers/sqlite/SQLiteResultSetIterator.php';
  45          return new SQLiteResultSetIterator($this);
  46      }
  47             
  48      /**
  49       * @see ResultSet::seek()
  50       */ 
  51      public function seek($rownum)
  52      {
  53          // MySQL rows start w/ 0, but this works, because we are
  54          // looking to move the position _before_ the next desired position
  55           if (!@sqlite_seek($this->result, $rownum)) {
  56                  return false;
  57          }
  58          $this->cursorPos = $rownum;
  59          return true;
  60      }
  61      
  62      /**
  63       * @see ResultSet::next()
  64       */ 
  65      function next()
  66      {
  67          $this->fields = sqlite_fetch_array($this->result, $this->fetchmode); // (ResultSet::FETCHMODE_NUM = SQLITE_NUM, etc.)
  68             if (!$this->fields) {
  69              $errno = sqlite_last_error($this->conn->getResource());
  70              if (!$errno) {
  71                  // We've advanced beyond end of recordset.
  72                  $this->afterLast();
  73                  return false;
  74              } else {
  75                  throw new SQLException("Error fetching result", sqlite_error_string($errno));
  76              }
  77          }
  78          
  79          // Advance cursor position
  80          $this->cursorPos++;
  81          return true;
  82      }
  83  
  84      /**
  85       * @see ResultSet::getRecordCount()
  86       */
  87      public function getRecordCount()
  88      {
  89          $rows = @sqlite_num_rows($this->result);
  90          if ($rows === null) {
  91              throw new SQLException("Error fetching num rows", sqlite_error_string(sqlite_last_error($this->conn->getResource())));
  92          }
  93          return (int) $rows;
  94      }    
  95  
  96      /**
  97       * Performs sqlite_udf_decode_binary on binary data.
  98       * @see ResultSet::getBlob()
  99       */
 100      public function getBlob($column) 
 101      {
 102          $idx = (is_int($column) ? $column - 1 : $column);
 103          if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
 104          if ($this->fields[$idx] === null) { return null; }
 105          require_once 'creole/util/Blob.php';
 106          $b = new Blob();
 107          $b->setContents(sqlite_udf_decode_binary($this->fields[$idx]));
 108          return $b;
 109      }    
 110      
 111      /**
 112       * Simply empties array as there is no result free method for sqlite.
 113       * @see ResultSet::close()
 114       */
 115      public function close()
 116      {
 117          $this->fields = array();
 118          $this->result = null;
 119      }
 120  }


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