1
0
mirror of synced 2025-01-06 00:57:10 +03:00

[2.0] Made MySqlPlatform default to innodb table engine. Some cleanups while investigating the optimistic locking failures.

This commit is contained in:
romanb 2009-08-28 12:36:06 +00:00
parent 59fff29c1b
commit 6a3aa84973
6 changed files with 27 additions and 22 deletions

View File

@ -1456,7 +1456,8 @@ abstract class AbstractPlatform
* the format of a stored datetime value of this platform. * the format of a stored datetime value of this platform.
* *
* @return string The format string. * @return string The format string.
* TODO: We need to get the specific format for each dbms and override this *
* @todo We need to get the specific format for each dbms and override this
* function for each platform * function for each platform
*/ */
public function getDateTimeFormatString() public function getDateTimeFormatString()

View File

@ -25,7 +25,8 @@ use Doctrine\Common\DoctrineException;
/** /**
* The MySqlPlatform provides the behavior, features and SQL dialect of the * The MySqlPlatform provides the behavior, features and SQL dialect of the
* MySQL database platform. * MySQL database platform. This platform represents a MySQL 5.0 or greater platform that
* uses the InnoDB storage engine.
* *
* @since 2.0 * @since 2.0
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
@ -472,17 +473,14 @@ class MySqlPlatform extends AbstractPlatform
} }
} }
$type = false;
// get the type of the table // get the type of the table
if (isset($options['type'])) { if (isset($options['engine'])) {
$type = $options['type']; $optionStrings[] = 'ENGINE = ' . $engine;
} else {
// default to innodb
$optionStrings[] = 'ENGINE = InnoDB';
} }
if ($type) {
$optionStrings[] = 'ENGINE = ' . $type;
}
if ( ! empty($optionStrings)) { if ( ! empty($optionStrings)) {
$query.= ' '.implode(' ', $optionStrings); $query.= ' '.implode(' ', $optionStrings);
} }

View File

@ -756,4 +756,15 @@ class PostgreSqlPlatform extends AbstractPlatform
{ {
return strtolower($column); return strtolower($column);
} }
/**
* Gets the format string, as accepted by the date() function, that describes
* the format of a stored datetime value of this platform.
*
* @return string The format string.
*/
/*public function getDateTimeFormatString()
{
return 'Y-m-d H:i:s.u';
}*/
} }

View File

@ -37,7 +37,7 @@ class MySqlPlatformTest extends \Doctrine\Tests\DbalTestCase
); );
$sql = $this->_platform->getCreateTableSql('test', $columns, $options); $sql = $this->_platform->getCreateTableSql('test', $columns, $options);
$this->assertEquals('CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) NOT NULL, PRIMARY KEY(id))', $sql[0]); $this->assertEquals('CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB', $sql[0]);
} }
public function testGeneratesTableAlterationSql() public function testGeneratesTableAlterationSql()

View File

@ -2,11 +2,6 @@
namespace Doctrine\Tests\ORM\Functional\Locking; namespace Doctrine\Tests\ORM\Functional\Locking;
use Doctrine\Tests\Mocks\MetadataDriverMock;
use Doctrine\Tests\Mocks\DatabasePlatformMock;
use Doctrine\Tests\Mocks\EntityManagerMock;
use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\DriverMock;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataFactory;

View File

@ -27,10 +27,10 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$tool = new SchemaTool($this->_em); $tool = new SchemaTool($this->_em);
$sql = $tool->getCreateSchemaSql($classes); $sql = $tool->getCreateSchemaSql($classes);
$this->assertEquals(count($sql), 8); $this->assertEquals(count($sql), 8);
$this->assertEquals("CREATE TABLE cms_addresses (id INT AUTO_INCREMENT NOT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(id))", $sql[0]); $this->assertEquals("CREATE TABLE cms_addresses (id INT AUTO_INCREMENT NOT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
$this->assertEquals("CREATE TABLE cms_users_groups (user_id INT DEFAULT NULL, group_id INT DEFAULT NULL, PRIMARY KEY(user_id, group_id))", $sql[1]); $this->assertEquals("CREATE TABLE cms_users_groups (user_id INT DEFAULT NULL, group_id INT DEFAULT NULL, PRIMARY KEY(user_id, group_id)) ENGINE = InnoDB", $sql[1]);
$this->assertEquals("CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, status VARCHAR(50) NOT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))", $sql[2]); $this->assertEquals("CREATE TABLE cms_users (id INT AUTO_INCREMENT NOT NULL, status VARCHAR(50) NOT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[2]);
$this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber))", $sql[3]); $this->assertEquals("CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber)) ENGINE = InnoDB", $sql[3]);
$this->assertEquals("ALTER TABLE cms_addresses ADD FOREIGN KEY (user_id) REFERENCES cms_users(id)", $sql[4]); $this->assertEquals("ALTER TABLE cms_addresses ADD FOREIGN KEY (user_id) REFERENCES cms_users(id)", $sql[4]);
$this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (user_id) REFERENCES cms_users(id)", $sql[5]); $this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (user_id) REFERENCES cms_users(id)", $sql[5]);
$this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (group_id) REFERENCES cms_groups(id)", $sql[6]); $this->assertEquals("ALTER TABLE cms_users_groups ADD FOREIGN KEY (group_id) REFERENCES cms_groups(id)", $sql[6]);
@ -78,7 +78,7 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
$sql = $tool->getUpdateSchemaSql($classes); $sql = $tool->getUpdateSchemaSql($classes);
$this->assertEquals(2, count($sql)); $this->assertEquals(2, count($sql));
$this->assertEquals("CREATE TABLE schematool_entity_b (id INT NOT NULL, field VARCHAR(255) NOT NULL, PRIMARY KEY(id))", $sql[0]); $this->assertEquals("CREATE TABLE schematool_entity_b (id INT NOT NULL, field VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
$this->assertEquals("ALTER TABLE schematool_entity_a ADD new_field VARCHAR(50) NOT NULL", $sql[1]); $this->assertEquals("ALTER TABLE schematool_entity_a ADD new_field VARCHAR(50) NOT NULL", $sql[1]);
} }