Commit 5840ff5b authored by Benjamin Eberlei's avatar Benjamin Eberlei

[DBAL-178] Fixed an undescriptive error message and a problem when using...

[DBAL-178] Fixed an undescriptive error message and a problem when using custom types and their reverse engineering from the database. Allows Type#getMappedDatabaseTypes() to be implemented in custom types, mapping to vendor database types during reverse engineering.
parent dd167039
...@@ -78,7 +78,11 @@ class DBALException extends \Exception ...@@ -78,7 +78,11 @@ class DBALException extends \Exception
public static function unknownColumnType($name) public static function unknownColumnType($name)
{ {
return new self('Unknown column type '.$name.' requested.'); return new self('Unknown column type "'.$name.'" requested. Any Doctrine type that you use has ' .
'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' .
'known types with \Doctrine\DBAL\Types\Type::getTypeMap(). If the type name is empty you might ' .
'have a problem with the cache or forgot some mapping information.'
);
} }
public static function typeNotFound($name) public static function typeNotFound($name)
......
...@@ -185,6 +185,21 @@ abstract class AbstractPlatform ...@@ -185,6 +185,21 @@ abstract class AbstractPlatform
*/ */
abstract protected function initializeDoctrineTypeMappings(); abstract protected function initializeDoctrineTypeMappings();
/**
* Initialize Doctrine Type Mappings with the platform defaults
* and with all additional type mappings.
*/
private function initializeAllDoctrineTypeMappings()
{
$this->initializeDoctrineTypeMappings();
foreach (Type::getTypesMap() as $typeName => $className) {
foreach (Type::getType($typeName)->getMappedDatabaseTypes($this) as $dbType) {
$this->doctrineTypeMapping[$dbType] = $typeName;
}
}
}
/** /**
* Gets the SQL snippet used to declare a VARCHAR column type. * Gets the SQL snippet used to declare a VARCHAR column type.
* *
...@@ -254,7 +269,7 @@ abstract class AbstractPlatform ...@@ -254,7 +269,7 @@ abstract class AbstractPlatform
public function registerDoctrineTypeMapping($dbType, $doctrineType) public function registerDoctrineTypeMapping($dbType, $doctrineType)
{ {
if ($this->doctrineTypeMapping === null) { if ($this->doctrineTypeMapping === null) {
$this->initializeDoctrineTypeMappings(); $this->initializeAllDoctrineTypeMappings();
} }
if (!Types\Type::hasType($doctrineType)) { if (!Types\Type::hasType($doctrineType)) {
...@@ -274,7 +289,7 @@ abstract class AbstractPlatform ...@@ -274,7 +289,7 @@ abstract class AbstractPlatform
public function getDoctrineTypeMapping($dbType) public function getDoctrineTypeMapping($dbType)
{ {
if ($this->doctrineTypeMapping === null) { if ($this->doctrineTypeMapping === null) {
$this->initializeDoctrineTypeMappings(); $this->initializeAllDoctrineTypeMappings();
} }
$dbType = strtolower($dbType); $dbType = strtolower($dbType);
...@@ -294,7 +309,7 @@ abstract class AbstractPlatform ...@@ -294,7 +309,7 @@ abstract class AbstractPlatform
public function hasDoctrineTypeMappingFor($dbType) public function hasDoctrineTypeMappingFor($dbType)
{ {
if ($this->doctrineTypeMapping === null) { if ($this->doctrineTypeMapping === null) {
$this->initializeDoctrineTypeMappings(); $this->initializeAllDoctrineTypeMappings();
} }
$dbType = strtolower($dbType); $dbType = strtolower($dbType);
......
...@@ -277,4 +277,15 @@ abstract class Type ...@@ -277,4 +277,15 @@ abstract class Type
{ {
return $sqlExpr; return $sqlExpr;
} }
/**
* Get an array of database types that map to this Doctrine type.
*
* @param AbstractPlatform $platform
* @return array
*/
public function getMappedDatabaseTypes(AbstractPlatform $platform)
{
return array();
}
} }
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