Commit 168fc6b1 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DBAL-42'

parents c330d97c 18bed8f2
......@@ -25,7 +25,9 @@ use Doctrine\DBAL\DBALException,
Doctrine\DBAL\Schema\Table,
Doctrine\DBAL\Schema\Index,
Doctrine\DBAL\Schema\ForeignKeyConstraint,
Doctrine\DBAL\Schema\TableDiff;
Doctrine\DBAL\Schema\TableDiff,
Doctrine\DBAL\Schema\Column,
Doctrine\DBAL\Types\Type;
/**
* Base class for all DatabasePlatforms. The DatabasePlatforms are the central
......@@ -80,6 +82,14 @@ abstract class AbstractPlatform
*/
protected $doctrineTypeMapping = null;
/**
* Contains a list of all columns that should generate parseable column comments for type-detection
* in reverse engineering scenarios.
*
* @var array
*/
protected $doctrineTypeComments = null;
/**
* Constructor.
*/
......@@ -209,6 +219,71 @@ abstract class AbstractPlatform
return isset($this->doctrineTypeMapping[$dbType]);
}
/**
* Initialize the Doctrine Type comments instance variable for in_array() checks.
*
* @return void
*/
protected function initializeCommentedDoctrineTypes()
{
$this->doctrineTypeComments = array(Type::TARRAY, Type::OBJECT);
}
/**
* Is it necessary for the platform to add a parsable type comment to allow reverse engineering the given type?
*
* @param Type $doctrineType
* @return bool
*/
public function isCommentedDoctrineType(Type $doctrineType)
{
if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes();
}
return in_array($doctrineType->getName(), $this->doctrineTypeComments);
}
/**
* Mark this type as to be commented in ALTER TABLE and CREATE TABLE statements.
*
* @param Type $doctrineType
* @return void
*/
public function markDoctrineTypeCommented(Type $doctrineType)
{
if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes();
}
$this->doctrineTypeComments[] = $doctrineType->getName();
}
/**
* Get the comment to append to a column comment that helps parsing this type in reverse engineering.
*
* @param Type $doctrineType
* @return string
*/
public function getDoctrineTypeComment(Type $doctrineType)
{
return '(DC2Type:' . $doctrineType->getName() . ')';
}
/**
* Return the comment of a passed column modified by potential doctrine type comment hints.
*
* @param Column $column
* @return string
*/
protected function getColumnComment(Column $column)
{
$comment = $column->getComment();
if ($this->isCommentedDoctrineType($column->getType())) {
$comment .= $this->getDoctrineTypeComment($column->getType());
}
return $comment;
}
/**
* Gets the character used for identifier quoting.
*
......@@ -797,6 +872,7 @@ abstract class AbstractPlatform
$columnData['default'] = $column->getDefault();
$columnData['columnDefinition'] = $column->getColumnDefinition();
$columnData['autoincrement'] = $column->getAutoincrement();
$columnData['comment'] = $this->getColumnComment($column);
if(in_array($column->getName(), $options['primary'])) {
$columnData['primary'] = true;
......@@ -812,7 +888,20 @@ abstract class AbstractPlatform
}
}
return $this->_getCreateTableSQL($tableName, $columns, $options);
$sql = $this->_getCreateTableSQL($tableName, $columns, $options);
if ($this->supportsCommentOnStatement()) {
foreach ($table->getColumns() AS $column) {
if ($column->getComment()) {
$sql[] = $this->getCommentOnColumnSQL($tableName, $column->getName(), $this->getColumnComment($column));
}
}
}
return $sql;
}
public function getCommentOnColumnSQL($tableName, $columnName, $comment)
{
return "COMMENT ON COLUMN " . $tableName . "." . $columnName . " IS '" . $comment . "'";
}
/**
......@@ -1142,6 +1231,10 @@ abstract class AbstractPlatform
$columnDef = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation;
}
if ($this->supportsInlineColumnComments() && isset($field['comment']) && $field['comment']) {
$columnDef .= " COMMENT '" . $field['comment'] . "'";
}
return $name . ' ' . $columnDef;
}
......@@ -1616,7 +1709,7 @@ abstract class AbstractPlatform
throw DBALException::notSupported(__METHOD__);
}
public function getListTableColumnsSQL($table)
public function getListTableColumnsSQL($table, $database = null)
{
throw DBALException::notSupported(__METHOD__);
}
......@@ -1880,6 +1973,26 @@ abstract class AbstractPlatform
return true;
}
/**
* Does this plaform support to add inline column comments as postfix.
*
* @return bool
*/
public function supportsInlineColumnComments()
{
return false;
}
/**
* Does this platform support the propriortary synatx "COMMENT ON asset"
*
* @return bool
*/
public function supportsCommentOnStatement()
{
return false;
}
public function getIdentityColumnNullInsertSQL()
{
return "";
......
......@@ -208,7 +208,7 @@ class DB2Platform extends AbstractPlatform
* @param string $table
* @return string
*/
public function getListTableColumnsSQL($table)
public function getListTableColumnsSQL($table, $database = null)
{
return "SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno,
c.typename, c.default, c.nulls, c.length, c.scale,
......
......@@ -311,7 +311,7 @@ class MsSqlPlatform extends AbstractPlatform
/**
* @override
*/
public function getListTableColumnsSQL($table)
public function getListTableColumnsSQL($table, $database = null)
{
return 'exec sp_columns @table_name = ' . $table;
}
......
......@@ -259,6 +259,11 @@ class MySqlPlatform extends AbstractPlatform
return true;
}
public function supportsInlineColumnComments()
{
return true;
}
public function getShowDatabasesSQL()
{
return 'SHOW DATABASES';
......@@ -269,9 +274,16 @@ class MySqlPlatform extends AbstractPlatform
return "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'";
}
public function getListTableColumnsSQL($table)
public function getListTableColumnsSQL($table, $database = null)
{
return 'DESCRIBE ' . $table;
if ($database) {
return "SELECT COLUMN_NAME AS Field, COLUMN_TYPE AS Type, IS_NULLABLE AS `Null`, ".
"COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment, " .
"CHARACTER_SET_NAME AS CharacterSet, COLLATION_NAME AS CollactionName ".
"FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . $database . "' AND TABLE_NAME = '" . $table . "'";
} else {
return 'DESCRIBE ' . $table;
}
}
/**
......@@ -410,7 +422,9 @@ class MySqlPlatform extends AbstractPlatform
}
foreach ($diff->addedColumns AS $fieldName => $column) {
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$columnArray = $column->toArray();
$columnArray['comment'] = $this->getColumnComment($column);
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
}
foreach ($diff->removedColumns AS $column) {
......@@ -420,13 +434,17 @@ class MySqlPlatform extends AbstractPlatform
foreach ($diff->changedColumns AS $columnDiff) {
/* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
$column = $columnDiff->column;
$columnArray = $column->toArray();
$columnArray['comment'] = $this->getColumnComment($column);
$queryParts[] = 'CHANGE ' . ($columnDiff->oldColumnName) . ' '
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
}
foreach ($diff->renamedColumns AS $oldColumnName => $column) {
$columnArray = $column->toArray();
$columnArray['comment'] = $this->getColumnComment($column);
$queryParts[] = 'CHANGE ' . $oldColumnName . ' '
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
}
$sql = array();
......
......@@ -441,10 +441,12 @@ LEFT JOIN all_cons_columns r_cols
return 'SELECT * FROM user_constraints WHERE table_name = \'' . $table . '\'';
}
public function getListTableColumnsSQL($table)
public function getListTableColumnsSQL($table, $database = null)
{
$table = strtoupper($table);
return "SELECT * FROM all_tab_columns WHERE table_name = '" . $table . "' ORDER BY column_name";
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 ".
"WHERE c.table_name = '" . $table . "' ORDER BY c.column_name";
}
/**
......@@ -499,10 +501,14 @@ LEFT JOIN all_cons_columns r_cols
public function getAlterTableSQL(TableDiff $diff)
{
$sql = array();
$commentsSQL = array();
$fields = array();
foreach ($diff->addedColumns AS $column) {
$fields[] = $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
if ($comment = $this->getColumnComment($column)) {
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
}
}
if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ADD (' . implode(', ', $fields) . ')';
......@@ -512,6 +518,9 @@ LEFT JOIN all_cons_columns r_cols
foreach ($diff->changedColumns AS $columnDiff) {
$column = $columnDiff->column;
$fields[] = $column->getQuotedName($this). ' ' . $this->getColumnDeclarationSQL('', $column->toArray());
if ($columnDiff->hasChanged('comment') && $comment = $this->getColumnComment($column)) {
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
}
}
if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' MODIFY (' . implode(', ', $fields) . ')';
......@@ -533,9 +542,7 @@ LEFT JOIN all_cons_columns r_cols
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff));
return $sql;
return array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL);
}
/**
......@@ -548,6 +555,11 @@ LEFT JOIN all_cons_columns r_cols
return true;
}
public function supportsCommentOnStatement()
{
return true;
}
/**
* Get the platform name for this instance
*
......
......@@ -135,6 +135,11 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return true;
}
public function supportsCommentOnStatement()
{
return true;
}
/**
* Whether the platform prefers sequences for ID generation.
......@@ -241,7 +246,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return $whereClause;
}
public function getListTableColumnsSQL($table)
public function getListTableColumnsSQL($table, $database = null)
{
return "SELECT
a.attnum,
......@@ -262,8 +267,11 @@ class PostgreSqlPlatform extends AbstractPlatform
FROM pg_attrdef
WHERE c.oid = pg_attrdef.adrelid
AND pg_attrdef.adnum=a.attnum
) AS default
FROM pg_attribute a, pg_class c, pg_type t, pg_namespace n
) AS default,
(SELECT pg_description.description
FROM pg_description WHERE pg_description.objoid = c.oid AND a.attnum = pg_description.objsubid
) AS comment
FROM pg_attribute a, pg_class c, pg_type t, pg_namespace n
WHERE ".$this->getTableWhereClause($table, 'c', 'n') ."
AND a.attnum > 0
AND a.attrelid = c.oid
......@@ -340,10 +348,14 @@ class PostgreSqlPlatform extends AbstractPlatform
public function getAlterTableSQL(TableDiff $diff)
{
$sql = array();
$commentsSQL = array();
foreach ($diff->addedColumns as $column) {
$query = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
if ($comment = $this->getColumnComment($column)) {
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
}
}
foreach ($diff->removedColumns as $column) {
......@@ -385,6 +397,9 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql[] = "ALTER TABLE " . $diff->name . " " . $query;
}
}
if ($columnDiff->hasChanged('comment') && $comment = $this->getColumnComment($column)) {
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
}
}
foreach ($diff->renamedColumns as $oldColumnName => $column) {
......@@ -395,9 +410,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName;
}
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff));
return $sql;
return array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL);
}
/**
......
......@@ -326,7 +326,7 @@ class SqlitePlatform extends AbstractPlatform
return "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = '$table' AND sql NOT NULL ORDER BY name";
}
public function getListTableColumnsSQL($table)
public function getListTableColumnsSQL($table, $database = null)
{
return "PRAGMA table_info($table)";
}
......
......@@ -141,11 +141,16 @@ abstract class AbstractSchemaManager
* in the platformDetails array.
*
* @param string $table The name of the table.
* @param string $database
* @return Column[]
*/
public function listTableColumns($table)
public function listTableColumns($table, $database = null)
{
$sql = $this->_platform->getListTableColumnsSQL($table);
if (!$database) {
$database = $this->_conn->getDatabase();
}
$sql = $this->_platform->getListTableColumnsSQL($table, $database);
$tableColumns = $this->_conn->fetchAll($sql);
......@@ -774,4 +779,25 @@ abstract class AbstractSchemaManager
return $schemaConfig;
}
/**
* Given a table comment this method tries to extract a typehint for Doctrine Type, or returns
* the type given as default.
*
* @param string $comment
* @param string $currentType
* @return string
*/
public function extractDoctrineTypeFromComment($comment, $currentType)
{
if (preg_match("(\(DC2Type:([a-zA-Z0-9]+)\))", $comment, $match)) {
$currentType = $match[1];
}
return $currentType;
}
public function removeDoctrineTypeFromComment($comment, $type)
{
return str_replace('(DC2Type:'.$type.')', '', $comment);
}
}
\ No newline at end of file
......@@ -88,6 +88,11 @@ class Column extends AbstractAsset
*/
protected $_columnDefinition = null;
/**
* @var string
*/
protected $_comment = null;
/**
* Create a new Column
*
......@@ -316,6 +321,17 @@ class Column extends AbstractAsset
return $this;
}
public function setComment($comment)
{
$this->_comment = $comment;
return $this;
}
public function getComment()
{
return $this->_comment;
}
/**
* @param Visitor $visitor
*/
......@@ -341,6 +357,7 @@ class Column extends AbstractAsset
'unsigned' => $this->_unsigned,
'autoincrement' => $this->_autoincrement,
'columnDefinition' => $this->_columnDefinition,
'comment' => $this->_comment,
), $this->_platformOptions);
}
}
\ No newline at end of file
......@@ -344,6 +344,11 @@ class Comparator
$changedProperties[] = 'autoincrement';
}
// only allow to delete comment if its set to '' not to null.
if ($column1->getComment() !== null && $column1->getComment() != $column2->getComment()) {
$changedProperties[] = 'comment';
}
return $changedProperties;
}
......
......@@ -107,6 +107,9 @@ class MySqlSchemaManager extends AbstractSchemaManager
$precision = null;
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
switch ($dbType) {
case 'char':
$fixed = true;
......@@ -156,6 +159,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
'scale' => null,
'precision' => null,
'autoincrement' => (bool) (strpos($tableColumn['extra'], 'auto_increment') !== false),
'comment' => (isset($tableColumn['comment'])) ? $tableColumn['comment'] : null
);
if ($scale !== null && $precision !== null) {
......
......@@ -117,6 +117,9 @@ class OracleSchemaManager extends AbstractSchemaManager
$scale = null;
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$type = $this->extractDoctrineTypeFromComment($tableColumn['comments'], $type);
$tableColumn['comments'] = $this->removeDoctrineTypeFromComment($tableColumn['comments'], $type);
switch ($dbType) {
case 'number':
if ($tableColumn['data_precision'] == 20 && $tableColumn['data_scale'] == 0) {
......@@ -186,6 +189,7 @@ class OracleSchemaManager extends AbstractSchemaManager
'length' => $length,
'precision' => $precision,
'scale' => $scale,
'comment' => (isset($tableColumn['comments'])) ? $tableColumn['comments'] : null,
'platformDetails' => array(),
);
......
......@@ -201,7 +201,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
if ((int) $length <= 0) {
$length = null;
}
$type = array();
$fixed = null;
if (!isset($tableColumn['name'])) {
......@@ -219,6 +218,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
}
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
switch ($dbType) {
case 'smallint':
case 'int2':
......@@ -270,15 +272,16 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
}
$options = array(
'length' => $length,
'notnull' => (bool) $tableColumn['isnotnull'],
'default' => $tableColumn['default'],
'primary' => (bool) ($tableColumn['pri'] == 't'),
'precision' => $precision,
'scale' => $scale,
'fixed' => $fixed,
'unsigned' => false,
'length' => $length,
'notnull' => (bool) $tableColumn['isnotnull'],
'default' => $tableColumn['default'],
'primary' => (bool) ($tableColumn['pri'] == 't'),
'precision' => $precision,
'scale' => $scale,
'fixed' => $fixed,
'unsigned' => false,
'autoincrement' => $autoincrement,
'comment' => $tableColumn['comment'],
);
return new Column($tableColumn['field'], \Doctrine\DBAL\Types\Type::getType($type), $options);
......
......@@ -66,7 +66,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
{
$config = $this->_conn->getConfiguration();
$this->assertType('Doctrine\DBAL\Configuration', $config);
$this->assertInstanceOf('Doctrine\DBAL\Configuration', $config);
}
public function testGetHost()
......@@ -91,12 +91,12 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
public function testGetDriver()
{
$this->assertType('Doctrine\DBAL\Driver\PDOMySql\Driver', $this->_conn->getDriver());
$this->assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $this->_conn->getDriver());
}
public function testGetEventManager()
{
$this->assertType('Doctrine\Common\EventManager', $this->_conn->getEventManager());
$this->assertInstanceOf('Doctrine\Common\EventManager', $this->_conn->getEventManager());
}
public function testConnectDispatchEvent()
......
......@@ -79,7 +79,7 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
$this->assertType($wrapperClass, $conn);
$this->assertInstanceOf($wrapperClass, $conn);
}
public function testInvalidWrapperClass()
......@@ -112,6 +112,6 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
$this->assertType('Doctrine\DBAL\Driver\PDOMySql\Driver', $conn->getDriver());
$this->assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $conn->getDriver());
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testGetWrappedConnection()
{
$this->assertType('Doctrine\DBAL\Driver\Connection', $this->_conn->getWrappedConnection());
$this->assertInstanceOf('Doctrine\DBAL\Driver\Connection', $this->_conn->getWrappedConnection());
}
public function testCommitWithRollbackOnlyThrowsException()
......
......@@ -33,7 +33,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
$stmt = $this->_conn->prepare($sql);
$this->assertType('Doctrine\DBAL\Statement', $stmt);
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
$stmt->bindValue(1, 1);
$stmt->bindValue(2, 'foo');
......@@ -51,7 +51,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
$stmt = $this->_conn->prepare($sql);
$this->assertType('Doctrine\DBAL\Statement', $stmt);
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
$stmt->bindParam(1, $paramInt);
$stmt->bindParam(2, $paramStr);
......@@ -69,7 +69,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
$stmt = $this->_conn->prepare($sql);
$this->assertType('Doctrine\DBAL\Statement', $stmt);
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
$stmt->bindParam(1, $paramInt);
$stmt->bindParam(2, $paramStr);
......@@ -87,7 +87,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sql = "SELECT test_int FROM fetch_table WHERE test_int = ? AND test_string = ?";
$stmt = $this->_conn->prepare($sql);
$this->assertType('Doctrine\DBAL\Statement', $stmt);
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
$stmt->bindParam(1, $paramInt);
$stmt->bindParam(2, $paramStr);
......@@ -106,7 +106,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sql = "SELECT test_int, test_string FROM " . $this->_conn->quoteIdentifier($table) . " ".
"WHERE test_int = " . $this->_conn->quote($paramInt) . " AND test_string = " . $this->_conn->quote($paramStr);
$stmt = $this->_conn->prepare($sql);
$this->assertType('Doctrine\DBAL\Statement', $stmt);
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
}
public function testPrepareWithExecuteParams()
......@@ -116,7 +116,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
$stmt = $this->_conn->prepare($sql);
$this->assertType('Doctrine\DBAL\Statement', $stmt);
$this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt);
$stmt->execute(array($paramInt, $paramStr));
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
......
......@@ -22,13 +22,13 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->_conn->exec($createTableSQL);
$table = $this->_conn->getSchemaManager()->listTableDetails('domain_type_test');
$this->assertType('Doctrine\DBAL\Types\DecimalType', $table->getColumn('value')->getType());
$this->assertInstanceOf('Doctrine\DBAL\Types\DecimalType', $table->getColumn('value')->getType());
Type::addType('MyMoney', 'Doctrine\Tests\DBAL\Functional\Schema\MoneyType');
$this->_conn->getDatabasePlatform()->registerDoctrineTypeMapping('MyMoney', 'MyMoney');
$table = $this->_conn->getSchemaManager()->listTableDetails('domain_type_test');
$this->assertType('Doctrine\Tests\DBAL\Functional\Schema\MoneyType', $table->getColumn('value')->getType());
$this->assertInstanceOf('Doctrine\Tests\DBAL\Functional\Schema\MoneyType', $table->getColumn('value')->getType());
}
/**
......@@ -91,7 +91,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$c = new \Doctrine\DBAL\Schema\Comparator();
$diff = $c->diffTable($tableFrom, $tableTo);
$this->assertType('Doctrine\DBAL\Schema\TableDiff', $diff, "There should be a difference and not false being returned from the table comparison");
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $diff, "There should be a difference and not false being returned from the table comparison");
$this->assertEquals(array("ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT"), $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff));
$this->_sm->alterTable($diff);
......
......@@ -165,4 +165,43 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$field = array('columnDefinition' => 'MEDIUMINT(6) UNSIGNED');
$this->assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->_platform->getColumnDeclarationSQL('foo', $field));
}
/**
* @group DBAL-42
*/
public function testCreateTableColumnComments()
{
$table = new \Doctrine\DBAL\Schema\Table('test');
$table->addColumn('id', 'integer', array('comment' => 'This is a comment'));
$table->setPrimaryKey(array('id'));
$this->assertEquals($this->getCreateTableColumnCommentsSQL(), $this->_platform->getCreateTableSQL($table));
}
/**
* @group DBAL-42
*/
public function testAlterTableColumnComments()
{
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('comment' => 'A comment'));
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'bar', new \Doctrine\DBAL\Schema\Column(
'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('comment' => 'B comment')
),
array('comment')
);
$this->assertEquals($this->getAlterTableColumnCommentsSQL(), $this->_platform->getAlterTableSQL($tableDiff));
}
public function getCreateTableColumnCommentsSQL()
{
$this->markTestSkipped('Platform does not support Column comments.');
}
public function getAlterTableColumnCommentsSQL()
{
$this->markTestSkipped('Platform does not support Column comments.');
}
}
......@@ -171,4 +171,5 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
$this->assertEquals('SELECT TOP 10 * FROM user ORDER BY username DESC', $sql);
}
}
\ No newline at end of file
......@@ -166,4 +166,14 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$this->assertEquals("TIMESTAMP", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true)));
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array()));
}
public function getCreateTableColumnCommentsSQL()
{
return array("CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) ENGINE = InnoDB");
}
public function getAlterTableColumnCommentsSQL()
{
return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'");
}
}
\ No newline at end of file
......@@ -186,4 +186,22 @@ class OraclePlatformTest extends AbstractPlatformTestCase
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10);
$this->assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username DESC) a WHERE ROWNUM <= 10', $sql);
}
public function getCreateTableColumnCommentsSQL()
{
return array(
"CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))",
"COMMENT ON COLUMN test.id IS 'This is a comment'",
);
}
public function getAlterTableColumnCommentsSQL()
{
return array(
"ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)",
"ALTER TABLE mytable MODIFY (baz VARCHAR2(255) NOT NULL)",
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
);
}
}
\ No newline at end of file
......@@ -199,4 +199,21 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
$this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
}
public function getCreateTableColumnCommentsSQL()
{
return array(
"CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))",
"COMMENT ON COLUMN test.id IS 'This is a comment'",
);
}
public function getAlterTableColumnCommentsSQL()
{
return array(
"ALTER TABLE mytable ADD quota INT NOT NULL",
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
);
}
}
\ No newline at end of file
......@@ -46,6 +46,7 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
'unsigned' => true,
'autoincrement' => false,
'columnDefinition' => null,
'comment' => null,
'foo' => 'bar',
);
......@@ -87,4 +88,20 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('`bar`', $column->getQuotedName($mysqlPlatform));
$this->assertEquals('"bar"', $column->getQuotedName($sqlitePlatform));
}
/**
* @group DBAL-42
*/
public function testColumnComment()
{
$column = new Column("bar", Type::getType('string'));
$this->assertNull($column->getComment());
$column->setComment("foo");
$this->assertEquals("foo", $column->getComment());
$columnArray = $column->toArray();
$this->assertArrayHasKey('comment', $columnArray);
$this->assertEquals('foo', $columnArray['comment']);
}
}
\ No newline at end of file
......@@ -426,7 +426,7 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$c = new Comparator();
$tableDiff = $c->diffTable($table1, $table2);
$this->assertType('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertEquals(1, count($tableDiff->addedForeignKeys));
}
......@@ -445,7 +445,7 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$c = new Comparator();
$tableDiff = $c->diffTable($table2, $table1);
$this->assertType('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertEquals(1, count($tableDiff->removedForeignKeys));
}
......@@ -465,7 +465,7 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$c = new Comparator();
$tableDiff = $c->diffTable($table1, $table2);
$this->assertType('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertEquals(1, count($tableDiff->changedForeignKeys));
}
......@@ -621,7 +621,7 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$c = new Comparator();
$tableDiff = $c->diffTable($tableA, $tableB);
$this->assertType('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertArrayHasKey('id', $tableDiff->changedColumns);
}
......
......@@ -92,7 +92,7 @@ class SchemaTest extends \PHPUnit_Framework_TestCase
$table = $schema->createTable("foo");
$this->assertType('Doctrine\DBAL\Schema\Table', $table);
$this->assertInstanceOf('Doctrine\DBAL\Schema\Table', $table);
$this->assertEquals("foo", $table->getName());
$this->assertTrue($schema->hasTable("foo"));
}
......@@ -104,7 +104,7 @@ class SchemaTest extends \PHPUnit_Framework_TestCase
$schema = new Schema(array(), array($sequence));
$this->assertTrue($schema->hasSequence("a_seq"));
$this->assertType('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq"));
$this->assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq"));
$sequences = $schema->getSequences();
$this->assertArrayHasKey('a_seq', $sequences);
......@@ -142,7 +142,7 @@ class SchemaTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(20, $sequence->getInitialValue());
$this->assertTrue($schema->hasSequence("a_seq"));
$this->assertType('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq"));
$this->assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq"));
$sequences = $schema->getSequences();
$this->assertArrayHasKey('a_seq', $sequences);
......
......@@ -38,8 +38,8 @@ class TableTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($table->hasColumn("bar"));
$this->assertFalse($table->hasColumn("baz"));
$this->assertType('Doctrine\DBAL\Schema\Column', $table->getColumn("foo"));
$this->assertType('Doctrine\DBAL\Schema\Column', $table->getColumn("bar"));
$this->assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn("foo"));
$this->assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn("bar"));
$this->assertEquals(2, count($table->getColumns()));
}
......@@ -153,9 +153,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($table->hasIndex("bar_idx"));
$this->assertFalse($table->hasIndex("some_idx"));
$this->assertType('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey());
$this->assertType('Doctrine\DBAL\Schema\Index', $table->getIndex('the_primary'));
$this->assertType('Doctrine\DBAL\Schema\Index', $table->getIndex('bar_idx'));
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey());
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('the_primary'));
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('bar_idx'));
}
public function testGetUnknownIndexThrowsException()
......@@ -219,7 +219,7 @@ class TableTest extends \PHPUnit_Framework_TestCase
$table->setPrimaryKey(array("bar"));
$this->assertTrue($table->hasIndex("primary"));
$this->assertType('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey());
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey());
$this->assertTrue($table->getIndex("primary")->isUnique());
$this->assertTrue($table->getIndex("primary")->isPrimary());
}
......
......@@ -21,12 +21,12 @@ class BooleanTest extends \Doctrine\Tests\DbalTestCase
public function testBooleanConvertsToDatabaseValue()
{
$this->assertType('integer', $this->_type->convertToDatabaseValue(1, $this->_platform));
$this->assertInternalType('integer', $this->_type->convertToDatabaseValue(1, $this->_platform));
}
public function testBooleanConvertsToPHPValue()
{
$this->assertType('bool', $this->_type->convertToPHPValue(0, $this->_platform));
$this->assertInternalType('bool', $this->_type->convertToPHPValue(0, $this->_platform));
}
public function testBooleanNullConvertsToPHPValue()
......
......@@ -33,7 +33,7 @@ class DateTimeTest extends \Doctrine\Tests\DbalTestCase
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
$date = $this->_type->convertToPHPValue('1985-09-01 00:00:00', $this->_platform);
$this->assertType('DateTime', $date);
$this->assertInstanceOf('DateTime', $date);
$this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
}
......
......@@ -33,7 +33,7 @@ class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
$date = $this->_type->convertToPHPValue('1985-09-01 00:00:00', $this->_platform);
$this->assertType('DateTime', $date);
$this->assertInstanceOf('DateTime', $date);
$this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
}
......
......@@ -21,7 +21,7 @@ class DecimalTest extends \Doctrine\Tests\DbalTestCase
public function testDecimalConvertsToPHPValue()
{
$this->assertType('float', $this->_type->convertToPHPValue('5.5', $this->_platform));
$this->assertInternalType('float', $this->_type->convertToPHPValue('5.5', $this->_platform));
}
public function testDecimalNullConvertsToPHPValue()
......
......@@ -19,7 +19,7 @@ class FloatTest extends \Doctrine\Tests\DbalTestCase
public function testFloatConvertsToPHPValue()
{
$this->assertType('float', $this->_type->convertToPHPValue('5.5', $this->_platform));
$this->assertInternalType('float', $this->_type->convertToPHPValue('5.5', $this->_platform));
}
public function testFloatNullConvertsToPHPValue()
......@@ -29,7 +29,7 @@ class FloatTest extends \Doctrine\Tests\DbalTestCase
public function testFloatConvertToDatabaseValue()
{
$this->assertType('float', $this->_type->convertToDatabaseValue(5.5, $this->_platform));
$this->assertInternalType('float', $this->_type->convertToDatabaseValue(5.5, $this->_platform));
}
public function testFloatNullConvertToDatabaseValue()
......
......@@ -21,8 +21,8 @@ class IntegerTest extends \Doctrine\Tests\DbalTestCase
public function testIntegerConvertsToPHPValue()
{
$this->assertType('integer', $this->_type->convertToPHPValue('1', $this->_platform));
$this->assertType('integer', $this->_type->convertToPHPValue('0', $this->_platform));
$this->assertInternalType('integer', $this->_type->convertToPHPValue('1', $this->_platform));
$this->assertInternalType('integer', $this->_type->convertToPHPValue('0', $this->_platform));
}
public function testIntegerNullConvertsToPHPValue()
......
......@@ -26,12 +26,12 @@ class ObjectTest extends \Doctrine\Tests\DbalTestCase
public function testObjectConvertsToDatabaseValue()
{
$this->assertType('string', $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform));
$this->assertInternalType('string', $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform));
}
public function testObjectConvertsToPHPValue()
{
$this->assertType('object', $this->_type->convertToPHPValue(serialize(new \stdClass), $this->_platform));
$this->assertInternalType('object', $this->_type->convertToPHPValue(serialize(new \stdClass), $this->_platform));
}
public function testConversionFailure()
......
......@@ -21,8 +21,8 @@ class SmallIntTest extends \Doctrine\Tests\DbalTestCase
public function testSmallIntConvertsToPHPValue()
{
$this->assertType('integer', $this->_type->convertToPHPValue('1', $this->_platform));
$this->assertType('integer', $this->_type->convertToPHPValue('0', $this->_platform));
$this->assertInternalType('integer', $this->_type->convertToPHPValue('1', $this->_platform));
$this->assertInternalType('integer', $this->_type->convertToPHPValue('0', $this->_platform));
}
public function testSmallIntNullConvertsToPHPValue()
......
......@@ -31,8 +31,8 @@ class StringTest extends \Doctrine\Tests\DbalTestCase
public function testConvertToPHPValue()
{
$this->assertType("string", $this->_type->convertToPHPValue("foo", $this->_platform));
$this->assertType("string", $this->_type->convertToPHPValue("", $this->_platform));
$this->assertInternalType("string", $this->_type->convertToPHPValue("foo", $this->_platform));
$this->assertInternalType("string", $this->_type->convertToPHPValue("", $this->_platform));
}
public function testNullConversion()
......
......@@ -36,7 +36,7 @@ class VarDateTimeTest extends \Doctrine\Tests\DbalTestCase
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
$date = $this->_type->convertToPHPValue('1985-09-01 00:00:00', $this->_platform);
$this->assertType('DateTime', $date);
$this->assertInstanceOf('DateTime', $date);
$this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
$this->assertEquals('000000', $date->format('u'));
}
......@@ -50,7 +50,7 @@ class VarDateTimeTest extends \Doctrine\Tests\DbalTestCase
public function testConversionWithMicroseconds()
{
$date = $this->_type->convertToPHPValue('1985-09-01 00:00:00.123456', $this->_platform);
$this->assertType('DateTime', $date);
$this->assertInstanceOf('DateTime', $date);
$this->assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s'));
$this->assertEquals('123456', $date->format('u'));
}
......
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