Commit f994680d authored by jwage's avatar jwage

[2.0] More general work on the Platform and SchemaManager classes(primarily pgsql)

parent a4e928e1
...@@ -1299,7 +1299,7 @@ abstract class AbstractPlatform ...@@ -1299,7 +1299,7 @@ abstract class AbstractPlatform
throw DoctrineException::updateMe('List functions not supported by this driver.'); throw DoctrineException::updateMe('List functions not supported by this driver.');
} }
public function getListTriggersSql() public function getListTriggersSql($table = null)
{ {
throw DoctrineException::updateMe('List triggers not supported by this driver.'); throw DoctrineException::updateMe('List triggers not supported by this driver.');
} }
...@@ -1339,6 +1339,11 @@ abstract class AbstractPlatform ...@@ -1339,6 +1339,11 @@ abstract class AbstractPlatform
throw DoctrineException::updateMe('List table indexes not supported by this driver.'); throw DoctrineException::updateMe('List table indexes not supported by this driver.');
} }
public function getListTableForeignKeysSql($table)
{
throw DoctrineException::updateMe('List table foreign keys not supported by this driver.');
}
public function getCreateViewSql($name, $sql) public function getCreateViewSql($name, $sql)
{ {
throw DoctrineException::updateMe('Create view not supported by this driver'); throw DoctrineException::updateMe('Create view not supported by this driver');
......
...@@ -2,11 +2,6 @@ ...@@ -2,11 +2,6 @@
namespace Doctrine\DBAL\Platforms; namespace Doctrine\DBAL\Platforms;
/**
* Enter description here...
*
* @since 2.0
*/
class FirebirdPlatform extends AbstractPlatform class FirebirdPlatform extends AbstractPlatform
{ {
/** /**
...@@ -84,24 +79,12 @@ class FirebirdPlatform extends AbstractPlatform ...@@ -84,24 +79,12 @@ class FirebirdPlatform extends AbstractPlatform
{ {
return 'COLLATE ' . $collation; return 'COLLATE ' . $collation;
} }
/**
* Enter description here...
*
* @param unknown_type $sequenceName
* @override
*/
public function getSequenceNextValSql($sequenceName) public function getSequenceNextValSql($sequenceName)
{ {
return 'SELECT GEN_ID(' . $this->quoteIdentifier($sequenceName) . ', 1) FROM RDB$DATABASE'; return 'SELECT GEN_ID(' . $this->quoteIdentifier($sequenceName) . ', 1) FROM RDB$DATABASE';
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
protected function _getTransactionIsolationLevelSql($level) protected function _getTransactionIsolationLevelSql($level)
{ {
switch ($level) { switch ($level) {
...@@ -117,13 +100,7 @@ class FirebirdPlatform extends AbstractPlatform ...@@ -117,13 +100,7 @@ class FirebirdPlatform extends AbstractPlatform
return parent::_getTransactionIsolationLevelSql($level); return parent::_getTransactionIsolationLevelSql($level);
} }
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level) public function getSetTransactionIsolationSql($level)
{ {
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level); return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
......
...@@ -2,11 +2,6 @@ ...@@ -2,11 +2,6 @@
namespace Doctrine\DBAL\Platforms; namespace Doctrine\DBAL\Platforms;
/**
* Enter description here...
*
* @since 2.0
*/
class InformixPlatform extends AbstractPlatform class InformixPlatform extends AbstractPlatform
{ {
public function __construct() public function __construct()
......
...@@ -302,23 +302,11 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -302,23 +302,11 @@ class MsSqlPlatform extends AbstractPlatform
return false; return false;
} }
/**
* Enter description here...
*
* @return unknown
* @override
*/
public function getShowDatabasesSql() public function getShowDatabasesSql()
{ {
return 'SHOW DATABASES'; return 'SHOW DATABASES';
} }
/**
* Enter description here...
*
* @todo Throw exception by default?
* @override
*/
public function getListTablesSql() public function getListTablesSql()
{ {
return 'SHOW TABLES'; return 'SHOW TABLES';
...@@ -348,12 +336,6 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -348,12 +336,6 @@ class MsSqlPlatform extends AbstractPlatform
return 'DROP DATABASE ' . $this->quoteIdentifier($name); return 'DROP DATABASE ' . $this->quoteIdentifier($name);
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level) public function getSetTransactionIsolationSql($level)
{ {
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level); return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
......
...@@ -185,6 +185,19 @@ class MySqlPlatform extends AbstractPlatform ...@@ -185,6 +185,19 @@ class MySqlPlatform extends AbstractPlatform
} }
} }
public function getListTableForeignKeysSql($table, $database = null)
{
$sql = "SELECT column_name, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME FROM information_schema.key_column_usage WHERE table_name = '" . $table . "'";
if ( ! is_null($database)) {
$sql .= " AND table_schema = 'doctrine_tests'";
}
$sql .= " AND REFERENCED_COLUMN_NAME is not NULL";
return $sql;
}
public function getCreateViewSql($name, $sql) public function getCreateViewSql($name, $sql)
{ {
return 'CREATE VIEW ' . $name . ' AS ' . $sql; return 'CREATE VIEW ' . $name . ' AS ' . $sql;
...@@ -216,12 +229,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -216,12 +229,7 @@ class MySqlPlatform extends AbstractPlatform
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT'); : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
} }
/**
* Enter description here...
*
* @param array $field
*/
public function getClobDeclarationSql(array $field) public function getClobDeclarationSql(array $field)
{ {
if ( ! empty($field['length'])) { if ( ! empty($field['length'])) {
...@@ -298,24 +306,12 @@ class MySqlPlatform extends AbstractPlatform ...@@ -298,24 +306,12 @@ class MySqlPlatform extends AbstractPlatform
{ {
return false; return false;
} }
/**
* Enter description here...
*
* @return unknown
* @override
*/
public function getShowDatabasesSql() public function getShowDatabasesSql()
{ {
return 'SHOW DATABASES'; return 'SHOW DATABASES';
} }
/**
* Enter description here...
*
* @todo Throw exception by default?
* @override
*/
public function getListTablesSql() public function getListTablesSql()
{ {
return 'SHOW TABLES'; return 'SHOW TABLES';
...@@ -899,13 +895,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -899,13 +895,7 @@ class MySqlPlatform extends AbstractPlatform
{ {
return 'DROP TABLE ' . $this->quoteIdentifier($table); return 'DROP TABLE ' . $this->quoteIdentifier($table);
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level) public function getSetTransactionIsolationSql($level)
{ {
return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level); return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
......
...@@ -134,13 +134,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -134,13 +134,7 @@ class OraclePlatform extends AbstractPlatform
{ {
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level); return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
} }
/**
* Enter description here...
*
* @param integer $level
* @override
*/
protected function _getTransactionIsolationLevelSql($level) protected function _getTransactionIsolationLevelSql($level)
{ {
switch ($level) { switch ($level) {
......
...@@ -484,22 +484,12 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -484,22 +484,12 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return true; return true;
} }
/**
* Enter description here...
*
* @override
*/
public function getListDatabasesSql() public function getListDatabasesSql()
{ {
return 'SELECT datname FROM pg_database'; return 'SELECT datname FROM pg_database';
} }
/**
* Enter description here...
*
* @override
*/
public function getListFunctionsSql() public function getListFunctionsSql()
{ {
return "SELECT return "SELECT
...@@ -514,12 +504,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -514,12 +504,7 @@ class PostgreSqlPlatform extends AbstractPlatform
(SELECT oid FROM pg_namespace (SELECT oid FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema'"; WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema'";
} }
/**
* Enter description here...
*
* @override
*/
public function getListSequencesSql($database) public function getListSequencesSql($database)
{ {
return "SELECT return "SELECT
...@@ -530,12 +515,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -530,12 +515,7 @@ class PostgreSqlPlatform extends AbstractPlatform
(SELECT oid FROM pg_namespace (SELECT oid FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')"; WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
} }
/**
* Enter description here...
*
* @override
*/
public function getListTablesSql() public function getListTablesSql()
{ {
return "SELECT return "SELECT
...@@ -553,32 +533,55 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -553,32 +533,55 @@ class PostgreSqlPlatform extends AbstractPlatform
AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner)
AND c.relname !~ '^pg_'"; AND c.relname !~ '^pg_'";
} }
/**
* Enter description here...
*
* @override
*/
public function getListViewsSql() public function getListViewsSql()
{ {
return 'SELECT viewname FROM pg_views'; return 'SELECT viewname, definition FROM pg_views';
} }
/** public function getListTriggersSql($table = null)
* Enter description here... {
* $sql = 'SELECT trg.tgname AS trigger_name
* @override FROM pg_trigger trg,
*/ pg_class tbl
WHERE trg.tgrelid = tbl.oid';
if ( ! is_null($table)) {
$sql .= " AND tbl.relname = ".$this->quoteIdentifier($table);
}
return $sql;
}
public function getListUsersSql() public function getListUsersSql()
{ {
return 'SELECT usename FROM pg_user'; return 'SELECT usename, passwd FROM pg_user';
} }
/** public function getListTableForeignKeysSql($table, $database = null)
* Enter description here... {
* return "SELECT pg_catalog.pg_get_constraintdef(oid, true) as condef
* @override FROM pg_catalog.pg_constraint r
*/ WHERE r.conrelid =
(
SELECT c.oid
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = '" . $table . "' AND pg_catalog.pg_table_is_visible(c.oid)
)
AND r.contype = 'f'";
}
public function getCreateViewSql($name, $sql)
{
return 'CREATE VIEW ' . $name . ' AS ' . $sql;
}
public function getDropViewSql($name)
{
return 'DROP VIEW '. $name;
}
public function getListTableConstraintsSql($table) public function getListTableConstraintsSql($table)
{ {
return "SELECT return "SELECT
...@@ -593,16 +596,16 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -593,16 +596,16 @@ class PostgreSqlPlatform extends AbstractPlatform
AND (indisunique = 't' OR indisprimary = 't') AND (indisunique = 't' OR indisprimary = 't')
)"; )";
} }
/**
* Enter description here...
*
* @override
*/
public function getListTableIndexesSql($table) public function getListTableIndexesSql($table)
{ {
return "SELECT return "SELECT
relname relname,
(
SELECT indisunique
FROM pg_index
WHERE oid = indexrelid
) as unique
FROM FROM
pg_class pg_class
WHERE oid IN ( WHERE oid IN (
...@@ -610,16 +613,10 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -610,16 +613,10 @@ class PostgreSqlPlatform extends AbstractPlatform
FROM pg_index, pg_class FROM pg_index, pg_class
WHERE pg_class.relname = '$table' WHERE pg_class.relname = '$table'
AND pg_class.oid=pg_index.indrelid AND pg_class.oid=pg_index.indrelid
AND indisunique != 't'
AND indisprimary != 't' AND indisprimary != 't'
)"; )";
} }
/**
* Enter description here...
*
* @override
*/
public function getListTableColumnsSql($table) public function getListTableColumnsSql($table)
{ {
return "SELECT return "SELECT
...@@ -877,24 +874,12 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -877,24 +874,12 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
return $item; return $item;
} }
/**
* Enter description here...
*
* @param string $sequenceName
* @override
*/
public function getSequenceNextValSql($sequenceName) public function getSequenceNextValSql($sequenceName)
{ {
return "SELECT NEXTVAL('" . $sequenceName . "')"; return "SELECT NEXTVAL('" . $sequenceName . "')";
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level) public function getSetTransactionIsolationSql($level)
{ {
return 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' return 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL '
......
...@@ -174,12 +174,6 @@ class SqlitePlatform extends AbstractPlatform ...@@ -174,12 +174,6 @@ class SqlitePlatform extends AbstractPlatform
return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))'; return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))';
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
protected function _getTransactionIsolationLevelSql($level) protected function _getTransactionIsolationLevelSql($level)
{ {
switch ($level) { switch ($level) {
...@@ -193,13 +187,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -193,13 +187,7 @@ class SqlitePlatform extends AbstractPlatform
return parent::_getTransactionIsolationLevelSql($level); return parent::_getTransactionIsolationLevelSql($level);
} }
} }
/**
* Enter description here...
*
* @param unknown_type $level
* @override
*/
public function getSetTransactionIsolationSql($level) public function getSetTransactionIsolationSql($level)
{ {
return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSql($level); return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSql($level);
......
...@@ -54,7 +54,7 @@ abstract class AbstractSchemaManager ...@@ -54,7 +54,7 @@ abstract class AbstractSchemaManager
/** /**
* Constructor. Accepts the Connection instance to manage the schema for * Constructor. Accepts the Connection instance to manage the schema for
* *
* @param \Doctrine\DBAL\Connection $conn * @param \Doctrine\DBAL\Connection $conn
*/ */
public function __construct(\Doctrine\DBAL\Connection $conn) public function __construct(\Doctrine\DBAL\Connection $conn)
{ {
...@@ -208,6 +208,24 @@ abstract class AbstractSchemaManager ...@@ -208,6 +208,24 @@ abstract class AbstractSchemaManager
return $this->_getPortableViewsList($views); return $this->_getPortableViewsList($views);
} }
/**
* List the foreign keys for the given table
*
* @param string $table The name of the table
* @return array $tableForeignKeys
*/
public function listTableForeignKeys($table, $database = null)
{
if (is_null($database)) {
$database = $this->_conn->getDatabase();
}
$sql = $this->_platform->getListTableForeignKeysSql($table, $database);
$tableForeignKeys = $this->_conn->fetchAll($sql);
return $this->_getPortableTableForeignKeysList($tableForeignKeys);
}
/** /**
* Drop the database for this connection * Drop the database for this connection
* *
...@@ -227,7 +245,7 @@ abstract class AbstractSchemaManager ...@@ -227,7 +245,7 @@ abstract class AbstractSchemaManager
/** /**
* Drop the given table * Drop the given table
* *
* @param string $table The name of the table to drop * @param string $table The name of the table to drop
* @return boolean $result * @return boolean $result
*/ */
public function dropTable($table) public function dropTable($table)
...@@ -442,7 +460,7 @@ abstract class AbstractSchemaManager ...@@ -442,7 +460,7 @@ abstract class AbstractSchemaManager
/** /**
* Create a new view * Create a new view
* *
* @param string $name The name of the view * @param string $name The name of the view
* @param string $sql The sql to set to the view * @param string $sql The sql to set to the view
* @return boolean $result * @return boolean $result
*/ */
...@@ -456,7 +474,7 @@ abstract class AbstractSchemaManager ...@@ -456,7 +474,7 @@ abstract class AbstractSchemaManager
/** /**
* Drop a view * Drop a view
* *
* @param string $name The name of the view * @param string $name The name of the view
* @return boolean $result * @return boolean $result
*/ */
public function dropView($name) public function dropView($name)
...@@ -600,7 +618,7 @@ abstract class AbstractSchemaManager ...@@ -600,7 +618,7 @@ abstract class AbstractSchemaManager
* Remove a column from a table * Remove a column from a table
* *
* @param string $tableName The name of the table * @param string $tableName The name of the table
* @param array|string $column The column name or array of names * @param array|string $column The column name or array of names
* @return boolean $result * @return boolean $result
*/ */
public function removeTableColumn($name, $column) public function removeTableColumn($name, $column)
...@@ -745,6 +763,9 @@ abstract class AbstractSchemaManager ...@@ -745,6 +763,9 @@ abstract class AbstractSchemaManager
$list = array(); $list = array();
foreach ($tableColumns as $key => $value) { foreach ($tableColumns as $key => $value) {
if ($value = $this->_getPortableTableColumnDefinition($value)) { if ($value = $this->_getPortableTableColumnDefinition($value)) {
if (is_string($value['type'])) {
$value['type'] = \Doctrine\DBAL\Types\Type::getType($value['type']);
}
$list[] = $value; $list[] = $value;
} }
} }
...@@ -820,6 +841,22 @@ abstract class AbstractSchemaManager ...@@ -820,6 +841,22 @@ abstract class AbstractSchemaManager
return $view; return $view;
} }
protected function _getPortableTableForeignKeysList($tableForeignKeys)
{
$list = array();
foreach ($tableForeignKeys as $key => $value) {
if ($value = $this->_getPortableTableForeignKeyDefinition($value)) {
$list[] = $value;
}
}
return $list;
}
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
{
return $tableForeignKey;
}
protected function _executeSql($sql, $method = 'exec') protected function _executeSql($sql, $method = 'exec')
{ {
$result = true; $result = true;
......
...@@ -71,15 +71,12 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -71,15 +71,12 @@ class MySqlSchemaManager extends AbstractSchemaManager
{ {
$tableConstraint = array_change_key_case($tableConstraint, CASE_LOWER); $tableConstraint = array_change_key_case($tableConstraint, CASE_LOWER);
$result = array();
if ( ! $tableConstraint['non_unique']) { if ( ! $tableConstraint['non_unique']) {
$index = $tableConstraint['key_name']; $index = $tableConstraint['key_name'];
if ( ! empty($index)) { if ( ! empty($index)) {
$result[] = $index; return $index;
} }
} }
return $result;
} }
protected function _getPortableSequenceDefinition($sequence) protected function _getPortableSequenceDefinition($sequence)
...@@ -275,8 +272,6 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -275,8 +272,6 @@ class MySqlSchemaManager extends AbstractSchemaManager
$values = isset($def['values']) ? $def['values'] : array(); $values = isset($def['values']) ? $def['values'] : array();
$def['type'] = \Doctrine\DBAL\Types\Type::getType($def['type']);
$column = array( $column = array(
'name' => $tableColumn['field'], 'name' => $tableColumn['field'],
'values' => $values, 'values' => $values,
...@@ -291,48 +286,17 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -291,48 +286,17 @@ class MySqlSchemaManager extends AbstractSchemaManager
return $column; return $column;
} }
/** public function _getPortableTableForeignKeyDefinition($tableForeignKey)
* lists table foreign keys
*
* @param string $table database table name
* @return array
* @override
*/
public function listTableForeignKeys($table)
{ {
$sql = 'SHOW CREATE TABLE ' . $this->_conn->quoteIdentifier($table, true); $tableForeignKey = array_change_key_case($tableForeignKey, CASE_LOWER);
$definition = $this->_conn->fetchOne($sql); $foreignKey = array(
if (!empty($definition)) { 'table' => $tableForeignKey['referenced_table_name'],
$pattern = '/\bCONSTRAINT\s+([^\s]+)\s+FOREIGN KEY\b/i'; 'local' => $tableForeignKey['column_name'],
if (preg_match_all($pattern, str_replace('`', '', $definition), $matches) > 1) { 'foreign' => $tableForeignKey['referenced_column_name']
foreach ($matches[1] as $constraint) { );
$result[$constraint] = true; return $foreignKey;
}
}
}
if ($this->_conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_FIX_CASE) {
$result = array_change_key_case($result, $this->_conn->getAttribute(Doctrine::ATTR_FIELD_CASE));
}
return $result;
} }
/**
* create sequence
*
* @param string $sequenceName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @param array $options An associative array of table options:
* array(
* 'comment' => 'Foo',
* 'charset' => 'utf8',
* 'collate' => 'utf8_unicode_ci',
* 'type' => 'innodb',
* );
* @return boolean
* @override
*/
public function createSequence($sequenceName, $start = 1, array $options = array()) public function createSequence($sequenceName, $start = 1, array $options = array())
{ {
$sequenceName = $this->_conn->quoteIdentifier($this->_conn->getSequenceName($sequenceName), true); $sequenceName = $this->_conn->quoteIdentifier($this->_conn->getSequenceName($sequenceName), true);
...@@ -395,19 +359,4 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -395,19 +359,4 @@ class MySqlSchemaManager extends AbstractSchemaManager
return $res; return $res;
} }
/**
* Enter description here...
*
* @param unknown_type $table
* @param unknown_type $name
* @return unknown
* @override
*/
public function dropForeignKey($table, $name)
{
$table = $this->_conn->quoteIdentifier($table);
$name = $this->_conn->quoteIdentifier($name);
return $this->_conn->exec('ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $name);
}
} }
\ No newline at end of file
...@@ -191,8 +191,6 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -191,8 +191,6 @@ class SqliteSchemaManager extends AbstractSchemaManager
$length = null; $length = null;
} }
$type = \Doctrine\DBAL\Types\Type::getType($type);
return array('name' => $tableColumn['name'], return array('name' => $tableColumn['name'],
'primary' => (bool) $tableColumn['pk'], 'primary' => (bool) $tableColumn['pk'],
'type' => $type, 'type' => $type,
......
...@@ -4,9 +4,6 @@ namespace Doctrine\ORM\Id; ...@@ -4,9 +4,6 @@ namespace Doctrine\ORM\Id;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
/**
* Enter description here...
*/
abstract class AbstractIdGenerator abstract class AbstractIdGenerator
{ {
/** /**
......
...@@ -97,24 +97,12 @@ class CommitOrderCalculator ...@@ -97,24 +97,12 @@ class CommitOrderCalculator
{ {
$this->_nodes[$key] = $node; $this->_nodes[$key] = $node;
} }
/**
* Enter description here...
*
* @param unknown_type $key
* @param unknown_type $item
*/
public function addNodeWithItem($key, $item) public function addNodeWithItem($key, $item)
{ {
$this->_nodes[$key] = new CommitOrderNode($item, $this); $this->_nodes[$key] = new CommitOrderNode($item, $this);
} }
/**
* Enter description here...
*
* @param unknown_type $key
* @return unknown
*/
public function getNodeForKey($key) public function getNodeForKey($key)
{ {
return $this->_nodes[$key]; return $this->_nodes[$key];
......
...@@ -35,11 +35,6 @@ namespace Doctrine\ORM\Query\Exec; ...@@ -35,11 +35,6 @@ namespace Doctrine\ORM\Query\Exec;
*/ */
class MultiTableDeleteExecutor extends AbstractExecutor class MultiTableDeleteExecutor extends AbstractExecutor
{ {
/**
* Enter description here...
*
* @param Node $AST
*/
public function __construct($AST) public function __construct($AST)
{ {
// 1. Create a INSERT INTO temptable ... VALUES ( SELECT statement where the SELECT statement // 1. Create a INSERT INTO temptable ... VALUES ( SELECT statement where the SELECT statement
......
...@@ -787,13 +787,6 @@ class UnitOfWork implements PropertyChangedListener ...@@ -787,13 +787,6 @@ class UnitOfWork implements PropertyChangedListener
$this->_entityStates[$oid]); $this->_entityStates[$oid]);
} }
/**
* Enter description here...
*
* @param object $entity
* @return boolean
* @todo Rename to isScheduled()
*/
public function isEntityRegistered($entity) public function isEntityRegistered($entity)
{ {
$oid = spl_object_hash($entity); $oid = spl_object_hash($entity);
......
...@@ -23,6 +23,7 @@ class AllTests ...@@ -23,6 +23,7 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\SqliteSchemaManagerTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\SqliteSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaManagerTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\MySqlSchemaManagerTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schema\PostgreSQLSchemaManagerTest');
return $suite; return $suite;
} }
......
...@@ -19,7 +19,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -19,7 +19,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{ {
$this->markTestSkipped('The MySqlSchemaTest requires the use of mysql'); $this->markTestSkipped('The MySqlSchemaTest requires the use of mysql');
} }
$this->_sm = new Schema\MySqlSchemaManager($this->_conn); $this->_sm = $this->_conn->getSchemaManager();
} }
public function testListDatabases() public function testListDatabases()
...@@ -31,7 +31,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -31,7 +31,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_sm->createDatabase('test_mysql_create_database'); $this->_sm->createDatabase('test_mysql_create_database');
$databases = $this->_sm->listDatabases(); $databases = $this->_sm->listDatabases();
$this->assertEquals(in_array('test_mysql_create_database', $databases), true); $this->assertEquals(true, in_array('test_mysql_create_database', $databases));
} }
public function testListFunctions() public function testListFunctions()
...@@ -80,7 +80,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -80,7 +80,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_sm->createTable('list_sequences_test', $columns, $options); $this->_sm->createTable('list_sequences_test', $columns, $options);
$sequences = $this->_sm->listSequences(); $sequences = $this->_sm->listSequences();
$this->assertEquals(in_array('list_sequences_test', $sequences), true); $this->assertEquals(true, in_array('list_sequences_test', $sequences));
} }
public function testListTableConstraints() public function testListTableConstraints()
...@@ -108,7 +108,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -108,7 +108,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test'); $tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test');
$this->assertEquals($tableConstraints, array(array('PRIMARY'))); $this->assertEquals(array('PRIMARY'), $tableConstraints);
} }
public function testListTableColumns() public function testListTableColumns()
...@@ -136,23 +136,23 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -136,23 +136,23 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$columns = $this->_sm->listTableColumns('list_tables_test'); $columns = $this->_sm->listTableColumns('list_tables_test');
$this->assertEquals($columns[0]['name'], 'id'); $this->assertEquals('id', $columns[0]['name']);
$this->assertEquals($columns[0]['primary'], true); $this->assertEquals(true, $columns[0]['primary']);
$this->assertEquals(get_class($columns[0]['type']), 'Doctrine\DBAL\Types\IntegerType'); $this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($columns[0]['type']));
$this->assertEquals($columns[0]['length'], 4); $this->assertEquals(4, $columns[0]['length']);
$this->assertEquals($columns[0]['unsigned'], false); $this->assertEquals(false, $columns[0]['unsigned']);
$this->assertEquals($columns[0]['fixed'], false); $this->assertEquals(false, $columns[0]['fixed']);
$this->assertEquals($columns[0]['notnull'], true); $this->assertEquals(true, $columns[0]['notnull']);
$this->assertEquals($columns[0]['default'], null); $this->assertEquals(null, $columns[0]['default']);
$this->assertEquals($columns[1]['name'], 'test'); $this->assertEquals('test', $columns[1]['name']);
$this->assertEquals($columns[1]['primary'], false); $this->assertEquals(false, $columns[1]['primary']);
$this->assertEquals(get_class($columns[1]['type']), 'Doctrine\DBAL\Types\StringType'); $this->assertEquals('Doctrine\DBAL\Types\StringType', get_class($columns[1]['type']));
$this->assertEquals($columns[1]['length'], 255); $this->assertEquals(255, $columns[1]['length']);
$this->assertEquals($columns[1]['unsigned'], false); $this->assertEquals(false, $columns[1]['unsigned']);
$this->assertEquals($columns[1]['fixed'], false); $this->assertEquals(false, $columns[1]['fixed']);
$this->assertEquals($columns[1]['notnull'], false); $this->assertEquals(false, $columns[1]['notnull']);
$this->assertEquals($columns[1]['default'], null); $this->assertEquals(null, $columns[1]['default']);
} }
public function testListTableIndexes() public function testListTableIndexes()
...@@ -189,12 +189,12 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -189,12 +189,12 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test'); $tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test');
$this->assertEquals($tableIndexes[0]['name'], 'test_index_name'); $this->assertEquals('test_index_name', $tableIndexes[0]['name']);
$this->assertEquals($tableIndexes[0]['column'], 'test'); $this->assertEquals('test', $tableIndexes[0]['column']);
$this->assertEquals($tableIndexes[0]['unique'], true); $this->assertEquals(true, $tableIndexes[0]['unique']);
} }
public function testListTable() public function testListTables()
{ {
$columns = array( $columns = array(
'id' => array( 'id' => array(
...@@ -219,13 +219,13 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -219,13 +219,13 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$tables = $this->_sm->listTables(); $tables = $this->_sm->listTables();
$this->assertEquals(in_array('list_tables_test', $tables), true); $this->assertEquals(true, in_array('list_tables_test', $tables));
} }
public function testListUsers() public function testListUsers()
{ {
$users = $this->_sm->listUsers(); $users = $this->_sm->listUsers();
$this->assertEquals(is_array($users), true); $this->assertEquals(true, is_array($users));
$params = $this->_conn->getParams(); $params = $this->_conn->getParams();
$testUser = $params['user']; $testUser = $params['user'];
$found = false; $found = false;
...@@ -234,7 +234,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -234,7 +234,7 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$found = true; $found = true;
} }
} }
$this->assertEquals($found, true); $this->assertEquals(true, $found);
} }
public function testListViews() public function testListViews()
...@@ -249,4 +249,66 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -249,4 +249,66 @@ class MysqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->assertEquals('test_create_view', $views[0]['name']); $this->assertEquals('test_create_view', $views[0]['name']);
$this->assertEquals('/* ALGORITHM=UNDEFINED */ select `mysql`.`user`.`Host` AS `Host`,`mysql`.`user`.`User` AS `User`,`mysql`.`user`.`Password` AS `Password`,`mysql`.`user`.`Select_priv` AS `Select_priv`,`mysql`.`user`.`Insert_priv` AS `Insert_priv`,`mysql`.`user`.`Update_priv` AS `Update_priv`,`mysql`.`user`.`Delete_priv` AS `Delete_priv`,`mysql`.`user`.`Create_priv` AS `Create_priv`,`mysql`.`user`.`Drop_priv` AS `Drop_priv`,`mysql`.`user`.`Reload_priv` AS `Reload_priv`,`mysql`.`user`.`Shutdown_priv` AS `Shutdown_priv`,`mysql`.`user`.`Process_priv` AS `Process_priv`,`mysql`.`user`.`File_priv` AS `File_priv`,`mysql`.`user`.`Grant_priv` AS `Grant_priv`,`mysql`.`user`.`References_priv` AS `References_priv`,`mysql`.`user`.`Index_priv` AS `Index_priv`,`mysql`.`user`.`Alter_priv` AS `Alter_priv`,`mysql`.`user`.`Show_db_priv` AS `Show_db_priv`,`mysql`.`user`.`Super_priv` AS `Super_priv`,`mysql`.`user`.`Create_tmp_table_priv` AS `Create_tmp_table_priv`,`mysql`.`user`.`Lock_tables_priv` AS `Lock_tables_priv`,`mysql`.`user`.`Execute_priv` AS `Execute_priv`,`mysql`.`user`.`Repl_slave_priv` AS `Repl_slave_priv`,`mysql`.`user`.`Repl_client_priv` AS `Repl_client_priv`,`mysql`.`user`.`Create_view_priv` AS `Create_view_priv`,`mysql`.`user`.`Show_view_priv` AS `Show_view_priv`,`mysql`.`user`.`Create_routine_priv` AS `Create_routine_priv`,`mysql`.`user`.`Alter_routine_priv` AS `Alter_routine_priv`,`mysql`.`user`.`Create_user_priv` AS `Create_user_priv`,`mysql`.`user`.`ssl_type` AS `ssl_type`,`mysql`.`user`.`ssl_cipher` AS `ssl_cipher`,`mysql`.`user`.`x509_issuer` AS `x509_issuer`,`mysql`.`user`.`x509_subject` AS `x509_subject`,`mysql`.`user`.`max_questions` AS `max_questions`,`mysql`.`user`.`max_updates` AS `max_updates`,`mysql`.`user`.`max_connections` AS `max_connections`,`mysql`.`user`.`max_user_connections` AS `max_user_connections` from `mysql`.`user`', $views[0]['sql']); $this->assertEquals('/* ALGORITHM=UNDEFINED */ select `mysql`.`user`.`Host` AS `Host`,`mysql`.`user`.`User` AS `User`,`mysql`.`user`.`Password` AS `Password`,`mysql`.`user`.`Select_priv` AS `Select_priv`,`mysql`.`user`.`Insert_priv` AS `Insert_priv`,`mysql`.`user`.`Update_priv` AS `Update_priv`,`mysql`.`user`.`Delete_priv` AS `Delete_priv`,`mysql`.`user`.`Create_priv` AS `Create_priv`,`mysql`.`user`.`Drop_priv` AS `Drop_priv`,`mysql`.`user`.`Reload_priv` AS `Reload_priv`,`mysql`.`user`.`Shutdown_priv` AS `Shutdown_priv`,`mysql`.`user`.`Process_priv` AS `Process_priv`,`mysql`.`user`.`File_priv` AS `File_priv`,`mysql`.`user`.`Grant_priv` AS `Grant_priv`,`mysql`.`user`.`References_priv` AS `References_priv`,`mysql`.`user`.`Index_priv` AS `Index_priv`,`mysql`.`user`.`Alter_priv` AS `Alter_priv`,`mysql`.`user`.`Show_db_priv` AS `Show_db_priv`,`mysql`.`user`.`Super_priv` AS `Super_priv`,`mysql`.`user`.`Create_tmp_table_priv` AS `Create_tmp_table_priv`,`mysql`.`user`.`Lock_tables_priv` AS `Lock_tables_priv`,`mysql`.`user`.`Execute_priv` AS `Execute_priv`,`mysql`.`user`.`Repl_slave_priv` AS `Repl_slave_priv`,`mysql`.`user`.`Repl_client_priv` AS `Repl_client_priv`,`mysql`.`user`.`Create_view_priv` AS `Create_view_priv`,`mysql`.`user`.`Show_view_priv` AS `Show_view_priv`,`mysql`.`user`.`Create_routine_priv` AS `Create_routine_priv`,`mysql`.`user`.`Alter_routine_priv` AS `Alter_routine_priv`,`mysql`.`user`.`Create_user_priv` AS `Create_user_priv`,`mysql`.`user`.`ssl_type` AS `ssl_type`,`mysql`.`user`.`ssl_cipher` AS `ssl_cipher`,`mysql`.`user`.`x509_issuer` AS `x509_issuer`,`mysql`.`user`.`x509_subject` AS `x509_subject`,`mysql`.`user`.`max_questions` AS `max_questions`,`mysql`.`user`.`max_updates` AS `max_updates`,`mysql`.`user`.`max_connections` AS `max_connections`,`mysql`.`user`.`max_user_connections` AS `max_user_connections` from `mysql`.`user`', $views[0]['sql']);
} }
public function testListTableForeignKeys()
{
// Create table that has foreign key
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => Type::getType('integer'),
'length' => 4
)
);
$options = array('type' => 'innodb');
try {
$this->_sm->dropTable('list_table_foreign_keys_test2');
} catch (\Exception $e) {}
$this->_sm->createTable('list_table_foreign_keys_test2', $columns, $options);
// Create the table that is being referenced in the foreign key
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'whatever' => array(
'type' => Type::getType('string'),
'length' => 255
)
);
$options = array('type' => 'innodb');
try {
$this->_sm->dropTable('list_table_foreign_keys_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_table_foreign_keys_test', $columns, $options);
// Create the foreign key between the tables
$definition = array(
'name' => 'testing',
'local' => 'test',
'foreign' => 'id',
'foreignTable' => 'list_table_foreign_keys_test'
);
$this->_sm->createForeignKey('list_table_foreign_keys_test2', $definition);
$tableForeignKeys = $this->_sm->listTableForeignKeys('list_table_foreign_keys_test2');
$this->assertEquals(1, count($tableForeignKeys));
$this->assertEquals('list_table_foreign_keys_test', $tableForeignKeys[0]['table']);
$this->assertEquals('test', $tableForeignKeys[0]['local']);
$this->assertEquals('id', $tableForeignKeys[0]['foreign']);
}
} }
\ No newline at end of file
<?php
namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\Tests\TestUtil;
use Doctrine\DBAL\Schema;
use Doctrine\DBAL\Types\Type;
require_once __DIR__ . '/../../../TestInit.php';
class PostgreSqlSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
private $_conn;
protected function setUp()
{
$this->_conn = TestUtil::getConnection();
if ($this->_conn->getDatabasePlatform()->getName() !== 'postgresql')
{
$this->markTestSkipped('The PostgreSQLSchemaTest requires the use of postgresql');
}
$this->_sm = $this->_conn->getSchemaManager();
}
public function testListDatabases()
{
try {
$this->_sm->dropDatabase('test_pgsql_create_database');
} catch (\Exception $e) {}
$this->_sm->createDatabase('test_pgsql_create_database');
$databases = $this->_sm->listDatabases();
$this->assertEquals(in_array('test_pgsql_create_database', $databases), true);
}
public function testListFunctions()
{
try {
$this->_sm->listFunctions();
} catch (\Exception $e) {
return;
}
$this->fail('PostgreSql listFunctions() should throw an exception because it is not supported');
}
public function testListTriggers()
{
$triggers = $this->_sm->listTriggers();
$this->assertEquals(true, is_array($triggers));
$this->assertEquals(true, count($triggers) > 0);
}
public function testListSequences()
{
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => Type::getType('string'),
'length' => 255
)
);
$options = array();
try {
$this->_sm->dropTable('list_sequences_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_sequences_test', $columns, $options);
$sequences = $this->_sm->listSequences();
$this->assertEquals(true, in_array('list_sequences_test_id_seq', $sequences));
}
public function testListTableConstraints()
{
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => Type::getType('string'),
'length' => 255
)
);
$options = array();
try {
$this->_sm->dropTable('list_table_constraints_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_table_constraints_test', $columns, $options);
$tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test');
$this->assertEquals(array('list_table_constraints_test_pkey'), $tableConstraints);
}
public function testListTableColumns()
{
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => Type::getType('string'),
'length' => 255
)
);
$options = array();
try {
$this->_sm->dropTable('list_tables_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_tables_test', $columns, $options);
$columns = $this->_sm->listTableColumns('list_tables_test');
$this->assertEquals('id', $columns[0]['name']);
$this->assertEquals(true, $columns[0]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($columns[0]['type']));
$this->assertEquals(4, $columns[0]['length']);
$this->assertEquals(false, $columns[0]['unsigned']);
$this->assertEquals(false, $columns[0]['fixed']);
$this->assertEquals(true, $columns[0]['notnull']);
$this->assertEquals(null, $columns[0]['default']);
$this->assertEquals('test', $columns[1]['name']);
$this->assertEquals(false, $columns[1]['primary']);
$this->assertEquals('Doctrine\DBAL\Types\StringType', get_class($columns[1]['type']));
$this->assertEquals(255, $columns[1]['length']);
$this->assertEquals(false, $columns[1]['unsigned']);
$this->assertEquals(false, $columns[1]['fixed']);
$this->assertEquals(false, $columns[1]['notnull']);
$this->assertEquals(null, $columns[1]['default']);
}
public function testListTableIndexes()
{
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => Type::getType('string'),
'length' => 255
)
);
$options = array(
'indexes' => array(
'test' => array(
'fields' => array(
'test' => array()
),
'type' => 'unique'
)
)
);
try {
$this->_sm->dropTable('list_table_indexes_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_table_indexes_test', $columns, $options);
$tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test');
$this->assertEquals('test', $tableIndexes[0]['name']);
$this->assertEquals(true, $tableIndexes[0]['unique']);
}
public function testListTables()
{
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => Type::getType('string'),
'length' => 255
)
);
$options = array();
try {
$this->_sm->dropTable('list_tables_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_tables_test', $columns, $options);
$tables = $this->_sm->listTables();
$this->assertEquals(true, in_array('list_tables_test', $tables));
}
public function testListUsers()
{
$users = $this->_sm->listUsers();
$this->assertEquals(true, is_array($users));
$params = $this->_conn->getParams();
$testUser = $params['user'];
$found = false;
foreach ($users as $user) {
if ($user['user'] == $testUser) {
$found = true;
}
}
$this->assertEquals(true, $found);
}
public function testListViews()
{
try {
$this->_sm->dropView('test_create_view');
} catch (\Exception $e) {}
$this->_sm->createView('test_create_view', 'SELECT usename, passwd FROM pg_user');
$views = $this->_sm->listViews();
$found = false;
foreach ($views as $view) {
if ($view['name'] == 'test_create_view') {
$found = true;
break;
}
}
$this->assertEquals(true, $found);
$this->assertEquals('SELECT pg_user.usename, pg_user.passwd FROM pg_user;', $view['sql']);
}
public function testListTableForeignKeys()
{
// Create table that has foreign key
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => Type::getType('integer'),
'length' => 4
)
);
$options = array('type' => 'innodb');
try {
$this->_sm->dropTable('list_table_foreign_keys_test2');
} catch (\Exception $e) {}
$this->_sm->createTable('list_table_foreign_keys_test2', $columns, $options);
// Create the table that is being referenced in the foreign key
$columns = array(
'id' => array(
'type' => Type::getType('integer'),
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'whatever' => array(
'type' => Type::getType('string'),
'length' => 255
)
);
$options = array('type' => 'innodb');
try {
$this->_sm->dropTable('list_table_foreign_keys_test');
} catch (\Exception $e) {}
$this->_sm->createTable('list_table_foreign_keys_test', $columns, $options);
// Create the foreign key between the tables
$definition = array(
'name' => 'testing',
'local' => 'test',
'foreign' => 'id',
'foreignTable' => 'list_table_foreign_keys_test'
);
$this->_sm->createForeignKey('list_table_foreign_keys_test2', $definition);
$tableForeignKeys = $this->_sm->listTableForeignKeys('list_table_foreign_keys_test2');
$this->assertEquals(1, count($tableForeignKeys));
$this->assertEquals('list_table_foreign_keys_test', $tableForeignKeys[0]['table']);
$this->assertEquals('test', $tableForeignKeys[0]['local']);
$this->assertEquals('id', $tableForeignKeys[0]['foreign']);
}
}
\ No newline at end of file
...@@ -19,7 +19,7 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -19,7 +19,7 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
{ {
$this->markTestSkipped('The SqliteSchemaTest requires the use of sqlite'); $this->markTestSkipped('The SqliteSchemaTest requires the use of sqlite');
} }
$this->_sm = new Schema\SqliteSchemaManager($this->_conn); $this->_sm = $this->_conn->getSchemaManager();
} }
public function testListDatabases() public function testListDatabases()
...@@ -75,8 +75,8 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -75,8 +75,8 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_sm->createTable('list_sequences_test', $columns, $options); $this->_sm->createTable('list_sequences_test', $columns, $options);
$sequences = $this->_sm->listSequences(); $sequences = $this->_sm->listSequences();
$this->assertEquals($sequences[0]['name'], 'list_sequences_test'); $this->assertEquals('list_sequences_test', $sequences[0]['name']);
$this->assertEquals($sequences[1]['name'], 'sqlite_sequence'); $this->assertEquals('sqlite_sequence', $sequences[1]['name']);
} }
public function testListTableConstraints() public function testListTableConstraints()
...@@ -85,7 +85,7 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -85,7 +85,7 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
// when creating tables. Sqlite does not support adding them after // when creating tables. Sqlite does not support adding them after
// the table has already been created // the table has already been created
$tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test'); $tableConstraints = $this->_sm->listTableConstraints('list_table_constraints_test');
$this->assertEquals($tableConstraints, array()); $this->assertEquals(array(), $tableConstraints);
} }
public function testListTableColumns() public function testListTableColumns()
...@@ -109,23 +109,23 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -109,23 +109,23 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$tableColumns = $this->_sm->listTableColumns('list_table_columns_test'); $tableColumns = $this->_sm->listTableColumns('list_table_columns_test');
$this->assertEquals($tableColumns[0]['name'], 'id'); $this->assertEquals('id', $tableColumns[0]['name']);
$this->assertEquals($tableColumns[0]['primary'], true); $this->assertEquals(true, $tableColumns[0]['primary']);
$this->assertEquals(get_class($tableColumns[0]['type']), 'Doctrine\DBAL\Types\IntegerType'); $this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($tableColumns[0]['type']));
$this->assertEquals($tableColumns[0]['length'], 4); $this->assertEquals(4, $tableColumns[0]['length']);
$this->assertEquals($tableColumns[0]['unsigned'], false); $this->assertEquals(false, $tableColumns[0]['unsigned']);
$this->assertEquals($tableColumns[0]['fixed'], false); $this->assertEquals(false, $tableColumns[0]['fixed']);
$this->assertEquals($tableColumns[0]['notnull'], true); $this->assertEquals(true, $tableColumns[0]['notnull']);
$this->assertEquals($tableColumns[0]['default'], null); $this->assertEquals(null, $tableColumns[0]['default']);
$this->assertEquals($tableColumns[1]['name'], 'test'); $this->assertEquals('test', $tableColumns[1]['name']);
$this->assertEquals($tableColumns[1]['primary'], false); $this->assertEquals(false, $tableColumns[1]['primary']);
$this->assertEquals(get_class($tableColumns[1]['type']), 'Doctrine\DBAL\Types\StringType'); $this->assertEquals('Doctrine\DBAL\Types\StringType', get_class($tableColumns[1]['type']));
$this->assertEquals($tableColumns[1]['length'], 255); $this->assertEquals(255, $tableColumns[1]['length']);
$this->assertEquals($tableColumns[1]['unsigned'], false); $this->assertEquals(false, $tableColumns[1]['unsigned']);
$this->assertEquals($tableColumns[1]['fixed'], false); $this->assertEquals(false, $tableColumns[1]['fixed']);
$this->assertEquals($tableColumns[1]['notnull'], false); $this->assertEquals(false, $tableColumns[1]['notnull']);
$this->assertEquals($tableColumns[1]['default'], null); $this->assertEquals(null, $tableColumns[1]['default']);
} }
public function testListTableIndexes() public function testListTableIndexes()
...@@ -157,11 +157,11 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -157,11 +157,11 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_sm->createTable('list_table_indexes_test', $columns, $options); $this->_sm->createTable('list_table_indexes_test', $columns, $options);
$tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test'); $tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test');
$this->assertEquals($tableIndexes[0]['name'], 'test'); $this->assertEquals('test', $tableIndexes[0]['name']);
$this->assertEquals($tableIndexes[0]['unique'], true); $this->assertEquals(true, $tableIndexes[0]['unique']);
} }
public function testListTable() public function testListTables()
{ {
$columns = array( $columns = array(
'id' => array( 'id' => array(
...@@ -181,7 +181,7 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -181,7 +181,7 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_sm->createTable('list_tables_test', $columns, $options); $this->_sm->createTable('list_tables_test', $columns, $options);
$tables = $this->_sm->listTables(); $tables = $this->_sm->listTables();
$this->assertEquals(in_array('list_tables_test', $tables), true); $this->assertEquals(true, in_array('list_tables_test', $tables));
} }
public function testListUsers() public function testListUsers()
...@@ -221,8 +221,8 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -221,8 +221,8 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_sm->createView('test_create_view', 'SELECT * from test_views'); $this->_sm->createView('test_create_view', 'SELECT * from test_views');
$views = $this->_sm->listViews(); $views = $this->_sm->listViews();
$this->assertEquals($views[0]['name'], 'test_create_view'); $this->assertEquals('test_create_view', $views[0]['name']);
$this->assertEquals($views[0]['sql'], 'CREATE VIEW test_create_view AS SELECT * from test_views'); $this->assertEquals('CREATE VIEW test_create_view AS SELECT * from test_views', $views[0]['sql']);
} }
public function testCreateAndDropDatabase() public function testCreateAndDropDatabase()
...@@ -239,11 +239,11 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -239,11 +239,11 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sm = $conn->getSchemaManager(); $sm = $conn->getSchemaManager();
$sm->createDatabase(); $sm->createDatabase();
$this->assertEquals(file_exists($path), true); $this->assertEquals(true, file_exists($path));
$sm->dropDatabase(); $sm->dropDatabase();
$this->assertEquals(file_exists($path), false); $this->assertEquals(false, file_exists($path));
$sm->createDatabase(); $sm->createDatabase();
$this->assertEquals(file_exists($path), true); $this->assertEquals(true, file_exists($path));
$sm->dropDatabase(); $sm->dropDatabase();
} }
...@@ -266,27 +266,27 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -266,27 +266,27 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_sm->createTable('test_create_table', $columns, $options); $this->_sm->createTable('test_create_table', $columns, $options);
$tables = $this->_sm->listTables(); $tables = $this->_sm->listTables();
$this->assertEquals(in_array('test_create_table', $tables), true); $this->assertEquals(true, in_array('test_create_table', $tables));
$tableColumns = $this->_sm->listTableColumns('test_create_table'); $tableColumns = $this->_sm->listTableColumns('test_create_table');
$this->assertEquals($tableColumns[0]['name'], 'id'); $this->assertEquals('id', $tableColumns[0]['name']);
$this->assertEquals($tableColumns[0]['primary'], true); $this->assertEquals(true, $tableColumns[0]['primary']);
$this->assertEquals(get_class($tableColumns[0]['type']), 'Doctrine\DBAL\Types\IntegerType'); $this->assertEquals('Doctrine\DBAL\Types\IntegerType', get_class($tableColumns[0]['type']));
$this->assertEquals($tableColumns[0]['length'], 4); $this->assertEquals(4, $tableColumns[0]['length']);
$this->assertEquals($tableColumns[0]['unsigned'], false); $this->assertEquals(false, $tableColumns[0]['unsigned']);
$this->assertEquals($tableColumns[0]['fixed'], false); $this->assertEquals(false, $tableColumns[0]['fixed']);
$this->assertEquals($tableColumns[0]['notnull'], true); $this->assertEquals(true, $tableColumns[0]['notnull']);
$this->assertEquals($tableColumns[0]['default'], null); $this->assertEquals(null, $tableColumns[0]['default']);
$this->assertEquals($tableColumns[1]['name'], 'test'); $this->assertEquals('test', $tableColumns[1]['name']);
$this->assertEquals($tableColumns[1]['primary'], false); $this->assertEquals(false, $tableColumns[1]['primary']);
$this->assertEquals(get_class($tableColumns[1]['type']), 'Doctrine\DBAL\Types\StringType'); $this->assertEquals('Doctrine\DBAL\Types\StringType', get_class($tableColumns[1]['type']));
$this->assertEquals($tableColumns[1]['length'], 255); $this->assertEquals(255, $tableColumns[1]['length']);
$this->assertEquals($tableColumns[1]['unsigned'], false); $this->assertEquals(false, $tableColumns[1]['unsigned']);
$this->assertEquals($tableColumns[1]['fixed'], false); $this->assertEquals(false, $tableColumns[1]['fixed']);
$this->assertEquals($tableColumns[1]['notnull'], false); $this->assertEquals(false, $tableColumns[1]['notnull']);
$this->assertEquals($tableColumns[1]['default'], null); $this->assertEquals(null, $tableColumns[1]['default']);
} }
public function testCreateSequence() public function testCreateSequence()
...@@ -339,8 +339,8 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -339,8 +339,8 @@ class SqliteSchemaManagerTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_sm->createIndex('test_create_index', 'test', $index); $this->_sm->createIndex('test_create_index', 'test', $index);
$tableIndexes = $this->_sm->listTableIndexes('test_create_index'); $tableIndexes = $this->_sm->listTableIndexes('test_create_index');
$this->assertEquals($tableIndexes[0]['name'], 'test'); $this->assertEquals('test', $tableIndexes[0]['name']);
$this->assertEquals($tableIndexes[0]['unique'], true); $this->assertEquals(true, $tableIndexes[0]['unique']);
} }
public function testCreateForeignKey() public function testCreateForeignKey()
......
...@@ -7,18 +7,12 @@ use Doctrine\ORM\EntityManager; ...@@ -7,18 +7,12 @@ use Doctrine\ORM\EntityManager;
class SequenceMock extends \Doctrine\ORM\Id\SequenceGenerator class SequenceMock extends \Doctrine\ORM\Id\SequenceGenerator
{ {
private $_sequenceNumber = 0; private $_sequenceNumber = 0;
/**
* Enter description here...
*
* @param object $entity
* @override
*/
public function generate(EntityManager $em, $entity) public function generate(EntityManager $em, $entity)
{ {
return $this->_sequenceNumber++; return $this->_sequenceNumber++;
} }
/** /**
* @override * @override
*/ */
...@@ -42,14 +36,14 @@ class SequenceMock extends \Doctrine\ORM\Id\SequenceGenerator ...@@ -42,14 +36,14 @@ class SequenceMock extends \Doctrine\ORM\Id\SequenceGenerator
{ {
return $this->_sequenceNumber; return $this->_sequenceNumber;
} }
/* Mock API */ /* Mock API */
public function reset() public function reset()
{ {
$this->_sequenceNumber = 0; $this->_sequenceNumber = 0;
} }
public function autoinc() public function autoinc()
{ {
$this->_sequenceNumber++; $this->_sequenceNumber++;
......
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