Skip to content

Commit

Permalink
[2.0] Made MySqlPlatform default to innodb table engine. Some cleanup…
Browse files Browse the repository at this point in the history
…s while investigating the optimistic locking failures.
  • Loading branch information
romanb committed Aug 28, 2009
1 parent 59fff29 commit 6a3aa84
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
3 changes: 2 additions & 1 deletion lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Expand Up @@ -1456,7 +1456,8 @@ public function getIdentityColumnNullInsertSql()
* the format of a stored datetime value of this platform.
*
* @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
*/
public function getDateTimeFormatString()
Expand Down
18 changes: 8 additions & 10 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Expand Up @@ -25,7 +25,8 @@

/**
* 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
* @author Roman Borschel <roman@code-factory.org>
Expand Down Expand Up @@ -472,17 +473,14 @@ public function getCreateTableSql($name, array $fields, array $options = array()
}
}

$type = false;

// get the type of the table
if (isset($options['type'])) {
$type = $options['type'];
}

if ($type) {
$optionStrings[] = 'ENGINE = ' . $type;
if (isset($options['engine'])) {
$optionStrings[] = 'ENGINE = ' . $engine;
} else {
// default to innodb
$optionStrings[] = 'ENGINE = InnoDB';
}

if ( ! empty($optionStrings)) {
$query.= ' '.implode(' ', $optionStrings);
}
Expand Down
11 changes: 11 additions & 0 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Expand Up @@ -756,4 +756,15 @@ public function getSqlResultCasing($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';
}*/
}
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
Expand Up @@ -37,7 +37,7 @@ public function testGeneratesTableCreationSql()
);

$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()
Expand Down
Expand Up @@ -2,11 +2,6 @@

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\Common\EventManager;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
Expand Down
Expand Up @@ -27,10 +27,10 @@ public function testGetCreateSchemaSql()
$tool = new SchemaTool($this->_em);
$sql = $tool->getCreateSchemaSql($classes);
$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_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 (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_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber))", $sql[3]);
$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)) 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)) ENGINE = InnoDB", $sql[2]);
$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_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]);
Expand Down Expand Up @@ -78,7 +78,7 @@ public function testGetUpdateSchemaSql()
$sql = $tool->getUpdateSchemaSql($classes);

$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]);

}
Expand Down

0 comments on commit 6a3aa84

Please sign in to comment.