DEFAULT can also be empty string

This commit is contained in:
Sebastian Mendel
2008-05-06 14:06:39 +00:00
parent e8a6b1af54
commit f35c4ce7cc

View File

@@ -311,23 +311,19 @@ class PMA_Table {
$query .= ' DEFAULT CURRENT_TIMESTAMP'; $query .= ' DEFAULT CURRENT_TIMESTAMP';
// auto_increment field cannot have a default value // auto_increment field cannot have a default value
} elseif ($extra !== 'AUTO_INCREMENT' } elseif ($extra !== 'AUTO_INCREMENT'
&& (strlen($default) || $default != $default_orig)) { && $default !== false) {
if (strtoupper($default) == 'NULL') { if (strtoupper($default) == 'NULL') {
$query .= ' DEFAULT NULL'; $query .= ' DEFAULT NULL';
} else { } elseif ($is_timestamp && $default === '0') {
if (strlen($default)) {
if ($is_timestamp && $default == '0') {
// a TIMESTAMP does not accept DEFAULT '0' // a TIMESTAMP does not accept DEFAULT '0'
// but DEFAULT 0 works // but DEFAULT 0 works
$query .= ' DEFAULT ' . PMA_sqlAddslashes($default); $query .= ' DEFAULT ' . PMA_sqlAddslashes($default);
} elseif ($default && $type == 'BIT') { } elseif ($type == 'BIT') {
$query .= ' DEFAULT b\'' . preg_replace('/[^01]/', '0', $default) . '\''; $query .= ' DEFAULT b\'' . preg_replace('/[^01]/', '0', $default) . '\'';
} else { } else {
$query .= ' DEFAULT \'' . PMA_sqlAddslashes($default) . '\''; $query .= ' DEFAULT \'' . PMA_sqlAddslashes($default) . '\'';
} }
} }
}
}
if (!empty($extra)) { if (!empty($extra)) {
$query .= ' ' . $extra; $query .= ' ' . $extra;
@@ -448,13 +444,12 @@ class PMA_Table {
*/ */
static public function generateAlter($oldcol, $newcol, $type, $length, static public function generateAlter($oldcol, $newcol, $type, $length,
$attribute, $collation, $null, $default, $default_current_timestamp, $attribute, $collation, $null, $default, $default_current_timestamp,
$extra, $comment='', $default_orig) $extra, $comment='', &$field_primary, $index, $default_orig)
{ {
$empty_a = array();
return PMA_backquote($oldcol) . ' ' return PMA_backquote($oldcol) . ' '
. PMA_Table::generateFieldSpec($newcol, $type, $length, $attribute, . PMA_Table::generateFieldSpec($newcol, $type, $length, $attribute,
$collation, $null, $default, $default_current_timestamp, $extra, $collation, $null, $default, $default_current_timestamp, $extra,
$comment, $empty_a, -1, $default_orig); $comment, $field_primary, $index, $default_orig);
} // end function } // end function
/** /**