Source for file Firebird.php

Documentation is available at Firebird.php

  1. <?php
  2. /*
  3.  *  $Id: Firebird.php 1731 2007-06-18 18:30:19Z 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.  * @subpackage  Doctrine_DataDict
  25.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  26.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  27.  * @author      Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
  28.  * @author      Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
  29.  * @version     $Revision: 1731 $
  30.  * @category    Object Relational Mapping
  31.  * @link        www.phpdoctrine.com
  32.  * @since       1.0
  33.  */
  34. {
  35.     /**
  36.      * Obtain DBMS specific SQL code portion needed to declare an text type
  37.      * field to be used in statements like CREATE TABLE.
  38.      *
  39.      * @param array $field  associative array with the name of the properties
  40.      *       of the field being declared as array indexes. Currently, the types
  41.      *       of supported field properties are as follows:
  42.      *
  43.      *       length
  44.      *           Integer value that determines the maximum length of the text
  45.      *           field. If this argument is missing the field should be
  46.      *           declared to have the longest length allowed by the DBMS.
  47.      *
  48.      *       default
  49.      *           Text value to be used as default for this field.
  50.      *
  51.      *       notnull
  52.      *           Boolean flag that indicates whether this field is constrained
  53.      *           to not be set to null.
  54.      * @return string  DBMS specific SQL code portion that should be used to
  55.      *       declare the specified field.
  56.      */
  57.     public function getNativeDeclaration($field)
  58.     {
  59.         if isset($field['type'])) {
  60.             throw new Doctrine_DataDict_Exception('Missing column type.');
  61.         }
  62.         switch ($field['type']{
  63.             case 'varchar':
  64.             case 'string':
  65.             case 'array':
  66.             case 'object':
  67.             case 'char':
  68.             case 'text':
  69.             case 'gzip':
  70.                 $length !empty($field['length'])
  71.                     ? $field['length'16777215// TODO: $this->conn->options['default_text_field_length'];
  72.  
  73.                 $fixed  ((isset($field['fixed']&& $field['fixed']|| $field['type'== 'char'true false;
  74.  
  75.                 return $fixed 'CHAR('.$length.')' 'VARCHAR('.$length.')';
  76.             case 'clob':
  77.                 return 'BLOB SUB_TYPE 1';
  78.             case 'blob':
  79.                 return 'BLOB SUB_TYPE 0';
  80.             case 'integer':
  81.             case 'enum':
  82.             case 'int':
  83.                 return 'INT';
  84.             case 'boolean':
  85.                 return 'SMALLINT';
  86.             case 'date':
  87.                 return 'DATE';
  88.             case 'time':
  89.                 return 'TIME';
  90.             case 'timestamp':
  91.                 return 'TIMESTAMP';
  92.             case 'float':
  93.                 return 'DOUBLE PRECISION';
  94.             case 'decimal':
  95.                 $length !empty($field['length']$field['length'18;
  96.                 $scale !empty($field['scale']$field['scale'$this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
  97.                 return 'DECIMAL('.$length.','.$scale.')';
  98.         }
  99.  
  100.         throw new Doctrine_DataDict_Exception('Unknown field type \'' $field['type'.  '\'.');
  101.     }
  102.     /**
  103.      * Maps a native array description of a field to a Doctrine datatype and length
  104.      *
  105.      * @param array  $field native field description
  106.      * @return array containing the various possible types, length, sign, fixed
  107.      */
  108.     public function getPortableDeclaration($field)
  109.     {
  110.         $length  (isset($field['length']&& $field['length'0$field['length'null;
  111.  
  112.         $type array();
  113.         $unsigned $fixed null;
  114.         $dbType strtolower($field['type']);
  115.         $field['field_sub_type'!empty($field['field_sub_type'])
  116.             ? strtolower($field['field_sub_type']null;
  117.  
  118.         if isset($field['name'])) {
  119.             $field['name''';
  120.         }
  121.  
  122.         switch ($dbType{
  123.             case 'smallint':
  124.             case 'integer':
  125.             case 'int64':
  126.                 //these may be 'numeric' or 'decimal'
  127.                 if (isset($field['field_sub_type'])) {
  128.                     $field['type'$field['field_sub_type'];
  129.                     return $this->getPortableDeclaration($field);
  130.                 }
  131.             case 'bigint':
  132.             case 'quad':
  133.                 $type['integer';
  134.                 if ($length == '1'{
  135.                     $type['boolean';
  136.                     if (preg_match('/^(is|has)/'$field['name'])) {
  137.                         $type array_reverse($type);
  138.                     }
  139.                 }
  140.                 break;
  141.             case 'varchar':
  142.                 $fixed false;
  143.             case 'char':
  144.             case 'cstring':
  145.                 $type['string';
  146.                 if ($length == '1'{
  147.                     $type['boolean';
  148.                     if (preg_match('/^(is|has)/'$field['name'])) {
  149.                         $type array_reverse($type);
  150.                     }
  151.                 }
  152.                 if ($fixed !== false{
  153.                     $fixed true;
  154.                 }
  155.                 break;
  156.             case 'date':
  157.                 $type['date';
  158.                 $length null;
  159.                 break;
  160.             case 'timestamp':
  161.                 $type['timestamp';
  162.                 $length null;
  163.                 break;
  164.             case 'time':
  165.                 $type['time';
  166.                 $length null;
  167.                 break;
  168.             case 'float':
  169.             case 'double':
  170.             case 'double precision':
  171.             case 'd_float':
  172.                 $type['float';
  173.                 break;
  174.             case 'decimal':
  175.             case 'numeric':
  176.                 $type['decimal';
  177.                 break;
  178.             case 'blob':
  179.                 $type[($field['field_sub_type'== 'text''clob' 'blob';
  180.                 $length null;
  181.                 break;
  182.             default:
  183.                 throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$dbType);
  184.         }
  185.  
  186.         return array('type'     => $type,
  187.                      'length'   => $length,
  188.                      'unsigned' => $unsigned,
  189.                      'fixed'    => $fixed);
  190.     }
  191.     /**
  192.      * Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
  193.      * of a field declaration to be used in statements like CREATE TABLE.
  194.      *
  195.      * @param string $charset   name of the charset
  196.      * @return string  DBMS specific SQL code portion needed to set the CHARACTER SET
  197.      *                  of a field declaration.
  198.      */
  199.     public function getCharsetFieldDeclaration($charset)
  200.     {
  201.         return 'CHARACTER SET ' $charset;
  202.     }
  203.     /**
  204.      * Obtain DBMS specific SQL code portion needed to set the COLLATION
  205.      * of a field declaration to be used in statements like CREATE TABLE.
  206.      *
  207.      * @param string $collation   name of the collation
  208.      * @return string  DBMS specific SQL code portion needed to set the COLLATION
  209.      *                  of a field declaration.
  210.      */
  211.     public function getCollationFieldDeclaration($collation)
  212.     {
  213.         return 'COLLATE ' $collation;
  214.     }
  215. }