[ 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/odbc/ -> ODBCResultSet.php (source)

   1  <?php
   2  /*
   3   *  $Id: ODBCResultSet.php,v 1.2 2005/04/01 17:10:42 dlawson_mi 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/drivers/odbc/ODBCResultSetCommon.php';
  23  
  24  /**
  25   * ODBC implementation of ResultSet.
  26   *
  27   * If the current ODBC driver does not support LIMIT or OFFSET natively,
  28   * the methods in here perform some adjustments and extra checking to make
  29   * sure that this behaves the same as RDBMS drivers using native OFFSET/LIMIT.
  30   *
  31   * This class also emulates a row count if the driver is not capable of 
  32   * providing one natively.
  33   * 
  34   * NOTE: This class only works with drivers that support absolute cursor 
  35   *       positioning (SQL_FETCH_DIRECTION = SQL_FD_FETCH_ABSOLUTE). If the
  36   *       driver you are using does not support reverse/absolute cursor 
  37   *       scrolling, you should use the {@link ODBCCachedResultSet} class instead.
  38   *       See the documentation for ODBCCachedResultSet for instructions on how
  39   *       to use it.
  40   *
  41   * @author    Dave Lawson <dlawson@masterytech.com>
  42   * @version   $Revision: 1.2 $
  43   * @package   creole.drivers.odbc
  44   */
  45  class ODBCResultSet extends ODBCResultSetCommon implements ResultSet
  46  {
  47      /**
  48       * Number of rows in resultset.
  49       *
  50       * @var int
  51       */
  52      protected $numRows = -1;
  53  
  54      /**
  55       * True if ODBC driver supports odbc_num_rows().
  56       *
  57       * @var boolean
  58       */
  59      protected $hasRowCount = false;
  60      
  61      /**
  62       * @see ResultSet::__construct()
  63       */
  64      public function __construct(Connection $conn, $result, $fetchmode = null)
  65      {
  66          parent::__construct($conn, $result, $fetchmode);
  67  
  68          /**
  69           * Some ODBC drivers appear not to handle odbc_num_rows() very well when
  70           * more than one result handle is active at once. For example, the MySQL
  71           * ODBC driver always returns the number of rows for the last executed
  72           * result. For this reason, we'll store the row count here.
  73           *
  74           * Note also that many ODBC drivers do not support this method. In this
  75           * case, getRecordCount() will perform a manual count.
  76           */
  77          $this->numRows = @odbc_num_rows($result->getHandle());
  78          $this->hasRowCount = $this->numRows != -1;
  79      }
  80  
  81      /**
  82       * @see ODBCResultSetCommon::close()
  83       */
  84      function close()
  85      {
  86          parent::close();
  87          $numRows = -1;
  88      }
  89  
  90      /**
  91       * @see ResultSet::seek()
  92       */
  93      public function seek($rownum)
  94      {
  95          if ($rownum < 0 || $this->limit > 0 && $rownum > $this->limit)
  96              return false;
  97          
  98          $this->cursorPos = $rownum;
  99  
 100          return true;
 101      }
 102  
 103      /**
 104       * @see ResultSet::next()
 105       */
 106      public function next()
 107      {
 108          $this->cursorPos++;
 109          
 110          if ($this->limit > 0 && $this->cursorPos > $this->limit) {
 111              $this->cursorPos = $this->limit+1;
 112              return false;
 113          }
 114  
 115          $rowNum = $this->offset + $this->cursorPos;
 116          $fields = null;
 117          
 118          $cols = @odbc_fetch_into($this->result->getHandle(), $fields, $rowNum);
 119  
 120          if ($cols === false) {
 121              $this->cursorPos = -1;
 122              return false;
 123          }
 124  
 125          $this->fields =& $this->checkFetchMode($fields);
 126          
 127          return true;
 128      }
 129  
 130      /**
 131       * @see ResultSet::isAfterLast()
 132       */
 133      public function isAfterLast()
 134      {
 135          // Force calculation of last record pos.
 136          if ($this->cursorPos == -1)
 137              $this->getRecordCount();
 138              
 139          return parent::isAfterLast();
 140      }
 141  
 142      /**
 143       * @see ResultSet::getRecordCount()
 144       */
 145      function getRecordCount()
 146      {
 147          if ($this->hasRowCount)
 148          {
 149              // Use driver row count if provided.
 150              $numRows = $this->numRows - $this->offset;
 151  
 152              if ($this->limit > 0 && $numRows > $this->limit)
 153                  $numRows = $this->limit;
 154          }
 155          else 
 156          {
 157              // Do manual row count if driver doesn't provide one.
 158              if ($this->numRows == -1) 
 159              {
 160                  $this->numRows = 0;
 161                  $this->beforeFirst();
 162              
 163                  while($this->next()) 
 164                      $this->numRows++;
 165              }
 166                  
 167              $numRows = $this->numRows;
 168          }
 169  
 170          // Cursor pos is -1 when an attempt to fetch past the last row was made
 171          // (or a fetch error occured).
 172          
 173          if ($this->cursorPos == -1)
 174              $this->cursorPos = $numRows+1;
 175              
 176          return $numRows;
 177      }
 178  
 179      /**
 180       * @see ResultSet::getBlob()
 181       */
 182      public function getBlob($column)
 183      {
 184          require_once 'creole/util/Blob.php';
 185          $idx = (is_int($column) ? $column - 1 : $column);
 186          if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
 187          $data = $this->readLobData($column, ODBC_BINMODE_RETURN, $this->fields[$idx]);
 188          if (!$data) { return null; }
 189          $b = new Blob();
 190          $b->setContents($data);
 191          return $b;
 192      }
 193  
 194      /**
 195       * @see ResultSet::getClob()
 196       */
 197      public function getClob($column)
 198      {
 199          require_once 'creole/util/Clob.php';
 200          $idx = (is_int($column) ? $column - 1 : $column);
 201          if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); }
 202          $data = $this->readLobData($column, ODBC_BINMODE_CONVERT, $this->fields[$idx]);
 203          if (!$data) { return null; }
 204          $c = new Clob();
 205          $c->setContents($data);
 206          return $c;
 207      }
 208  
 209  }


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