experimental support in table structure editing for MySQL 4.1.2+ TIMESTAMP options
This commit is contained in:
@@ -5,6 +5,12 @@ phpMyAdmin - Changelog
|
||||
$Id$
|
||||
$Source$
|
||||
|
||||
2005-03-16 Marc Delisle <lem9@users.sourceforge.net>
|
||||
* tbl_properties_structure.php, tbl_alter.php, tbl_properties.inc.php,
|
||||
config.inc.php (comment only), libraries/common.lib.php:
|
||||
experimental support for table structure editing with MySQL 4.1.2+
|
||||
TIMESTAMP options
|
||||
|
||||
2005-03-13 Marc Delisle <lem9@users.sourceforge.net>
|
||||
* tbl_row_delete.php renamed to tbl_row_action.php (RFE 1097729)
|
||||
|
||||
|
@@ -670,6 +670,9 @@ $cfg['ColumnTypes'] = array(
|
||||
);
|
||||
|
||||
// Attributes
|
||||
// Note: the "ON UPDATE CURRENT_TIMESTAMP" attribute is added dynamically
|
||||
// for MySQL >= 4.1.2, in tbl_properties.inc.php
|
||||
|
||||
$cfg['AttributeTypes'] = array(
|
||||
'',
|
||||
'BINARY',
|
||||
|
@@ -2517,24 +2517,30 @@ if (typeof(document.getElementById) != 'undefined'
|
||||
} // end function
|
||||
|
||||
|
||||
function PMA_generateAlterTable($oldcol, $newcol, $full_field_type, $collation, $null, $default, $extra, $comment='') {
|
||||
function PMA_generateAlterTable($oldcol, $newcol, $full_field_type, $collation, $null, $default, $default_current_timestamp, $extra, $comment='') {
|
||||
|
||||
// $default_current_timestamp has priority over $default
|
||||
// TODO: on the interface, some js to clear the default value
|
||||
// when the default current_timestamp is checked
|
||||
|
||||
$query = PMA_backquote($oldcol) . ' ' . PMA_backquote($newcol) . ' '
|
||||
. $full_field_type;
|
||||
if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($collation) && $collation != 'NULL' && preg_match('@^(TINYTEXT|TEXT|MEDIUMTEXT|LONGTEXT|VARCHAR|CHAR)$@i', $full_field_type)) {
|
||||
$query .= PMA_generateCharsetQueryPart($collation);
|
||||
}
|
||||
if (!empty($default)) {
|
||||
|
||||
if ($default_current_timestamp) {
|
||||
$query .= ' DEFAULT CURRENT_TIMESTAMP';
|
||||
} elseif (!empty($default)) {
|
||||
if (strtoupper($default) == 'NULL') {
|
||||
$query .= ' DEFAULT NULL';
|
||||
} else {
|
||||
$query .= ' DEFAULT \'' . PMA_sqlAddslashes($default) . '\'';
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($null)) {
|
||||
$query .= ' NOT NULL';
|
||||
//} else {
|
||||
// $query .= ' NULL';
|
||||
}
|
||||
if (!empty($extra)) {
|
||||
$query .= ' ' . $extra;
|
||||
|
@@ -2,7 +2,6 @@
|
||||
/* $Id$ */
|
||||
// vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
|
||||
/**
|
||||
* Gets some core libraries
|
||||
*/
|
||||
@@ -67,7 +66,7 @@ if (isset($do_save_data)) {
|
||||
$full_field_type .= ' ' . $field_attribute[$i];
|
||||
}
|
||||
// take care of native MySQL comments here
|
||||
$query .= PMA_generateAlterTable($field_orig[$i], $field_name[$i], $full_field_type, (PMA_MYSQL_INT_VERSION >= 40100 && $field_collation[$i] != '' ? $field_collation[$i] : ''), $field_null[$i], $field_default[$i], $field_extra[$i], (PMA_MYSQL_INT_VERSION >= 40100 && $field_comments[$i] != '' ? $field_comments[$i] : ''));
|
||||
$query .= PMA_generateAlterTable($field_orig[$i], $field_name[$i], $full_field_type, (PMA_MYSQL_INT_VERSION >= 40100 && $field_collation[$i] != '' ? $field_collation[$i] : ''), $field_null[$i], $field_default[$i], $field_default_current_timestamp[$i], $field_extra[$i], (PMA_MYSQL_INT_VERSION >= 40100 && $field_comments[$i] != '' ? $field_comments[$i] : ''));
|
||||
} // end for
|
||||
|
||||
// To allow replication, we first select the db to use and then run queries
|
||||
@@ -181,6 +180,24 @@ if ($abort == FALSE) {
|
||||
}
|
||||
$num_fields = count($fields_meta);
|
||||
$action = 'tbl_alter.php';
|
||||
|
||||
// Get more complete field information
|
||||
// For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
|
||||
// but later, if the analyser returns more information, it
|
||||
// could be executed for any MySQL version and replace
|
||||
// the info given by SHOW FULL FIELDS FROM.
|
||||
// TODO: put this code into a require()
|
||||
|
||||
if (PMA_MYSQL_INT_VERSION >= 40102) {
|
||||
$show_create_table_query = 'SHOW CREATE TABLE '
|
||||
. PMA_backquote($db) . '.' . PMA_backquote($table);
|
||||
$show_create_table_res = PMA_DBI_query($show_create_table_query);
|
||||
list(,$show_create_table) = PMA_DBI_fetch_row($show_create_table_res);
|
||||
PMA_DBI_free_result($show_create_table_res);
|
||||
unset($show_create_table_res, $show_create_table_query);
|
||||
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
|
||||
}
|
||||
|
||||
require('./tbl_properties.inc.php');
|
||||
}
|
||||
|
||||
|
@@ -116,7 +116,6 @@ if (!$is_backup) {
|
||||
$header_cells[] = $cfg['PropertiesIconic'] ? '<img src="' . $pmaThemeImage . 'b_ftext.png" width="16" height="16" alt="' . $strIdxFulltext . '" title="' . $strIdxFulltext . '" />' : $strIdxFulltext;
|
||||
}
|
||||
|
||||
|
||||
require_once('./libraries/relation.lib.php');
|
||||
require_once('./libraries/transformations.lib.php');
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
@@ -302,30 +301,48 @@ for ($i = 0 ; $i < $num_fields; $i++) {
|
||||
$ci++;
|
||||
}
|
||||
|
||||
$content_cells[$i][$ci] = '<select name="field_attribute[]" id="field_' . $i . '_' . ($ci - $ci_offset) . '">' . "\n";
|
||||
$content_cells[$i][$ci] = '<select style="font-size: ' . $font_smallest . ';" name="field_attribute[]" id="field_' . $i . '_' . ($ci - $ci_offset) . '">' . "\n";
|
||||
|
||||
$strAttribute = '';
|
||||
$attribute = '';
|
||||
if ($binary) {
|
||||
$strAttribute = 'BINARY';
|
||||
$attribute = 'BINARY';
|
||||
}
|
||||
if ($unsigned) {
|
||||
$strAttribute = 'UNSIGNED';
|
||||
$attribute = 'UNSIGNED';
|
||||
}
|
||||
if ($zerofill) {
|
||||
$strAttribute = 'UNSIGNED ZEROFILL';
|
||||
$attribute = 'UNSIGNED ZEROFILL';
|
||||
}
|
||||
|
||||
if (isset($submit_attribute) && $submit_attribute != FALSE) {
|
||||
$strAttribute = $submit_attribute;
|
||||
$attribute = $submit_attribute;
|
||||
}
|
||||
|
||||
|
||||
// MySQL 4.1.2+ TIMESTAMP options
|
||||
// (if on_update_current_timestamp is set, then it's TRUE)
|
||||
if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
|
||||
$attribute = 'ON UPDATE CURRENT_TIMESTAMP';
|
||||
}
|
||||
if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp'])) {
|
||||
$default_current_timestamp = TRUE;
|
||||
} else {
|
||||
$default_current_timestamp = FALSE;
|
||||
}
|
||||
|
||||
// Dynamically add ON UPDATE CURRENT_TIMESTAMP to the possible attributes
|
||||
if (PMA_MYSQL_INT_VERSION >= 40102) {
|
||||
$cfg['AttributeTypes'][] = 'ON UPDATE CURRENT_TIMESTAMP';
|
||||
}
|
||||
|
||||
|
||||
$cnt_attribute_types = count($cfg['AttributeTypes']);
|
||||
for ($j = 0;$j < $cnt_attribute_types; $j++) {
|
||||
if (PMA_MYSQL_INT_VERSION >= 40100 && $cfg['AttributeTypes'][$j] == 'BINARY') {
|
||||
continue;
|
||||
}
|
||||
$content_cells[$i][$ci] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
|
||||
if (strtoupper($strAttribute) == strtoupper($cfg['AttributeTypes'][$j])) {
|
||||
if (strtoupper($attribute) == strtoupper($cfg['AttributeTypes'][$j])) {
|
||||
$content_cells[$i][$ci] .= ' selected="selected"';
|
||||
}
|
||||
$content_cells[$i][$ci] .= '>' . $cfg['AttributeTypes'][$j] . '</option>' . "\n";
|
||||
@@ -360,7 +377,23 @@ for ($i = 0 ; $i < $num_fields; $i++) {
|
||||
$content_cells[$i][$ci] = "\n";
|
||||
}
|
||||
|
||||
// for a TIMESTAMP, do not show CURRENT_TIMESTAMP as a default value
|
||||
if (PMA_MYSQL_INT_VERSION >= 40102
|
||||
&& $type == 'timestamp'
|
||||
&& $default_current_timestamp
|
||||
&& isset($row)
|
||||
&& isset($row['Default'])) {
|
||||
$row['Default'] = '';
|
||||
}
|
||||
|
||||
$content_cells[$i][$ci] .= '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '" type="text" name="field_default[]" size="12" value="' . (isset($row) && isset($row['Default']) ? str_replace('"', '"', $row['Default']) : '') . '" class="textfield" />';
|
||||
if (PMA_MYSQL_INT_VERSION >= 40102 && $type == 'timestamp') {
|
||||
$content_cells[$i][$ci] .= '<br /><input id="field_' . $i . '_' . ($ci - $ci_offset) . 'a" type="checkbox" name="field_default_current_timestamp[' . $i . ']"';
|
||||
if ($default_current_timestamp) {
|
||||
$content_cells[$i][$ci] .= ' checked="checked" ';
|
||||
}
|
||||
$content_cells[$i][$ci] .= ' /><label for="field_' . $i . '_' . ($ci - $ci_offset) . 'a" style="font-size: ' . $font_smallest . ';">CURRENT_TIMESTAMP</label>';
|
||||
}
|
||||
$ci++;
|
||||
|
||||
$content_cells[$i][$ci] = '<select name="field_extra[]" id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
|
||||
|
@@ -83,9 +83,7 @@ $fields_cnt = PMA_DBI_num_rows($fields_rs);
|
||||
// For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
|
||||
// but later, if the analyser returns more information, it
|
||||
// could be executed for any MySQL version and replace
|
||||
// the info given by the previous SHOW FULL FIELDS FROM query.
|
||||
|
||||
// TODO: use this information for proper treatment of TIMESTAMPs
|
||||
// the info given by SHOW FULL FIELDS FROM.
|
||||
|
||||
if (PMA_MYSQL_INT_VERSION >= 40102) {
|
||||
$show_create_table_query = 'SHOW CREATE TABLE '
|
||||
@@ -232,16 +230,23 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
|
||||
$type_mime = '';
|
||||
}
|
||||
|
||||
$strAttribute = ' ';
|
||||
$attribute = ' ';
|
||||
if ($binary) {
|
||||
$strAttribute = 'BINARY';
|
||||
$attribute = 'BINARY';
|
||||
}
|
||||
if ($unsigned) {
|
||||
$strAttribute = 'UNSIGNED';
|
||||
$attribute = 'UNSIGNED';
|
||||
}
|
||||
if ($zerofill) {
|
||||
$strAttribute = 'UNSIGNED ZEROFILL';
|
||||
$attribute = 'UNSIGNED ZEROFILL';
|
||||
}
|
||||
|
||||
// MySQL 4.1.2+ TIMESTAMP options
|
||||
// (if on_update_current_timestamp is set, then it's TRUE)
|
||||
if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
|
||||
$attribute = 'ON UPDATE CURRENT_TIMESTAMP';
|
||||
}
|
||||
|
||||
if (!isset($row['Default'])) {
|
||||
if ($row['Null'] != '') {
|
||||
$row['Default'] = '<i>NULL</i>';
|
||||
@@ -330,7 +335,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
|
||||
<td <?php echo $click_mouse; ?> bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"> <label onclick="return (document.getElementById('checkbox_row_<?php echo $i; ?>') ? false : true)" for="checkbox_row_<?php echo $i; ?>"><?php echo $field_name; ?></label> </td>
|
||||
<td <?php echo $click_mouse; ?> bgcolor="<?php echo $bgcolor; ?>"<?php echo $type_nowrap; ?>><?php echo $type; echo $type_mime; ?><bdo dir="ltr"></bdo></td>
|
||||
<?php echo PMA_MYSQL_INT_VERSION >= 40100 ? ' <td bgcolor="' . $bgcolor . '" ' . $click_mouse . '>' . (empty($field_charset) ? ' ' : '<dfn title="' . PMA_getCollationDescr($field_charset) . '">' . $field_charset . '</dfn>') . '</td>' . "\n" : '' ?>
|
||||
<td <?php echo $click_mouse; ?> bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>
|
||||
<td <?php echo $click_mouse; ?> bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap" style="font-size: <?php echo $font_smallest; ?>"><?php echo $attribute; ?></td>
|
||||
<td <?php echo $click_mouse; ?> bgcolor="<?php echo $bgcolor; ?>"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?> </td>
|
||||
<td <?php echo $click_mouse; ?> bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?> </td>
|
||||
<td <?php echo $click_mouse; ?> bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?> </td>
|
||||
|
Reference in New Issue
Block a user