Fixed bug #3408377 - Deleting table from the DB does not change the table counter

This commit is contained in:
asdfrede 2011-12-02 00:48:19 +00:00 committed by Rouslan Placella
parent 14b9e4cfa3
commit d39a230992
6 changed files with 112 additions and 37 deletions

View File

@ -61,6 +61,7 @@ phpMyAdmin - ChangeLog
+ patch #3432835 [interface] Add useful intermediate pages to pageselector
+ [interface] Improved index editor
+ View editing via a generated ALTER VIEW
- bug #3408377 [interface] Deleting table from the DB does not change the table counter
3.4.9.0 (not yet released)
- bug #3442028 [edit] Inline editing enum fields with null shows no dropdown

View File

@ -14,6 +14,7 @@ $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.16.custom.js';
$GLOBALS['js_include'][] = 'db_structure.js';
$GLOBALS['js_include'][] = 'tbl_change.js';
$GLOBALS['js_include'][] = 'jquery/timepicker.js';
$GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
/**
* Prepares the tables list if the user where not redirected to this script
@ -244,8 +245,8 @@ foreach ($tables as $keyname => $each_table) {
if ($is_show_stats) {
if (isset($formatted_overhead)) {
$overhead = '<a href="tbl_structure.php?'
. $tbl_url_query . '#showusage">' . $formatted_overhead
. ' ' . $overhead_unit . '</a>' . "\n";
. $tbl_url_query . '#showusage"><span>' . $formatted_overhead
. '</span> <span class="unit">' . $overhead_unit . '</span></a>' . "\n";
unset($formatted_overhead);
$overhead_check .=
"document.getElementById('checkbox_tbl_" . ($i + 1) . "').checked = true;";
@ -472,8 +473,8 @@ foreach ($tables as $keyname => $each_table) {
<?php if ($is_show_stats) { ?>
<td class="value tbl_size"><a
href="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
><?php echo $formatted_size . ' ' . $unit; ?></a></td>
<td class="value"><?php echo $overhead; ?></td>
><?php echo '<span>' . $formatted_size . '</span> <span class="unit">' . $unit . '</span>'; ?></a></td>
<td class="value tbl_overhead"><?php echo $overhead; ?></td>
<?php } // end if ?>
<?php } elseif ($table_is_view) { ?>
<td class="value">-</td>
@ -502,7 +503,7 @@ if ($is_show_stats) {
</tbody>
<tbody id="tbl_summary_row">
<tr><th></th>
<th align="center" nowrap="nowrap">
<th align="center" nowrap="nowrap" class="tbl_num">
<?php
// for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
// (we don't want negative numbers here)
@ -543,7 +544,7 @@ if (!($cfg['PropertiesNumColumns'] > 1)) {
if ($is_show_stats) {
?>
<th class="value tbl_size"><?php echo $sum_formatted . ' ' . $unit; ?></th>
<th class="value"><?php echo $overhead_formatted . ' ' . $overhead_unit; ?></th>
<th class="value tbl_overhead"><?php echo $overhead_formatted . ' ' . $overhead_unit; ?></th>
<?php
}
?>

View File

@ -20,35 +20,90 @@
/**
* Adjust number of rows and total size in the summary
* when emptying or dropping a table
*
* @param jQuery object $this_anchor
* when truncating, creating, dropping or inserting into a table
*/
function PMA_adjustTotals($this_anchor)
{
var $parent_tr = $this_anchor.closest('tr');
var $rows_td = $parent_tr.find('.tbl_rows');
var $size_td = $parent_tr.find('.tbl_size');
var num_rows = parseInt($rows_td.text());
// set number of rows to 0
// (not really needed in case we are dropping the table)
$rows_td.text('0');
// set size to unknown (not sure how to get the exact
// value here, as an empty InnoDB table would have a size)
$size_td.text('-');
// try to compute a new total row number
if (! isNaN(num_rows)) {
$total_rows_td = $('#tbl_summary_row').find('.tbl_rows');
var total_rows = parseInt($total_rows_td.text());
if (! isNaN(total_rows)) {
$total_rows_td.text(total_rows - num_rows);
function PMA_adjustTotals() {
var byteUnits = new Array(
PMA_messages['strB'],
PMA_messages['strKiB'],
PMA_messages['strMiB'],
PMA_messages['strGiB'],
PMA_messages['strTiB'],
PMA_messages['strPiB'],
PMA_messages['strEiB']
);
/**
* @var $allTr jQuery object that references all the rows in the list of tables
*/
var $allTr = $("#tablesForm table.data tbody:first tr");
// New summary values for the table
var tableSum = $allTr.size();
var rowsSum = 0;
var sizeSum = 0;
var overheadSum = 0;
$allTr.each(function () {
var $this = $(this);
// Get the number of rows for this SQL table
var strRows = $this.find('.tbl_rows').text();
strRows = strRows.replace(/[,.]/g , '');
var intRow = parseInt(strRows, 10);
if (! isNaN(intRow)) {
rowsSum += intRow;
}
// Extract the size and overhead
var valSize = 0;
var valOverhead = 0;
var strSize = $.trim($this.find('.tbl_size span:not(.unit)').text());
var strSizeUnit = $.trim($this.find('.tbl_size span.unit').text());
var strOverhead = $.trim($this.find('.tbl_overhead span:not(.unit)').text());
var strOverheadUnit = $.trim($this.find('.tbl_overhead span.unit').text());
// Given a value and a unit, such as 100 and KiB, for the table size
// and overhead calculate their numeric values in bytes, such as 102400
for (var i = 0; i < byteUnits.length; i++) {
if (strSizeUnit == byteUnits[i]) {
var tmpVal = parseFloat(strSize);
valSize = tmpVal * Math.pow(1024, i);
break;
}
}
for (var i = 0; i < byteUnits.length; i++) {
if (strOverheadUnit == byteUnits[i]) {
var tmpVal = parseFloat(strOverhead);
valOverhead = tmpVal * Math.pow(1024, i);
break;
}
}
sizeSum += valSize;
overheadSum += valOverhead;
});
// Add some commas for readablility:
// 1000000 becomes 1,000,000
var strRowSum = rowsSum + "";
var regex = /(\d+)(\d{3})/;
while (regex.test(strRowSum)) {
strRowSum = strRowSum.replace(regex, '$1' + ',' + '$2');
}
// Calculate the magnitude for the size and overhead values
var size_magnitude = 0, overhead_magnitude = 0;
while (sizeSum >= 1024) {
sizeSum /= 1024;
size_magnitude++;
}
while (overheadSum >= 1024) {
overheadSum /= 1024;
overhead_magnitude++;
}
// prefix total size with "~"
var $total_size_td = $('#tbl_summary_row').find('.tbl_size');
$total_size_td.text($total_size_td.text().replace(/^/,'~'));
sizeSum = Math.round(sizeSum * 10) / 10;
overheadSum = Math.round(overheadSum * 10) / 10;
// Update summary with new data
var $summary = $("#tbl_summary_row");
$summary.find('.tbl_num').text($.sprintf(PMA_messages['strTables'], tableSum));
$summary.find('.tbl_rows').text(strRowSum);
$summary.find('.tbl_size').text(sizeSum + " " + byteUnits[size_magnitude]);
$summary.find('.tbl_overhead').text(overheadSum + " " + byteUnits[overhead_magnitude]);
}
$(document).ready(function() {
@ -146,6 +201,7 @@ $(document).ready(function() {
}
/**Update the row count at the tableForm*/
current_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
PMA_adjustTotals();
}) // end $.post()
}) // end insert table button "Go"
@ -182,6 +238,7 @@ $(document).ready(function() {
}
/**Update the row count at the tableForm*/
current_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
PMA_adjustTotals();
}) // end $.post()
});
@ -217,16 +274,19 @@ $(document).ready(function() {
$.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
if (data.success == true) {
PMA_ajaxShowMessage(data.message);
// Adjust table statistics
var $tr = $this_anchor.closest('tr');
$tr.find('.tbl_rows').text('0');
$tr.find('.tbl_size, .tbl_overhead').text('-');
//Fetch inner span of this anchor
//and replace the icon with its disabled version
var span = $this_anchor.html().replace(/b_empty/, 'bd_empty');
PMA_adjustTotals($this_anchor);
//To disable further attempts to truncate the table,
//replace the a element with its inner span (modified)
$this_anchor
.replaceWith(span)
.removeClass('truncate_table_anchor');
PMA_adjustTotals();
} else {
PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error, false);
}
@ -267,8 +327,8 @@ $(document).ready(function() {
$.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
if (data.success == true) {
PMA_ajaxShowMessage(data.message);
PMA_adjustTotals($this_anchor);
$curr_row.hide("medium").remove();
PMA_adjustTotals();
if (window.parent && window.parent.frame_navigation) {
window.parent.frame_navigation.location.reload();

View File

@ -2131,6 +2131,9 @@ $(document).ready(function() {
//Sort the table
$(tables_table).PMA_sort_table('th');
// Adjust summary row
PMA_adjustTotals();
}
//Refresh navigation frame as a new table has been added

View File

@ -121,6 +121,16 @@ $js_messages['strBytesReceived'] = __('Bytes received');
$js_messages['strConnections'] = __('Connections');
$js_messages['strProcesses'] = __('Processes');
/* summary row */
$js_messages['strB'] = __('B');
$js_messages['strKiB'] = __('KiB');
$js_messages['strMiB'] = __('MiB');
$js_messages['strGiB'] = __('GiB');
$js_messages['strTiB'] = __('TiB');
$js_messages['strPiB'] = __('PiB');
$js_messages['strEiB'] = __('EiB');
$js_messages['strTables'] = __('%d table(s)');
/* l10n: Questions is the name of a MySQL Status variable */
$js_messages['strQuestions'] = __('Questions');
$js_messages['strTraffic'] = __('Traffic');

View File

@ -261,7 +261,7 @@ if (isset($_REQUEST['do_save_data'])) {
}
if (isset($formatted_overhead)) {
$overhead = $formatted_overhead . ' ' . $overhead_unit;
$overhead = '<span>' . $formatted_overhead . '</span> <span class="unit">' . $overhead_unit . '</span>';
unset($formatted_overhead);
} else {
$overhead = '-';
@ -310,8 +310,8 @@ if (isset($_REQUEST['do_save_data'])) {
$new_table_string .= '<td> <dfn title="' . PMA_getCollationDescr($tbl_stats['Collation']) . '">'. $tbl_stats['Collation'] .'</dfn></td>' . "\n";
if ($is_show_stats) {
$new_table_string .= '<td class="value"> <a href="tbl_structure.php' . PMA_generate_common_url($tbl_url_params) . '#showusage" >' . $formatted_size . ' ' . $unit . '</a> </td>' . "\n" ;
$new_table_string .= '<td class="value">' . $overhead . '</td>' . "\n" ;
$new_table_string .= '<td class="value tbl_size"> <a href="tbl_structure.php' . PMA_generate_common_url($tbl_url_params) . '#showusage" ><span>' . $formatted_size . '</span> <span class="unit">' . $unit . '</class></a> </td>' . "\n" ;
$new_table_string .= '<td class="value tbl_overhead">' . $overhead . '</td>' . "\n" ;
}
$new_table_string .= '</tr>' . "\n";