Commit b6934334 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #541 from jsor/mysql-spatial-index

Allow mysql spatial indexes
parents 8ffaaa88 16d2ccfb
...@@ -718,6 +718,8 @@ class MySqlPlatform extends AbstractPlatform ...@@ -718,6 +718,8 @@ class MySqlPlatform extends AbstractPlatform
$type .= 'UNIQUE '; $type .= 'UNIQUE ';
} elseif ($index->hasFlag('fulltext')) { } elseif ($index->hasFlag('fulltext')) {
$type .= 'FULLTEXT '; $type .= 'FULLTEXT ';
} elseif ($index->hasFlag('spatial')) {
$type .= 'SPATIAL ';
} }
return $type; return $type;
......
...@@ -73,6 +73,8 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -73,6 +73,8 @@ class MySqlSchemaManager extends AbstractSchemaManager
} }
if (strpos($v['index_type'], 'FULLTEXT') !== false) { if (strpos($v['index_type'], 'FULLTEXT') !== false) {
$v['flags'] = array('FULLTEXT'); $v['flags'] = array('FULLTEXT');
} elseif (strpos($v['index_type'], 'SPATIAL') !== false) {
$v['flags'] = array('SPATIAL');
} }
$tableIndexes[$k] = $v; $tableIndexes[$k] = $v;
} }
......
...@@ -5,11 +5,21 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; ...@@ -5,11 +5,21 @@ namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
require_once __DIR__ . '/../../../TestInit.php'; require_once __DIR__ . '/../../../TestInit.php';
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{ {
protected function setUp()
{
parent::setUp();
if (!Type::hasType('point')) {
Type::addType('point', 'Doctrine\Tests\Types\MySqlPointType');
}
}
public function testSwitchPrimaryKeyColumns() public function testSwitchPrimaryKeyColumns()
{ {
$tableOld = new Table("switch_primary_key_columns"); $tableOld = new Table("switch_primary_key_columns");
...@@ -66,6 +76,23 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -66,6 +76,23 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertTrue($indexes['f_index']->hasFlag('fulltext')); $this->assertTrue($indexes['f_index']->hasFlag('fulltext'));
} }
public function testSpatialIndex()
{
$table = new Table('spatial_index');
$table->addColumn('point', 'point');
$table->addIndex(array('point'), 's_index');
$table->addOption('engine', 'MyISAM');
$index = $table->getIndex('s_index');
$index->addFlag('spatial');
$this->_sm->dropAndCreateTable($table);
$indexes = $this->_sm->listTableIndexes('spatial_index');
$this->assertArrayHasKey('s_index', $indexes);
$this->assertTrue($indexes['s_index']->hasFlag('spatial'));
}
/** /**
* @group DBAL-400 * @group DBAL-400
*/ */
......
...@@ -268,6 +268,20 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -268,6 +268,20 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$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 testCreateTableWithSpatialIndex()
{
$table = new Table('spatial_table');
$table->addOption('engine', 'MyISAM');
$table->addColumn('point', 'text'); // This should be a point type
$table->addIndex(array('point'), 'spatial_text');
$index = $table->getIndex('spatial_text');
$index->addFlag('spatial');
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals(array('CREATE TABLE spatial_table (point LONGTEXT NOT NULL, SPATIAL INDEX spatial_text (point)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql);
}
public function testClobTypeDeclarationSQL() public function testClobTypeDeclarationSQL()
{ {
$this->assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 1))); $this->assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 1)));
......
<?php
namespace Doctrine\Tests\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
class MySqlPointType extends Type
{
public function getName()
{
return 'point';
}
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return strtoupper($this->getName());
}
public function getMappedDatabaseTypes(AbstractPlatform $platform)
{
return array('point');
}
}
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