[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * $Id: SQLiteTypes.php,v 1.3 2004/03/20 04:16:50 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 * MySQL types / type map. 27 * 28 * @author Hans Lellelid <hans@xmpl.org> 29 * @version $Revision: 1.3 $ 30 * @package creole.drivers.sqlite 31 */ 32 class SQLiteTypes extends CreoleTypes { 33 34 /** 35 * Map some fake SQLite types CreoleTypes. 36 * SQLite is typeless so this is really only for "hint" / readability 37 * purposes. 38 * @var array 39 */ 40 private static $typeMap = array( 41 'tinyint' => CreoleTypes::TINYINT, 42 'smallint' => CreoleTypes::SMALLINT, 43 'mediumint' => CreoleTypes::SMALLINT, 44 'int' => CreoleTypes::INTEGER, 45 'integer' => CreoleTypes::INTEGER, 46 'bigint' => CreoleTypes::BIGINT, 47 'int24' => CreoleTypes::BIGINT, 48 'real' => CreoleTypes::REAL, 49 'float' => CreoleTypes::FLOAT, 50 'decimal' => CreoleTypes::DECIMAL, 51 'numeric' => CreoleTypes::NUMERIC, 52 'double' => CreoleTypes::DOUBLE, 53 'char' => CreoleTypes::CHAR, 54 'varchar' => CreoleTypes::VARCHAR, 55 'date' => CreoleTypes::DATE, 56 'time' => CreoleTypes::TIME, 57 'year' => CreoleTypes::YEAR, 58 'datetime' => CreoleTypes::TIMESTAMP, 59 'timestamp' => CreoleTypes::TIMESTAMP, 60 'tinyblob' => CreoleTypes::BINARY, 61 'blob' => CreoleTypes::VARBINARY, 62 'mediumblob' => CreoleTypes::VARBINARY, 63 'longblob' => CreoleTypes::VARBINARY, 64 'tinytext' => CreoleTypes::VARCHAR, 65 'mediumtext' => CreoleTypes::LONGVARCHAR, 66 'text' => CreoleTypes::LONGVARCHAR, 67 ); 68 69 /** Reverse mapping, created on demand. */ 70 private static $reverseMap = null; 71 72 /** 73 * This method returns the generic Creole (JDBC-like) type 74 * when given the native db type. If no match is found then we just 75 * return CreoleTypes::TEXT because SQLite is typeless. 76 * @param string $nativeType DB native type (e.g. 'TEXT', 'byetea', etc.). 77 * @return int Creole native type (e.g. CreoleTypes::LONGVARCHAR, CreoleTypes::BINARY, etc.). 78 */ 79 public static function getType($nativeType) 80 { 81 $t = strtolower($nativeType); 82 if (isset(self::$typeMap[$t])) { 83 return self::$typeMap[$t]; 84 } else { 85 return CreoleTypes::TEXT; // because SQLite is typeless 86 } 87 } 88 89 /** 90 * This method will return a native type that corresponds to the specified 91 * Creole (JDBC-like) type. Remember that this is really only for "hint" purposes 92 * as SQLite is typeless. 93 * 94 * If there is more than one matching native type, then the LAST defined 95 * native type will be returned. 96 * 97 * @param int $creoleType 98 * @return string Native type string. 99 */ 100 public static function getNativeType($creoleType) 101 { 102 if (self::$reverseMap === null) { 103 self::$reverseMap = array_flip(self::$typeMap); 104 } 105 return @self::$reverseMap[$creoleType]; 106 } 107 108 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |