Commit 7426baf5 authored by jwage's avatar jwage

[2.0] General work on Platform and SchemaManager classes

parent b9510560
......@@ -434,7 +434,7 @@ class Connection
*/
public function fetchRow($statement, array $params = array())
{
return $this->execute($statement, $params)->fetch(PDO::FETCH_ASSOC);
return $this->execute($statement, $params)->fetch(\PDO::FETCH_ASSOC);
}
/**
......@@ -446,7 +446,7 @@ class Connection
*/
public function fetchArray($statement, array $params = array())
{
return $this->execute($statement, $params)->fetch(PDO::FETCH_NUM);
return $this->execute($statement, $params)->fetch(\PDO::FETCH_NUM);
}
/**
......@@ -459,7 +459,7 @@ class Connection
*/
public function fetchColumn($statement, array $params = array(), $colnum = 0)
{
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_COLUMN, $colnum);
return $this->execute($statement, $params)->fetchAll(\PDO::FETCH_COLUMN, $colnum);
}
/**
......@@ -471,7 +471,7 @@ class Connection
*/
public function fetchBoth($statement, array $params = array())
{
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_BOTH);
return $this->execute($statement, $params)->fetchAll(\PDO::FETCH_BOTH);
}
/**
......@@ -515,7 +515,6 @@ class Connection
{
$this->connect();
try {
echo "DBAL:" . $query . PHP_EOL;
if ( ! empty($params)) {
$stmt = $this->prepare($query);
$stmt->execute($params);
......@@ -542,7 +541,6 @@ class Connection
public function exec($query, array $params = array()) {
$this->connect();
try {
echo "DBAL:" . $query . PHP_EOL;
if ( ! empty($params)) {
var_dump($params);
$stmt = $this->prepare($query);
......
......@@ -36,4 +36,11 @@ interface Driver
* @return Doctrine\DBAL\SchemaManager
*/
public function getSchemaManager(Connection $conn);
/**
* Get the name of the driver
*
* @return string The name of the driver
*/
public function getName();
}
\ No newline at end of file
......@@ -57,4 +57,9 @@ class Driver implements \Doctrine\DBAL\Driver
{
return new \Doctrine\DBAL\Schema\MsSqlSchemaManager($conn);
}
public function getName()
{
return 'pdo_mssql';
}
}
\ No newline at end of file
......@@ -82,4 +82,9 @@ class Driver implements \Doctrine\DBAL\Driver
{
return new \Doctrine\DBAL\Schema\MySqlSchemaManager($conn);
}
public function getName()
{
return 'pdo_mysql';
}
}
\ No newline at end of file
......@@ -74,4 +74,9 @@ class Driver implements \Doctrine\DBAL\Driver
{
return new \Doctrine\DBAL\Schema\OracleSchemaManager($conn);
}
public function getName()
{
return 'pdo_oracle';
}
}
\ No newline at end of file
......@@ -51,4 +51,9 @@ class Driver implements \Doctrine\DBAL\Driver
{
return new \Doctrine\DBAL\Schema\PostgreSqlSchemaManager($conn);
}
public function getName()
{
return 'pdo_pgsql';
}
}
\ No newline at end of file
......@@ -83,4 +83,9 @@ class Driver implements \Doctrine\DBAL\Driver
{
return new \Doctrine\DBAL\Schema\SqliteSchemaManager($conn);
}
public function getName()
{
return 'pdo_sqlite';
}
}
\ No newline at end of file
......@@ -4,8 +4,19 @@ namespace Doctrine\DBAL\Platforms;
class Db2Platform extends AbstractPlatform
{
public function getSequenceNextValSql($sequenceName) {
public function getSequenceNextValSql($sequenceName)
{
return 'SELECT NEXTVAL FOR ' . $this->quoteIdentifier($sequenceName)
. ' FROM SYSIBM.SYSDUMMY1';
}
/**
* Get the platform name for this instance
*
* @return string
*/
public function getName()
{
return 'db2';
}
}
\ No newline at end of file
......@@ -58,166 +58,6 @@ class FirebirdPlatform extends AbstractPlatform
{
return " ESCAPE '". $this->_properties['escape_pattern'] ."'";
}
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @override
*/
public function getNativeDeclaration($field)
{
if ( ! isset($field['type'])) {
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
case 'varchar':
case 'string':
case 'array':
case 'object':
case 'char':
case 'text':
case 'gzip':
$length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $this->conn->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')';
case 'clob':
return 'BLOB SUB_TYPE 1';
case 'blob':
return 'BLOB SUB_TYPE 0';
case 'integer':
case 'enum':
case 'int':
return 'INT';
case 'boolean':
return 'SMALLINT';
case 'date':
return 'DATE';
case 'time':
return 'TIME';
case 'timestamp':
return 'TIMESTAMP';
case 'float':
return 'DOUBLE PRECISION';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')';
}
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}
/**
* Maps a native array description of a field to a Doctrine datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @override
*/
public function getPortableDeclaration($field)
{
$length = (isset($field['length']) && $field['length'] > 0) ? $field['length'] : null;
$type = array();
$unsigned = $fixed = null;
$dbType = strtolower($field['type']);
$field['field_sub_type'] = !empty($field['field_sub_type'])
? strtolower($field['field_sub_type']) : null;
if ( ! isset($field['name'])) {
$field['name'] = '';
}
switch ($dbType) {
case 'smallint':
case 'integer':
case 'int64':
//these may be 'numeric' or 'decimal'
if (isset($field['field_sub_type'])) {
$field['type'] = $field['field_sub_type'];
return $this->getPortableDeclaration($field);
}
case 'bigint':
case 'quad':
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
break;
case 'varchar':
$fixed = false;
case 'char':
case 'cstring':
$type[] = 'string';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type[] = 'date';
$length = null;
break;
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'time':
$type[] = 'time';
$length = null;
break;
case 'float':
case 'double':
case 'double precision':
case 'd_float':
$type[] = 'float';
break;
case 'decimal':
case 'numeric':
$type[] = 'decimal';
break;
case 'blob':
$type[] = ($field['field_sub_type'] == 'text') ? 'clob' : 'blob';
$length = null;
break;
default:
throw \Doctrine\Common\DoctrineException::updateMe('unknown database attribute type: '.$dbType);
}
return array('type' => $type,
'length' => $length,
'unsigned' => $unsigned,
'fixed' => $fixed);
}
/**
* Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
......@@ -288,4 +128,9 @@ class FirebirdPlatform extends AbstractPlatform
{
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level);
}
public function getName()
{
return 'firebird';
}
}
\ No newline at end of file
......@@ -13,82 +13,14 @@ class InformixPlatform extends AbstractPlatform
{
parent::__construct();
}
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
* Get the platform name for this instance
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
*
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @override
* @return string
*/
public function getNativeDeclaration($field)
public function getName()
{
if ( ! isset($field['type'])) {
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
case 'char':
case 'varchar':
case 'array':
case 'object':
case 'string':
if (empty($field['length']) && array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length;
}
$length = ( ! empty($field['length'])) ? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR('.$length.')' : 'NVARCHAR');
case 'clob':
return 'TEXT';
case 'blob':
return 'BLOB';
case 'integer':
if ( ! empty($field['length'])) {
$length = $field['length'];
if ($length <= 1) {
return 'SMALLINT';
} elseif ($length == 2) {
return 'SMALLINT';
} elseif ($length == 3 || $length == 4) {
return 'INTEGER';
} elseif ($length > 4) {
return 'DECIMAL(20)';
}
}
return 'INT';
case 'boolean':
return 'SMALLINT';
case 'date':
return 'DATE';
case 'time':
return 'DATETIME YEAR TO SECOND';
case 'timestamp':
return 'DATETIME';
case 'float':
return 'FLOAT';
case 'decimal':
return 'DECIMAL';
}
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
return 'informix';
}
}
\ No newline at end of file
......@@ -5,4 +5,14 @@ class MockPlatform extends AbstractPlatform
{
public function getNativeDeclaration(array $field) {}
public function getPortableDeclaration(array $field) {}
/**
* Get the platform name for this instance
*
* @return string
*/
public function getName()
{
return 'mock';
}
}
\ No newline at end of file
......@@ -302,167 +302,6 @@ class MsSqlPlatform extends AbstractPlatform
return false;
}
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
*
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @override
*/
public function getNativeDeclaration($field)
{
if ( ! isset($field['type'])) {
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
case 'array':
case 'object':
case 'text':
case 'char':
case 'varchar':
case 'string':
case 'gzip':
$length = !empty($field['length'])
? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$this->conn->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob':
if ( ! empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return 'VARCHAR('.$length.')';
}
}
return 'TEXT';
case 'blob':
if ( ! empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return "VARBINARY($length)";
}
}
return 'IMAGE';
case 'integer':
case 'enum':
case 'int':
return 'INT';
case 'boolean':
return 'BIT';
case 'date':
return 'CHAR(' . strlen('YYYY-MM-DD') . ')';
case 'time':
return 'CHAR(' . strlen('HH:MM:SS') . ')';
case 'timestamp':
return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
case 'float':
return 'FLOAT';
case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18;
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')';
}
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}
/**
* Maps a native array description of a field to a MDB2 datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @override
*/
public function getPortableDeclaration($field)
{
$db_type = preg_replace('/[\d\(\)]/','', strtolower($field['type']) );
$length = (isset($field['length']) && $field['length'] > 0) ? $field['length'] : null;
$type = array();
// todo: unsigned handling seems to be missing
$unsigned = $fixed = null;
if ( ! isset($field['name']))
$field['name'] = '';
switch ($db_type) {
case 'bit':
$type[0] = 'boolean';
break;
case 'tinyint':
case 'smallint':
case 'int':
$type[0] = 'integer';
if ($length == 1) {
$type[] = 'boolean';
}
break;
case 'datetime':
$type[0] = 'timestamp';
break;
case 'float':
case 'real':
case 'numeric':
$type[0] = 'float';
break;
case 'decimal':
case 'money':
$type[0] = 'decimal';
break;
case 'text':
case 'varchar':
case 'ntext':
case 'nvarchar':
$fixed = false;
case 'char':
case 'nchar':
$type[0] = 'string';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^[is|has]/', $field['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($db_type, 'text')) {
$type[] = 'clob';
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'image':
case 'varbinary':
$type[] = 'blob';
$length = null;
break;
default:
throw \Doctrine\Common\DoctrineException::updateMe('unknown database attribute type: '.$db_type);
}
return array('type' => $type,
'length' => $length,
'unsigned' => $unsigned,
'fixed' => $fixed);
}
/**
* Enter description here...
*
......@@ -578,4 +417,14 @@ class MsSqlPlatform extends AbstractPlatform
{
return 'CHARACTER SET ' . $charset;
}
/**
* Get the platform name for this instance
*
* @return string
*/
public function getName()
{
return 'mssql';
}
}
\ No newline at end of file
......@@ -37,36 +37,7 @@ class OraclePlatform extends AbstractPlatform
{
parent::__construct();
}
/**
* @todo Doc
*/
/*private function _createLimitSubquery($query, $limit, $offset, $column = null)
{
$limit = (int) $limit;
$offset = (int) $offset;
if (preg_match('/^\s*SELECT/i', $query)) {
if ( ! preg_match('/\sFROM\s/i', $query)) {
$query .= " FROM dual";
}
if ($limit > 0) {
$max = $offset + $limit;
$column = $column === null ? '*' : $column;
if ($offset > 0) {
$min = $offset + 1;
$query = 'SELECT b.'.$column.' FROM ('.
'SELECT a.*, ROWNUM AS doctrine_rownum FROM ('
. $query . ') a '.
') b '.
'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max;
} else {
$query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max;
}
}
}
return $query;
}*/
/**
* return string to call a function to get a substring inside an SQL statement
*
......@@ -80,8 +51,9 @@ class OraclePlatform extends AbstractPlatform
*/
public function getSubstringExpression($value, $position, $length = null)
{
if ($length !== null)
if ($length !== null) {
return "SUBSTR($value, $position, $length)";
}
return "SUBSTR($value, $position)";
}
......@@ -128,175 +100,6 @@ class OraclePlatform extends AbstractPlatform
{
return 'SYS_GUID()';
}
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @override
*/
/*public function getNativeDeclaration(array $field)
{
if ( ! isset($field['type'])) {
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
case 'string':
case 'array':
case 'object':
case 'gzip':
case 'char':
case 'varchar':
$length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $this->conn->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR2('.$length.')';
case 'clob':
return 'CLOB';
case 'blob':
return 'BLOB';
case 'integer':
case 'enum':
case 'int':
if ( ! empty($field['length'])) {
return 'NUMBER('.$field['length'].')';
}
return 'INT';
case 'boolean':
return 'NUMBER(1)';
case 'date':
case 'time':
case 'timestamp':
return 'DATE';
case 'float':
case 'double':
return 'NUMBER';
case 'decimal':
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'NUMBER(*,'.$scale.')';
default:
}
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}*/
/**
* Maps a native array description of a field to a doctrine datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @throws Doctrine_DataDict_Oracle_Exception
* @override
*/
/*public function getPortableDeclaration(array $field)
{
if ( ! isset($field['data_type'])) {
throw \Doctrine\Common\DoctrineException::updateMe('Native oracle definition must have a data_type key specified');
}
$dbType = strtolower($field['data_type']);
$type = array();
$length = $unsigned = $fixed = null;
if ( ! empty($field['data_length'])) {
$length = $field['data_length'];
}
if ( ! isset($field['column_name'])) {
$field['column_name'] = '';
}
switch ($dbType) {
case 'integer':
case 'pls_integer':
case 'binary_integer':
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['column_name'])) {
$type = array_reverse($type);
}
}
break;
case 'varchar':
case 'varchar2':
case 'nvarchar2':
$fixed = false;
case 'char':
case 'nchar':
$type[] = 'string';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['column_name'])) {
$type = array_reverse($type);
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
case 'timestamp':
$type[] = 'timestamp';
$length = null;
break;
case 'float':
$type[] = 'float';
break;
case 'number':
if ( ! empty($field['data_scale'])) {
$type[] = 'decimal';
} else {
$type[] = 'integer';
if ($length == '1') {
$type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['column_name'])) {
$type = array_reverse($type);
}
}
}
break;
case 'long':
$type[] = 'string';
case 'clob':
case 'nclob':
$type[] = 'clob';
break;
case 'blob':
case 'raw':
case 'long raw':
case 'bfile':
$type[] = 'blob';
$length = null;
break;
case 'rowid':
case 'urowid':
default:
throw \Doctrine\Common\DoctrineException::updateMe('unknown database attribute type: ' . $dbType);
}
return array('type' => $type,
'length' => $length,
'unsigned' => $unsigned,
'fixed' => $fixed);
}*/
/**
* {@inheritdoc}
......@@ -416,4 +219,14 @@ class OraclePlatform extends AbstractPlatform
{
return true;
}
/**
* Get the platform name for this instance
*
* @return string
*/
public function getName()
{
return 'oracle';
}
}
\ No newline at end of file
......@@ -63,7 +63,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* declare the specified field.
* @override
*/
/*public function getNativeDeclaration(array $field)
public function getNativeDeclaration(array $field)
{
if ( ! isset($field['type'])) {
throw DoctrineException::updateMe('Missing column type.');
......@@ -127,7 +127,7 @@ class PostgreSqlPlatform extends AbstractPlatform
return 'NUMERIC('.$length.','.$scale.')';
}
throw DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}*/
}
/**
* Maps a native array description of a field to a portable Doctrine datatype and length
......@@ -137,7 +137,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @return array containing the various possible types, length, sign, fixed
* @override
*/
/*public function getPortableDeclaration(array $field)
public function getPortableDeclaration(array $field)
{
$length = (isset($field['length'])) ? $field['length'] : null;
if ($length == '-1' && isset($field['atttypmod'])) {
......@@ -264,7 +264,7 @@ class PostgreSqlPlatform extends AbstractPlatform
'length' => $length,
'unsigned' => $unsigned,
'fixed' => $fixed);
}*/
}
/**
* Returns the md5 sum of a field.
......@@ -579,7 +579,7 @@ class PostgreSqlPlatform extends AbstractPlatform
*
* @override
*/
public function getListTableConstraintsSql()
public function getListTableConstraintsSql($table)
{
return "SELECT
relname
......@@ -588,7 +588,7 @@ class PostgreSqlPlatform extends AbstractPlatform
WHERE oid IN (
SELECT indexrelid
FROM pg_index, pg_class
WHERE pg_class.relname = %s
WHERE pg_class.relname = '$table'
AND pg_class.oid = pg_index.indrelid
AND (indisunique = 't' OR indisprimary = 't')
)";
......@@ -620,7 +620,7 @@ class PostgreSqlPlatform extends AbstractPlatform
*
* @override
*/
public function getListTableColumnsSql()
public function getListTableColumnsSql($table)
{
return "SELECT
a.attnum,
......@@ -640,7 +640,7 @@ class PostgreSqlPlatform extends AbstractPlatform
AND pg_attrdef.adnum=a.attnum
) AS default
FROM pg_attribute a, pg_class c, pg_type t
WHERE c.relname = %s
WHERE c.relname = '$table'
AND a.attnum > 0
AND a.attrelid = c.oid
AND a.atttypid = t.oid
......@@ -961,4 +961,14 @@ class PostgreSqlPlatform extends AbstractPlatform
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
}
/**
* Get the platform name for this instance
*
* @return string
*/
public function getName()
{
return 'postgresql';
}
}
\ No newline at end of file
......@@ -32,129 +32,6 @@ namespace Doctrine\DBAL\Schema;
*/
class PostgreSqlSchemaManager extends AbstractSchemaManager
{
/**
* alter an existing table
*
* @param string $name name of the table that is intended to be changed.
* @param array $changes associative array that contains the details of each type
* of change that is intended to be performed. The types of
* changes that are currently supported are defined as follows:
*
* name
*
* New name for the table.
*
* add
*
* Associative array with the names of fields to be added as
* indexes of the array. The value of each entry of the array
* should be set to another associative array with the properties
* of the fields to be added. The properties of the fields should
* be the same as defined by the Metabase parser.
*
*
* remove
*
* Associative array with the names of fields to be removed as indexes
* of the array. Currently the values assigned to each entry are ignored.
* An empty array should be used for future compatibility.
*
* rename
*
* Associative array with the names of fields to be renamed as indexes
* of the array. The value of each entry of the array should be set to
* another associative array with the entry named name with the new
* field name and the entry named Declaration that is expected to contain
* the portion of the field declaration already in DBMS specific SQL code
* as it is used in the CREATE TABLE statement.
*
* change
*
* Associative array with the names of the fields to be changed as indexes
* of the array. Keep in mind that if it is intended to change either the
* name of a field and any other properties, the change array entries
* should have the new names of the fields as array indexes.
*
* The value of each entry of the array should be set to another associative
* array with the properties of the fields to that are meant to be changed as
* array entries. These entries should be assigned to the new values of the
* respective properties. The properties of the fields should be the same
* as defined by the Metabase parser.
*
* Example
* array(
* 'name' => 'userlist',
* 'add' => array(
* 'quota' => array(
* 'type' => 'integer',
* 'unsigned' => 1
* )
* ),
* 'remove' => array(
* 'file_limit' => array(),
* 'time_limit' => array()
* ),
* 'change' => array(
* 'name' => array(
* 'length' => '20',
* 'definition' => array(
* 'type' => 'text',
* 'length' => 20,
* ),
* )
* ),
* 'rename' => array(
* 'sex' => array(
* 'name' => 'gender',
* 'definition' => array(
* 'type' => 'text',
* 'length' => 1,
* 'default' => 'M',
* ),
* )
* )
* )
*
* @param boolean $check indicates whether the function should just check if the DBMS driver
* can perform the requested table alterations if the value is true or
* actually perform them otherwise.
* @throws Doctrine\DBAL\ConnectionException
* @return boolean
*/
public function alterTable($name, array $changes, $check = false)
{
$sql = $this->alterTableSql($name, $changes, $check);
foreach ($sql as $query) {
$this->_conn->exec($query);
}
return true;
}
/**
* lists all database triggers
*
* @param string|null $database
* @return array
*/
public function listTriggers($database = null)
{
}
/**
* lists table constraints
*
* @param string $table database table name
* @return array
*/
public function listTableConstraints($table)
{
$table = $this->conn->quote($table);
$query = sprintf($this->sql['listTableConstraints'], $table);
return $this->conn->fetchColumn($query);
}
/**
* lists table constraints
*
......
......@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL;
use Doctrine\Tests\DBAL\Component;
use Doctrine\Tests\DBAL\Ticker;
use Doctrine\Tests\DBAL\Functional;
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Dbal_Platforms_AllTests::main');
......@@ -27,6 +28,8 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\DBAL\Platforms\PostgreSqlPlatformTest');
$suite->addTestSuite('Doctrine\Tests\DBAL\Platforms\MsSqlPlatformTest');
$suite->addTest(Functional\AllTests::suite());
return $suite;
}
}
......
<?php
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\Tests\DBAL\Functional;
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Dbal_Functional_AllTests::main');
}
require_once __DIR__ . '/../../TestInit.php';
class AllTests
{
public static function main()
{
\PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new \Doctrine\Tests\DbalFunctionalTestSuite('Doctrine Dbal Functional');
$suite->addTestSuite('Doctrine\Tests\DBAL\Functional\Schemas\SqliteSchemaTest');
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'Dbal_Functional_AllTests::main') {
AllTests::main();
}
\ No newline at end of file
<?php
namespace Doctrine\Tests\DBAL\Functional\Schemas;
use Doctrine\Tests\TestUtil;
use Doctrine\DBAL\Schema;
require_once __DIR__ . '/../../../TestInit.php';
class SqliteSchemaTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
private $_conn;
protected function setUp()
{
$this->_conn = TestUtil::getConnection();
if ($this->_conn->getDatabasePlatform()->getName() !== 'sqlite')
{
$this->markTestSkipped('The SqliteSchemaTest requires the use of the pdo_sqlite');
}
$this->_sm = new Schema\SqliteSchemaManager($this->_conn);
}
public function testListTableColumns()
{
$columns = array(
'id' => array(
'type' => new \Doctrine\DBAL\Types\IntegerType,
'autoincrement' => true,
'primary' => true,
'notnull' => true
),
'test' => array(
'type' => new \Doctrine\DBAL\Types\StringType,
'length' => 255
)
);
$options = array();
$this->_sm->createTable('list_tables_test', $columns, $options);
$columns = $this->_sm->listTableColumns('list_tables_test');
$this->assertEquals($columns[0]['name'], 'id');
$this->assertEquals($columns[1]['name'], 'test');
}
}
\ No newline at end of file
<?php
namespace Doctrine\Tests;
class DbalFunctionalTestSuite extends DbalTestSuite
{
}
\ No newline at end of file
......@@ -7,17 +7,17 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
private $_sequenceNextValSql = "";
private $_prefersIdentityColumns = true;
private $_prefersSequences = false;
/**
* @override
*/
public function getNativeDeclaration(array $field) {}
/**
* @override
*/
public function getPortableDeclaration(array $field) {}
/**
* @override
*/
......@@ -54,9 +54,9 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
/** @override */
public function getVarcharTypeDeclarationSql(array $field) {}
/* MOCK API */
public function setPrefersIdentityColumns($bool)
{
$this->_prefersIdentityColumns = $bool;
......@@ -71,4 +71,9 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
{
$this->_sequenceNextValSql = $sql;
}
public function getName()
{
return 'mock';
}
}
\ No newline at end of file
......@@ -48,4 +48,9 @@ class DriverMock implements \Doctrine\DBAL\Driver
{
$this->_platformMock = $platform;
}
public function getName()
{
return 'mock';
}
}
\ No newline at end of file
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