Source for file Informix.php

Documentation is available at Informix.php

  1. <?php
  2. /*
  3.  *  $Id: Informix.php 1273 2007-04-18 11:11:07Z zYne $
  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, see
  19.  * <http://www.phpdoctrine.com>.
  20.  */
  21. Doctrine::autoload('Doctrine_DataDict');
  22. /**
  23.  * @package     Doctrine
  24.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  25.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  26.  * @author      Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
  27.  * @version     $Revision: 1273 $
  28.  * @category    Object Relational Mapping
  29.  * @link        www.phpdoctrine.com
  30.  * @since       1.0
  31.  */
  32. {
  33.     /**
  34.      * Obtain DBMS specific SQL code portion needed to declare an text type
  35.      * field to be used in statements like CREATE TABLE.
  36.      *
  37.      * @param array $field  associative array with the name of the properties
  38.      *       of the field being declared as array indexes. Currently, the types
  39.      *       of supported field properties are as follows:
  40.      *
  41.      *       length
  42.      *           Integer value that determines the maximum length of the text
  43.      *           field. If this argument is missing the field should be
  44.      *           declared to have the longest length allowed by the DBMS.
  45.      *
  46.      *       default
  47.      *           Text value to be used as default for this field.
  48.      *
  49.      *       notnull
  50.      *           Boolean flag that indicates whether this field is constrained
  51.      *           to not be set to null.
  52.      *
  53.      * @return string  DBMS specific SQL code portion that should be used to
  54.      *       declare the specified field.
  55.      */
  56.     public function getNativeDeclaration($field)
  57.     {
  58.         if isset($field['type'])) {
  59.             throw new Doctrine_DataDict_Exception('Missing column type.');
  60.         }
  61.         switch ($field['type']{
  62.             case 'char':
  63.             case 'varchar':
  64.             case 'array':
  65.             case 'object':
  66.             case 'string':
  67.                 if (empty($field['length']&& array_key_exists('default'$field)) {
  68.                     $field['length'$this->conn->varchar_max_length;
  69.                 }
  70.  
  71.                 $length (empty($field['length'])) $field['length'false;
  72.                 $fixed  ((isset($field['fixed']&& $field['fixed']|| $field['type'== 'char'true false;
  73.  
  74.                 return $fixed ($length 'CHAR('.$length.')' 'CHAR(255)')
  75.                     : ($length 'VARCHAR('.$length.')' 'NVARCHAR');
  76.             case 'clob':
  77.                 return 'TEXT';
  78.             case 'blob':
  79.                 return 'BLOB';
  80.             case 'integer':
  81.                 if (!empty($field['length'])) {
  82.                     $length $field['length'];
  83.                     if ($length <= 1{
  84.                         return 'SMALLINT';
  85.                     elseif ($length == 2{
  86.                         return 'SMALLINT';
  87.                     elseif ($length == || $length == 4{
  88.                         return 'INTEGER';
  89.                     elseif ($length 4{
  90.                         return 'DECIMAL(20)';
  91.                     }
  92.                 }
  93.                 return 'INT';
  94.             case 'boolean':
  95.                 return 'SMALLINT';
  96.             case 'date':
  97.                 return 'DATE';
  98.             case 'time':
  99.                 return 'DATETIME YEAR TO SECOND';
  100.             case 'timestamp':
  101.                 return 'DATETIME';
  102.             case 'float':
  103.                 return 'FLOAT';
  104.             case 'decimal':
  105.                 return 'DECIMAL';
  106.         }
  107.         throw new Doctrine_DataDict_Exception('Unknown field type \'' $field['type'.  '\'.');
  108.     }
  109. }