Commit eb6ee9a8 authored by Alexander's avatar Alexander

Merge branch 'jappie-master-rebase'

parents 71589391 451aec6d
...@@ -36,6 +36,14 @@ use Doctrine\DBAL\DBALException, ...@@ -36,6 +36,14 @@ use Doctrine\DBAL\DBALException,
*/ */
class MySqlPlatform extends AbstractPlatform class MySqlPlatform extends AbstractPlatform
{ {
const LENGTH_LIMIT_TINYTEXT = 255;
const LENGTH_LIMIT_TEXT = 65535;
const LENGTH_LIMIT_MEDIUMTEXT = 16777215;
const LENGTH_LIMIT_TINYBLOB = 255;
const LENGTH_LIMIT_BLOB = 65535;
const LENGTH_LIMIT_MEDIUMBLOB = 16777215;
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
...@@ -193,21 +201,30 @@ class MySqlPlatform extends AbstractPlatform ...@@ -193,21 +201,30 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* {@inheritDoc} * Gets the SQL snippet used to declare a CLOB column type.
* TINYTEXT : 2 ^ 8 - 1 = 255
* TEXT : 2 ^ 16 - 1 = 65535
* MEDIUMTEXT : 2 ^ 24 - 1 = 16777215
* LONGTEXT : 2 ^ 32 - 1 = 4294967295
*
* @param array $field
*
* @return string
*/ */
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
if ( ! empty($field['length']) && is_numeric($field['length'])) { if ( ! empty($field['length']) && is_numeric($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 255) {
if ($length <= static::LENGTH_LIMIT_TINYTEXT) {
return 'TINYTEXT'; return 'TINYTEXT';
} }
if ($length <= 65532) { if ($length <= static::LENGTH_LIMIT_TEXT) {
return 'TEXT'; return 'TEXT';
} }
if ($length <= 16777215) { if ($length <= static::LENGTH_LIMIT_MEDIUMTEXT) {
return 'MEDIUMTEXT'; return 'MEDIUMTEXT';
} }
} }
...@@ -701,10 +718,34 @@ class MySqlPlatform extends AbstractPlatform ...@@ -701,10 +718,34 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* {@inheritDoc} * Gets the SQL Snippet used to declare a BLOB column type.
* TINYBLOB : 2 ^ 8 - 1 = 255
* BLOB : 2 ^ 16 - 1 = 65535
* MEDIUMBLOB : 2 ^ 24 - 1 = 16777215
* LONGBLOB : 2 ^ 32 - 1 = 4294967295
*
* @param array $field
*
* @return string
*/ */
public function getBlobTypeDeclarationSQL(array $field) public function getBlobTypeDeclarationSQL(array $field)
{ {
if ( ! empty($field['length']) && is_numeric($field['length'])) {
$length = $field['length'];
if ($length <= static::LENGTH_LIMIT_TINYBLOB) {
return 'TINYBLOB';
}
if ($length <= static::LENGTH_LIMIT_BLOB) {
return 'BLOB';
}
if ($length <= static::LENGTH_LIMIT_MEDIUMBLOB) {
return 'MEDIUMBLOB';
}
}
return 'LONGBLOB'; return 'LONGBLOB';
} }
} }
...@@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\TableDiff; ...@@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
class MySqlPlatformTest extends AbstractPlatformTestCase class MySqlPlatformTest extends AbstractPlatformTestCase
{ {
public function createPlatform() public function createPlatform()
...@@ -254,4 +255,28 @@ class MySqlPlatformTest extends AbstractPlatformTestCase ...@@ -254,4 +255,28 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$sql = $this->_platform->getCreateTableSQL($table); $sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals(array('CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql); $this->assertEquals(array('CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql);
} }
public function testClobTypeDeclarationSQL()
{
$this->assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 1)));
$this->assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 255)));
$this->assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 256)));
$this->assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65535)));
$this->assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65536)));
$this->assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777215)));
$this->assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777216)));
$this->assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array()));
}
public function testBlobTypeDeclarationSQL()
{
$this->assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 1)));
$this->assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 255)));
$this->assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 256)));
$this->assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65535)));
$this->assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65536)));
$this->assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777215)));
$this->assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777216)));
$this->assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(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