Commit 61873e38 authored by Guilherme Blanco's avatar Guilherme Blanco

Added support for table options and partition options in mysql.

parent eb6ee9a8
......@@ -16,6 +16,7 @@
"doctrine/common": "2.4.x-dev"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"symfony/console": "2.*"
},
"suggest": {
......
This diff is collapsed.
......@@ -371,42 +371,94 @@ class MySqlPlatform extends AbstractPlatform
}
$query = 'CREATE ';
if (!empty($options['temporary'])) {
$query .= 'TEMPORARY ';
}
$query .= 'TABLE ' . $tableName . ' (' . $queryFields . ') ';
$query .= $this->buildTableOptions($options);
$query .= $this->buildPartitionOptions($options);
if (isset($options['comment'])) {
$comment = trim($options['comment'], " '");
$sql[] = $query;
if (isset($options['foreignKeys'])) {
foreach ((array) $options['foreignKeys'] as $definition) {
$sql[] = $this->getCreateForeignKeySQL($definition, $tableName);
}
}
$query .= sprintf("COMMENT = '%s' ", str_replace("'", "''", $comment));
return $sql;
}
/**
* Build SQL for table options
*
* @param array $options
*
* @return string
*/
private function buildTableOptions(array $options)
{
if (isset($options['table_options'])) {
return $options['table_options'];
}
$tableOptions = array();
// Charset
if ( ! isset($options['charset'])) {
$options['charset'] = 'utf8';
}
$tableOptions[] = sprintf('DEFAULT CHARACTER SET %s', $options['charset']);
// Collate
if ( ! isset($options['collate'])) {
$options['collate'] = 'utf8_unicode_ci';
}
$query .= 'DEFAULT CHARACTER SET ' . $options['charset'];
$query .= ' COLLATE ' . $options['collate'];
$tableOptions[] = sprintf('COLLATE %s', $options['collate']);
// Engine
if ( ! isset($options['engine'])) {
$options['engine'] = 'InnoDB';
}
$query .= ' ENGINE = ' . $options['engine'];
$sql[] = $query;
$tableOptions[] = sprintf('ENGINE = %s', $options['engine']);
if (isset($options['foreignKeys'])) {
foreach ((array) $options['foreignKeys'] as $definition) {
$sql[] = $this->getCreateForeignKeySQL($definition, $tableName);
}
// Auto increment
if (isset($options['auto_increment'])) {
$tableOptions[] = sprintf('AUTO_INCREMENT = %s', $options['auto_increment']);
}
return $sql;
// Comment
if (isset($options['comment'])) {
$comment = trim($options['comment'], " '");
$tableOptions[] = sprintf("COMMENT = '%s' ", str_replace("'", "''", $comment));
}
// Row format
if (isset($options['row_format'])) {
$tableOptions[] = sprintf('ROW_FORMAT = %s', $options['row_format']);
}
return implode(' ', $tableOptions);
}
/**
* Build SQL for partition options.
*
* @param array $options
*
* @return string
*/
private function buildPartitionOptions(array $options)
{
return (isset($options['partition_options']))
? $options['partition_options']
: '';
}
/**
......
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