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