3
* $Id: Oracle.php 5116 2008-10-21 20:35:42Z adrive $
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.
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.org>.
23
* Doctrine_Connection_Oracle
26
* @subpackage Connection
27
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
28
* @link www.phpdoctrine.org
30
* @version $Revision: 5116 $
31
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
33
class Doctrine_Connection_Oracle extends Doctrine_Connection
36
* @var string $driverName the name of this connection driver
38
protected $driverName = 'Oracle';
40
public function __construct(Doctrine_Manager $manager, $adapter)
42
$this->supported = array(
45
'summary_functions' => true,
46
'order_by_text' => true,
48
'affected_rows' => true,
49
'transactions' => true,
51
'limit_queries' => 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,
63
$this->properties['sql_file_delimiter'] = "\n/\n";
64
$this->properties['varchar2_max_length'] = 4000;
65
$this->properties['number_max_precision'] = 38;
67
parent::__construct($manager, $adapter);
71
* Sets up the date/time format
74
public function setDateFormat($format = 'YYYY-MM-DD HH24:MI:SS')
76
$this->exec('ALTER SESSION SET NLS_DATE_FORMAT = "' . $format . '"');
80
* Adds an driver-specific LIMIT clause to the query
82
* @param string $query query to modify
83
* @param integer $limit limit the number of rows
84
* @param integer $offset start reading from given offset
85
* @return string the modified query
87
public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false)
89
return $this->_createLimitSubquery($query, $limit, $offset);
92
private function _createLimitSubquery($query, $limit, $offset, $column = null)
94
$limit = (int) $limit;
95
$offset = (int) $offset;
96
if (preg_match('/^\s*SELECT/i', $query)) {
97
if ( ! preg_match('/\sFROM\s/i', $query)) {
98
$query .= " FROM dual";
101
$max = $offset + $limit;
102
$column = $column === null ? '*' : $column;
105
$query = 'SELECT b.'.$column.' FROM ('.
106
'SELECT a.*, ROWNUM AS doctrine_rownum FROM ('
109
'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max;
111
$query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max;
119
* Creates the SQL for Oracle that can be used in the subquery for the limit-subquery
122
public function modifyLimitSubquery(Doctrine_Table $rootTable, $query, $limit = false,
123
$offset = false, $isManip = false)
125
// NOTE: no composite key support
126
$columnNames = $rootTable->getIdentifierColumnNames();
127
if (count($columnNames) > 1) {
128
throw new Doctrine_Connection_Exception("Composite keys in LIMIT queries are "
129
. "currently not supported.");
131
$column = $columnNames[0];
132
return $this->_createLimitSubquery($query, $limit, $offset, $column);
b'\\ No newline at end of file'