Commit 16c4efcc authored by romanb's avatar romanb

[2.0] DBAL streamlining and starting to increase test coverage.

parent 80de5678
...@@ -152,7 +152,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -152,7 +152,7 @@ class MySqlPlatform extends AbstractPlatform
* *
* @params array $field * @params array $field
*/ */
public function getVarcharDeclarationSql(array $field) public function getVarcharTypeDeclarationSql(array $field)
{ {
if ( ! isset($field['length'])) { if ( ! isset($field['length'])) {
if (array_key_exists('default', $field)) { if (array_key_exists('default', $field)) {
...@@ -215,8 +215,8 @@ class MySqlPlatform extends AbstractPlatform ...@@ -215,8 +215,8 @@ class MySqlPlatform extends AbstractPlatform
*/ */
public function getNativeDeclaration(array $field) public function getNativeDeclaration(array $field)
{ {
if ( ! isset($field['type'])) { /*if ( ! isset($field['type'])) {
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.'); throw DoctrineException::updateMe('Missing column type.');
} }
switch ($field['type']) { switch ($field['type']) {
...@@ -229,7 +229,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -229,7 +229,7 @@ class MySqlPlatform extends AbstractPlatform
case 'object': case 'object':
case 'string': case 'string':
case 'gzip': case 'gzip':
return $this->getVarcharDeclarationSql($field); return $this->getVarcharTypeDeclarationSql($field);
case 'clob': case 'clob':
return $this->getClobDeclarationSql($field); return $this->getClobDeclarationSql($field);
case 'blob': case 'blob':
...@@ -285,8 +285,8 @@ class MySqlPlatform extends AbstractPlatform ...@@ -285,8 +285,8 @@ class MySqlPlatform extends AbstractPlatform
$length = !empty($field['length']) ? $field['length'] : 18; $length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES); $scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')'; return 'DECIMAL('.$length.','.$scale.')';
} }*/
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.'); throw DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
} }
/** /**
...@@ -298,7 +298,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -298,7 +298,7 @@ class MySqlPlatform extends AbstractPlatform
*/ */
public function getPortableDeclaration(array $field) public function getPortableDeclaration(array $field)
{ {
$dbType = strtolower($field['type']); /*$dbType = strtolower($field['type']);
$dbType = strtok($dbType, '(), '); $dbType = strtok($dbType, '(), ');
if ($dbType == 'national') { if ($dbType == 'national') {
$dbType = strtok('(), '); $dbType = strtok('(), ');
...@@ -448,7 +448,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -448,7 +448,7 @@ class MySqlPlatform extends AbstractPlatform
return array('type' => $type, 'length' => $length, 'unsigned' => $unsigned, 'fixed' => $fixed); return array('type' => $type, 'length' => $length, 'unsigned' => $unsigned, 'fixed' => $fixed);
} else { } else {
return array('type' => $type, 'length' => $length, 'unsigned' => $unsigned, 'fixed' => $fixed, 'values' => $values); return array('type' => $type, 'length' => $length, 'unsigned' => $unsigned, 'fixed' => $fixed, 'values' => $values);
} }*/
} }
/** /**
...@@ -602,7 +602,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -602,7 +602,7 @@ class MySqlPlatform extends AbstractPlatform
if (empty($fields)) { if (empty($fields)) {
throw DoctrineException::updateMe('no fields specified for table "'.$name.'"'); throw DoctrineException::updateMe('no fields specified for table "'.$name.'"');
} }
$queryFields = $this->getFieldDeclarationListSql($fields); $queryFields = $this->getColumnDeclarationListSql($fields);
// build indexes for all foreign key fields (needed in MySQL!!) // build indexes for all foreign key fields (needed in MySQL!!)
if (isset($options['foreignKeys'])) { if (isset($options['foreignKeys'])) {
...@@ -694,10 +694,10 @@ class MySqlPlatform extends AbstractPlatform ...@@ -694,10 +694,10 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* alter an existing table * Gets the SQL to alter an existing table.
* *
* @param string $name name of the table that is intended to be changed. * @param string $name The name of the table that is intended to be changed.
* @param array $changes associative array that contains the details of each type * @param array $changes Associative array that contains the details of each type
* of change that is intended to be performed. The types of * of change that is intended to be performed. The types of
* changes that are currently supported are defined as follows: * changes that are currently supported are defined as follows:
* *
...@@ -815,7 +815,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -815,7 +815,7 @@ class MySqlPlatform extends AbstractPlatform
if ($query) { if ($query) {
$query.= ', '; $query.= ', ';
} }
$query.= 'ADD ' . $this->getDeclarationSql($fieldName, $field); $query.= 'ADD ' . $this->getColumnDeclarationSql($fieldName, $field);
} }
} }
...@@ -849,7 +849,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -849,7 +849,7 @@ class MySqlPlatform extends AbstractPlatform
} }
$oldFieldName = $this->quoteIdentifier($oldFieldName, true); $oldFieldName = $this->quoteIdentifier($oldFieldName, true);
$query .= 'CHANGE ' . $oldFieldName . ' ' $query .= 'CHANGE ' . $oldFieldName . ' '
. $this->getDeclarationSql($fieldName, $field['definition']); . $this->getColumnDeclarationSql($fieldName, $field['definition']);
} }
} }
...@@ -861,7 +861,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -861,7 +861,7 @@ class MySqlPlatform extends AbstractPlatform
$field = $changes['rename'][$renamedField]; $field = $changes['rename'][$renamedField];
$renamedField = $this->quoteIdentifier($renamedField, true); $renamedField = $this->quoteIdentifier($renamedField, true);
$query .= 'CHANGE ' . $renamedField . ' ' $query .= 'CHANGE ' . $renamedField . ' '
. $this->getDeclarationSql($field['name'], $field['definition']); . $this->getColumnDeclarationSql($field['name'], $field['definition']);
} }
} }
...@@ -912,7 +912,6 @@ class MySqlPlatform extends AbstractPlatform ...@@ -912,7 +912,6 @@ class MySqlPlatform extends AbstractPlatform
public function getCreateIndexSql($table, $name, array $definition) public function getCreateIndexSql($table, $name, array $definition)
{ {
$table = $table; $table = $table;
$name = $this->formatter->getIndexName($name);
$name = $this->quoteIdentifier($name); $name = $this->quoteIdentifier($name);
$type = ''; $type = '';
if (isset($definition['type'])) { if (isset($definition['type'])) {
...@@ -968,24 +967,12 @@ class MySqlPlatform extends AbstractPlatform ...@@ -968,24 +967,12 @@ class MySqlPlatform extends AbstractPlatform
return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSql($field); return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
} }
/** @override */
/*public function getTinyIntTypeDeclarationSql(array $field)
{
return 'TINYINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
}*/
/** @override */ /** @override */
public function getSmallIntTypeDeclarationSql(array $field) public function getSmallIntTypeDeclarationSql(array $field)
{ {
return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSql($field); return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
} }
/** @override */
/*public function getMediumIntTypeDeclarationSql(array $field)
{
return 'MEDIUMINT' . $this->_getCommonIntegerTypeDeclarationSql($field);
}*/
/** @override */ /** @override */
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef) protected function _getCommonIntegerTypeDeclarationSql(array $columnDef)
{ {
...@@ -998,27 +985,6 @@ class MySqlPlatform extends AbstractPlatform ...@@ -998,27 +985,6 @@ class MySqlPlatform extends AbstractPlatform
return $unsigned . $autoinc; return $unsigned . $autoinc;
} }
/**
* Obtain DBMS specific SQL code portion needed to set a default value
* declaration to be used in statements like CREATE TABLE.
*
* @param array $field field definition array
* @return string DBMS specific SQL code portion needed to set a default value
* @override
*/
public function getDefaultFieldDeclarationSql($field)
{
$default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
if (isset($field['default']) && ( ! isset($field['length']) || $field['length'] <= 255)) {
if ($field['default'] === '') {
$field['default'] = null;
}
$default = ' DEFAULT ' . $this->quote($field['default'], $field['type']);
}
return $default;
}
/** /**
* Obtain DBMS specific SQL code portion needed to set an index * Obtain DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE. * declaration to be used in statements like CREATE TABLE.
...@@ -1097,7 +1063,6 @@ class MySqlPlatform extends AbstractPlatform ...@@ -1097,7 +1063,6 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* getAdvancedForeignKeyOptions
* Return the FOREIGN KEY query section dealing with non-standard options * Return the FOREIGN KEY query section dealing with non-standard options
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ... * as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
* *
...@@ -1121,32 +1086,28 @@ class MySqlPlatform extends AbstractPlatform ...@@ -1121,32 +1086,28 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* drop existing index * Gets the SQL to drop an index of a table.
* *
* @param string $table name of table that should be used in method * @param string $table name of table that should be used in method
* @param string $name name of the index to be dropped * @param string $name name of the index to be dropped
* @return void
* @override * @override
*/ */
public function getDropIndexSql($table, $name) public function getDropIndexSql($table, $name)
{ {
$table = $this->quoteIdentifier($table, true); $table = $this->quoteIdentifier($table);
$name = $this->quoteIdentifier($this->formatter->getIndexName($name), true); $name = $this->quoteIdentifier($name);
return 'DROP INDEX ' . $name . ' ON ' . $table; return 'DROP INDEX ' . $name . ' ON ' . $table;
} }
/** /**
* dropTable * Gets the SQL to drop a table.
* *
* @param string $table name of table that should be dropped from the database * @param string $table The name of table to drop.
* @throws PDOException
* @return void
* @override * @override
*/ */
public function getDropTableSql($table) public function getDropTableSql($table)
{ {
$table = $this->quoteIdentifier($table, true); return 'DROP TABLE ' . $this->quoteIdentifier($table);
return 'DROP TABLE ' . $table;
} }
/** /**
......
...@@ -26,6 +26,7 @@ namespace Doctrine\DBAL\Platforms; ...@@ -26,6 +26,7 @@ namespace Doctrine\DBAL\Platforms;
* database platform. * database platform.
* *
* @since 2.0 * @since 2.0
* @author Roman Borschel <roman@code-factory.org>
*/ */
class SqlitePlatform extends AbstractPlatform class SqlitePlatform extends AbstractPlatform
{ {
...@@ -73,18 +74,22 @@ class SqlitePlatform extends AbstractPlatform ...@@ -73,18 +74,22 @@ class SqlitePlatform extends AbstractPlatform
{ {
return strpos($str, $substr); return strpos($str, $substr);
} }
public static function sha1Impl($str) public static function sha1Impl($str)
{ {
return sha1($str); return sha1($str);
} }
public static function ltrimImpl($str) public static function ltrimImpl($str)
{ {
return ltrim($str); return ltrim($str);
} }
public static function rtrimImpl($str) public static function rtrimImpl($str)
{ {
return rtrim($str); return rtrim($str);
} }
public static function trimImpl($str) public static function trimImpl($str)
{ {
return trim($str); return trim($str);
...@@ -193,7 +198,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -193,7 +198,7 @@ class SqlitePlatform extends AbstractPlatform
*/ */
public function getNativeDeclaration(array $field) public function getNativeDeclaration(array $field)
{ {
if ( ! isset($field['type'])) { /*if ( ! isset($field['type'])) {
throw DoctrineException::updateMe('Missing column type.'); throw DoctrineException::updateMe('Missing column type.');
} }
switch ($field['type']) { switch ($field['type']) {
...@@ -253,7 +258,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -253,7 +258,7 @@ class SqlitePlatform extends AbstractPlatform
$length = !empty($field['length']) ? $field['length'] : 18; $length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES); $scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')'; return 'DECIMAL('.$length.','.$scale.')';
} }*/
throw DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.'); throw DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
} }
...@@ -266,7 +271,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -266,7 +271,7 @@ class SqlitePlatform extends AbstractPlatform
*/ */
public function getPortableDeclaration(array $field) public function getPortableDeclaration(array $field)
{ {
$dbType = strtolower($field['type']); /*$dbType = strtolower($field['type']);
$length = (isset($field['length'])) ? $field['length'] : null; $length = (isset($field['length'])) ? $field['length'] : null;
$unsigned = (isset($field['unsigned'])) ? $field['unsigned'] : null; $unsigned = (isset($field['unsigned'])) ? $field['unsigned'] : null;
$fixed = null; $fixed = null;
...@@ -377,7 +382,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -377,7 +382,7 @@ class SqlitePlatform extends AbstractPlatform
return array('type' => $type, return array('type' => $type,
'length' => $length, 'length' => $length,
'unsigned' => $unsigned, 'unsigned' => $unsigned,
'fixed' => $fixed); 'fixed' => $fixed);*/
} }
/** /**
...@@ -389,11 +394,11 @@ class SqlitePlatform extends AbstractPlatform ...@@ -389,11 +394,11 @@ class SqlitePlatform extends AbstractPlatform
protected function _getTransactionIsolationLevelSql($level) protected function _getTransactionIsolationLevelSql($level)
{ {
switch ($level) { switch ($level) {
case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED: case \Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED:
return 0; return 0;
case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED: case \Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED:
case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ: case \Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ:
case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE: case \Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE:
return 1; return 1;
default: default:
return parent::_getTransactionIsolationLevelSql($level); return parent::_getTransactionIsolationLevelSql($level);
...@@ -493,7 +498,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -493,7 +498,7 @@ class SqlitePlatform extends AbstractPlatform
if (empty($fields)) { if (empty($fields)) {
throw ConnectionException::noFieldsSpecifiedForTable($name); throw ConnectionException::noFieldsSpecifiedForTable($name);
} }
$queryFields = $this->getFieldDeclarationListSql($fields); $queryFields = $this->getColumnDeclarationListSql($fields);
$autoinc = false; $autoinc = false;
foreach($fields as $field) { foreach($fields as $field) {
...@@ -535,7 +540,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -535,7 +540,7 @@ class SqlitePlatform extends AbstractPlatform
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getVarcharDeclarationSql(array $field) public function getVarcharTypeDeclarationSql(array $field)
{ {
if ( ! isset($field['length'])) { if ( ! isset($field['length'])) {
if (array_key_exists('default', $field)) { if (array_key_exists('default', $field)) {
......
...@@ -12,7 +12,7 @@ class VarcharType extends Type ...@@ -12,7 +12,7 @@ class VarcharType extends Type
/** @override */ /** @override */
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform) public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{ {
return $platform->getVarcharDeclarationSql($fieldDeclaration); return $platform->getVarcharTypeDeclarationSql($fieldDeclaration);
} }
/** @override */ /** @override */
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>. * <http://www.doctrine-project.org>.
*/ */
namespace Doctrine\ORM; namespace Doctrine\ORM;
...@@ -26,12 +26,11 @@ use Doctrine\ORM\Mapping\Driver\AnnotationDriver; ...@@ -26,12 +26,11 @@ use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
/** /**
* Configuration container for all configuration options of Doctrine. * Configuration container for all configuration options of Doctrine.
* It combines all configuration options from DBAL & ORM. * It combines all configuration options from DBAL & ORM.
*
* INTERNAL: When adding a new configuration option just write a getter/setter
* pair and add the option to the _attributes array with a proper default value.
* *
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @since 2.0 * @since 2.0
* @internal When adding a new configuration option just write a getter/setter
* pair and add the option to the _attributes array with a proper default value.
*/ */
class Configuration extends \Doctrine\DBAL\Configuration class Configuration extends \Doctrine\DBAL\Configuration
{ {
...@@ -44,10 +43,21 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -44,10 +43,21 @@ class Configuration extends \Doctrine\DBAL\Configuration
'resultCacheImpl' => null, 'resultCacheImpl' => null,
'queryCacheImpl' => null, 'queryCacheImpl' => null,
'metadataCacheImpl' => null, 'metadataCacheImpl' => null,
'metadataDriverImpl' => new AnnotationDriver() 'metadataDriverImpl' => new AnnotationDriver(),
'dqlClassAliasMap' => array()
)); ));
} }
public function getDqlClassAliasMap()
{
return $this->_attributes['dqlClassAliasMap'];
}
public function setDqlClassAliasMap(array $map)
{
$this->_attributes['dqlClassAliasMap'] = $map;
}
public function setMetadataDriverImpl($driverImpl) public function setMetadataDriverImpl($driverImpl)
{ {
$this->_attributes['metadataDriverImpl'] = $driverImpl; $this->_attributes['metadataDriverImpl'] = $driverImpl;
......
...@@ -75,7 +75,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection ...@@ -75,7 +75,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
private $_association; private $_association;
/** /**
* The name of the field that is used for collection key mapping. * The name of the field that is used for collection indexing.
* *
* @var string * @var string
*/ */
...@@ -90,7 +90,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection ...@@ -90,7 +90,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
/** /**
* The name of the field on the target entities that points to the owner * The name of the field on the target entities that points to the owner
* of the collection. This is only set if the association is bidirectional. * of the collection. This is only set if the association is bi-directional.
* *
* @var string * @var string
*/ */
...@@ -102,7 +102,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection ...@@ -102,7 +102,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
* @var boolean * @var boolean
* @see setHydrationFlag() * @see setHydrationFlag()
*/ */
private $_hydrationFlag; private $_hydrationFlag = false;
/** /**
* The class descriptor of the owning entity. * The class descriptor of the owning entity.
......
...@@ -661,6 +661,12 @@ class SqlWalker ...@@ -661,6 +661,12 @@ class SqlWalker
return $sql; return $sql;
} }
/**
* Generates a discriminator column SQL condition for the class with the given DQL alias.
*
* @param string $dqlAlias
* @return string
*/
private function _generateDiscriminatorColumnConditionSql($dqlAlias) private function _generateDiscriminatorColumnConditionSql($dqlAlias)
{ {
$sql = ''; $sql = '';
......
...@@ -23,6 +23,8 @@ class AllTests ...@@ -23,6 +23,8 @@ class AllTests
$suite = new \Doctrine\Tests\DbalTestSuite('Doctrine DBAL'); $suite = new \Doctrine\Tests\DbalTestSuite('Doctrine DBAL');
$suite->addTestSuite('Doctrine\Tests\DBAL\Platforms\SqlitePlatformTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Platforms\SqlitePlatformTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Platforms\MySqlPlatformTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Platforms\PostgreSqlPlatformTest');
return $suite; return $suite;
} }
......
<?php
namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Types\Type;
require_once __DIR__ . '/../../TestInit.php';
class MySqlPlatformTest extends \Doctrine\Tests\DbalTestCase
{
private $_platform;
public function setUp()
{
$this->_platform = new MySqlPlatform;
}
public function testCreateTableSql()
{
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => Type::getType('varchar'),
'length' => 255,
'notnull' => true
)
);
$options = array(
'primary' => array('id')
);
$sql = $this->_platform->getCreateTableSql('test', $columns, $options);
$this->assertEquals('CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) NOT NULL, PRIMARY KEY(id))', $sql[0]);
}
public function testAlterTableSql()
{
$changes = array(
'name' => 'userlist',
'add' => array(
'quota' => array(
'type' => Type::getType('integer'),
'unsigned' => 1
)
));
$this->assertEquals(
'ALTER TABLE mytable RENAME TO userlist, ADD quota INT UNSIGNED DEFAULT NULL',
$this->_platform->getAlterTableSql('mytable', $changes)
);
}
public function testCreateIndexSql()
{
$indexDef = array(
'fields' => array(
'user_name' => array(
'sorting' => 'ASC',
'length' => 10
),
'last_login' => array()
)
);
$this->assertEquals(
'CREATE INDEX my_idx ON mytable (user_name(10) ASC, last_login)',
$this->_platform->getCreateIndexSql('mytable', 'my_idx', $indexDef)
);
}
public function testSqlSnippets()
{
$this->assertEquals('RLIKE', $this->_platform->getRegexpExpression());
$this->assertEquals('`', $this->_platform->getIdentifierQuoteCharacter());
$this->assertEquals('RAND()', $this->_platform->getRandomExpression());
$this->assertEquals('CONCAT(column1, column2, column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'));
$this->assertEquals('CHARACTER SET utf8', $this->_platform->getCharsetFieldDeclaration('utf8'));
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
);
}
public function testDDLSnippets()
{
$this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSql());
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSql('foobar'));
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSql('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSql('foobar'));
}
public function testTypeDeclarationSql()
{
$this->assertEquals(
'INT',
$this->_platform->getIntegerTypeDeclarationSql(array())
);
$this->assertEquals(
'INT AUTO_INCREMENT',
$this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true)
));
$this->assertEquals(
'INT AUTO_INCREMENT',
$this->_platform->getIntegerTypeDeclarationSql(
array('autoincrement' => true, 'primary' => true)
));
$this->assertEquals(
'CHAR(10)',
$this->_platform->getVarcharTypeDeclarationSql(
array('length' => 10, 'fixed' => true)
));
$this->assertEquals(
'VARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSql(array('length' => 50))
);
$this->assertEquals(
'TEXT',
$this->_platform->getVarcharTypeDeclarationSql(array())
);
}
public function testPreferences()
{
$this->assertTrue($this->_platform->prefersIdentityColumns());
$this->assertTrue($this->_platform->supportsIdentityColumns());
$this->assertFalse($this->_platform->supportsSavepoints());
}
/*
public function testGetCreateConstraintSql()
{
$sql = $this->_platform->getCreateConstraintSql('test', 'constraint_name', array('fields' => array('test' => array())));
$this->assertEquals($sql, 'ALTER TABLE test ADD CONSTRAINT constraint_name (test)');
}
public function testGetCreateIndexSql()
{
$sql = $this->_platform->getCreateIndexSql('test', 'index_name', array('type' => 'unique', 'fields' => array('test', 'test2')));
$this->assertEquals($sql, 'CREATE UNIQUE INDEX index_name ON test (test, test2)');
}
public function testGetCreateForeignKeySql()
{
$sql = $this->_platform->getCreateForeignKeySql('test', array('foreignTable' => 'other_table', 'local' => 'fk_name_id', 'foreign' => 'id'));
$this->assertEquals($sql, 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)');
}
*/
}
\ No newline at end of file
<?php
namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Connection;
require_once __DIR__ . '/../../TestInit.php';
class PostgreSqlPlatformTest extends \Doctrine\Tests\DbalTestCase
{
private $_platform;
public function setUp()
{
$this->_platform = new PostgreSqlPlatform;
}
public function testCreateTableSql()
{
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => Type::getType('varchar'),
'length' => 255,
'notnull' => true
)
);
$options = array(
'primary' => array('id')
);
$sql = $this->_platform->getCreateTableSql('test', $columns, $options);
$this->assertEquals('CREATE TABLE test (id INT NOT NULL, test VARCHAR(255) NOT NULL, PRIMARY KEY(id))', $sql[0]);
}
public function testAlterTableSql()
{
$changes = array(
'name' => 'userlist',
'add' => array(
'quota' => array(
'type' => Type::getType('integer')
)
));
$sql = $this->_platform->getAlterTableSql('mytable', $changes);
$this->assertEquals(
'ALTER TABLE mytable ADD quota INT DEFAULT NULL',
$sql[0]
);
$this->assertEquals(
'ALTER TABLE mytable RENAME TO userlist',
$sql[1]
);
}
public function testCreateIndexSql()
{
$indexDef = array(
'fields' => array(
'user_name',
'last_login'
)
);
$sql = $this->_platform->getCreateIndexSql('mytable', 'my_idx', $indexDef);
$this->assertEquals(
'CREATE INDEX my_idx ON mytable (user_name, last_login)',
$sql
);
}
public function testSqlSnippets()
{
$this->assertEquals('SIMILAR TO', $this->_platform->getRegexpExpression());
$this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter());
$this->assertEquals('RANDOM()', $this->_platform->getRandomExpression());
$this->assertEquals('column1 || column2 || column3', $this->_platform->getConcatExpression('column1', 'column2', 'column3'));
$this->assertEquals(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
$this->_platform->getSetTransactionIsolationSql(Connection::TRANSACTION_READ_UNCOMMITTED)
);
$this->assertEquals(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED',
$this->_platform->getSetTransactionIsolationSql(Connection::TRANSACTION_READ_COMMITTED)
);
$this->assertEquals(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ',
$this->_platform->getSetTransactionIsolationSql(Connection::TRANSACTION_REPEATABLE_READ)
);
$this->assertEquals(
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSql(Connection::TRANSACTION_SERIALIZABLE)
);
}
public function testDDLSnippets()
{
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSql('foobar'));
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSql('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSql('foobar'));
}
public function testTypeDeclarationSql()
{
$this->assertEquals(
'INT',
$this->_platform->getIntegerTypeDeclarationSql(array())
);
$this->assertEquals(
'SERIAL',
$this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true)
));
$this->assertEquals(
'SERIAL',
$this->_platform->getIntegerTypeDeclarationSql(
array('autoincrement' => true, 'primary' => true)
));
$this->assertEquals(
'CHAR(10)',
$this->_platform->getVarcharTypeDeclarationSql(
array('length' => 10, 'fixed' => true)
));
$this->assertEquals(
'VARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSql(array('length' => 50))
);
$this->assertEquals(
'TEXT',
$this->_platform->getVarcharTypeDeclarationSql(array())
);
}
public function testSequenceSQL()
{
$this->assertEquals(
'CREATE SEQUENCE myseq INCREMENT BY 20 START 1',
$this->_platform->getCreateSequenceSql('myseq', 1, 20)
);
$this->assertEquals(
'DROP SEQUENCE myseq',
$this->_platform->getDropSequenceSql('myseq')
);
$this->assertEquals(
"SELECT NEXTVAL('myseq')",
$this->_platform->getSequenceNextValSql('myseq')
);
}
public function testPreferences()
{
$this->assertFalse($this->_platform->prefersIdentityColumns());
$this->assertTrue($this->_platform->prefersSequences());
$this->assertTrue($this->_platform->supportsIdentityColumns());
$this->assertTrue($this->_platform->supportsSavepoints());
$this->assertTrue($this->_platform->supportsSequences());
}
}
\ No newline at end of file
...@@ -20,7 +20,9 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase ...@@ -20,7 +20,9 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase
$columns = array( $columns = array(
'id' => array( 'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType, 'type' => new \Doctrine\DBAL\Types\IntegerType,
'autoincrement' => true 'autoincrement' => true,
'primary' => true,
'notnull' => true
), ),
'test' => array( 'test' => array(
'type' => new \Doctrine\DBAL\Types\VarcharType, 'type' => new \Doctrine\DBAL\Types\VarcharType,
...@@ -28,29 +30,74 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase ...@@ -28,29 +30,74 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase
) )
); );
$options = array( $options = array();
'primary' => array('id')
);
$sql = $this->_platform->getCreateTableSql('test', $columns, $options); $sql = $this->_platform->getCreateTableSql('test', $columns, $options);
$this->assertEquals($sql[0], 'CREATE TABLE test (id INTEGER AUTOINCREMENT, test VARCHAR(255))'); $this->assertEquals('CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL)', $sql[0]);
} }
public function testGetCreateConstraintSql() public function testGetCreateConstraintSql()
{ {
$sql = $this->_platform->getCreateConstraintSql('test', 'constraint_name', array('fields' => array('test' => array()))); $sql = $this->_platform->getCreateConstraintSql('test', 'constraint_name', array('fields' => array('test' => array())));
$this->assertEquals($sql, 'ALTER TABLE test ADD CONSTRAINT constraint_name (test)'); $this->assertEquals('ALTER TABLE test ADD CONSTRAINT constraint_name (test)', $sql);
} }
public function testGetCreateIndexSql() public function testGetCreateIndexSql()
{ {
$sql = $this->_platform->getCreateIndexSql('test', 'index_name', array('type' => 'unique', 'fields' => array('test', 'test2'))); $sql = $this->_platform->getCreateIndexSql('test', 'index_name', array('type' => 'unique', 'fields' => array('test', 'test2')));
$this->assertEquals($sql, 'CREATE UNIQUE INDEX index_name ON test (test, test2)'); $this->assertEquals('CREATE UNIQUE INDEX index_name ON test (test, test2)', $sql);
} }
public function testGetCreateForeignKeySql() public function testGetCreateForeignKeySql()
{ {
$sql = $this->_platform->getCreateForeignKeySql('test', array('foreignTable' => 'other_table', 'local' => 'fk_name_id', 'foreign' => 'id')); $sql = $this->_platform->getCreateForeignKeySql('test', array('foreignTable' => 'other_table', 'local' => 'fk_name_id', 'foreign' => 'id'));
$this->assertEquals($sql, 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)'); $this->assertEquals('ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)', $sql);
}
public function testExpressionsSql()
{
$this->assertEquals('RLIKE', $this->_platform->getRegexpExpression());
$this->assertEquals('SUBSTR(column, 5, LENGTH(column))', $this->_platform->getSubstringExpression('column', 5));
$this->assertEquals('SUBSTR(column, 0, 5)', $this->_platform->getSubstringExpression('column', 0, 5));
$this->assertEquals('PRAGMA read_uncommitted = 0', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED));
$this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED));
$this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ));
$this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE));
}
public function testPreferences()
{
$this->assertTrue($this->_platform->prefersIdentityColumns());
}
public function testTypeDeclarationSql()
{
$this->assertEquals(
'INTEGER',
$this->_platform->getIntegerTypeDeclarationSql(array())
);
$this->assertEquals(
'INTEGER AUTOINCREMENT',
$this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true)
));
$this->assertEquals(
'INTEGER PRIMARY KEY AUTOINCREMENT',
$this->_platform->getIntegerTypeDeclarationSql(
array('autoincrement' => true, 'primary' => true)
));
$this->assertEquals(
'CHAR(10)',
$this->_platform->getVarcharTypeDeclarationSql(
array('length' => 10, 'fixed' => true)
));
$this->assertEquals(
'VARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSql(array('length' => 50))
);
$this->assertEquals(
'TEXT',
$this->_platform->getVarcharTypeDeclarationSql(array())
);
} }
} }
\ No newline at end of file
...@@ -53,7 +53,7 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform ...@@ -53,7 +53,7 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
protected function _getCommonIntegerTypeDeclarationSql(array $columnDef) {} protected function _getCommonIntegerTypeDeclarationSql(array $columnDef) {}
/** @override */ /** @override */
public function getVarcharDeclarationSql(array $field) {} public function getVarcharTypeDeclarationSql(array $field) {}
/* MOCK API */ /* MOCK API */
......
...@@ -22,7 +22,6 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -22,7 +22,6 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
public function testCRUD() public function testCRUD()
{ {
$parent = new ParentEntity; $parent = new ParentEntity;
$parent->setData('foobar'); $parent->setData('foobar');
...@@ -31,7 +30,6 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -31,7 +30,6 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$child = new ChildEntity; $child = new ChildEntity;
$child->setData('thedata'); $child->setData('thedata');
$child->setNumber(1234); $child->setNumber(1234);
//$child->setRelatedEntity($relatedEntity);
$this->_em->save($child); $this->_em->save($child);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment