Commit 148a049d authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge remote branch 'origin/2.1.x' into 2.1.x

parents 4d74fc0f 41359f21
...@@ -41,8 +41,8 @@ class DB2Driver implements Driver ...@@ -41,8 +41,8 @@ class DB2Driver implements Driver
*/ */
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
if ( !isset($params['schema']) ) { if ( ! isset($params['protocol'])) {
$params['protocol'] = 'TCPIP';
} }
if ($params['host'] !== 'localhost' && $params['host'] != '127.0.0.1') { if ($params['host'] !== 'localhost' && $params['host'] != '127.0.0.1') {
...@@ -50,10 +50,13 @@ class DB2Driver implements Driver ...@@ -50,10 +50,13 @@ class DB2Driver implements Driver
$params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' . $params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' .
';DATABASE=' . $params['dbname'] . ';DATABASE=' . $params['dbname'] .
';HOSTNAME=' . $params['host'] . ';HOSTNAME=' . $params['host'] .
';PORT=' . $params['port'] .
';PROTOCOL=' . $params['protocol'] . ';PROTOCOL=' . $params['protocol'] .
';UID=' . $username . ';UID=' . $username .
';PWD=' . $password .';'; ';PWD=' . $password .';';
if (isset($params['port'])) {
$params['dbname'] .= 'PORT=' . $params['port'];
}
$username = null; $username = null;
$password = null; $password = null;
} }
......
...@@ -987,7 +987,7 @@ abstract class AbstractPlatform ...@@ -987,7 +987,7 @@ abstract class AbstractPlatform
$sql = $this->_getCreateTableSQL($tableName, $columns, $options); $sql = $this->_getCreateTableSQL($tableName, $columns, $options);
if ($this->supportsCommentOnStatement()) { if ($this->supportsCommentOnStatement()) {
foreach ($table->getColumns() AS $column) { foreach ($table->getColumns() AS $column) {
if ($column->getComment()) { if ($this->getColumnComment($column)) {
$sql[] = $this->getCommentOnColumnSQL($tableName, $column->getName(), $this->getColumnComment($column)); $sql[] = $this->getCommentOnColumnSQL($tableName, $column->getName(), $this->getColumnComment($column));
} }
} }
......
...@@ -596,7 +596,7 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -596,7 +596,7 @@ class MsSqlPlatform extends AbstractPlatform
} }
if ($offset == 0) { if ($offset == 0) {
$query = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . $count . ' ', $query); $query = preg_replace('/^(SELECT\s(DISTINCT\s)?)/i', '\1TOP ' . $count . ' ', $query);
} else { } else {
$orderby = stristr($query, 'ORDER BY'); $orderby = stristr($query, 'ORDER BY');
......
...@@ -450,16 +450,13 @@ END;'; ...@@ -450,16 +450,13 @@ END;';
cols.position, cols.position,
r_alc.table_name \"references_table\", r_alc.table_name \"references_table\",
r_cols.column_name \"foreign_column\" r_cols.column_name \"foreign_column\"
FROM all_cons_columns cols FROM user_cons_columns cols
LEFT JOIN all_constraints alc LEFT JOIN user_constraints alc
ON alc.constraint_name = cols.constraint_name ON alc.constraint_name = cols.constraint_name
AND alc.owner = cols.owner LEFT JOIN user_constraints r_alc
LEFT JOIN all_constraints r_alc
ON alc.r_constraint_name = r_alc.constraint_name ON alc.r_constraint_name = r_alc.constraint_name
AND alc.r_owner = r_alc.owner LEFT JOIN user_cons_columns r_cols
LEFT JOIN all_cons_columns r_cols
ON r_alc.constraint_name = r_cols.constraint_name ON r_alc.constraint_name = r_cols.constraint_name
AND r_alc.owner = r_cols.owner
AND cols.position = r_cols.position AND cols.position = r_cols.position
WHERE alc.constraint_name = cols.constraint_name WHERE alc.constraint_name = cols.constraint_name
AND alc.constraint_type = 'R' AND alc.constraint_type = 'R'
...@@ -475,9 +472,18 @@ LEFT JOIN all_cons_columns r_cols ...@@ -475,9 +472,18 @@ LEFT JOIN all_cons_columns r_cols
public function getListTableColumnsSQL($table, $database = null) public function getListTableColumnsSQL($table, $database = null)
{ {
$table = strtoupper($table); $table = strtoupper($table);
return "SELECT c.*, d.comments FROM all_tab_columns c ".
"INNER JOIN all_col_comments d ON d.OWNER = c.OWNER AND d.TABLE_NAME = c.TABLE_NAME AND d.COLUMN_NAME = c.COLUMN_NAME ". $tabColumnsTableName = "user_tab_columns";
"WHERE c.table_name = '" . $table . "' ORDER BY c.column_name"; $ownerCondition = '';
if(null !== $database){
$database = strtoupper($database);
$tabColumnsTableName = "all_tab_columns";
$ownerCondition = "AND c.owner = '".$database."'";
}
return "SELECT c.*, d.comments FROM $tabColumnsTableName c ".
"INNER JOIN user_col_comments d ON d.TABLE_NAME = c.TABLE_NAME AND d.COLUMN_NAME = c.COLUMN_NAME ".
"WHERE c.table_name = '" . $table . "' ".$ownerCondition." ORDER BY c.column_name";
} }
/** /**
......
...@@ -269,10 +269,11 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -269,10 +269,11 @@ class PostgreSqlPlatform extends AbstractPlatform
$whereClause = $namespaceAlias.".nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND "; $whereClause = $namespaceAlias.".nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND ";
if (strpos($table, ".") !== false) { if (strpos($table, ".") !== false) {
list($schema, $table) = explode(".", $table); list($schema, $table) = explode(".", $table);
$whereClause .= "$classAlias.relname = '" . $table . "' AND $namespaceAlias.nspname = '" . $schema . "'"; $schema = "'" . $schema . "'";
} else { } else {
$whereClause .= "$classAlias.relname = '" . $table . "'"; $schema = "ANY(string_to_array((select setting from pg_catalog.pg_settings where name = 'search_path'),','))";
} }
$whereClause .= "$classAlias.relname = '" . $table . "' AND $namespaceAlias.nspname = $schema";
return $whereClause; return $whereClause;
} }
......
...@@ -470,6 +470,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -470,6 +470,7 @@ class SqlitePlatform extends AbstractPlatform
'longtext' => 'text', 'longtext' => 'text',
'text' => 'text', 'text' => 'text',
'varchar' => 'string', 'varchar' => 'string',
'longvarchar' => 'string',
'varchar2' => 'string', 'varchar2' => 'string',
'nvarchar' => 'string', 'nvarchar' => 'string',
'image' => 'string', 'image' => 'string',
......
...@@ -473,8 +473,8 @@ abstract class AbstractSchemaManager ...@@ -473,8 +473,8 @@ abstract class AbstractSchemaManager
*/ */
public function dropAndCreateSequence(Sequence $sequence) public function dropAndCreateSequence(Sequence $sequence)
{ {
$this->tryMethod('createSequence', $seqName, $start, $allocationSize); $this->tryMethod('dropSequence', $sequence->getQuotedName($this->_platform));
$this->createSequence($seqName, $start, $allocationSize); $this->createSequence($sequence);
} }
/** /**
......
...@@ -170,26 +170,44 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -170,26 +170,44 @@ class MySqlSchemaManager extends AbstractSchemaManager
return new Column($tableColumn['field'], \Doctrine\DBAL\Types\Type::getType($type), $options); return new Column($tableColumn['field'], \Doctrine\DBAL\Types\Type::getType($type), $options);
} }
public function _getPortableTableForeignKeyDefinition($tableForeignKey) protected function _getPortableTableForeignKeysList($tableForeignKeys)
{ {
$tableForeignKey = array_change_key_case($tableForeignKey, CASE_LOWER); $list = array();
foreach ($tableForeignKeys as $key => $value) {
if (!isset($tableForeignKey['delete_rule']) || $tableForeignKey['delete_rule'] == "RESTRICT") { $value = array_change_key_case($value, CASE_LOWER);
$tableForeignKey['delete_rule'] = null; if (!isset($list[$value['constraint_name']])) {
if (!isset($value['delete_rule']) || $value['delete_rule'] == "RESTRICT") {
$value['delete_rule'] = null;
}
if (!isset($value['update_rule']) || $value['update_rule'] == "RESTRICT") {
$value['update_rule'] = null;
}
$list[$value['constraint_name']] = array(
'name' => $value['constraint_name'],
'local' => array(),
'foreign' => array(),
'foreignTable' => $value['referenced_table_name'],
'onDelete' => $value['delete_rule'],
'onUpdate' => $value['update_rule'],
);
} }
if (!isset($tableForeignKey['update_rule']) || $tableForeignKey['update_rule'] == "RESTRICT") { $list[$value['constraint_name']]['local'][] = $value['column_name'];
$tableForeignKey['update_rule'] = null; $list[$value['constraint_name']]['foreign'][] = $value['referenced_column_name'];
} }
return new ForeignKeyConstraint( $result = array();
(array)$tableForeignKey['column_name'], foreach($list AS $constraint) {
$tableForeignKey['referenced_table_name'], $result[] = new ForeignKeyConstraint(
(array)$tableForeignKey['referenced_column_name'], array_values($constraint['local']), $constraint['foreignTable'],
$tableForeignKey['constraint_name'], array_values($constraint['foreign']), $constraint['name'],
array( array(
'onUpdate' => $tableForeignKey['update_rule'], 'onDelete' => $constraint['onDelete'],
'onDelete' => $tableForeignKey['delete_rule'], 'onUpdate' => $constraint['onUpdate'],
) )
); );
} }
return $result;
}
} }
...@@ -167,7 +167,7 @@ class Table extends AbstractAsset ...@@ -167,7 +167,7 @@ class Table extends AbstractAsset
*/ */
public function addUniqueIndex(array $columnNames, $indexName = null) public function addUniqueIndex(array $columnNames, $indexName = null)
{ {
if ($indexName == null) { if ($indexName === null) {
$indexName = $this->_generateIdentifierName( $indexName = $this->_generateIdentifierName(
array_merge(array($this->getName()), $columnNames), "uniq", $this->_getMaxIdentifierLength() array_merge(array($this->getName()), $columnNames), "uniq", $this->_getMaxIdentifierLength()
); );
......
...@@ -31,6 +31,19 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -31,6 +31,19 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->_sm = $this->_conn->getSchemaManager(); $this->_sm = $this->_conn->getSchemaManager();
} }
/**
* @group DBAL-195
*/
public function testDropAndCreateSequence()
{
if(!$this->_conn->getDatabasePlatform()->supportsSequences()) {
$this->markTestSkipped($this->_conn->getDriver()->getName().' does not support sequences.');
}
$sequence = new \Doctrine\DBAL\Schema\Sequence('dropcreate_sequences_test_seq', 20, 10);
$this->_sm->dropAndCreateSequence($sequence);
}
public function testListSequences() public function testListSequences()
{ {
if(!$this->_conn->getDatabasePlatform()->supportsSequences()) { if(!$this->_conn->getDatabasePlatform()->supportsSequences()) {
...@@ -523,3 +536,4 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -523,3 +536,4 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertTrue($foundTable, "Could not find new table"); $this->assertTrue($foundTable, "Could not find new table");
} }
} }
...@@ -205,6 +205,16 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -205,6 +205,16 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->assertEquals($this->getAlterTableColumnCommentsSQL(), $this->_platform->getAlterTableSQL($tableDiff)); $this->assertEquals($this->getAlterTableColumnCommentsSQL(), $this->_platform->getAlterTableSQL($tableDiff));
} }
public function testCreateTableColumnTypeComments()
{
$table = new \Doctrine\DBAL\Schema\Table('test');
$table->addColumn('id', 'integer');
$table->addColumn('data', 'array');
$table->setPrimaryKey(array('id'));
$this->assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->_platform->getCreateTableSQL($table));
}
public function getCreateTableColumnCommentsSQL() public function getCreateTableColumnCommentsSQL()
{ {
$this->markTestSkipped('Platform does not support Column comments.'); $this->markTestSkipped('Platform does not support Column comments.');
...@@ -215,6 +225,11 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -215,6 +225,11 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->markTestSkipped('Platform does not support Column comments.'); $this->markTestSkipped('Platform does not support Column comments.');
} }
public function getCreateTableColumnTypeCommentsSQL()
{
$this->markTestSkipped('Platform does not support Column comments.');
}
/** /**
* @group DBAL-45 * @group DBAL-45
*/ */
......
...@@ -204,4 +204,9 @@ class MySqlPlatformTest extends AbstractPlatformTestCase ...@@ -204,4 +204,9 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
{ {
return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'"); return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'");
} }
public function getCreateTableColumnTypeCommentsSQL()
{
return array("CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) ENGINE = InnoDB");
}
} }
\ No newline at end of file
...@@ -195,6 +195,14 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -195,6 +195,14 @@ class OraclePlatformTest extends AbstractPlatformTestCase
); );
} }
public function getCreateTableColumnTypeCommentsSQL()
{
return array(
"CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))",
"COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
);
}
public function getAlterTableColumnCommentsSQL() public function getAlterTableColumnCommentsSQL()
{ {
return array( return array(
......
...@@ -216,4 +216,12 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase ...@@ -216,4 +216,12 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
"COMMENT ON COLUMN mytable.baz IS 'B comment'", "COMMENT ON COLUMN mytable.baz IS 'B comment'",
); );
} }
public function getCreateTableColumnTypeCommentsSQL()
{
return array(
"CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))",
"COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
);
}
} }
\ No newline at end of file
<?php
namespace Doctrine\Tests\DBAL\Schema;
require_once __DIR__ . '/../../TestInit.php';
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Schema\MySqlSchemaManager;
use Doctrine\Tests\DBAL\Mocks;
use Doctrine\Tests\TestUtil;
class MySqlSchemaManagerTest extends \PHPUnit_Framework_TestCase
{
/**
*
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
private $manager;
public function setUp()
{
$eventManager = new EventManager();
$driverMock = $this->getMock('Doctrine\DBAL\Driver');
$platform = $this->getMock('Doctrine\DBAL\Platforms\MySqlPlatform');
$this->conn = $this->getMock(
'Doctrine\DBAL\Connection',
array('fetchAll'),
array(array('platform' => $platform), $driverMock, new Configuration(), $eventManager)
);
$this->manager = new MySqlSchemaManager($this->conn);
}
public function testCompositeForeignKeys()
{
$this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue($this->getFKDefinition()));
$fkeys = $this->manager->listTableForeignKeys('dummy');
$this->assertEquals(1, count($fkeys), "Table has to have one foreign key.");
$this->assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]);
$this->assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getLocalColumns()));
$this->assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getForeignColumns()));
}
public function getFKDefinition()
{
return array(
array(
"CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E",
"COLUMN_NAME" => "column_1",
"REFERENCED_TABLE_NAME" => "dummy",
"REFERENCED_COLUMN_NAME" => "column_1",
"update_rule" => "RESTRICT",
"delete_rule" => "RESTRICT",
),
array(
"CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E",
"COLUMN_NAME" => "column_2",
"REFERENCED_TABLE_NAME" => "dummy",
"REFERENCED_COLUMN_NAME" => "column_2",
"update_rule" => "RESTRICT",
"delete_rule" => "RESTRICT",
),
array(
"CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E",
"COLUMN_NAME" => "column_3",
"REFERENCED_TABLE_NAME" => "dummy",
"REFERENCED_COLUMN_NAME" => "column_3",
"update_rule" => "RESTRICT",
"delete_rule" => "RESTRICT",
)
);
}
}
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