Source for file Oracle.php

Documentation is available at Oracle.php

  1. <?php
  2. /*
  3.  *  $Id: Oracle.php 1334 2007-05-11 19:20:38Z lsmith $
  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.  * @version     $Revision: 1334 $
  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.      * @return string  DBMS specific SQL code portion that should be used to
  53.      *       declare the specified field.
  54.      */
  55.     public function getNativeDeclaration(array $field)
  56.     {
  57.         if isset($field['type'])) {
  58.             throw new Doctrine_DataDict_Exception('Missing column type.');
  59.         }
  60.         switch ($field['type']{
  61.             case 'string':
  62.             case 'array':
  63.             case 'object':
  64.             case 'gzip':
  65.             case 'char':
  66.             case 'varchar':
  67.                 $length !empty($field['length'])
  68.                     ? $field['length'16777215// TODO: $this->conn->options['default_text_field_length'];
  69.  
  70.                 $fixed  ((isset($field['fixed']&& $field['fixed']|| $field['type'== 'char'true false;
  71.  
  72.                 return $fixed 'CHAR('.$length.')' 'VARCHAR2('.$length.')';
  73.             case 'clob':
  74.                 return 'CLOB';
  75.             case 'blob':
  76.                 return 'BLOB';
  77.             case 'integer':
  78.             case 'enum':
  79.             case 'int':
  80.                 if (!empty($field['length'])) {
  81.                     return 'NUMBER('.$field['length'].')';
  82.                 }
  83.                 return 'INT';
  84.             case 'boolean':
  85.                 return 'NUMBER(1)';
  86.             case 'date':
  87.             case 'time':
  88.             case 'timestamp':
  89.                 return 'DATE';
  90.             case 'float':
  91.             case 'double':
  92.                 return 'NUMBER';
  93.             case 'decimal':
  94.                 $scale !empty($field['scale']$field['scale'$this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
  95.                 return 'NUMBER(*,'.$scale.')';
  96.             default:
  97.         }
  98.         throw new Doctrine_DataDict_Exception('Unknown field type \'' $field['type'.  '\'.');
  99.     }
  100.     /**
  101.      * Maps a native array description of a field to a doctrine datatype and length
  102.      *
  103.      * @param array  $field native field description
  104.      * @return array containing the various possible types, length, sign, fixed
  105.      * @throws Doctrine_DataDict_Oracle_Exception
  106.      */
  107.     public function getPortableDeclaration(array $field)
  108.     {
  109.         $dbType strtolower($field['type']);
  110.         $type array();
  111.         $length $unsigned $fixed null;
  112.         if (!empty($field['length'])) {
  113.             $length $field['length'];
  114.         }
  115.  
  116.         if isset($field['name'])) {
  117.             $field['name''';
  118.         }
  119.  
  120.         switch ($dbType{
  121.             case 'integer':
  122.             case 'pls_integer':
  123.             case 'binary_integer':
  124.                 $type['integer';
  125.                 if ($length == '1'{
  126.                     $type['boolean';
  127.                     if (preg_match('/^(is|has)/'$field['name'])) {
  128.                         $type array_reverse($type);
  129.                     }
  130.                 }
  131.                 break;
  132.             case 'varchar':
  133.             case 'varchar2':
  134.             case 'nvarchar2':
  135.                 $fixed false;
  136.             case 'char':
  137.             case 'nchar':
  138.                 $type['string';
  139.                 if ($length == '1'{
  140.                     $type['boolean';
  141.                     if (preg_match('/^(is|has)/'$field['name'])) {
  142.                         $type array_reverse($type);
  143.                     }
  144.                 }
  145.                 if ($fixed !== false{
  146.                     $fixed true;
  147.                 }
  148.                 break;
  149.             case 'date':
  150.             case 'timestamp':
  151.                 $type['timestamp';
  152.                 $length null;
  153.                 break;
  154.             case 'float':
  155.                 $type['float';
  156.                 break;
  157.             case 'number':
  158.                 if (!empty($field['scale'])) {
  159.                     $type['decimal';
  160.                 else {
  161.                     $type['integer';
  162.                     if ($length == '1'{
  163.                         $type['boolean';
  164.                         if (preg_match('/^(is|has)/'$field['name'])) {
  165.                             $type array_reverse($type);
  166.                         }
  167.                     }
  168.                 }
  169.                 break;
  170.             case 'long':
  171.                 $type['string';
  172.             case 'clob':
  173.             case 'nclob':
  174.                 $type['clob';
  175.                 break;
  176.             case 'blob':
  177.             case 'raw':
  178.             case 'long raw':
  179.             case 'bfile':
  180.                 $type['blob';
  181.                 $length null;
  182.             break;
  183.             case 'rowid':
  184.             case 'urowid':
  185.             default:
  186.                 throw new Doctrine_DataDict_Exception('unknown database attribute type: ' $dbType);
  187.         }
  188.  
  189.         return array('type'     => $type,
  190.                      'length'   => $length,
  191.                      'unsigned' => $unsigned,
  192.                      'fixed'    => $fixed);
  193.     }
  194. }