2008-08-01 22:46:14 +04:00
|
|
|
<?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
|
2009-05-05 21:20:55 +04:00
|
|
|
* <http://www.doctrine-project.org>.
|
2008-08-16 23:40:59 +04:00
|
|
|
*/
|
2008-08-01 22:46:14 +04:00
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\DBAL\Platforms;
|
2008-09-12 12:51:56 +04:00
|
|
|
|
2008-08-16 23:40:59 +04:00
|
|
|
/**
|
2009-05-05 21:20:55 +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)
|
|
|
|
*/
|
2009-01-22 22:38:10 +03:00
|
|
|
class OraclePlatform extends AbstractPlatform
|
2008-08-01 22:46:14 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-08-01 22:46:14 +04:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2009-05-27 22:54:40 +04:00
|
|
|
if ($length !== null) {
|
2008-08-01 22:46:14 +04:00
|
|
|
return "SUBSTR($value, $position, $length)";
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
2008-08-01 22:46:14 +04:00
|
|
|
|
|
|
|
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()';
|
|
|
|
}
|
2009-05-05 21:20:55 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@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-08-01 22:46:14 +04:00
|
|
|
}
|
2008-09-07 17:48:40 +04:00
|
|
|
|
|
|
|
/**
|
2009-05-05 21:20:55 +04:00
|
|
|
* {@inheritdoc}
|
2008-09-07 17:48:40 +04:00
|
|
|
*
|
2009-05-05 21:20:55 +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
|
|
|
|
|
|
|
/**
|
2009-05-05 21:20:55 +04:00
|
|
|
* {@inheritdoc}
|
2008-09-12 21:25:38 +04:00
|
|
|
*
|
2009-05-05 21:20:55 +04:00
|
|
|
* @param integer $level
|
2008-09-12 21:25:38 +04:00
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
public function getSetTransactionIsolationSql($level)
|
|
|
|
{
|
2009-05-17 23:27:12 +04:00
|
|
|
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
|
2008-09-12 21:25:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
2009-05-05 21:20:55 +04:00
|
|
|
* @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:
|
2009-05-17 23:27:12 +04:00
|
|
|
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
|
|
|
|
2009-05-07 17:54:01 +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;
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the platform name for this instance
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'oracle';
|
|
|
|
}
|
2009-02-20 08:46:20 +03:00
|
|
|
}
|