2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 require_once './libraries/common.inc.php';
13 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.16.custom.js';
14 $GLOBALS['js_include'][] = 'db_structure.js';
15 $GLOBALS['js_include'][] = 'tbl_change.js';
16 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
17 $GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
20 * Prepares the tables list if the user where not redirected to this script
21 * because there is no table in the database ($is_info is true)
23 if (empty($is_info)) {
24 // Drops/deletes/etc. multiple tables if required
25 if ((!empty($submit_mult) && isset($selected_tbl))
28 $action = 'db_structure.php';
29 $err_url = 'db_structure.php?'. PMA_generate_common_url($db);
31 // see bug #2794840; in this case, code path is:
32 // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
33 // -> db_structure.php and if we got an error on the multi submit,
34 // we must display it here and not call again mult_submits.inc.php
35 if (! isset($error) ||
false === $error) {
36 include './libraries/mult_submits.inc.php';
38 if (empty($message)) {
39 $message = PMA_Message
::success();
42 include './libraries/db_common.inc.php';
43 $url_query .= '&goto=db_structure.php';
45 // Gets the database structure
46 $sub_part = '_structure';
47 include './libraries/db_info.inc.php';
50 include_once './libraries/replication.inc.php';
52 $server_slave_status = false;
56 require_once './libraries/bookmark.lib.php';
58 require_once './libraries/mysql_charsets.lib.php';
59 $db_collation = PMA_getDbCollation($db);
61 // in a separate file to avoid redeclaration of functions in some code paths
62 require_once './libraries/db_structure.lib.php';
63 $titles = PMA_buildActionTitles();
67 if ($num_tables == 0) {
68 echo '<p>' . __('No tables found in database') . '</p>' . "\n";
70 if (empty($db_is_information_schema)) {
71 include './libraries/display_create_table.lib.php';
72 } // end if (Create Table dialog)
77 include_once './libraries/footer.inc.php';
82 // 2. Shows table informations
85 * Displays the tables list
87 echo '<div id="tableslistcontainer">';
92 // Add the sort options if they exists
93 if (isset($_REQUEST['sort'])) {
94 $_url_params['sort'] = $_REQUEST['sort'];
97 if (isset($_REQUEST['sort_order'])) {
98 $_url_params['sort_order'] = $_REQUEST['sort_order'];
102 $total_num_tables, $pos, $_url_params, 'db_structure.php',
103 'frame_content', $GLOBALS['cfg']['MaxTableList']
107 <form method
="post" action
="db_structure.php" name
="tablesForm" id
="tablesForm">
109 echo PMA_generate_common_hidden_inputs($db);
111 PMA_TableHeader($db_is_information_schema, $server_slave_status);
113 $i = $sum_entries = 0;
114 $sum_size = (double) 0;
115 $overhead_size = (double) 0;
116 $overhead_check = '';
117 $checked = !empty($checkall) ?
' checked="checked"' : '';
118 $num_columns = $cfg['PropertiesNumColumns'] > 1
119 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1
124 $hidden_fields = array();
126 $sum_row_count_pre = '';
128 $tableReductionCount = 0; // the amount to reduce the table count by
130 foreach ($tables as $keyname => $each_table) {
131 if (PMA_BS_IsHiddenTable($keyname)) {
132 $tableReductionCount++
;
136 // Get valid statistics whatever is the table type
138 $table_is_view = false;
139 $table_encoded = urlencode($each_table['TABLE_NAME']);
140 // Sets parameters for links
141 $tbl_url_query = $url_query . '&table=' . $table_encoded;
142 // do not list the previous table's size info for a view
143 $formatted_size = '-';
146 switch ( $each_table['ENGINE']) {
147 // MyISAM, ISAM or Heap table: Row count, data size and index size
148 // are accurate; data size is accurate for ARCHIVE
156 if ($db_is_information_schema) {
157 $each_table['Rows'] = PMA_Table
::countRecords(
158 $db, $each_table['Name']
162 if ($is_show_stats) {
163 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
164 $sum_size +
= $tblsize;
165 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
166 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
167 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
168 $overhead_size +
= $each_table['Data_free'];
174 // InnoDB table: Row count is not accurate but data and index sizes are.
175 // PBMS table in Drizzle: TABLE_ROWS is taken from table cache, so it may be unavailable
177 if (($each_table['ENGINE'] == 'InnoDB'
178 && $each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount'])
179 ||
!isset($each_table['TABLE_ROWS'])
181 $each_table['COUNTED'] = true;
182 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords(
183 $db, $each_table['TABLE_NAME'],
184 $force_exact = true, $is_view = false
187 $each_table['COUNTED'] = false;
190 // Drizzle doesn't provide data and index length, check for null
191 if ($is_show_stats && $each_table['Data_length'] !== null) {
192 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
193 $sum_size +
= $tblsize;
194 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
196 //$display_rows = ' - ';
198 // Mysql 5.0.x (and lower) uses MRG_MyISAM and MySQL 5.1.x (and higher) uses MRG_MYISAM
199 // Both are aliases for MERGE
204 // Merge or BerkleyDB table: Only row count is accurate.
205 if ($is_show_stats) {
206 $formatted_size = ' - ';
210 // for a view, the ENGINE is sometimes reported as null,
211 // or on some servers it's reported as "SYSTEM VIEW"
214 case 'FunctionEngine' :
215 // if table is broken, Engine is reported as null, so one more test
216 if ($each_table['TABLE_TYPE'] == 'VIEW') {
217 // countRecords() takes care of $cfg['MaxExactCountViews']
218 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords(
219 $db, $each_table['TABLE_NAME'],
220 $force_exact = true, $is_view = true
222 $table_is_view = true;
226 // Unknown table type.
227 if ($is_show_stats) {
228 $formatted_size = 'unknown';
233 if (! PMA_Table
::isMerge($db, $each_table['TABLE_NAME'])) {
234 $sum_entries +
= $each_table['TABLE_ROWS'];
237 if (isset($each_table['Collation'])) {
238 $collation = '<dfn title="'
239 . PMA_getCollationDescr($each_table['Collation']) . '">'
240 . $each_table['Collation'] . '</dfn>';
245 if ($is_show_stats) {
246 if (isset($formatted_overhead)) {
247 $overhead = '<a href="tbl_structure.php?'
248 . $tbl_url_query . '#showusage"><span>' . $formatted_overhead
249 . '</span> <span class="unit">' . $overhead_unit . '</span></a>' . "\n";
250 unset($formatted_overhead);
252 "document.getElementById('checkbox_tbl_" . ($i +
1) . "').checked = true;";
258 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
259 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
260 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
261 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
262 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
263 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
268 if ($table_is_view) {
269 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
270 . htmlspecialchars($each_table['TABLE_NAME']) . '" />';
274 * Always activate links for Browse, Search and Empty, even if
275 * the icons are greyed, because
276 * 1. for views, we don't know the number of rows at this point
277 * 2. for tables, another source could have populated them since the
280 * I could have used the PHP ternary conditional operator but I find
281 * the code easier to read without this operator.
283 if ($each_table['TABLE_ROWS'] > 0 ||
$table_is_view) {
284 $may_have_rows = true;
286 $may_have_rows = false;
288 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">';
289 if ($may_have_rows) {
290 $browse_table .= $titles['Browse'];
292 $browse_table .= $titles['NoBrowse'];
294 $browse_table .= '</a>';
296 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">';
297 if ($may_have_rows) {
298 $search_table .= $titles['Search'];
300 $search_table .= $titles['NoSearch'];
302 $search_table .= '</a>';
304 $browse_table_label = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $truename . '</a>';
306 if (! $db_is_information_schema) {
307 $empty_table = '<a ';
308 if ($GLOBALS['cfg']['AjaxEnable']) {
309 $empty_table .= 'class="truncate_table_anchor"';
311 $empty_table .= ' href="sql.php?' . $tbl_url_query
313 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
314 . '&message_to_show='
315 . urlencode(sprintf(__('Table %s has been emptied'), htmlspecialchars($each_table['TABLE_NAME'])))
317 if ($may_have_rows) {
318 $empty_table .= $titles['Empty'];
320 $empty_table .= $titles['NoEmpty'];
322 $empty_table .= '</a>';
324 $drop_query = 'DROP '
325 . ($table_is_view ?
'VIEW' : 'TABLE')
326 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
327 $drop_message = sprintf(
328 $table_is_view ?
__('View %s has been dropped') : __('Table %s has been dropped'),
329 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']))
334 if (PMA_Tracker
::isActive()) {
335 if (PMA_Tracker
::isTracked($GLOBALS["db"], $truename)) {
336 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query
337 . '&table=' . $truename . '">'
338 . PMA_getImage('eye.png', __('Tracking is active.'))
340 } elseif (PMA_Tracker
::getVersion($GLOBALS["db"], $truename) > 0) {
341 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query
342 . '&table=' . $truename . '">'
343 . PMA_getImage('eye.png', __('Tracking is not active.'))
349 && $num_tables > $num_columns
350 && ($row_count %
$num_columns) == 0
359 PMA_TableHeader(false, $server_slave_status);
365 if ($server_slave_status) {
366 ////////////////////////////////////////////////////////////////
368 if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
369 ||
(strlen(array_search($db, $server_slave_Do_DB)) > 0)
370 ||
(count($server_slave_Do_DB) == 1 && count($server_slave_Ignore_DB) == 1)
374 foreach ($server_slave_Wild_Do_Table as $db_table) {
375 $table_part = PMA_extract_db_or_table($db_table, 'table');
376 if (($db == PMA_extract_db_or_table($db_table, 'db'))
377 && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))
382 ////////////////////////////////////////////////////////////////////
383 if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0)
384 ||
(strlen(array_search($db, $server_slave_Ignore_DB)) > 0)
388 foreach ($server_slave_Wild_Ignore_Table as $db_table) {
389 $table_part = PMA_extract_db_or_table($db_table, 'table');
390 if (($db == PMA_extract_db_or_table($db_table))
391 && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))
399 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
401 <input type
="checkbox" name
="selected_tbl[]"
402 value
="<?php echo htmlspecialchars($each_table['TABLE_NAME']); ?>"
403 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
404 <th
><?php
echo $browse_table_label; ?
>
405 <?php
echo (! empty($tracking_icon) ?
$tracking_icon : ''); ?
>
407 <?php
if ($server_slave_status) { ?
><td align
="center"><?php
409 ?
PMA_getImage('s_cancel.png', 'NOT REPLICATED')
412 ?
PMA_getImage('s_success.png', 'REPLICATED')
413 : ''; ?
></td
><?php
} ?
>
414 <td align
="center"><?php
echo $browse_table; ?
></td
>
416 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
417 <?php
echo $titles['Structure']; ?
></a
></td
>
418 <td align
="center"><?php
echo $search_table; ?
></td
>
419 <?php
if (! $db_is_information_schema) { ?
>
420 <td align
="center" class="insert_table">
421 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="ajax"' : ''); ?
> href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
422 <?php
echo $titles['Insert']; ?
></a
></td
>
423 <td align
="center"><?php
echo $empty_table; ?
></td
>
425 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="drop_table_anchor"' : ''); ?
> href
="sql.php?<?php echo $tbl_url_query;
426 ?>&reload=1&purge=1&sql_query=<?php
427 echo urlencode($drop_query); ?>&message_to_show=<?php
428 echo urlencode($drop_message); ?>" >
429 <?php
echo $titles['Drop']; ?
></a
></td
>
430 <?php
} // end if (! $db_is_information_schema)
432 // there is a null value in the ENGINE
433 // - when the table needs to be repaired, or
434 // - when it's a view
435 // so ensure that we'll display "in use" below for a table
436 // that needs to be repaired
437 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
439 $show_superscript = '';
440 if ($table_is_view) {
441 // Drizzle views use FunctionEngine, and the only place where they are available are I_S and D_D
442 // schemas, where we do exact counting
443 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']
444 && $each_table['ENGINE'] != 'FunctionEngine'
446 $row_count_pre = '~';
447 $sum_row_count_pre = '~';
448 $show_superscript = PMA_showHint(
451 __('This view has at least this number of rows. Please refer to %sdocumentation%s.'),
452 '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]',
458 } elseif ($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
459 // InnoDB table: we did not get an accurate row count
460 $row_count_pre = '~';
461 $sum_row_count_pre = '~';
462 $show_superscript = '';
465 <td
class="value tbl_rows"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
466 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
467 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
__('View') : $each_table['ENGINE']); ?
></td
>
468 <?php
if (isset($collation)) { ?
>
469 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
473 <?php
if ($is_show_stats) { ?
>
474 <td
class="value tbl_size"><a
475 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
476 ><?php
echo '<span>' . $formatted_size . '</span> <span class="unit">' . $unit . '</span>'; ?
></a
></td
>
477 <td
class="value tbl_overhead"><?php
echo $overhead; ?
></td
>
479 <?php
} elseif ($table_is_view) { ?
>
480 <td
class="value">-</td
>
481 <td
><?php
echo __('View'); ?
></td
>
483 <?php
if ($is_show_stats) { ?
>
484 <td
class="value">-</td
>
485 <td
class="value">-</td
>
488 <td colspan
="<?php echo ($colspan_for_structure - ($db_is_information_schema ? 5 : 8)) ?>"
490 <?php
echo __('in use'); ?
></td
>
491 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
497 if ($is_show_stats) {
498 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
499 list($overhead_formatted, $overhead_unit)
500 = PMA_formatByteDown($overhead_size, 3, 1);
504 <tbody id
="tbl_summary_row">
506 <th align
="center" nowrap
="nowrap" class="tbl_num">
508 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
509 // (we don't want negative numbers here)
510 if ($num_tables == 0) {
511 $tableReductionCount = 0;
514 _ngettext('%s table', '%s tables', $num_tables - $tableReductionCount),
515 PMA_formatNumber($num_tables - $tableReductionCount, 0)
520 if ($server_slave_status) {
521 echo ' <th>' . __('Replication') . '</th>' . "\n";
524 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
525 <?php
echo __('Sum'); ?
></th
>
526 <th
class="value tbl_rows"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
528 if (!($cfg['PropertiesNumColumns'] > 1)) {
529 $default_engine = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'storage_engine\';', 0, 1);
530 echo ' <th align="center">' . "\n"
532 . sprintf(__('%s is the default storage engine on this MySQL server.'), $default_engine)
533 . '">' .$default_engine . '</dfn></th>' . "\n";
534 // we got a case where $db_collation was empty
535 echo ' <th align="center">' . "\n";
536 if (! empty($db_collation)) {
538 . PMA_getCollationDescr($db_collation) . ' (' . __('Default') . ')">' . $db_collation
544 if ($is_show_stats) {
546 <th
class="value tbl_size"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
547 <th
class="value tbl_overhead"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
555 <div
class="clearfloat">
557 // Check all tables url
558 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
560 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
561 width
="38" height
="22" alt
="<?php echo __('With selected:'); ?>" />
562 <a href
="<?php echo $checkall_url; ?>&checkall=1"
563 onclick
="if (markAllRows('tablesForm')) return false;">
564 <?php
echo __('Check All'); ?
></a
>
566 <a href
="<?php echo $checkall_url; ?>"
567 onclick
="if (unMarkAllRows('tablesForm')) return false;">
568 <?php
echo __('Uncheck All'); ?
></a
>
569 <?php
if ($overhead_check != '') { ?
>
571 <a href
="#" onclick
="unMarkAllRows('tablesForm');
572 <?php echo $overhead_check; ?> return false;">
573 <?php
echo __('Check tables having overhead'); ?
></a
>
576 <select name
="submit_mult" class="autosubmit" style
="margin: 0 3em 0 3em;">
578 echo ' <option value="' . __('With selected:') . '" selected="selected">'
579 . __('With selected:') . '</option>' . "\n";
580 echo ' <option value="export" >'
581 . __('Export') . '</option>' . "\n";
582 echo ' <option value="print" >'
583 . __('Print view') . '</option>' . "\n";
585 if (!$db_is_information_schema && !$cfg['DisableMultiTableMaintenance']) {
586 echo ' <option value="empty_tbl" >'
587 . __('Empty') . '</option>' . "\n";
588 echo ' <option value="drop_tbl" >'
589 . __('Drop') . '</option>' . "\n";
590 echo ' <option value="check_tbl" >'
591 . __('Check table') . '</option>' . "\n";
593 echo ' <option value="optimize_tbl" >'
594 . __('Optimize table') . '</option>' . "\n";
595 echo ' <option value="repair_tbl" >'
596 . __('Repair table') . '</option>' . "\n";
598 echo ' <option value="analyze_tbl" >'
599 . __('Analyze table') . '</option>' . "\n";
600 echo ' <option value="add_prefix_tbl" >'
601 . __('Add prefix to table') . '</option>' . "\n";
602 echo ' <option value="replace_prefix_tbl" >'
603 . __('Replace table prefix') . '</option>' . "\n";
604 echo ' <option value="copy_tbl_change_prefix" >'
605 . __('Copy table with prefix') . '</option>' . "\n";
609 <script type
="text/javascript">
611 // Fake js to allow the use of the <noscript> tag
615 <input type
="submit" value
="<?php echo __('Go'); ?>" />
617 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
621 // display again the table list navigator
623 $total_num_tables, $pos, $_url_params, 'db_structure.php',
624 'frame_content', $GLOBALS['cfg']['MaxTableList']
633 * Work on the database
636 /* Printable view of a table */
638 echo '<a href="db_printview.php?' . $url_query . '">';
639 echo PMA_getIcon('b_print.png', __('Print view'), true) . '</a>';
641 echo '<a href="./db_datadict.php?' . $url_query . '">';
642 echo PMA_getIcon('b_tblanalyse.png', __('Data Dictionary'), true) . '</a>';
645 if (empty($db_is_information_schema)) {
646 include './libraries/display_create_table.lib.php';
647 } // end if (Create Table dialog)
650 * Displays the footer
652 require './libraries/footer.inc.php';