[ Index ]
 

Code source de Symfony 1.0.0

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

title

Body

[fermer]

/lib/vendor/creole/ -> CreoleTypes.php (source)

   1  <?php
   2  /*
   3   *  $Id: CreoleTypes.php,v 1.18 2005/11/07 22:38:52 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  /**
  23   * Generic Creole types modeled on JDBC types.
  24   * 
  25   * @author    David Giffin <david@giffin.org>
  26   * @author    Hans Lellelid <hans@xmpl.org>
  27   * @version   $Revision: 1.18 $
  28   * @package   creole
  29   */
  30  abstract class CreoleTypes {
  31  
  32          const BOOLEAN = 1;
  33          const BIGINT = 2;
  34          const SMALLINT = 3;
  35          const TINYINT = 4;
  36          const INTEGER = 5;
  37          const CHAR = 6;
  38          const VARCHAR = 7;
  39          const TEXT = 17;
  40          const FLOAT = 8;
  41          const DOUBLE = 9;
  42          const DATE = 10;
  43          const TIME = 11;
  44          const TIMESTAMP = 12;
  45          const VARBINARY = 13;
  46          const NUMERIC = 14;
  47          const BLOB = 15;
  48          const CLOB = 16;
  49          const LONGVARCHAR = 17;
  50          const DECIMAL = 18;
  51          const REAL = 19;
  52          const BINARY = 20;
  53          const LONGVARBINARY = 21;
  54          const YEAR = 22;
  55          
  56          /** this is "ARRAY" from JDBC types */
  57          const ARR = 23;
  58          
  59          const OTHER = -1;
  60          
  61          /** Map of Creole type integers to the setter/getter affix. */
  62          protected static $affixMap = array(
  63                  self::BOOLEAN => 'Boolean',
  64                  self::BIGINT => 'String',
  65                  self::CHAR => 'String',
  66                  self::DATE => 'Date',
  67                  self::DOUBLE => 'Float',
  68                  self::FLOAT => 'Float',
  69                  self::INTEGER => 'Int',
  70                  self::SMALLINT => 'Int',
  71                  self::TINYINT => 'Int',
  72                  self::TIME => 'Time',
  73                  self::TIMESTAMP => 'Timestamp',
  74                  self::VARCHAR => 'String',                
  75                  self::VARBINARY => 'Blob',
  76                  self::NUMERIC => 'Float',
  77                  self::BLOB => 'Blob',
  78                  self::CLOB => 'Clob',
  79                  self::LONGVARCHAR => 'String',
  80                  self::DECIMAL => 'Float',
  81                  self::REAL => 'Float',
  82                  self::BINARY => 'Blob',
  83                  self::LONGVARBINARY => 'Blob',
  84                  self::YEAR => 'Int',
  85                  self::ARR => 'Array',
  86                  self::OTHER => '', // get() and set() for unknown
  87                  );
  88          
  89          /** Map of Creole type integers to their textual name. */
  90          protected static $creoleTypeMap = array(
  91                  self::BOOLEAN => 'BOOLEAN',
  92                  self::BIGINT => 'BIGINT',
  93                  self::SMALLINT => 'SMALLINT',
  94                  self::TINYINT => 'TINYINT',
  95                  self::INTEGER => 'INTEGER',
  96                  self::NUMERIC => 'NUMERIC',
  97                  self::DECIMAL => 'DECIMAL',
  98                  self::REAL => 'REAL',
  99                  self::FLOAT => 'FLOAT',
 100                  self::DOUBLE => 'DOUBLE',
 101                  self::CHAR => 'CHAR',
 102                  self::VARCHAR => 'VARCHAR',
 103                  self::TEXT => 'TEXT',
 104                  self::TIME => 'TIME',
 105                  self::TIMESTAMP => 'TIMESTAMP',
 106                  self::DATE => 'DATE',
 107                  self::YEAR => 'YEAR',
 108                  self::VARBINARY => 'VARBINARY',                
 109                  self::BLOB => 'BLOB',
 110                  self::CLOB => 'CLOB',
 111                  self::LONGVARCHAR => 'LONGVARCHAR',
 112                  self::BINARY => 'BINARY',
 113                  self::LONGVARBINARY => 'LONGVARBINARY',                
 114                  self::ARR => 'ARR',
 115                  self::OTHER => 'OTHER', // string is "raw" return
 116                  );
 117          
 118          /**
 119           * This method returns the generic Creole (JDBC-like) type
 120           * when given the native db type.
 121           * @param string $nativeType DB native type (e.g. 'TEXT', 'byetea', etc.).
 122           * @return int Creole native type (e.g. Types::LONGVARCHAR, Types::BINARY, etc.).
 123           */
 124          public static function getType($nativeType) {
 125              throw new Exception('This method must be overridden in subclasses!'); // abstract static not allowed since PHP 5.2
 126          }
 127          
 128          /**
 129           * This method will return a native type that corresponds to the specified
 130           * Creole (JDBC-like) type.
 131           * If there is more than one matching native type, then the LAST defined 
 132           * native type will be returned.
 133           * @return string Native type string.
 134           */
 135          public static function getNativeType($creoleType) {
 136               throw new Exception('This method must be overridden in subclasses!'); // abstract static not allowed since PHP 5.2
 137          }
 138          
 139          /**
 140           * Gets the "affix" to use for ResultSet::get*() and PreparedStatement::set*() methods.
 141           * <code>
 142           * $setter = 'set' . CreoleTypes::getAffix(CreoleTypes::INTEGER);
 143           * $stmt->$setter(1, $intval);
 144           * // or
 145           * $getter = 'get' . CreoleTypes::getAffix(CreoleTypes::TIMESTAMP);
 146           * $timestamp = $rs->$getter();
 147           * </code>
 148           * @param int $creoleType The Creole types.
 149           * @return string The default affix for getting/setting cols of this type.
 150           * @throws SQLException if $creoleType does not correspond to an affix
 151           */
 152          public static function getAffix($creoleType)
 153          {
 154              if (!isset(self::$affixMap[$creoleType])) {
 155                  $e = new SQLException("Unable to return 'affix' for unknown CreoleType: " . $creoleType);
 156                  throw $e;
 157              }
 158              return self::$affixMap[$creoleType];
 159          }
 160          
 161          /**
 162           * Given the integer type, this method will return the corresponding type name.
 163           * @param int $creoleType the integer Creole type.
 164           * @return string The name of the Creole type (e.g. 'VARCHAR').
 165           */
 166          public static function getCreoleName($creoleType)
 167          {
 168              if (!isset(self::$creoleTypeMap[$creoleType])) {
 169                  return null;
 170              }
 171              return self::$creoleTypeMap[$creoleType];
 172          }
 173          
 174          /**
 175           * Given the name of a type (e.g. 'VARCHAR') this method will return the corresponding integer.
 176           * @param string $creoleTypeName The case-sensisive (must be uppercase) name of the Creole type (e.g. 'VARCHAR').
 177           * @return int the Creole type.
 178           */
 179          public static function getCreoleCode($creoleTypeName)
 180          {
 181              $type = array_search($creoleTypeName, self::$creoleTypeMap);
 182              if ($type === false) {
 183                 return null;
 184              }
 185              return $type;
 186          }
 187  }


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