Do not waste the data for table-field creation, if MySQL shows an error.
Instead, give the user the opportunity to fix the errors and display the form again.
This commit is contained in:
@@ -14,9 +14,9 @@ $Source$
|
||||
* sql.php3: Fixed another occurence of addslashes() where it no longer
|
||||
belongs.
|
||||
* tbl_addfield.php3, tbl_alter.php3, tbl_create.php3,
|
||||
tbl_properties.inc.php3: Goodie for you all - when creating/altering/
|
||||
adding table fields you can now change the wrong form input, instead
|
||||
of losing all your data. Have fun. :-)
|
||||
tbl_properties.inc.php3, libraries/common.lib.php3: Goodie for you all
|
||||
- when creating/altering/adding table fields you can now change the
|
||||
wrong form input, instead of losing all your data. Have fun. :-)
|
||||
* tbl_dump.php3, tbl_properties_export.php3, css/phpmyadmin.css.php3,
|
||||
lang/*:
|
||||
Added new table export format by Michal Cihar. db_details_export.php3
|
||||
|
@@ -399,13 +399,15 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
|
||||
* @param string the sql query that failed
|
||||
* @param boolean whether to show a "modify" link or not
|
||||
* @param string the "back" link url (full path is not required)
|
||||
* @param boolean EXIT the page?
|
||||
*
|
||||
* @global array the configuration array
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_mysqlDie($error_message = '', $the_query = '',
|
||||
$is_modify_link = TRUE, $back_url = '')
|
||||
$is_modify_link = TRUE, $back_url = '',
|
||||
$exit = TRUE)
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
@@ -466,13 +468,15 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
|
||||
. '</pre>' . "\n";
|
||||
|
||||
|
||||
if (!empty($back_url)) {
|
||||
if (!empty($back_url) && $exit) {
|
||||
echo '<a href="' . $back_url . '">' . $GLOBALS['strBack'] . '</a>';
|
||||
}
|
||||
echo "\n";
|
||||
|
||||
if ($exit) {
|
||||
include('./footer.inc.php3');
|
||||
exit();
|
||||
}
|
||||
} // end of the 'PMA_mysqlDie()' function
|
||||
|
||||
|
||||
|
@@ -20,6 +20,7 @@ $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
|
||||
/**
|
||||
* The form used to define the field to add has been submitted
|
||||
*/
|
||||
$abort = false;
|
||||
if (isset($submit)) {
|
||||
$query = '';
|
||||
|
||||
@@ -101,7 +102,11 @@ if (isset($submit)) {
|
||||
$sql_query = 'USE ' . PMA_backquote($db);
|
||||
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
|
||||
$sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD ' . $query;
|
||||
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
|
||||
$error_create = false;
|
||||
$result = PMA_mysql_query($sql_query) or $error_create = true;
|
||||
|
||||
if ($error_create == false) {
|
||||
|
||||
$sql_query_cpy = $sql_query . ';';
|
||||
|
||||
// Builds the primary keys statements and updates the table
|
||||
@@ -203,12 +208,23 @@ if (isset($submit)) {
|
||||
$message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
|
||||
include('./tbl_properties_structure.php3');
|
||||
exit();
|
||||
} else {
|
||||
PMA_mysqlDie('', '', '', $err_url, FALSE);
|
||||
// garvin: An error happened while inserting/updating a table definition.
|
||||
// to prevent total loss of that data, we embed the form once again.
|
||||
// The variable $regenerate will be used to restore data in tbl_properties.inc.php3
|
||||
$num_fields = $orig_num_fields;
|
||||
if (isset($orig_after_field)) {
|
||||
$after_field = $orig_after_field;
|
||||
}
|
||||
$regenerate = true;
|
||||
}
|
||||
} // end do alter table
|
||||
|
||||
/**
|
||||
* Displays the form used to define the new field
|
||||
*/
|
||||
else{
|
||||
if ($abort == FALSE) {
|
||||
$action = 'tbl_addfield.php3';
|
||||
include('./tbl_properties.inc.php3');
|
||||
|
||||
|
@@ -22,6 +22,7 @@ $err_url = 'tbl_properties_structure.php3?' . PMA_generate_common_url($db, $tabl
|
||||
/**
|
||||
* Modifications have been submitted -> updates the table
|
||||
*/
|
||||
$abort = false;
|
||||
if (isset($submit)) {
|
||||
$field_cnt = count($field_orig);
|
||||
for ($i = 0; $i < $field_cnt; $i++) {
|
||||
@@ -78,7 +79,10 @@ if (isset($submit)) {
|
||||
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
|
||||
// Optimization fix - 2 May 2001 - Robbat2
|
||||
$sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . $query;
|
||||
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
|
||||
$error_create = false;
|
||||
$result = PMA_mysql_query($sql_query) or $error_create = true;
|
||||
|
||||
if ($error_create == false) {
|
||||
$message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
|
||||
$btnDrop = 'Fake';
|
||||
|
||||
@@ -106,13 +110,23 @@ if (isset($submit)) {
|
||||
|
||||
include('./tbl_properties_structure.php3');
|
||||
exit();
|
||||
} else {
|
||||
PMA_mysqlDie('', '', '', $err_url, FALSE);
|
||||
// garvin: An error happened while inserting/updating a table definition.
|
||||
// to prevent total loss of that data, we embed the form once again.
|
||||
// The variable $regenerate will be used to restore data in tbl_properties.inc.php3
|
||||
if (isset($orig_field)) {
|
||||
$field = $orig_field;
|
||||
}
|
||||
|
||||
$regenerate = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* No modifications yet required -> displays the table fields
|
||||
*/
|
||||
else {
|
||||
if ($abort == FALSE) {
|
||||
if (!isset($selected)) {
|
||||
$selected[] = $field;
|
||||
$selected_cnt = 1;
|
||||
|
@@ -26,6 +26,7 @@ PMA_mysql_select_db($db);
|
||||
/**
|
||||
* The form used to define the structure of the table has been submitted
|
||||
*/
|
||||
$abort = false;
|
||||
if (isset($submit)) {
|
||||
$sql_query = $query_cpy = '';
|
||||
|
||||
@@ -141,7 +142,7 @@ if (isset($submit)) {
|
||||
$fulltext .= PMA_backquote($field_name[$j]) . ', ';
|
||||
}
|
||||
} // end for
|
||||
unset($field_fulltext);
|
||||
|
||||
$fulltext = ereg_replace(', $', '', $fulltext);
|
||||
if (!empty($fulltext)) {
|
||||
$sql_query .= ', FULLTEXT (' . $fulltext . ')';
|
||||
@@ -164,7 +165,10 @@ if (isset($submit)) {
|
||||
}
|
||||
|
||||
// Executes the query
|
||||
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url);
|
||||
$error_create = false;
|
||||
$result = PMA_mysql_query($sql_query) or $error_create = true;
|
||||
|
||||
if ($error_create == false) {
|
||||
$sql_query = $query_cpy . ';';
|
||||
unset($query_cpy);
|
||||
$message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
|
||||
@@ -192,14 +196,22 @@ if (isset($submit)) {
|
||||
}
|
||||
|
||||
include('./' . $cfg['DefaultTabTable']);
|
||||
$abort = TRUE;
|
||||
exit();
|
||||
} else {
|
||||
PMA_mysqlDie('', '', '', $err_url, FALSE);
|
||||
// garvin: An error happened while inserting/updating a table definition.
|
||||
// to prevent total loss of that data, we embed the form once again.
|
||||
// The variable $regenerate will be used to restore data in tbl_properties.inc.php3
|
||||
$num_fields = $orig_num_fields;
|
||||
$regenerate = true;
|
||||
}
|
||||
} // end do create table
|
||||
|
||||
|
||||
/**
|
||||
* Displays the form used to define the structure of the table
|
||||
*/
|
||||
else {
|
||||
if ($abort == FALSE) {
|
||||
if (isset($num_fields)) {
|
||||
$num_fields = intval($num_fields);
|
||||
}
|
||||
|
@@ -26,6 +26,49 @@ else if ($action == 'tbl_addfield.php3') {
|
||||
<?php
|
||||
}
|
||||
echo "\n";
|
||||
|
||||
if (isset($num_fields)) {
|
||||
?>
|
||||
<input type="hidden" name="orig_num_fields" value="<?php echo $num_fields; ?>" />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (isset($after_field)) {
|
||||
?>
|
||||
<input type="hidden" name="orig_after_field" value="<?php echo $after_field; ?>" />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (isset($selected) && is_array($selected)) {
|
||||
@reset($selected);
|
||||
while(list($o_fld_nr, $o_fld_val) = each($selected)) {
|
||||
?>
|
||||
<input type="hidden" name="selected[<?php echo $o_fld_nr; ?>]" value="<?php echo urlencode($o_fld_val); ?>" />
|
||||
<?php
|
||||
if (!isset($true_selected)) {
|
||||
?>
|
||||
<input type="hidden" name="true_selected[<?php echo $o_fld_nr; ?>]" value="<?php echo urlencode($o_fld_val); ?>" />
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isset($true_selected) && is_array($true_selected)) {
|
||||
@reset($true_selected);
|
||||
while(list($o_fld_nr, $o_fld_val) = each($true_selected)) {
|
||||
?>
|
||||
<input type="hidden" name="true_selected[<?php echo $o_fld_nr; ?>]" value="<?php echo urlencode($o_fld_val); ?>" />
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
} elseif (isset($field)) {
|
||||
?>
|
||||
<input type="hidden" name="orig_field" value="<?php echo urlencode($field); ?>" />
|
||||
<input type="hidden" name="true_selected[] value="<?php echo (isset($orig_field) ? $orig_field : urlencode($field)); ?>" />
|
||||
<?php
|
||||
}
|
||||
|
||||
$is_backup = ($action != 'tbl_create.php3' && $action != 'tbl_addfield.php3');
|
||||
|
||||
$header_cells = array();
|
||||
@@ -74,17 +117,74 @@ if (!$is_backup) {
|
||||
$header_cells[] = $strIdxFulltext;
|
||||
}
|
||||
|
||||
// garvin: workaround for field_fulltext, because its submitted indizes contain
|
||||
// the index as a value, not a key. Inserted here for easier maintaineance
|
||||
// and less code to change in existing files.
|
||||
if (isset($field_fulltext) && is_array($field_fulltext)) {
|
||||
@reset($field_fulltext);
|
||||
while(list($fulltext_nr, $fulltext_indexkey) = each($field_fulltext)) {
|
||||
$submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0 ; $i < $num_fields; $i++) {
|
||||
if (isset($fields_meta)) {
|
||||
$submit_null = FALSE;
|
||||
if (isset($regenerate) && $regenerate == TRUE) {
|
||||
// An error happened with previous inputs, so we will restore the data
|
||||
// to embed it once again in this form.
|
||||
|
||||
$row['Field'] = (isset($field_name) && isset($field_name[$i]) ? $field_name[$i] : FALSE);
|
||||
$row['Type'] = (isset($field_type) && isset($field_type[$i]) ? $field_type[$i] : FALSE);
|
||||
$row['Null'] = (isset($field_null) && isset($field_null[$i]) ? $field_null[$i] : '');
|
||||
if ($row['Null'] == '') {
|
||||
$submit_null = TRUE;
|
||||
}
|
||||
|
||||
if (isset(${'field_key_' . $i}) && ${'field_key_' . $i} == 'primary_' . $i) {
|
||||
$row['Key'] = 'PRI';
|
||||
} elseif (isset(${'field_key_' . $i}) && ${'field_key_' . $i} == 'index_' . $i) {
|
||||
$row['Key'] = 'MUL';
|
||||
} elseif (isset(${'field_key_' . $i}) && ${'field_key_' . $i} == 'unique_' . $i) {
|
||||
$row['Key'] = 'UNI';
|
||||
} else {
|
||||
$row['Key'] = '';
|
||||
}
|
||||
|
||||
$row['Default'] = (isset($field_default) && isset($field_default[$i]) ? $field_default[$i] : FALSE);
|
||||
$row['Extra'] = (isset($field_extra) && isset($field_extra[$i]) ? $field_extra[$i] : FALSE);
|
||||
$row['Comment'] = (isset($submit_fulltext) && isset($submit_fulltext[$i]) && ($submit_fulltext[$i] == $i) ? 'FULLTEXT' : FALSE);
|
||||
|
||||
$submit_length = (isset($field_length) && isset($field_length[$i]) ? $field_length[$i] : FALSE);
|
||||
$submit_attribute = (isset($field_attribute) && isset($field_attribute[$i]) ? $field_attribute[$i] : FALSE);
|
||||
|
||||
if (isset($field_comments) && isset($field_comments[$i])) {
|
||||
$comments_map[$row['Field']] = $field_comments[$i];
|
||||
}
|
||||
|
||||
if (isset($field_mimetype) && isset($field_mimetype[$i])) {
|
||||
$mime_map[$row['Field']]['mimetype'] = $field_mimetype[$i];
|
||||
}
|
||||
|
||||
if (isset($field_transformation) && isset($field_transformation[$i])) {
|
||||
$mime_map[$row['Field']]['transformation'] = $field_transformation[$i];
|
||||
}
|
||||
|
||||
if (isset($field_transformation_options) && isset($field_transformation_options[$i])) {
|
||||
$mime_map[$row['Field']]['transformation_options'] = $field_transformation_options[$i];
|
||||
}
|
||||
|
||||
} elseif (isset($fields_meta)) {
|
||||
$row = $fields_meta[$i];
|
||||
}
|
||||
|
||||
$bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
|
||||
|
||||
// Cell index: If certain fields get left out, the counter shouldn't chage.
|
||||
$ci = 0;
|
||||
|
||||
if ($is_backup) {
|
||||
$content_cells[$i][$ci] = "\n" . '<input type="hidden" name="field_orig[]" value="' . (isset($row) && isset($row['Field']) ? urlencode($row['Field']) : '') . '" />' . "\n";
|
||||
$backup_field = (isset($true_selected) && $true_selected[$i] ? $true_selected[$i] : (isset($row) && isset($row['Field']) ? urlencode($row['Field']) : ''));
|
||||
$content_cells[$i][$ci] = "\n" . '<input type="hidden" name="field_orig[]" value="' . $backup_field . '" />' . "\n";
|
||||
} else {
|
||||
$content_cells[$i][$ci] = '';
|
||||
}
|
||||
@@ -120,6 +220,10 @@ for ($i = 0 ; $i < $num_fields; $i++) {
|
||||
}
|
||||
} // end if else
|
||||
|
||||
if (isset($submit_length) && $submit_length != FALSE) {
|
||||
$length = $submit_length;
|
||||
}
|
||||
|
||||
for ($j = 0; $j < count($cfg['ColumnTypes']); $j++) {
|
||||
$content_cells[$i][$ci] .= ' <option value="'. $cfg['ColumnTypes'][$j] . '"';
|
||||
if (strtoupper($type) == strtoupper($cfg['ColumnTypes'][$j])) {
|
||||
@@ -161,6 +265,11 @@ for ($i = 0 ; $i < $num_fields; $i++) {
|
||||
if ($zerofill) {
|
||||
$strAttribute = 'UNSIGNED ZEROFILL';
|
||||
}
|
||||
|
||||
if (isset($submit_attribute) && $submit_attribute != FALSE) {
|
||||
$strAttribute = $submit_attribute;
|
||||
}
|
||||
|
||||
for ($j = 0;$j < count($cfg['AttributeTypes']); $j++) {
|
||||
$content_cells[$i][3] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
|
||||
if (strtoupper($strAttribute) == strtoupper($cfg['AttributeTypes'][$j])) {
|
||||
@@ -174,7 +283,7 @@ for ($i = 0 ; $i < $num_fields; $i++) {
|
||||
|
||||
$content_cells[$i][$ci] = '<select name="field_null[]" id="field_' . $i . '_5">';
|
||||
|
||||
if (!isset($row) || empty($row['Null'])) {
|
||||
if ((!isset($row) || empty($row['Null']) || $row['Null'] == 'NOT NULL') && $submit_null == FALSE) {
|
||||
$content_cells[$i][$ci] .= "\n";
|
||||
$content_cells[$i][$ci] .= ' <option value="NOT NULL">not null</option>' . "\n";
|
||||
$content_cells[$i][$ci] .= ' <option value="">null</option>' . "\n";
|
||||
@@ -277,7 +386,10 @@ for ($i = 0 ; $i < $num_fields; $i++) {
|
||||
&& empty($checked_index)
|
||||
&& empty($checked_unique)) {
|
||||
$checked_none = ' checked="checked"';
|
||||
} else {
|
||||
$checked_none = '';
|
||||
}
|
||||
|
||||
if (PMA_MYSQL_INT_VERSION >= 32323
|
||||
&&(isset($row) && isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) {
|
||||
$checked_fulltext = ' checked="checked"';
|
||||
@@ -384,7 +496,7 @@ if ($action == 'tbl_create.php3' && PMA_MYSQL_INT_VERSION >= 32300) {
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" name="comment" size="40" maxlength="80" class="textfield" />
|
||||
<input type="text" name="comment" size="40" maxlength="80" value="<?php echo (isset($comment) ? $comment : ''); ?>" class="textfield" />
|
||||
</td>
|
||||
<?php
|
||||
// BEGIN - Table Type - 2 May 2001 - Robbat2
|
||||
@@ -428,14 +540,14 @@ if ($action == 'tbl_create.php3' && PMA_MYSQL_INT_VERSION >= 32300) {
|
||||
<td width="25"> </td>
|
||||
<td>
|
||||
<select name="tbl_type">
|
||||
<option value="Default"><?php echo $strDefault; ?></option>
|
||||
<option value="MYISAM">MyISAM</option>
|
||||
<option value="HEAP">Heap</option>
|
||||
<option value="MERGE">Merge</option>
|
||||
<?php if (isset($tbl_bdb)) { ?><option value="BDB">Berkeley DB</option><?php } ?>
|
||||
<?php if (isset($tbl_gemini)) { ?><option value="GEMINI">Gemini</option><?php } ?>
|
||||
<?php if (isset($tbl_innodb)) { ?><option value="InnoDB">INNO DB</option><?php } ?>
|
||||
<?php if (isset($tbl_isam)) { ?><option value="ISAM">ISAM</option><?php } ?>
|
||||
<option <?php echo (isset($tbl_type) && $tbl_type == 'Default' ? 'selected="checked"' : ''); ?> value="Default"><?php echo $strDefault; ?></option>
|
||||
<option <?php echo (isset($tbl_type) && $tbl_type == 'MYISAM' ? 'selected="checked"' : ''); ?> value="MYISAM">MyISAM</option>
|
||||
<option <?php echo (isset($tbl_type) && $tbl_type == 'HEAP' ? 'selected="checked"' : ''); ?> value="HEAP">Heap</option>
|
||||
<option <?php echo (isset($tbl_type) && $tbl_type == 'MERGE' ? 'selected="checked"' : ''); ?> value="MERGE">Merge</option>
|
||||
<?php if (isset($tbl_bdb)) { ?><option <?php echo (isset($tbl_type) && $tbl_type == 'BDB' ? 'selected="checked"' : ''); ?> value="BDB">Berkeley DB</option><?php } ?>
|
||||
<?php if (isset($tbl_gemini)) { ?><option <?php echo (isset($tbl_type) && $tbl_type == 'GEMINI' ? 'selected="checked"' : ''); ?> value="GEMINI">Gemini</option><?php } ?>
|
||||
<?php if (isset($tbl_innodb)) { ?><option <?php echo (isset($tbl_type) && $tbl_type == 'INNO DB' ? 'selected="checked"' : ''); ?> value="InnoDB">INNO DB</option><?php } ?>
|
||||
<?php if (isset($tbl_isam)) { ?><option <?php echo (isset($tbl_type) && $tbl_type == 'ISAM' ? 'selected="checked"' : ''); ?> value="ISAM">ISAM</option><?php } ?>
|
||||
</select>
|
||||
</td>
|
||||
<?php
|
||||
|
Reference in New Issue
Block a user