Commit d5fc8a64 authored by Benjamin Eberlei's avatar Benjamin Eberlei

[DBAL-752] Implement general fix to detect unsigned SQLite columns.

parent cd7a7dbd
......@@ -584,7 +584,6 @@ class SqlitePlatform extends AbstractPlatform
'decimal' => 'decimal',
'numeric' => 'decimal',
'blob' => 'blob',
'integer unsigned' => 'integer',
);
}
......
......@@ -244,16 +244,22 @@ class SqliteSchemaManager extends AbstractSchemaManager
*/
protected function _getPortableTableColumnDefinition($tableColumn)
{
$e = explode('(', $tableColumn['type']);
$tableColumn['type'] = $e[0];
if (isset($e[1])) {
$length = trim($e[1], ')');
$parts = explode('(', $tableColumn['type']);
$tableColumn['type'] = $parts[0];
if (isset($parts[1])) {
$length = trim($parts[1], ')');
$tableColumn['length'] = $length;
}
$dbType = strtolower($tableColumn['type']);
$length = isset($tableColumn['length']) ? $tableColumn['length'] : null;
$unsigned = (boolean) isset($tableColumn['unsigned']) ? $tableColumn['unsigned'] : false;
$unsigned = false;
if (strpos($dbType, ' unsigned') !== false) {
$dbType = str_replace(' unsigned', '', $dbType);
$unsigned = true;
}
$fixed = false;
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$default = $tableColumn['dflt_value'];
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Ticket;
use Doctrine\DBAL\Schema\Table;
/**
* @group DBAL-752
*/
class DBAL752Test extends \Doctrine\Tests\DbalFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
$platform = $this->_conn->getDatabasePlatform()->getName();
if (!in_array($platform, array('sqlite'))) {
$this->markTestSkipped('Related to SQLite only');
}
}
public function testUnsignedIntegerDetection()
{
$this->_conn->exec(<<<SQL
CREATE TABLE dbal752_unsigneds (
id BIGINT UNSIGNED,
flag SMALLINT UNSIGNED,
masks INTEGER UNSIGNED
);
SQL
);
$schemaManager = $this->_conn->getSchemaManager();
$fetchedTable = $schemaManager->listTableDetails('dbal752_unsigneds');
$this->assertEquals('bigint', $fetchedTable->getColumn('id')->getType()->getName());
$this->assertEquals('smallint', $fetchedTable->getColumn('flag')->getType()->getName());
$this->assertEquals('integer', $fetchedTable->getColumn('masks')->getType()->getName());
$this->assertTrue($fetchedTable->getColumn('id')->getUnsigned());
$this->assertTrue($fetchedTable->getColumn('flag')->getUnsigned());
$this->assertTrue($fetchedTable->getColumn('masks')->getUnsigned());
}
}
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