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

   1  <?php
   2  /*
   3   *  $Id: ODBCResultSetCommon.php,v 1.3 2006/01/17 19:44:39 hlellelid 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   * Base class for ODBC implementation of ResultSet.
  27   *
  28   * @author    Dave Lawson <dlawson@masterytech.com>
  29   * @version   $Revision: 1.3 $
  30   * @package   creole.drivers.odbc
  31   */
  32  abstract class ODBCResultSetCommon extends ResultSetCommon
  33  {
  34      /**
  35       * Offset at which to start reading rows (for emulated offset).
  36       * @var int
  37       */
  38      protected $offset = 0;
  39  
  40      /**
  41       * Maximum rows to retrieve, or 0 if all (for emulated limit).
  42       * @var int
  43       */
  44      protected $limit = 0;
  45  
  46      /**
  47       * @see ResultSet::__construct()
  48       */
  49      public function __construct(Connection $conn, $result, $fetchmode = null)
  50      {
  51          parent::__construct($conn, $result, $fetchmode);
  52      }
  53  
  54      /**
  55       * @see ResultSet::close()
  56       */
  57      public function close()
  58      {
  59          $this->result = null;
  60          $this->conn = null;
  61          $this->fetchmode = null;
  62          $this->cursorPos = 0;
  63          $this->fields = null;
  64          $this->lowerAssocCase = false;
  65          $this->limit = 0;
  66          $this->offset = 0;
  67      }
  68  
  69      /**
  70       * This function exists to set offset after ResultSet is instantiated.
  71       * This function should be "protected" in Java sense: only available to classes in package.
  72       * THIS METHOD SHOULD NOT BE CALLED BY ANYTHING EXCEPTION DRIVER CLASSES.
  73       * @param int $offset New offset.
  74       * @access protected
  75       */
  76      public function _setOffset($offset)
  77      {
  78          $this->offset = $offset;
  79      }
  80  
  81      /**
  82       * This function exists to set limit after ResultSet is instantiated.
  83       * This function should be "protected" in Java sense: only available to classes in package.
  84       * THIS METHOD SHOULD NOT BE CALLED BY ANYTHING EXCEPTION DRIVER CLASSES.
  85       * @param int $limit New limit.
  86       * @access protected
  87       */
  88      public function _setLimit($limit)
  89      {
  90          $this->limit = $limit;
  91      }
  92  
  93      /**
  94       * If fetchmode is FETCHMODE_ASSOC, returns the 1-based field index number
  95       * for the specified column name. Otherwise returns 0 (false).
  96       * @return int
  97       */
  98      function getFieldNum($colname)
  99      {
 100          $fieldnum = 0;
 101  
 102          if ($this->fetchmode == ResultSet::FETCHMODE_ASSOC)
 103          {
 104              $keys = array_keys($this->fields);
 105              $fieldnum = array_search($colname, $keys);
 106          }
 107  
 108          return $fieldnum;
 109      }
 110  
 111      /**
 112       * Reads in any unread LOB data. For long char fields, we may already
 113       * have up to odbc_longreadlen() bytes in the buffer. These are passed
 114       * in via the $curdata parm. For long binary fields, no data is read
 115       * initially since odbc_binmode() is set to ODBC_BINMODE_PASSTHRU.
 116       * This method adjusts the binmode and longreadlen to finish reading
 117       * these datatypes into the buffer. Returns a string with the complete
 118       * contents.
 119       *
 120       * @param int|string $column Column index or name to read data from.
 121       * @param int $binmode ODBC_BINMODE_RETURN for binary data, ODBC_BINMODE_CONVERT for char data.
 122       * @param string $curdata Existing LOB data already in buffer.
 123       * @return string
 124       */
 125      protected function readLobData($column, $binmode, $curdata = null)
 126      {
 127          // Retrieve field num
 128          $fldNum = (is_int($column) ? $column : getFieldNum($column));
 129  
 130          $data = $curdata;
 131          $newdata = null;
 132  
 133          // Adjust binmode and longreadlen
 134          odbc_binmode($this->result->getHandle(), $binmode);
 135          odbc_longreadlen($this->result->getHandle(), 4096);
 136  
 137          while (1)
 138          {
 139              $newdata = odbc_result($this->result->getHandle(), $fldNum);
 140  
 141              if ($newdata === false)
 142                  break;
 143              else
 144                  $data .= $newdata;
 145          }
 146  
 147          // Restore the default binmode and longreadlen
 148          odbc_binmode($this->result->getHandle(), ODBC_BINMODE_PASSTHRU);
 149          odbc_longreadlen($this->result->getHandle(), ini_get('odbc.defaultlrl'));
 150  
 151          // The ODBC driver I use seems to return a string with an escaped
 152          // null char at the end for clob data.
 153          $data = rtrim($data, "\x0");
 154  
 155          return $data;
 156      }
 157      
 158      /**
 159       * Converts row fields to names if FETCHMODE_ASSOC is set.
 160       *
 161       * @param array& Row to convert.
 162       *
 163       * @return array& Converted row.
 164       */
 165      protected function checkFetchMode(&$row)
 166      {
 167          if ($this->fetchmode == ResultSet::FETCHMODE_ASSOC)
 168          {
 169              $newrow = array();
 170              
 171              for ($i = 0, $n = count($row); $i < $n; $i++)
 172              {
 173                  $colname = @odbc_field_name($this->result->getHandle(), $i+1);
 174                  
 175                  if ($this->lowerAssocCase) {
 176                      $colname = strtolower($colname);
 177                  }
 178                  
 179                  $newrow[$colname] = $row[$i];
 180              }
 181              
 182              $row =& $newrow;
 183          }
 184          
 185          return $row;
 186      }
 187  
 188  }


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