Commit 456a756f authored by Benjamin Eberlei's avatar Benjamin Eberlei

DDC-451 - GUID support through a specific GUID Type, SQL Server specific...

DDC-451 - GUID support through a specific GUID Type, SQL Server specific implementation all others fallback to Varchar fields, no automatic default value = new guid support yet.
parent b8d8d953
......@@ -198,6 +198,20 @@ abstract class AbstractPlatform
}
}
/**
* Get the SQL Snippet to create a GUID/UUID field.
*
* By default this maps directly to a VARCHAR and only maps to more
* special datatypes when the underlying databases support this datatype.
*
* @param array $field
* @return string
*/
public function getGuidTypeDeclartionSQL(array $field)
{
return $this->getVarcharTypeDeclarationSQL($field);
}
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
throw DBALException::notSupported('VARCHARs not supported by Platform.');
......
......@@ -606,6 +606,17 @@ class SQLServerPlatform extends AbstractPlatform
return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/**
* Decleration for a UNIQUEIDENTIFIER (GUID) field in SQL Server
*
* @param array $field
* @return string
*/
public function getGuidTypeDeclartionSQL(array $field)
{
return 'UNIQUEIDENTIFIER';
}
/** @override */
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
......@@ -817,6 +828,7 @@ class SQLServerPlatform extends AbstractPlatform
'binary' => 'text',
'varbinary' => 'blob',
'image' => 'text',
'uniqueidentifier' => 'guid',
);
}
......
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* Represents a GUID/UUID datatype (both are actually synomys) in the database.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @since 2.3
*/
class GuidType extends StringType
{
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getGuidTypeDeclartionSQL($fieldDeclaration);
}
}
......@@ -48,6 +48,7 @@ abstract class Type
const TEXT = 'text';
const BLOB = 'blob';
const FLOAT = 'float';
const GUID = 'guid';
/** Map of already instantiated type objects. One instance per type (flyweight). */
private static $_typeObjects = array();
......@@ -69,6 +70,7 @@ abstract class Type
self::DECIMAL => 'Doctrine\DBAL\Types\DecimalType',
self::FLOAT => 'Doctrine\DBAL\Types\FloatType',
self::BLOB => 'Doctrine\DBAL\Types\BlobType',
self::GUID => 'Doctrine\DBAL\Types\GuidType',
);
/* Prevent instantiation and force use of the factory method. */
......@@ -271,4 +273,4 @@ abstract class Type
{
return $sqlExpr;
}
}
\ No newline at end of file
}
......@@ -2,8 +2,6 @@
namespace Doctrine\Tests\DBAL\Schema;
require_once __DIR__ . '/../../TestInit.php';
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Configuration;
......
<?php
namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks;
class GuidTest extends \Doctrine\Tests\DbalTestCase
{
protected
$_platform,
$_type;
protected function setUp()
{
$this->_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
$this->_type = Type::getType('guid');
}
public function testConvertToPHPValue()
{
$this->assertInternalType("string", $this->_type->convertToPHPValue("foo", $this->_platform));
$this->assertInternalType("string", $this->_type->convertToPHPValue("", $this->_platform));
}
public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
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