Commit 390717ed authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge DBAL-5 into Master

parents b5f90e09 626a334e
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -42,6 +40,7 @@ use Doctrine\DBAL\DBALException, ...@@ -42,6 +40,7 @@ use Doctrine\DBAL\DBALException,
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @todo Remove any unnecessary methods. * @todo Remove any unnecessary methods.
*/ */
abstract class AbstractPlatform abstract class AbstractPlatform
...@@ -76,11 +75,63 @@ abstract class AbstractPlatform ...@@ -76,11 +75,63 @@ abstract class AbstractPlatform
*/ */
const TRIM_BOTH = 3; const TRIM_BOTH = 3;
/**
* @var array
*/
protected $doctrineTypeMapping = null;
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() {} public function __construct() {}
/**
* Register a doctrine type to be used in conjunction with a column type of this platform.
*
* @param string $dbType
* @param string $doctrineType
*/
public function registerDoctrineTypeMapping($dbType, $doctrineType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeDoctrineTypeMappings();
}
if (!Types\Type::hasType($doctrineType)) {
throw DBALException::typeNotFound($doctrineType);
}
$dbType = strtolower($dbType);
$this->doctrineTypeMapping[$dbType] = $doctrineType;
}
/**
* Get the Doctrine type that is mapped for the given database column type.
*
* @param string $dbType
* @return string
*/
public function getDoctrineTypeMapping($dbType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeDoctrineTypeMappings();
}
$dbType = strtolower($dbType);
if (isset($this->doctrineTypeMapping[$dbType])) {
return $this->doctrineTypeMapping[$dbType];
} else {
throw new \Doctrine\DBAL\DBALException("Unknown database type ".$dbType." requested, " . get_class($this) . " may not support it.");
}
}
/**
* Lazy load Doctrine Type Mappings
*
* @return void
*/
abstract protected function initializeDoctrineTypeMappings();
/** /**
* Gets the character used for identifier quoting. * Gets the character used for identifier quoting.
* *
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -27,6 +25,24 @@ use Doctrine\DBAL\Schema\TableDiff; ...@@ -27,6 +25,24 @@ use Doctrine\DBAL\Schema\TableDiff;
class DB2Platform extends AbstractPlatform class DB2Platform extends AbstractPlatform
{ {
public function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = array(
'smallint' => 'smallint',
'bigint' => 'bigint',
'integer' => 'integer',
'time' => 'time',
'date' => 'date',
'varchar' => 'string',
'character' => 'string',
'clob' => 'text',
'decimal' => 'decimal',
'double' => 'decimal',
'real' => 'decimal',
'timestamp' => 'datetime',
);
}
/** /**
* Gets the SQL snippet used to declare a VARCHAR column type. * Gets the SQL snippet used to declare a VARCHAR column type.
* *
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -511,4 +509,9 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -511,4 +509,9 @@ class MsSqlPlatform extends AbstractPlatform
return $fromClause; return $fromClause;
} }
} }
protected function initializeDoctrineTypeMappings()
{
}
} }
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -588,4 +586,33 @@ class MySqlPlatform extends AbstractPlatform ...@@ -588,4 +586,33 @@ class MySqlPlatform extends AbstractPlatform
{ {
return 'LOCK IN SHARE MODE'; return 'LOCK IN SHARE MODE';
} }
protected function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = array(
'tinyint' => 'boolean',
'smallint' => 'smallint',
'mediumint' => 'integer',
'int' => 'integer',
'integer' => 'integer',
'bigint' => 'bigint',
'tinytext' => 'text',
'mediumtext' => 'text',
'longtext' => 'text',
'text' => 'text',
'varchar' => 'string',
'string' => 'string',
'char' => 'string',
'date' => 'date',
'datetime' => 'datetime',
'timestamp' => 'datetime',
'time' => 'time',
'float' => 'decimal',
'double' => 'decimal',
'real' => 'decimal',
'decimal' => 'decimal',
'numeric' => 'decimal',
'year' => 'date',
);
}
} }
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -660,4 +658,27 @@ LEFT JOIN all_cons_columns r_cols ...@@ -660,4 +658,27 @@ LEFT JOIN all_cons_columns r_cols
{ {
return 'SELECT 1 FROM DUAL'; return 'SELECT 1 FROM DUAL';
} }
protected function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = array(
'integer' => 'integer',
'number' => 'integer',
'pls_integer' => 'boolean',
'binary_integer' => 'boolean',
'varchar' => 'string',
'varchar2' => 'string',
'nvarchar2' => 'string',
'char' => 'string',
'nchar' => 'string',
'date' => 'datetime',
'timestamp' => 'datetime',
'float' => 'decimal',
'long' => 'string',
'clob' => 'text',
'nclob' => 'text',
'rowid' => 'string',
'urowid' => 'string'
);
}
} }
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -642,4 +640,45 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -642,4 +640,45 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return 'FOR SHARE'; return 'FOR SHARE';
} }
protected function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = array(
'smallint' => 'smallint',
'int2' => 'smallint',
'serial' => 'integer',
'serial4' => 'integer',
'int' => 'integer',
'int4' => 'integer',
'integer' => 'integer',
'bigserial' => 'bigint',
'serial8' => 'bigint',
'bigint' => 'bigint',
'int8' => 'bigint',
'bool' => 'boolean',
'boolean' => 'boolean',
'text' => 'text',
'varchar' => 'string',
'interval' => 'string',
'_varchar' => 'string',
'char' => 'string',
'bpchar' => 'string',
'date' => 'date',
'datetime' => 'datetime',
'timestamp' => 'datetime',
'timestamptz' => 'datetime',
'time' => 'time',
'timetz' => 'time',
'float' => 'decimal',
'float4' => 'decimal',
'float8' => 'decimal',
'double' => 'decimal',
'double precision' => 'decimal',
'real' => 'decimal',
'decimal' => 'decimal',
'money' => 'decimal',
'numeric' => 'decimal',
'year' => 'date',
);
}
} }
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -433,4 +431,39 @@ class SqlitePlatform extends AbstractPlatform ...@@ -433,4 +431,39 @@ class SqlitePlatform extends AbstractPlatform
{ {
return ''; return '';
} }
protected function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = array(
'boolean' => 'boolean',
'tinyint' => 'boolean',
'smallint' => 'smallint',
'mediumint' => 'integer',
'int' => 'integer',
'integer' => 'integer',
'serial' => 'integer',
'bigint' => 'bigint',
'bigserial' => 'bigint',
'clob' => 'text',
'tinytext' => 'text',
'mediumtext' => 'text',
'longtext' => 'text',
'text' => 'text',
'varchar' => 'string',
'varchar2' => 'string',
'nvarchar' => 'string',
'image' => 'string',
'ntext' => 'string',
'char' => 'string',
'date' => 'date',
'datetime' => 'datetime',
'timestamp' => 'datetime',
'time' => 'time',
'float' => 'decimal',
'double' => 'decimal',
'real' => 'decimal',
'decimal' => 'decimal',
'numeric' => 'decimal',
);
}
} }
...@@ -67,40 +67,26 @@ class DB2SchemaManager extends AbstractSchemaManager ...@@ -67,40 +67,26 @@ class DB2SchemaManager extends AbstractSchemaManager
$scale = false; $scale = false;
$precision = false; $precision = false;
$type = $this->_platform->getDoctrineTypeMapping($tableColumn['typename']);
switch (strtolower($tableColumn['typename'])) { switch (strtolower($tableColumn['typename'])) {
case 'smallint':
case 'bigint':
case 'integer':
case 'time':
case 'date':
$type = strtolower($tableColumn['typename']);
break;
case 'varchar': case 'varchar':
$type = 'string';
$length = $tableColumn['length']; $length = $tableColumn['length'];
$fixed = false; $fixed = false;
break; break;
case 'character': case 'character':
$type = 'string';
$length = $tableColumn['length']; $length = $tableColumn['length'];
$fixed = true; $fixed = true;
break; break;
case 'clob': case 'clob':
$type = 'text';
$length = $tableColumn['length']; $length = $tableColumn['length'];
break; break;
case 'decimal': case 'decimal':
case 'double': case 'double':
case 'real': case 'real':
$type = 'decimal';
$scale = $tableColumn['scale']; $scale = $tableColumn['scale'];
$precision = $tableColumn['length']; $precision = $tableColumn['length'];
break; break;
case 'timestamp':
$type = 'datetime';
break;
default:
throw new \Doctrine\DBAL\DBALException("Unknown Type: ".$tableColumn['typename']);
} }
$options = array( $options = array(
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -89,9 +87,6 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -89,9 +87,6 @@ class MySqlSchemaManager extends AbstractSchemaManager
{ {
$dbType = strtolower($tableColumn['Type']); $dbType = strtolower($tableColumn['Type']);
$dbType = strtok($dbType, '(), '); $dbType = strtok($dbType, '(), ');
if ($dbType == 'national') {
$dbType = strtok('(), ');
}
if (isset($tableColumn['length'])) { if (isset($tableColumn['length'])) {
$length = $tableColumn['length']; $length = $tableColumn['length'];
$decimal = ''; $decimal = '';
...@@ -109,70 +104,10 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -109,70 +104,10 @@ class MySqlSchemaManager extends AbstractSchemaManager
$scale = null; $scale = null;
$precision = null; $precision = null;
// Map db type to Doctrine mapping type $type = $this->_platform->getDoctrineTypeMapping($dbType);
switch ($dbType) { switch ($dbType) {
case 'tinyint':
$type = 'boolean';
$length = null;
break;
case 'smallint':
$type = 'smallint';
$length = null;
break;
case 'mediumint':
$type = 'integer';
$length = null;
break;
case 'int':
case 'integer':
$type = 'integer';
$length = null;
break;
case 'bigint':
$type = 'bigint';
$length = null;
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
$type = 'text';
$fixed = false;
break;
case 'varchar':
$fixed = false;
case 'string':
case 'char': case 'char':
$type = 'string';
if ($length == '1') {
$type = 'boolean';
if (preg_match('/^(is|has)/', $tableColumn['name'])) {
$type = array_reverse($type);
}
} else if (strstr($dbType, 'text')) {
$type = 'text';
if ($decimal == 'binary') {
$type = 'blob';
}
}
if ($fixed !== false) {
$fixed = true; $fixed = true;
}
break;
case 'set':
$fixed = false;
$type = 'text';
$type = 'integer'; //FIXME:???
break;
case 'date':
$type = 'date';
break;
case 'datetime':
case 'timestamp':
$type = 'datetime';
break;
case 'time':
$type = 'time';
break; break;
case 'float': case 'float':
case 'double': case 'double':
...@@ -184,36 +119,22 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -184,36 +119,22 @@ class MySqlSchemaManager extends AbstractSchemaManager
$scale = $match[2]; $scale = $match[2];
$length = null; $length = null;
} }
$type = 'decimal';
break; break;
case 'tinyint':
case 'smallint':
case 'mediumint':
case 'int':
case 'integer':
case 'bigint':
case 'tinyblob': case 'tinyblob':
case 'mediumblob': case 'mediumblob':
case 'longblob': case 'longblob':
case 'blob': case 'blob':
case 'binary': case 'binary':
case 'varbinary': case 'varbinary':
$type = 'blob';
$length = null;
break;
case 'year': case 'year':
$type = 'integer';
$type = 'date';
$length = null;
break;
case 'geometry':
case 'geometrycollection':
case 'point':
case 'multipoint':
case 'linestring':
case 'multilinestring':
case 'polygon':
case 'multipolygon':
$type = 'blob';
$length = null; $length = null;
break; break;
default:
$type = 'string';
$length = null;
} }
$length = ((int) $length == 0) ? null : (int) $length; $length = ((int) $length == 0) ? null : (int) $length;
......
...@@ -112,67 +112,56 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -112,67 +112,56 @@ class OracleSchemaManager extends AbstractSchemaManager
$precision = null; $precision = null;
$scale = null; $scale = null;
$type = $this->_platform->getDoctrineTypeMapping($dbType);
switch ($dbType) { switch ($dbType) {
case 'integer':
case 'number': case 'number':
// @todo this sucks for the mapping stuff, is this deterministic maybe?
if($tableColumn['data_scale'] > 0) { if($tableColumn['data_scale'] > 0) {
$type = 'decimal';
$precision = $tableColumn['data_precision']; $precision = $tableColumn['data_precision'];
$scale = $tableColumn['data_scale']; $scale = $tableColumn['data_scale'];
if ($precision == 0 && $scale == 1) {
$type = 'boolean';
} else { } else {
$type = 'integer'; $type = 'decimal';
}
} }
$length = null; $length = null;
break; break;
case 'pls_integer': case 'pls_integer':
case 'binary_integer': case 'binary_integer':
$type = 'boolean';
$length = null; $length = null;
break; break;
case 'varchar': case 'varchar':
case 'varchar2': case 'varchar2':
case 'nvarchar2': case 'nvarchar2':
$fixed = false; $fixed = false;
break;
case 'char': case 'char':
case 'nchar': case 'nchar':
if ($length == '1' && preg_match('/^(is|has)/', $tableColumn['column_name'])) {
$type = 'boolean';
} else {
$type = 'string';
}
if ($fixed !== false) {
$fixed = true; $fixed = true;
}
break; break;
case 'date': case 'date':
case 'timestamp': case 'timestamp':
$type = 'datetime';
$length = null; $length = null;
break; break;
case 'float': case 'float':
$precision = $tableColumn['data_precision']; $precision = $tableColumn['data_precision'];
$scale = $tableColumn['data_scale']; $scale = $tableColumn['data_scale'];
$type = 'decimal';
$length = null; $length = null;
break; break;
case 'long':
$type = 'string';
case 'clob': case 'clob':
case 'nclob': case 'nclob':
$length = null; $length = null;
$type = 'text';
break; break;
case 'blob': case 'blob':
case 'raw': case 'raw':
case 'long raw': case 'long raw':
case 'bfile': case 'bfile':
$type = 'blob';
$length = null; $length = null;
break; break;
case 'rowid': case 'rowid':
case 'urowid': case 'urowid':
default: default:
$type = 'string';
$length = null; $length = null;
} }
......
...@@ -199,11 +199,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -199,11 +199,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$dbType = strtolower($tableColumn['type']); $dbType = strtolower($tableColumn['type']);
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$autoincrement = false; $autoincrement = false;
switch ($dbType) { switch ($dbType) {
case 'smallint': case 'smallint':
case 'int2': case 'int2':
$type = 'smallint';
$length = null; $length = null;
break; break;
case 'serial': case 'serial':
...@@ -213,7 +213,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -213,7 +213,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case 'int': case 'int':
case 'int4': case 'int4':
case 'integer': case 'integer':
$type = 'integer';
$length = null; $length = null;
break; break;
case 'bigserial': case 'bigserial':
...@@ -222,52 +221,23 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -222,52 +221,23 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
// break missing intentionally // break missing intentionally
case 'bigint': case 'bigint':
case 'int8': case 'int8':
$type = 'bigint';
$length = null; $length = null;
break; break;
case 'bool': case 'bool':
case 'boolean': case 'boolean':
$type = 'boolean';
$length = null; $length = null;
break; break;
case 'text': case 'text':
$fixed = false; $fixed = false;
$type = 'text';
break; break;
case 'varchar': case 'varchar':
case 'interval': case 'interval':
case '_varchar': case '_varchar':
$fixed = false; $fixed = false;
case 'tsvector': break;
case 'unknown':
case 'char': case 'char':
case 'bpchar': case 'bpchar':
$type = 'string';
if ($length == '1') {
if (preg_match('/^(is|has)/', $tableColumn['name'])) {
$type = 'boolean';
}
} elseif (strstr($dbType, 'text')) {
$type = 'text';
}
if ($fixed !== false) {
$fixed = true; $fixed = true;
}
break;
case 'date':
$type = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
case 'timetz':
case 'timestamptz':
$type = 'datetime';
$length = null;
break;
case 'time':
$type = 'time';
$length = null;
break; break;
case 'float': case 'float':
case 'float4': case 'float4':
...@@ -283,34 +253,10 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -283,34 +253,10 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$scale = $match[2]; $scale = $match[2];
$length = null; $length = null;
} }
$type = 'decimal';
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
case 'bytea':
case 'geometry':
case 'geometrycollection':
case 'point':
case 'multipoint':
case 'linestring':
case 'multilinestring':
case 'polygon':
case 'multipolygon':
$type = 'blob';
$length = null;
break;
case 'oid':
$type = 'blob';
$length = null;
break; break;
case 'year': case 'year':
$type = 'date';
$length = null; $length = null;
break; break;
default:
$type = 'string';
} }
$options = array( $options = array(
......
<?php <?php
/* /*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...@@ -131,11 +129,10 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -131,11 +129,10 @@ class SqliteSchemaManager extends AbstractSchemaManager
} }
$dbType = strtolower($tableColumn['type']); $dbType = strtolower($tableColumn['type']);
$length = isset($tableColumn['length']) ? $tableColumn['length'] : null; $length = isset($tableColumn['length']) ? $tableColumn['length'] : null;
$unsigned = (boolean) isset($tableColumn['unsigned']) ? $tableColumn['unsigned'] : false; $unsigned = (boolean) isset($tableColumn['unsigned']) ? $tableColumn['unsigned'] : false;
$fixed = false; $fixed = false;
$type = null; $type = $this->_platform->getDoctrineTypeMapping($dbType);
$default = $tableColumn['dflt_value']; $default = $tableColumn['dflt_value'];
if ($default == 'NULL') { if ($default == 'NULL') {
$default = null; $default = null;
...@@ -150,72 +147,8 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -150,72 +147,8 @@ class SqliteSchemaManager extends AbstractSchemaManager
$scale = null; $scale = null;
switch ($dbType) { switch ($dbType) {
case 'boolean':
$type = 'boolean';
break;
case 'tinyint':
$type = 'boolean';
$length = null;
break;
case 'smallint':
$type = 'smallint';
$length = null;
break;
case 'mediumint':
case 'int':
case 'integer':
case 'serial':
$type = 'integer';
$length = null;
break;
case 'bigint':
case 'bigserial':
$type = 'bigint';
$length = null;
break;
case 'clob':
$fixed = false;
$type = 'text';
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
$type = 'text';
break;
case 'varchar':
case 'varchar2':
case 'nvarchar':
case 'ntext':
case 'image':
case 'nchar':
$fixed = false;
case 'char': case 'char':
$type = 'string';
if ($length == '1') {
$type = 'boolean';
if (preg_match('/^(is|has)/', $tableColumn['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($dbType, 'text')) {
$type = 'clob';
}
if ($fixed !== false) {
$fixed = true; $fixed = true;
}
break;
case 'date':
$type = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
$type = 'datetime';
$length = null;
break;
case 'time':
$type = 'time';
$length = null;
break; break;
case 'float': case 'float':
case 'double': case 'double':
...@@ -223,23 +156,8 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -223,23 +156,8 @@ class SqliteSchemaManager extends AbstractSchemaManager
case 'decimal': case 'decimal':
case 'numeric': case 'numeric':
list($precision, $scale) = array_map('trim', explode(', ', $tableColumn['length'])); list($precision, $scale) = array_map('trim', explode(', ', $tableColumn['length']));
$type = 'decimal';
$length = null;
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
$type = 'blob';
$length = null; $length = null;
break; break;
case 'year':
$type = 'date';
$length = null;
break;
default:
$type = 'string';
$length = null;
} }
$options = array( $options = array(
......
...@@ -32,4 +32,6 @@ class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform ...@@ -32,4 +32,6 @@ class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform
{ {
return 'mock'; return 'mock';
} }
protected function initializeDoctrineTypeMappings() {
}
} }
...@@ -16,6 +16,24 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -16,6 +16,24 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->_platform = $this->createPlatform(); $this->_platform = $this->createPlatform();
} }
public function testGetUnknownDoctrineMappingType()
{
$this->setExpectedException('Doctrine\DBAL\DBALException');
$this->_platform->getDoctrineTypeMapping('foobar');
}
public function testRegisterDoctrineMappingType()
{
$this->_platform->registerDoctrineTypeMapping('foo', 'integer');
$this->assertEquals('integer', $this->_platform->getDoctrineTypeMapping('foo'));
}
public function testRegisterUnknownDoctrineMappingType()
{
$this->setExpectedException('Doctrine\DBAL\DBALException');
$this->_platform->registerDoctrineTypeMapping('foo', 'bar');
}
public function testCreateWithNoColumns() public function testCreateWithNoColumns()
{ {
$table = new \Doctrine\DBAL\Schema\Table('test'); $table = new \Doctrine\DBAL\Schema\Table('test');
......
...@@ -4,7 +4,11 @@ namespace Doctrine\Tests; ...@@ -4,7 +4,11 @@ namespace Doctrine\Tests;
class DbalFunctionalTestCase extends DbalTestCase class DbalFunctionalTestCase extends DbalTestCase
{ {
/* Shared connection when a TestCase is run alone (outside of it's functional suite) */ /**
* Shared connection when a TestCase is run alone (outside of it's functional suite)
*
* @var Doctrine\DBAL\Connection
*/
private static $_sharedConn; private static $_sharedConn;
/** /**
......
...@@ -82,4 +82,6 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform ...@@ -82,4 +82,6 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
{ {
return 'mock'; return 'mock';
} }
protected function initializeDoctrineTypeMappings() {
}
} }
\ 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