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

   1  <?php
   2  
   3  /*
   4   *  $Id: ODBCTypes.php,v 1.1 2004/07/27 23:08:30 hlellelid Exp $
   5   *
   6   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   7   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   8   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   9   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17   *
  18   * This software consists of voluntary contributions made by many individuals
  19   * and is licensed under the LGPL. For more information please see
  20   * <http://creole.phpdb.org>.
  21   */
  22  
  23  require_once 'creole/CreoleTypes.php';
  24  
  25  /**
  26   * ODBC types / type map.
  27   *
  28   * @author    Dave Lawson <dlawson@masterytech.com>
  29   * @version   $Revision: 1.1 $
  30   * @package   creole.drivers.odbc
  31   */
  32  class ODBCTypes extends CreoleTypes {
  33  
  34      /**
  35       * Map ODBC native types to Creole (JDBC) types.
  36       */
  37      protected static $typeMap = null;
  38  
  39      /**
  40       * Reverse mapping, created on demand.
  41       */
  42      protected static $reverseMap = null;
  43  
  44      /**
  45       * Loads the map of ODBC data types to Creole (JDBC) types.
  46       *
  47       * NOTE: This function cannot map DBMS-specific datatypes. If you use a
  48       *       driver which implements DBMS-specific datatypes, you will need
  49       *       to modify/extend this class to add the correct mapping.
  50       */
  51      public static function loadTypeMap($conn = null)
  52      {
  53          if (self::$typeMap !== null && count(self::$typeMap) > 0)
  54              return;
  55  
  56          if ($conn == null)
  57              throw new SQLException('No connection specified when loading ODBC type map.');
  58  
  59          self::$typeMap = array();
  60  
  61          $result = @odbc_gettypeinfo($conn->getResource());
  62  
  63          if ($result === false)
  64              throw new SQLException('Failed to retrieve type info.', $conn->nativeError());
  65  
  66          $rowNum = 1;
  67  
  68          while (odbc_fetch_row($result, $rowNum++))
  69          {
  70              $odbctypeid = odbc_result($result, 'DATA_TYPE');
  71              $odbctypename = odbc_result($result, 'TYPE_NAME');
  72  
  73              switch ($odbctypeid)
  74              {
  75                  case SQL_CHAR:
  76                      self::$typeMap[$odbctypename] = CreoleTypes::CHAR;
  77                      break;
  78                  case SQL_VARCHAR:
  79                      self::$typeMap[$odbctypename] = CreoleTypes::VARCHAR;
  80                      break;
  81                  case SQL_LONGVARCHAR:
  82                      self::$typeMap[$odbctypename] = CreoleTypes::LONGVARCHAR;
  83                      break;
  84                  case SQL_DECIMAL:
  85                      self::$typeMap[$odbctypename] = CreoleTypes::DECIMAL;
  86                      break;
  87                  case SQL_NUMERIC:
  88                      self::$typeMap[$odbctypename] = CreoleTypes::NUMERIC;
  89                      break;
  90                  case SQL_BIT:
  91                      self::$typeMap[$odbctypename] = CreoleTypes::BOOLEAN;
  92                      break;
  93                  case SQL_TINYINT:
  94                      self::$typeMap[$odbctypename] = CreoleTypes::TINYINT;
  95                      break;
  96                  case SQL_SMALLINT:
  97                      self::$typeMap[$odbctypename] = CreoleTypes::SMALLINT;
  98                      break;
  99                  case SQL_INTEGER:
 100                      self::$typeMap[$odbctypename] = CreoleTypes::INTEGER;
 101                      break;
 102                  case SQL_BIGINT:
 103                      self::$typeMap[$odbctypename] = CreoleTypes::BIGINT;
 104                      break;
 105                  case SQL_REAL:
 106                      self::$typeMap[$odbctypename] = CreoleTypes::REAL;
 107                      break;
 108                  case SQL_FLOAT:
 109                      self::$typeMap[$odbctypename] = CreoleTypes::FLOAT;
 110                      break;
 111                  case SQL_DOUBLE:
 112                      self::$typeMap[$odbctypename] = CreoleTypes::DOUBLE;
 113                      break;
 114                  case SQL_BINARY:
 115                      self::$typeMap[$odbctypename] = CreoleTypes::BINARY;
 116                      break;
 117                  case SQL_VARBINARY:
 118                      self::$typeMap[$odbctypename] = CreoleTypes::VARBINARY;
 119                      break;
 120                  case SQL_LONGVARBINARY:
 121                      self::$typeMap[$odbctypename] = CreoleTypes::LONGVARBINARY;
 122                      break;
 123                  case SQL_DATE:
 124                      self::$typeMap[$odbctypename] = CreoleTypes::DATE;
 125                      break;
 126                  case SQL_TIME:
 127                      self::$typeMap[$odbctypename] = CreoleTypes::TIME;
 128                      break;
 129                  case SQL_TIMESTAMP:
 130                      self::$typeMap[$odbctypename] = CreoleTypes::TIMESTAMP;
 131                      break;
 132                  case SQL_TYPE_DATE:
 133                      self::$typeMap[$odbctypename] = CreoleTypes::DATE;
 134                      break;
 135                  case SQL_TYPE_TIME:
 136                      self::$typeMap[$odbctypename] = CreoleTypes::TIME;
 137                      break;
 138                  case SQL_TYPE_TIMESTAMP:
 139                      self::$typeMap[$odbctypename] = CreoleTypes::TIMESTAMP;
 140                      break;
 141                  default:
 142                      self::$typeMap[$odbctypename] = CreoleTypes::OTHER;
 143                      break;
 144              }
 145          }
 146  
 147          @odbc_free_result($result);
 148      }
 149  
 150      /**
 151       * This method returns the generic Creole (JDBC-like) type
 152       * when given the native db type.
 153       * @param string $nativeType DB native type (e.g. 'TEXT', 'byetea', etc.).
 154       * @return int Creole native type (e.g. CreoleTypes::LONGVARCHAR, CreoleTypes::BINARY, etc.).
 155       */
 156      public static function getType($nativeType)
 157      {
 158          if (!self::$typeMap)
 159              self::loadTypeMap();
 160  
 161          $t = strtoupper($nativeType);
 162  
 163          if (isset(self::$typeMap[$t])) {
 164              return self::$typeMap[$t];
 165          } else {
 166              return CreoleTypes::OTHER;
 167          }
 168      }
 169  
 170      /**
 171       * This method will return a native type that corresponds to the specified
 172       * Creole (JDBC-like) type.
 173       * If there is more than one matching native type, then the LAST defined
 174       * native type will be returned.
 175       * @param int $creoleType
 176       * @return string Native type string.
 177       */
 178      public static function getNativeType($creoleType)
 179      {
 180          if (!self::$typeMap)
 181              self::loadTypeMap();
 182  
 183          if (self::$reverseMap === null) {
 184              self::$reverseMap = array_flip(self::$typeMap);
 185          }
 186          return @self::$reverseMap[$creoleType];
 187      }
 188  
 189  }


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