diff --git a/tbl_change.php b/tbl_change.php index 05085439d..7a8faa37e 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -310,11 +310,6 @@ foreach ($rows as $row_id => $vrow) { $vrow) { $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']); $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']); $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']); + + // d a t e t i m e + // + // loic1: current date should not be set as default if the field is NULL + // for the current row + // lem9: but do not put here the current datetime if there is a default + // value (the real default value will be set in the + // Default value logic below) + + // Note: (tested in MySQL 4.0.16): when lang is some UTF-8, + // $field['Default'] is not set if it contains NULL: + // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime) + // but, look what we get if we switch to iso: (Default is NULL) + // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime) + // so I force a NULL into it (I don't think it's possible + // to have an empty default value for DATETIME) + // then, the "if" after this one will work + if ($table_fields[$i]['Type'] == 'datetime' + && ! isset($table_fields[$i]['Default']) + && isset($table_fields[$i]['Null']) + && $table_fields[$i]['Null'] == 'YES') { + $table_fields[$i]['Default'] = null; + } + + $table_fields[$i]['len'] = + preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1; + + + if (isset($comments_map[$table_fields[$i]['Field']])) { + $table_fields[$i]['Field_title'] = '' + . $table_fields[$i]['Field_html'] . ''; + } else { + $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html']; + } + + // The type column + $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary'); + $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob'); + $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char'); + $table_fields[$i]['first_timestamp'] = false; + switch ($table_fields[$i]['True_Type']) { + case 'set': + $table_fields[$i]['pma_type'] = 'set'; + $table_fields[$i]['wrap'] = ''; + break; + case 'enum': + $table_fields[$i]['pma_type'] = 'enum'; + $table_fields[$i]['wrap'] = ''; + break; + case 'timestamp': + if (!$timestamp_seen) { // can only occur once per table + $timestamp_seen = 1; + $table_fields[$i]['first_timestamp'] = true; + } + $table_fields[$i]['pma_type'] = $table_fields[$i]['Type']; + $table_fields[$i]['wrap'] = ' nowrap="nowrap"'; + break; + + default: + $table_fields[$i]['pma_type'] = $table_fields[$i]['Type']; + $table_fields[$i]['wrap'] = ' nowrap="nowrap"'; + break; + } } $field = $table_fields[$i]; + if (-1 === $field['len']) { + $field['len'] = PMA_DBI_field_len($vresult, $i); + } + $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('" . PMA_escapeJsString($field['Field_html']) . "', '" . PMA_escapeJsString($jsvkey) . "')\""; @@ -334,33 +397,6 @@ foreach ($rows as $row_id => $vrow) { $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]'; - // removed previous PHP3-workaround that caused a problem with - // field names like '000' - //$rowfield = $field; - - // d a t e t i m e - // - // loic1: current date should not be set as default if the field is NULL - // for the current row - // lem9: but do not put here the current datetime if there is a default - // value (the real default value will be set in the - // Default value logic below) - - // Note: (tested in MySQL 4.0.16): when lang is some UTF-8, - // $field['Default'] is not set if it contains NULL: - // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime) - // but, look what we get if we switch to iso: (Default is NULL) - // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime) - // so I force a NULL into it (I don't think it's possible - // to have an empty default value for DATETIME) - // then, the "if" after this one will work - if ($field['Type'] == 'datetime' - && ! isset($field['Default']) - && isset($field['Null']) - && $field['Null'] == 'YES') { - $field['Default'] = null; - } - if ($field['Type'] == 'datetime' && ! isset($field['Default']) && ! is_null($field['Default'])) { @@ -373,52 +409,11 @@ foreach ($rows as $row_id => $vrow) { $vrow[$field['Field']] = date('Y-m-d H:i:s', time()); } // end if... elseif... } - $len = (preg_match('@float|double@', $field['Type'])) - ? 100 - : PMA_DBI_field_len($vresult, $i); - $first_timestamp = 0; - - $field_name = $field['Field_html']; - if (isset($comments_map[$field['Field']])) { - $field_name = '' . $field_name . ''; - } - ?> - align="center"> - - - > - + align="center"> + > + $vrow) { $data = $vrow[$field['Field']]; } elseif ($field['True_Type'] == 'bit') { $special_chars = ''; - for ($j = 0; $j < ceil($len / 8); $j++) { + for ($j = 0; $j < ceil($field['len'] / 8); $j++) { $special_chars .= sprintf('%08d', decbin(ord(substr($vrow[$field['Field']], $j, 1)))); } - $special_chars = substr($special_chars, -$len); + $special_chars = substr($special_chars, -$field['len']); } else { // loic1: special binary "characters" - if ($is_binary || $is_blob) { + if ($field['is_binary'] || $field['is_blob']) { $vrow[$field['Field']] = str_replace("\x00", '\0', $vrow[$field['Field']]); $vrow[$field['Field']] = str_replace("\x08", '\b', $vrow[$field['Field']]); $vrow[$field['Field']] = str_replace("\x0a", '\n', $vrow[$field['Field']]); @@ -481,8 +476,8 @@ foreach ($rows as $row_id => $vrow) { // stored or retrieved" so it does not mean that the contents is // binary if ($cfg['ShowFunctionFields']) { - if (($cfg['ProtectBinary'] && $is_blob && !$is_upload) - || ($cfg['ProtectBinary'] == 'all' && $is_binary)) { + if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload) + || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) { echo ' ' . $strBinary . '' . "\n"; } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) { echo ' --' . "\n"; @@ -527,8 +522,8 @@ foreach ($rows as $row_id => $vrow) { if (!($field['True_Type'] == 'timestamp' && !empty($field['Default']) && !isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp']))) { - $selected = ($first_timestamp && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp']) - || (!$first_timestamp && $dropdown[$j] == $default_function) + $selected = ($field['first_timestamp'] && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp']) + || (!$field['first_timestamp'] && $dropdown[$j] == $default_function) ? ' selected="selected"' : ''; } @@ -545,8 +540,8 @@ foreach ($rows as $row_id => $vrow) { for ($j = 0; $j < $cnt_functions; $j++) { if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') { // Is current function defined as default? - $selected = ($first_timestamp && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp']) - || (!$first_timestamp && $cfg['Functions'][$j] == $default_function) + $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp']) + || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function) ? ' selected="selected"' : ''; if ($op_spacing_needed == TRUE) { @@ -573,16 +568,16 @@ foreach ($rows as $row_id => $vrow) { echo ' ' . "\n"; if ($field['Null'] == 'YES') { echo ' ' . "\n"; - if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary))) { + if (!(($cfg['ProtectBinary'] && $field['is_blob']) || ($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) { echo ' $vrow) { echo $onclick; } else { echo ' ' . "\n"; @@ -655,7 +650,7 @@ foreach ($rows as $row_id => $vrow) {   @@ -671,7 +666,7 @@ foreach ($rows as $row_id => $vrow) { tabindex="" >