1
0
mirror of synced 2024-12-13 14:56:01 +03:00
doctrine2/lib/Doctrine/DBAL/Platforms/OraclePlatform.php

232 lines
6.3 KiB
PHP
Raw Normal View History

<?php
2008-08-16 23:40:59 +04:00
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
2008-08-16 23:40:59 +04:00
*/
namespace Doctrine\DBAL\Platforms;
2008-08-16 23:40:59 +04:00
/**
* OraclePlatform.
2008-08-16 23:40:59 +04:00
*
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
*/
class OraclePlatform extends AbstractPlatform
{
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
}
/**
* return string to call a function to get a substring inside an SQL statement
*
* Note: Not SQL92, but common functionality.
*
* @param string $value an sql string literal or column name/alias
* @param integer $position where to start the substring portion
* @param integer $length the substring portion length
* @return string SQL substring function with given parameters
* @override
*/
public function getSubstringExpression($value, $position, $length = null)
{
if ($length !== null) {
return "SUBSTR($value, $position, $length)";
}
return "SUBSTR($value, $position)";
}
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @return string to call a variable with the current timestamp
* @override
*/
public function getNowExpression($type = 'timestamp')
{
switch ($type) {
case 'date':
case 'time':
case 'timestamp':
default:
return 'TO_CHAR(CURRENT_TIMESTAMP, \'YYYY-MM-DD HH24:MI:SS\')';
}
}
/**
* random
*
* @return string an oracle SQL string that generates a float between 0 and 1
* @override
*/
public function getRandomExpression()
{
return 'dbms_random.value';
}
/**
* Returns global unique identifier
*
* @return string to get global unique identifier
* @override
*/
public function getGuidExpression()
{
return 'SYS_GUID()';
}
/**
* {@inheritdoc}
*
* @return string
* @override
*/
public function getCreateSequenceSql($sequenceName, $start = 1, $allocationSize = 1)
{
return 'CREATE SEQUENCE ' . $this->quoteIdentifier($sequenceName)
. ' START WITH ' . $start . ' INCREMENT BY ' . $allocationSize;
}
2008-09-07 17:48:40 +04:00
/**
* {@inheritdoc}
2008-09-07 17:48:40 +04:00
*
* @param string $sequenceName
2008-09-07 17:48:40 +04:00
* @override
*/
public function getSequenceNextValSql($sequenceName)
{
return 'SELECT ' . $this->quoteIdentifier($sequenceName) . '.nextval FROM DUAL';
}
2008-09-12 21:25:38 +04:00
/**
* {@inheritdoc}
2008-09-12 21:25:38 +04:00
*
* @param integer $level
2008-09-12 21:25:38 +04:00
* @override
*/
public function getSetTransactionIsolationSql($level)
{
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
2008-09-12 21:25:38 +04:00
}
/**
* Enter description here...
*
* @param integer $level
2008-09-12 21:25:38 +04:00
* @override
*/
protected function _getTransactionIsolationLevelSql($level)
{
switch ($level) {
case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED:
case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED:
return 'READ COMMITTED';
2008-09-12 21:25:38 +04:00
case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ:
case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE:
return 'SERIALIZABLE';
default:
return parent::_getTransactionIsolationLevelSql($level);
}
}
2009-05-05 22:39:25 +04:00
/**
* @override
*/
public function getIntegerTypeDeclarationSql(array $field)
{
return 'NUMBER(10)';
}
/**
* @override
*/
public function getBigIntTypeDeclarationSql(array $field)
{
return 'NUMBER(20)';
}
/**
* @override
*/
public function getSmallIntTypeDeclarationSql(array $field)
{
return 'NUMBER(5)';
}
/**
* @override
*/
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
{
return '';
}
/**
* Gets the SQL snippet used to declare a VARCHAR column on the Oracle platform.
*
* @params array $field
* @override
*/
public function getVarcharTypeDeclarationSql(array $field)
{
if ( ! isset($field['length'])) {
if (array_key_exists('default', $field)) {
$field['length'] = $this->getVarcharMaxLength();
} else {
$field['length'] = false;
}
}
$length = ($field['length'] <= $this->getVarcharMaxLength()) ? $field['length'] : false;
$fixed = (isset($field['fixed'])) ? $field['fixed'] : false;
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(2000)')
: ($length ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)');
}
2009-05-05 22:39:25 +04:00
/**
* Whether the platform prefers sequences for ID generation.
*
* @return boolean
*/
public function prefersSequences()
{
return true;
}
/**
* Get the platform name for this instance
*
* @return string
*/
public function getName()
{
return 'oracle';
}
}