[2.0] Various necessary fixes and adjustments for oracle as well as fixes for better handling of temporal types. Closed #2452.
This commit is contained in:
parent
6a3aa84973
commit
733c3c24f7
13 changed files with 91 additions and 23 deletions
|
@ -520,6 +520,11 @@ abstract class AbstractPlatform
|
|||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function getCreateTemporaryTableSnippetSql()
|
||||
{
|
||||
return "CREATE TEMPORARY TABLE";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SQL to create a sequence on this platform.
|
||||
|
@ -1339,6 +1344,18 @@ abstract class AbstractPlatform
|
|||
{
|
||||
throw DoctrineException::getDateTimeTypeDeclarationNotSupported($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain DBMS specific SQL to be used to create date fields in statements
|
||||
* like CREATE TABLE.
|
||||
*
|
||||
* @param array $fieldDeclaration
|
||||
* @return string
|
||||
*/
|
||||
public function getDateTypeDeclarationSql(array $fieldDeclaration)
|
||||
{
|
||||
throw DoctrineException::getDateTypeDeclarationNotSupported($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default transaction isolation level of the platform.
|
||||
|
@ -1529,4 +1546,16 @@ abstract class AbstractPlatform
|
|||
{
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes any fixes to a name of a schema element (table, sequence, ...) that are required
|
||||
* by restrictions of the platform, like a maximum length.
|
||||
*
|
||||
* @param string $schemaName
|
||||
* @return string
|
||||
*/
|
||||
public function fixSchemaElementName($schemaElementName)
|
||||
{
|
||||
return $schemaElementName;
|
||||
}
|
||||
}
|
|
@ -266,6 +266,14 @@ class MySqlPlatform extends AbstractPlatform
|
|||
{
|
||||
return 'DATETIME';
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getDateTypeDeclarationSql(array $fieldDeclaration)
|
||||
{
|
||||
return 'DATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
|
|
|
@ -182,7 +182,7 @@ class OraclePlatform extends AbstractPlatform
|
|||
*/
|
||||
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
|
||||
{
|
||||
return 'DATE';
|
||||
return 'TIMESTAMP(0) WITH TIME ZONE';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -247,7 +247,7 @@ class OraclePlatform extends AbstractPlatform
|
|||
|
||||
foreach ($columns as $name => $column) {
|
||||
if (isset($column['sequence'])) {
|
||||
$sql[] = $this->getCreateSequenceSql($column['sequence'], 1);
|
||||
$sql[] = $this->getCreateSequenceSql($column['sequence'], 1);
|
||||
}
|
||||
|
||||
if (isset($column['autoincrement']) && $column['autoincrement'] ||
|
||||
|
@ -513,4 +513,23 @@ END;';
|
|||
{
|
||||
return strtoupper($column);
|
||||
}
|
||||
|
||||
public function getCreateTemporaryTableSnippetSql()
|
||||
{
|
||||
return "CREATE GLOBAL TEMPORARY TABLE";
|
||||
}
|
||||
|
||||
public function getDateTimeFormatString()
|
||||
{
|
||||
return 'Y-m-d H:i:sP';
|
||||
}
|
||||
|
||||
public function fixSchemaElementName($schemaElementName)
|
||||
{
|
||||
if (strlen($schemaElementName) > 30) {
|
||||
// Trim it
|
||||
return substr($schemaElementName, 0, 30);
|
||||
}
|
||||
return $schemaElementName;
|
||||
}
|
||||
}
|
|
@ -692,7 +692,15 @@ class PostgreSqlPlatform extends AbstractPlatform
|
|||
*/
|
||||
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
|
||||
{
|
||||
return 'TIMESTAMP without time zone';
|
||||
return 'TIMESTAMP(0) WITH TIME ZONE';
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getDateTypeDeclarationSql(array $fieldDeclaration)
|
||||
{
|
||||
return 'DATE';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -757,14 +765,8 @@ class PostgreSqlPlatform extends AbstractPlatform
|
|||
return strtolower($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the format string, as accepted by the date() function, that describes
|
||||
* the format of a stored datetime value of this platform.
|
||||
*
|
||||
* @return string The format string.
|
||||
*/
|
||||
/*public function getDateTimeFormatString()
|
||||
public function getDateTimeFormatString()
|
||||
{
|
||||
return 'Y-m-d H:i:s.u';
|
||||
}*/
|
||||
return 'Y-m-d H:i:sO';
|
||||
}
|
||||
}
|
|
@ -234,6 +234,14 @@ class SqlitePlatform extends AbstractPlatform
|
|||
{
|
||||
return 'DATETIME';
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
public function getDateTypeDeclarationSql(array $fieldDeclaration)
|
||||
{
|
||||
return 'DATE';
|
||||
}
|
||||
|
||||
/** @override */
|
||||
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
|
||||
|
|
|
@ -187,10 +187,10 @@ class OracleSchemaManager extends AbstractSchemaManager
|
|||
$password = $params['password'];
|
||||
|
||||
$query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password;
|
||||
$result = $this->_conn->exec($query);
|
||||
$result = $this->_conn->executeUpdate($query);
|
||||
|
||||
$query = 'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO ' . $username;
|
||||
$result = $this->_conn->exec($query);
|
||||
$result = $this->_conn->executeUpdate($query);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ class OracleSchemaManager extends AbstractSchemaManager
|
|||
{
|
||||
$sql = $this->_platform->getDropAutoincrementSql($table);
|
||||
foreach ($sql as $query) {
|
||||
$this->_conn->exec($query);
|
||||
$this->_conn->executeUpdate($query);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Doctrine\DBAL\Types;
|
|||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
|
||||
/**
|
||||
* Type that maps an SQL DATETIME to a PHP Date object.
|
||||
* Type that maps an SQL DATE to a PHP Date object.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
|
|
|
@ -398,7 +398,8 @@ class ClassMetadataFactory
|
|||
// If there is no sequence definition yet, create a default definition
|
||||
$definition = $class->getSequenceGeneratorDefinition();
|
||||
if ( ! $definition) {
|
||||
$definition['sequenceName'] = $class->getTableName() . '_' . $class->getSingleIdentifierColumnName() . '_seq';
|
||||
$sequenceName = $class->getTableName() . '_' . $class->getSingleIdentifierColumnName() . '_seq';
|
||||
$definition['sequenceName'] = $this->_targetPlatform->fixSchemaElementName($sequenceName);
|
||||
$definition['allocationSize'] = 20;
|
||||
$definition['initialValue'] = 1;
|
||||
$class->setSequenceGeneratorDefinition($definition);
|
||||
|
|
|
@ -95,7 +95,7 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor
|
|||
'type' => \Doctrine\DBAL\Types\Type::getType($rootClass->getTypeOfColumn($idColumnName))
|
||||
);
|
||||
}
|
||||
$this->_createTempTableSql = 'CREATE TEMPORARY TABLE ' . $tempTable . ' ('
|
||||
$this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSql() . ' ' . $tempTable . ' ('
|
||||
. $conn->getDatabasePlatform()->getColumnDeclarationListSql($columnDefinitions)
|
||||
. ', PRIMARY KEY(' . $idColumnList . '))';
|
||||
$this->_dropTempTableSql = 'DROP TABLE ' . $tempTable;
|
||||
|
|
|
@ -127,8 +127,8 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
|
|||
'type' => \Doctrine\DBAL\Types\Type::getType($rootClass->getTypeOfColumn($idColumnName))
|
||||
);
|
||||
}
|
||||
$this->_createTempTableSql = 'CREATE TEMPORARY TABLE ' . $tempTable . ' ('
|
||||
. $conn->getDatabasePlatform()->getColumnDeclarationListSql($columnDefinitions)
|
||||
$this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSql() . ' ' . $tempTable . ' ('
|
||||
. $platform->getColumnDeclarationListSql($columnDefinitions)
|
||||
. ', PRIMARY KEY(' . $idColumnList . '))';
|
||||
$this->_dropTempTableSql = 'DROP TABLE ' . $tempTable;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||
/**
|
||||
* @Entity
|
||||
* @HasLifecycleCallbacks
|
||||
* @Table(name="lifecycle_callback_test_entity")
|
||||
* @Table(name="lc_cb_test_entity")
|
||||
*/
|
||||
class LifecycleCallbackTestEntity
|
||||
{
|
||||
|
|
|
@ -136,7 +136,8 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||
$test = $q->getSingleResult();
|
||||
|
||||
// Manually increment the version datetime column
|
||||
$this->_conn->execute('UPDATE optimistic_timestamp SET version = ? WHERE id = ?', array(date('Y-m-d H:i:s', strtotime($test->version->format('Y-m-d H:i:s')) + 3600), $test->id));
|
||||
$format = $this->_em->getConnection()->getDatabasePlatform()->getDateTimeFormatString();
|
||||
$this->_conn->execute('UPDATE optimistic_timestamp SET version = ? WHERE id = ?', array(date($format, strtotime($test->version->format($format)) + 3600), $test->id));
|
||||
|
||||
// Try and update the record and it should throw an exception
|
||||
$test->name = 'Testing again';
|
||||
|
|
|
@ -20,7 +20,7 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||
parent::setUp();
|
||||
|
||||
if ($this->_em->getConnection()->getDatabasePlatform()->getName() == 'oracle') {
|
||||
$this->markTestSkipped('The ' . $testClass .' does not work with Oracle due to character casing.');
|
||||
$this->markTestSkipped('The ' . __CLASS__ .' does not work with Oracle due to character casing.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue