Source for file Oracle.php

Documentation is available at Oracle.php

  1. <?php
  2. /*
  3.  *  $Id: Oracle.php 1798 2007-06-24 21:05:12Z 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_Connection');
  22. /**
  23.  * Doctrine_Connection_Oracle
  24.  *
  25.  * @package     Doctrine
  26.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  27.  * @category    Object Relational Mapping
  28.  * @link        www.phpdoctrine.com
  29.  * @since       1.0
  30.  * @version     $Revision: 1798 $
  31.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  32.  */
  33. {
  34.     /**
  35.      * @var string $driverName                  the name of this connection driver
  36.      */
  37.     protected $driverName = 'Oracle';
  38.  
  39.     public function __construct(Doctrine_Manager $manager$adapter)
  40.     {
  41.         $this->supported = array(
  42.                           'sequences'            => true,
  43.                           'indexes'              => true,
  44.                           'summary_functions'    => true,
  45.                           'order_by_text'        => true,
  46.                           'current_id'           => true,
  47.                           'affected_rows'        => true,
  48.                           'transactions'         => true,
  49.                           'savepoints'           => true,
  50.                           'limit_queries'        => true,
  51.                           'LOBs'                 => true,
  52.                           'replace'              => 'emulated',
  53.                           'sub_selects'          => true,
  54.                           'auto_increment'       => false// implementation is broken
  55.                           'primary_key'          => true,
  56.                           'result_introspection' => true,
  57.                           'prepared_statements'  => true,
  58.                           'identifier_quoting'   => true,
  59.                           'pattern_escaping'     => true,
  60.                           );
  61.         /**
  62.         $this->options['DBA_username'] = false;
  63.         $this->options['DBA_password'] = false;
  64.         $this->options['database_name_prefix'] = false;
  65.         $this->options['emulate_database'] = true;
  66.         $this->options['default_tablespace'] = false;
  67.         $this->options['default_text_field_length'] = 2000;
  68.         $this->options['result_prefetching'] = false;
  69.         */
  70.         parent::__construct($manager$adapter);
  71.     }
  72.     /**
  73.      * Sets up the date/time format
  74.      *
  75.      */
  76.     public function setDateFormat($format 'YYYY-MM-DD HH24:MI:SS')
  77.     {
  78.       $this->exec('ALTER SESSION SET NLS_DATE_FORMAT = "' $format '"');
  79.     }
  80.     /**
  81.      * Adds an driver-specific LIMIT clause to the query
  82.      *
  83.      * @param string $query         query to modify
  84.      * @param integer $limit        limit the number of rows
  85.      * @param integer $offset       start reading from given offset
  86.      * @return string               the modified query
  87.      */
  88.     public function modifyLimitQuery($query$limit$offset)
  89.     {
  90.         /**
  91.         $e      = explode("select ",strtolower($query));
  92.         $e2     = explode(" from ",$e[1]);
  93.         $fields = $e2[0];
  94.         */
  95.         $limit = (int) $limit;
  96.         $offset = (int) $offset;
  97.         if (preg_match('/^\s*SELECT/i'$query)) {
  98.             if preg_match('/\sFROM\s/i'$query)) {
  99.                 $query .= " FROM dual";
  100.             }
  101.             if ($limit 0{
  102.                 // taken from http://svn.ez.no/svn/ezcomponents/packages/Database
  103.                 $max $offset $limit;
  104.                 if ($offset 0{
  105.                     $min $offset 1;
  106.                     $query 'SELECT * FROM (SELECT a.*, ROWNUM dctrn_rownum FROM (' $query
  107.                            . ') a WHERE ROWNUM <= ' $max ') WHERE dctrn_rownum >= ' $min;
  108.                 else {
  109.                     $query 'SELECT a.* FROM (' $query .') a WHERE ROWNUM <= ' $max;
  110.                 }
  111.             }
  112.         }
  113.         return $query;
  114.     }
  115. }