Commit 16ef556f authored by lsmith's avatar lsmith

- added support for temporary tables, tweaked createSequence and enum support...

- added support for temporary tables, tweaked createSequence and enum support in getDefaultFieldDeclaration()
parent 406c57b5
......@@ -91,8 +91,9 @@ class Doctrine_Export_Mysql extends Doctrine_Export
*/
public function createTableSql($name, array $fields, array $options = array())
{
if ( ! $name)
if ( ! $name) {
throw new Doctrine_Export_Exception('no valid table name specified');
}
if (empty($fields)) {
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) . ')';
}
$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();
......@@ -408,21 +413,23 @@ class Doctrine_Export_Mysql extends Doctrine_Export
$optionsStrings[] = 'ENGINE = ' . $type;
}
try {
$query = 'CREATE TABLE ' . $sequenceName
. ' (' . $seqcolName . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
. $seqcolName . '))'
. strlen($this->conn->default_table_type) ? ' TYPE = '
. $this->conn->default_table_type : '';
. $seqcolName . '))';
if (!empty($options_strings)) {
$query .= ' '.implode(' ', $options_strings);
}
$res = $this->conn->exec($query);
} catch(Doctrine_Connection_Exception $e) {
throw new Doctrine_Export_Exception('could not create sequence table');
}
if ($start == 1)
if ($start == 1) {
return true;
}
$query = 'INSERT INTO ' . $sequenceName
. ' (' . $seqcolName . ') VALUES (' . ($start - 1) . ')';
......@@ -431,12 +438,12 @@ class Doctrine_Export_Mysql extends Doctrine_Export
// Handle error
try {
$result = $this->conn->exec('DROP TABLE ' . $sequenceName);
$res = $this->conn->exec('DROP TABLE ' . $sequenceName);
} catch(Doctrine_Connection_Exception $e) {
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 = '';
if (isset($field['default']) && ( ! isset($field['length']) || $field['length'] <= 255)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull'])
? null : $this->valid_default_values[$field['type']];
$field['default'] = null;
if (! empty($field['notnull']) && array_key_exists($field['type'], $this->valid_default_values)) {
$field['default'] = $this->valid_default_values[$field['type']];
}
if ($field['default'] === ''
&& ($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)) {
$fieldType = 'varchar';
} 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'], $field['type']);
}
return $default;
}
......
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