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';
19 * Prepares the tables list if the user where not redirected to this script
20 * because there is no table in the database ($is_info is true)
22 if (empty($is_info)) {
23 // Drops/deletes/etc. multiple tables if required
24 if ((!empty($submit_mult) && isset($selected_tbl))
27 $action = 'db_structure.php';
28 $err_url = 'db_structure.php?'. PMA_generate_common_url($db);
30 // see bug #2794840; in this case, code path is:
31 // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
32 // -> db_structure.php and if we got an error on the multi submit,
33 // we must display it here and not call again mult_submits.inc.php
34 if (! isset($error) ||
false === $error) {
35 include './libraries/mult_submits.inc.php';
37 if (empty($message)) {
38 $message = PMA_Message
::success();
41 include './libraries/db_common.inc.php';
42 $url_query .= '&goto=db_structure.php';
44 // Gets the database structure
45 $sub_part = '_structure';
46 include './libraries/db_info.inc.php';
49 include './libraries/replication.inc.php';
51 $server_slave_status = false;
55 require_once './libraries/bookmark.lib.php';
57 require_once './libraries/mysql_charsets.lib.php';
58 $db_collation = PMA_getDbCollation($db);
60 // in a separate file to avoid redeclaration of functions in some code paths
61 require_once './libraries/db_structure.lib.php';
62 $titles = PMA_buildActionTitles();
66 if ($num_tables == 0) {
67 echo '<p>' . __('No tables found in database') . '</p>' . "\n";
69 if (empty($db_is_information_schema)) {
70 include './libraries/display_create_table.lib.php';
71 } // end if (Create Table dialog)
76 include_once './libraries/footer.inc.php';
81 // 2. Shows table informations
84 * Displays the tables list
86 echo '<div id="tableslistcontainer">';
91 // Add the sort options if they exists
92 if (isset($_REQUEST['sort'])) {
93 $_url_params['sort'] = $_REQUEST['sort'];
96 if (isset($_REQUEST['sort_order'])) {
97 $_url_params['sort_order'] = $_REQUEST['sort_order'];
101 $total_num_tables, $pos, $_url_params, 'db_structure.php',
102 'frame_content', $GLOBALS['cfg']['MaxTableList']
106 <form method
="post" action
="db_structure.php" name
="tablesForm" id
="tablesForm">
108 echo PMA_generate_common_hidden_inputs($db);
110 PMA_TableHeader($db_is_information_schema, $server_slave_status);
112 $i = $sum_entries = 0;
113 $sum_size = (double) 0;
114 $overhead_size = (double) 0;
115 $overhead_check = '';
116 $checked = !empty($checkall) ?
' checked="checked"' : '';
117 $num_columns = $cfg['PropertiesNumColumns'] > 1
118 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1
123 $hidden_fields = array();
125 $sum_row_count_pre = '';
127 $tableReductionCount = 0; // the amount to reduce the table count by
129 foreach ($tables as $keyname => $each_table) {
130 if (PMA_BS_IsHiddenTable($keyname)) {
131 $tableReductionCount++
;
135 // Get valid statistics whatever is the table type
137 $table_is_view = false;
138 $table_encoded = urlencode($each_table['TABLE_NAME']);
139 // Sets parameters for links
140 $tbl_url_query = $url_query . '&table=' . $table_encoded;
141 // do not list the previous table's size info for a view
142 $formatted_size = '-';
145 switch ( $each_table['ENGINE']) {
146 // MyISAM, ISAM or Heap table: Row count, data size and index size
147 // are accurate; data size is accurate for ARCHIVE
155 if ($db_is_information_schema) {
156 $each_table['Rows'] = PMA_Table
::countRecords(
157 $db, $each_table['Name']
161 if ($is_show_stats) {
162 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
163 $sum_size +
= $tblsize;
164 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
165 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
166 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
167 $overhead_size +
= $each_table['Data_free'];
173 // InnoDB table: Row count is not accurate but data and index sizes are.
174 // PBMS table in Drizzle: TABLE_ROWS is taken from table cache, so it may be unavailable
176 if (($each_table['ENGINE'] == 'InnoDB'
177 && $each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount'])
178 ||
!isset($each_table['TABLE_ROWS'])
180 $each_table['COUNTED'] = true;
181 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords(
182 $db, $each_table['TABLE_NAME'],
183 $force_exact = true, $is_view = false
186 $each_table['COUNTED'] = false;
189 // Drizzle doesn't provide data and index length, check for null
190 if ($is_show_stats && $each_table['Data_length'] !== null) {
191 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
192 $sum_size +
= $tblsize;
193 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
195 //$display_rows = ' - ';
197 // Mysql 5.0.x (and lower) uses MRG_MyISAM and MySQL 5.1.x (and higher) uses MRG_MYISAM
198 // Both are aliases for MERGE
203 // Merge or BerkleyDB table: Only row count is accurate.
204 if ($is_show_stats) {
205 $formatted_size = ' - ';
209 // for a view, the ENGINE is sometimes reported as null,
210 // or on some servers it's reported as "SYSTEM VIEW"
213 case 'FunctionEngine' :
214 // if table is broken, Engine is reported as null, so one more test
215 if ($each_table['TABLE_TYPE'] == 'VIEW') {
216 // countRecords() takes care of $cfg['MaxExactCountViews']
217 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords(
218 $db, $each_table['TABLE_NAME'],
219 $force_exact = true, $is_view = true
221 $table_is_view = true;
225 // Unknown table type.
226 if ($is_show_stats) {
227 $formatted_size = 'unknown';
232 if (! PMA_Table
::isMerge($db, $each_table['TABLE_NAME'])) {
233 $sum_entries +
= $each_table['TABLE_ROWS'];
236 if (isset($each_table['Collation'])) {
237 $collation = '<dfn title="'
238 . PMA_getCollationDescr($each_table['Collation']) . '">'
239 . $each_table['Collation'] . '</dfn>';
244 if ($is_show_stats) {
245 if (isset($formatted_overhead)) {
246 $overhead = '<a href="tbl_structure.php?'
247 . $tbl_url_query . '#showusage">' . $formatted_overhead
248 . ' ' . $overhead_unit . '</a>' . "\n";
249 unset($formatted_overhead);
251 "document.getElementById('checkbox_tbl_" . ($i +
1) . "').checked = true;";
257 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
258 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
259 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
260 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
261 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
262 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
267 if ($table_is_view) {
268 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
269 . htmlspecialchars($each_table['TABLE_NAME']) . '" />';
273 * Always activate links for Browse, Search and Empty, even if
274 * the icons are greyed, because
275 * 1. for views, we don't know the number of rows at this point
276 * 2. for tables, another source could have populated them since the
279 * I could have used the PHP ternary conditional operator but I find
280 * the code easier to read without this operator.
282 if ($each_table['TABLE_ROWS'] > 0 ||
$table_is_view) {
283 $may_have_rows = true;
285 $may_have_rows = false;
287 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">';
288 if ($may_have_rows) {
289 $browse_table .= $titles['Browse'];
291 $browse_table .= $titles['NoBrowse'];
293 $browse_table .= '</a>';
295 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">';
296 if ($may_have_rows) {
297 $search_table .= $titles['Search'];
299 $search_table .= $titles['NoSearch'];
301 $search_table .= '</a>';
303 $browse_table_label = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $truename . '</a>';
305 if (! $db_is_information_schema) {
306 $empty_table = '<a ';
307 if ($GLOBALS['cfg']['AjaxEnable']) {
308 $empty_table .= 'class="truncate_table_anchor"';
310 $empty_table .= ' href="sql.php?' . $tbl_url_query
312 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
313 . '&message_to_show='
314 . urlencode(sprintf(__('Table %s has been emptied'), htmlspecialchars($each_table['TABLE_NAME'])))
316 if ($may_have_rows) {
317 $empty_table .= $titles['Empty'];
319 $empty_table .= $titles['NoEmpty'];
321 $empty_table .= '</a>';
323 $drop_query = 'DROP '
324 . ($table_is_view ?
'VIEW' : 'TABLE')
325 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
326 $drop_message = sprintf(
327 $table_is_view ?
__('View %s has been dropped') : __('Table %s has been dropped'),
328 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']))
333 if (PMA_Tracker
::isActive()) {
334 if (PMA_Tracker
::isTracked($GLOBALS["db"], $truename)) {
335 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query
336 . '&table=' . $truename . '">'
337 . PMA_getImage('eye.png', __('Tracking is active.'))
339 } elseif (PMA_Tracker
::getVersion($GLOBALS["db"], $truename) > 0) {
340 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query
341 . '&table=' . $truename . '">'
342 . PMA_getImage('eye.png', __('Tracking is not active.'))
348 && $num_tables > $num_columns
349 && ($row_count %
$num_columns) == 0
358 PMA_TableHeader(false, $server_slave_status);
364 if ($server_slave_status) {
365 ////////////////////////////////////////////////////////////////
367 if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
368 ||
(strlen(array_search($db, $server_slave_Do_DB)) > 0)
369 ||
(count($server_slave_Do_DB) == 1 && count($server_slave_Ignore_DB) == 1)
373 foreach ($server_slave_Wild_Do_Table as $db_table) {
374 $table_part = PMA_extract_db_or_table($db_table, 'table');
375 if (($db == PMA_extract_db_or_table($db_table, 'db'))
376 && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))
381 ////////////////////////////////////////////////////////////////////
382 if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0)
383 ||
(strlen(array_search($db, $server_slave_Ignore_DB)) > 0)
387 foreach ($server_slave_Wild_Ignore_Table as $db_table) {
388 $table_part = PMA_extract_db_or_table($db_table, 'table');
389 if (($db == PMA_extract_db_or_table($db_table))
390 && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))
398 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
400 <input type
="checkbox" name
="selected_tbl[]"
401 value
="<?php echo htmlspecialchars($each_table['TABLE_NAME']); ?>"
402 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
403 <th
><?php
echo $browse_table_label; ?
>
404 <?php
echo (! empty($tracking_icon) ?
$tracking_icon : ''); ?
>
406 <?php
if ($server_slave_status) { ?
><td align
="center"><?php
408 ?
PMA_getImage('s_cancel.png', 'NOT REPLICATED')
411 ?
PMA_getImage('s_success.png', 'REPLICATED')
412 : ''; ?
></td
><?php
} ?
>
413 <td align
="center"><?php
echo $browse_table; ?
></td
>
415 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
416 <?php
echo $titles['Structure']; ?
></a
></td
>
417 <td align
="center"><?php
echo $search_table; ?
></td
>
418 <?php
if (! $db_is_information_schema) { ?
>
419 <td align
="center" class="insert_table">
420 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="ajax"' : ''); ?
> href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
421 <?php
echo $titles['Insert']; ?
></a
></td
>
422 <td align
="center"><?php
echo $empty_table; ?
></td
>
424 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="drop_table_anchor"' : ''); ?
> href
="sql.php?<?php echo $tbl_url_query;
425 ?>&reload=1&purge=1&sql_query=<?php
426 echo urlencode($drop_query); ?>&message_to_show=<?php
427 echo urlencode($drop_message); ?>" >
428 <?php
echo $titles['Drop']; ?
></a
></td
>
429 <?php
} // end if (! $db_is_information_schema)
431 // there is a null value in the ENGINE
432 // - when the table needs to be repaired, or
433 // - when it's a view
434 // so ensure that we'll display "in use" below for a table
435 // that needs to be repaired
436 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
438 $show_superscript = '';
439 if ($table_is_view) {
440 // Drizzle views use FunctionEngine, and the only place where they are available are I_S and D_D
441 // schemas, where we do exact counting
442 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']
443 && $each_table['ENGINE'] != 'FunctionEngine'
445 $row_count_pre = '~';
446 $sum_row_count_pre = '~';
447 $show_superscript = PMA_showHint(
450 __('This view has at least this number of rows. Please refer to %sdocumentation%s.'),
451 '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]',
457 } elseif ($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
458 // InnoDB table: we did not get an accurate row count
459 $row_count_pre = '~';
460 $sum_row_count_pre = '~';
461 $show_superscript = '';
464 <td
class="value tbl_rows"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
465 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
466 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
__('View') : $each_table['ENGINE']); ?
></td
>
467 <?php
if (isset($collation)) { ?
>
468 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
472 <?php
if ($is_show_stats) { ?
>
473 <td
class="value tbl_size"><a
474 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
475 ><?php
echo $formatted_size . ' ' . $unit; ?
></a
></td
>
476 <td
class="value"><?php
echo $overhead; ?
></td
>
478 <?php
} elseif ($table_is_view) { ?
>
479 <td
class="value">-</td
>
480 <td
><?php
echo __('View'); ?
></td
>
482 <?php
if ($is_show_stats) { ?
>
483 <td
class="value">-</td
>
484 <td
class="value">-</td
>
487 <td colspan
="<?php echo ($colspan_for_structure - ($db_is_information_schema ? 5 : 8)) ?>"
489 <?php
echo __('in use'); ?
></td
>
490 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
496 if ($is_show_stats) {
497 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
498 list($overhead_formatted, $overhead_unit) =
499 PMA_formatByteDown($overhead_size, 3, 1);
503 <tbody id
="tbl_summary_row">
505 <th align
="center" nowrap
="nowrap">
507 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
508 // (we don't want negative numbers here)
509 if ($num_tables == 0) {
510 $tableReductionCount = 0;
513 _ngettext('%s table', '%s tables', $num_tables - $tableReductionCount),
514 PMA_formatNumber($num_tables - $tableReductionCount, 0)
519 if ($server_slave_status) {
520 echo ' <th>' . __('Replication') . '</th>' . "\n";
523 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
524 <?php
echo __('Sum'); ?
></th
>
525 <th
class="value tbl_rows"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
527 if (!($cfg['PropertiesNumColumns'] > 1)) {
528 $default_engine = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'storage_engine\';', 0, 1);
529 echo ' <th align="center">' . "\n"
531 . sprintf(__('%s is the default storage engine on this MySQL server.'), $default_engine)
532 . '">' .$default_engine . '</dfn></th>' . "\n";
533 // we got a case where $db_collation was empty
534 echo ' <th align="center">' . "\n";
535 if (! empty($db_collation)) {
537 . PMA_getCollationDescr($db_collation) . ' (' . __('Default') . ')">' . $db_collation
543 if ($is_show_stats) {
545 <th
class="value tbl_size"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
546 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
554 <div
class="clearfloat">
556 // Check all tables url
557 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
559 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
560 width
="38" height
="22" alt
="<?php echo __('With selected:'); ?>" />
561 <a href
="<?php echo $checkall_url; ?>&checkall=1"
562 onclick
="if (markAllRows('tablesForm')) return false;">
563 <?php
echo __('Check All'); ?
></a
>
565 <a href
="<?php echo $checkall_url; ?>"
566 onclick
="if (unMarkAllRows('tablesForm')) return false;">
567 <?php
echo __('Uncheck All'); ?
></a
>
568 <?php
if ($overhead_check != '') { ?
>
570 <a href
="#" onclick
="unMarkAllRows('tablesForm');
571 <?php echo $overhead_check; ?> return false;">
572 <?php
echo __('Check tables having overhead'); ?
></a
>
575 <select name
="submit_mult" class="autosubmit" style
="margin: 0 3em 0 3em;">
577 echo ' <option value="' . __('With selected:') . '" selected="selected">'
578 . __('With selected:') . '</option>' . "\n";
579 echo ' <option value="export" >'
580 . __('Export') . '</option>' . "\n";
581 echo ' <option value="print" >'
582 . __('Print view') . '</option>' . "\n";
584 if (!$db_is_information_schema && !$cfg['DisableMultiTableMaintenance']) {
585 echo ' <option value="empty_tbl" >'
586 . __('Empty') . '</option>' . "\n";
587 echo ' <option value="drop_tbl" >'
588 . __('Drop') . '</option>' . "\n";
589 echo ' <option value="check_tbl" >'
590 . __('Check table') . '</option>' . "\n";
592 echo ' <option value="optimize_tbl" >'
593 . __('Optimize table') . '</option>' . "\n";
594 echo ' <option value="repair_tbl" >'
595 . __('Repair table') . '</option>' . "\n";
597 echo ' <option value="analyze_tbl" >'
598 . __('Analyze table') . '</option>' . "\n";
599 echo ' <option value="add_prefix_tbl" >'
600 . __('Add prefix to table') . '</option>' . "\n";
601 echo ' <option value="replace_prefix_tbl" >'
602 . __('Replace table prefix') . '</option>' . "\n";
603 echo ' <option value="copy_tbl_change_prefix" >'
604 . __('Copy table with prefix') . '</option>' . "\n";
608 <script type
="text/javascript">
610 // Fake js to allow the use of the <noscript> tag
614 <input type
="submit" value
="<?php echo __('Go'); ?>" />
616 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
620 // display again the table list navigator
622 $total_num_tables, $pos, $_url_params, 'db_structure.php',
623 'frame_content', $GLOBALS['cfg']['MaxTableList']
632 * Work on the database
635 /* Printable view of a table */
637 echo '<a href="db_printview.php?' . $url_query . '">';
638 echo PMA_getIcon('b_print.png', __('Print view'), true) . '</a>';
640 echo '<a href="./db_datadict.php?' . $url_query . '">';
641 echo PMA_getIcon('b_tblanalyse.png', __('Data Dictionary'), true) . '</a>';
644 if (empty($db_is_information_schema)) {
645 include './libraries/display_create_table.lib.php';
646 } // end if (Create Table dialog)
649 * Displays the footer
651 require './libraries/footer.inc.php';