- added support for temporary tables, tweaked createSequence and enum support in getDefaultFieldDeclaration()
This commit is contained in:
parent
406c57b53b
commit
16ef556f62
@ -91,8 +91,9 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
*/
|
*/
|
||||||
public function createTableSql($name, array $fields, array $options = array())
|
public function createTableSql($name, array $fields, array $options = array())
|
||||||
{
|
{
|
||||||
if ( ! $name)
|
if ( ! $name) {
|
||||||
throw new Doctrine_Export_Exception('no valid table name specified');
|
throw new Doctrine_Export_Exception('no valid table name specified');
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($fields)) {
|
if (empty($fields)) {
|
||||||
throw new Doctrine_Export_Exception('no fields specified for table "'.$name.'"');
|
throw new Doctrine_Export_Exception('no fields specified for table "'.$name.'"');
|
||||||
@ -141,7 +142,11 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
$queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')';
|
$queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = 'CREATE TABLE ' . $this->conn->quoteIdentifier($name, true) . ' (' . $queryFields . ')';
|
$query = 'CREATE ';
|
||||||
|
if (!empty($options['temporary'])) {
|
||||||
|
$query .= 'TEMPORARY ';
|
||||||
|
}
|
||||||
|
$query.= 'TABLE ' . $this->conn->quoteIdentifier($name, true) . ' (' . $queryFields . ')';
|
||||||
|
|
||||||
$optionStrings = array();
|
$optionStrings = array();
|
||||||
|
|
||||||
@ -408,35 +413,37 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
$optionsStrings[] = 'ENGINE = ' . $type;
|
$optionsStrings[] = 'ENGINE = ' . $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$query = 'CREATE TABLE ' . $sequenceName
|
$query = 'CREATE TABLE ' . $sequenceName
|
||||||
. ' (' . $seqcolName . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
|
. ' (' . $seqcolName . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
|
||||||
. $seqcolName . '))'
|
. $seqcolName . '))';
|
||||||
. strlen($this->conn->default_table_type) ? ' TYPE = '
|
|
||||||
. $this->conn->default_table_type : '';
|
if (!empty($options_strings)) {
|
||||||
|
$query .= ' '.implode(' ', $options_strings);
|
||||||
|
}
|
||||||
|
|
||||||
$res = $this->conn->exec($query);
|
$res = $this->conn->exec($query);
|
||||||
} catch(Doctrine_Connection_Exception $e) {
|
} catch(Doctrine_Connection_Exception $e) {
|
||||||
throw new Doctrine_Export_Exception('could not create sequence table');
|
throw new Doctrine_Export_Exception('could not create sequence table');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($start == 1)
|
if ($start == 1) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$query = 'INSERT INTO ' . $sequenceName
|
$query = 'INSERT INTO ' . $sequenceName
|
||||||
. ' (' . $seqcolName . ') VALUES (' . ($start - 1) . ')';
|
. ' (' . $seqcolName . ') VALUES (' . ($start - 1) . ')';
|
||||||
|
|
||||||
$res = $this->conn->exec($query);
|
$res = $this->conn->exec($query);
|
||||||
|
|
||||||
// Handle error
|
// Handle error
|
||||||
try {
|
try {
|
||||||
$result = $this->conn->exec('DROP TABLE ' . $sequenceName);
|
$res = $this->conn->exec('DROP TABLE ' . $sequenceName);
|
||||||
} catch(Doctrine_Connection_Exception $e) {
|
} catch(Doctrine_Connection_Exception $e) {
|
||||||
throw new Doctrine_Export_Exception('could not drop inconsistent sequence table');
|
throw new Doctrine_Export_Exception('could not drop inconsistent sequence table');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -508,8 +515,10 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
$default = '';
|
$default = '';
|
||||||
if (isset($field['default']) && ( ! isset($field['length']) || $field['length'] <= 255)) {
|
if (isset($field['default']) && ( ! isset($field['length']) || $field['length'] <= 255)) {
|
||||||
if ($field['default'] === '') {
|
if ($field['default'] === '') {
|
||||||
$field['default'] = empty($field['notnull'])
|
$field['default'] = null;
|
||||||
? null : $this->valid_default_values[$field['type']];
|
if (! empty($field['notnull']) && array_key_exists($field['type'], $this->valid_default_values)) {
|
||||||
|
$field['default'] = $this->valid_default_values[$field['type']];
|
||||||
|
}
|
||||||
|
|
||||||
if ($field['default'] === ''
|
if ($field['default'] === ''
|
||||||
&& ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)
|
&& ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)
|
||||||
@ -518,7 +527,6 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proposed patch:
|
|
||||||
if ($field['type'] == 'enum' && $this->conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
|
if ($field['type'] == 'enum' && $this->conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
|
||||||
$fieldType = 'varchar';
|
$fieldType = 'varchar';
|
||||||
} else {
|
} else {
|
||||||
@ -526,7 +534,6 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
}
|
}
|
||||||
|
|
||||||
$default = ' DEFAULT ' . $this->conn->quote($field['default'], $fieldType);
|
$default = ' DEFAULT ' . $this->conn->quote($field['default'], $fieldType);
|
||||||
//$default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']);
|
|
||||||
}
|
}
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user