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 foreach ($tables as $keyname => $each_table) {
129 // Get valid statistics whatever is the table type
131 $table_is_view = false;
132 $table_encoded = urlencode($each_table['TABLE_NAME']);
133 // Sets parameters for links
134 $tbl_url_query = $url_query . '&table=' . $table_encoded;
135 // do not list the previous table's size info for a view
136 $formatted_size = '-';
139 switch ( $each_table['ENGINE']) {
140 // MyISAM, ISAM or Heap table: Row count, data size and index size
141 // are accurate; data size is accurate for ARCHIVE
149 if ($db_is_information_schema) {
150 $each_table['Rows'] = PMA_Table
::countRecords(
151 $db, $each_table['Name']
155 if ($is_show_stats) {
156 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
157 $sum_size +
= $tblsize;
158 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
159 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
160 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
161 $overhead_size +
= $each_table['Data_free'];
167 // InnoDB table: Row count is not accurate but data and index sizes are.
168 // PBMS table in Drizzle: TABLE_ROWS is taken from table cache, so it may be unavailable
170 if (($each_table['ENGINE'] == 'InnoDB'
171 && $each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount'])
172 ||
!isset($each_table['TABLE_ROWS'])
174 $each_table['COUNTED'] = true;
175 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords(
176 $db, $each_table['TABLE_NAME'],
177 $force_exact = true, $is_view = false
180 $each_table['COUNTED'] = false;
183 // Drizzle doesn't provide data and index length, check for null
184 if ($is_show_stats && $each_table['Data_length'] !== null) {
185 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
186 $sum_size +
= $tblsize;
187 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
189 //$display_rows = ' - ';
191 // Mysql 5.0.x (and lower) uses MRG_MyISAM and MySQL 5.1.x (and higher) uses MRG_MYISAM
192 // Both are aliases for MERGE
197 // Merge or BerkleyDB table: Only row count is accurate.
198 if ($is_show_stats) {
199 $formatted_size = ' - ';
203 // for a view, the ENGINE is sometimes reported as null,
204 // or on some servers it's reported as "SYSTEM VIEW"
207 case 'FunctionEngine' :
208 // if table is broken, Engine is reported as null, so one more test
209 if ($each_table['TABLE_TYPE'] == 'VIEW') {
210 // countRecords() takes care of $cfg['MaxExactCountViews']
211 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords(
212 $db, $each_table['TABLE_NAME'],
213 $force_exact = true, $is_view = true
215 $table_is_view = true;
219 // Unknown table type.
220 if ($is_show_stats) {
221 $formatted_size = __('unknown');
226 if (! PMA_Table
::isMerge($db, $each_table['TABLE_NAME'])) {
227 $sum_entries +
= $each_table['TABLE_ROWS'];
230 if (isset($each_table['Collation'])) {
231 $collation = '<dfn title="'
232 . PMA_getCollationDescr($each_table['Collation']) . '">'
233 . $each_table['Collation'] . '</dfn>';
238 if ($is_show_stats) {
239 if (isset($formatted_overhead)) {
240 $overhead = '<a href="tbl_structure.php?'
241 . $tbl_url_query . '#showusage"><span>' . $formatted_overhead
242 . '</span> <span class="unit">' . $overhead_unit . '</span></a>' . "\n";
243 unset($formatted_overhead);
245 "document.getElementById('checkbox_tbl_" . ($i +
1) . "').checked = true;";
251 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
252 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
253 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
254 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
255 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
256 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
261 if ($table_is_view) {
262 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
263 . htmlspecialchars($each_table['TABLE_NAME']) . '" />';
267 * Always activate links for Browse, Search and Empty, even if
268 * the icons are greyed, because
269 * 1. for views, we don't know the number of rows at this point
270 * 2. for tables, another source could have populated them since the
273 * I could have used the PHP ternary conditional operator but I find
274 * the code easier to read without this operator.
276 if ($each_table['TABLE_ROWS'] > 0 ||
$table_is_view) {
277 $may_have_rows = true;
279 $may_have_rows = false;
281 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">';
282 if ($may_have_rows) {
283 $browse_table .= $titles['Browse'];
285 $browse_table .= $titles['NoBrowse'];
287 $browse_table .= '</a>';
289 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">';
290 if ($may_have_rows) {
291 $search_table .= $titles['Search'];
293 $search_table .= $titles['NoSearch'];
295 $search_table .= '</a>';
297 $browse_table_label = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $truename . '</a>';
299 if (! $db_is_information_schema) {
300 $empty_table = '<a ';
301 if ($GLOBALS['cfg']['AjaxEnable']) {
302 $empty_table .= 'class="truncate_table_anchor"';
304 $empty_table .= ' href="sql.php?' . $tbl_url_query
306 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
307 . '&message_to_show='
308 . urlencode(sprintf(__('Table %s has been emptied'), htmlspecialchars($each_table['TABLE_NAME'])))
310 if ($may_have_rows) {
311 $empty_table .= $titles['Empty'];
313 $empty_table .= $titles['NoEmpty'];
315 $empty_table .= '</a>';
317 $drop_query = 'DROP '
318 . ($table_is_view ?
'VIEW' : 'TABLE')
319 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
320 $drop_message = sprintf(
321 $table_is_view ?
__('View %s has been dropped') : __('Table %s has been dropped'),
322 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']))
327 if (PMA_Tracker
::isActive()) {
328 if (PMA_Tracker
::isTracked($GLOBALS["db"], $truename)) {
329 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query
330 . '&table=' . $truename . '">'
331 . PMA_getImage('eye.png', __('Tracking is active.'))
333 } elseif (PMA_Tracker
::getVersion($GLOBALS["db"], $truename) > 0) {
334 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query
335 . '&table=' . $truename . '">'
336 . PMA_getImage('eye.png', __('Tracking is not active.'))
342 && $num_tables > $num_columns
343 && ($row_count %
$num_columns) == 0
352 PMA_TableHeader(false, $server_slave_status);
358 if ($server_slave_status) {
359 ////////////////////////////////////////////////////////////////
361 if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
362 ||
(strlen(array_search($db, $server_slave_Do_DB)) > 0)
363 ||
(count($server_slave_Do_DB) == 1 && count($server_slave_Ignore_DB) == 1)
367 foreach ($server_slave_Wild_Do_Table as $db_table) {
368 $table_part = PMA_extract_db_or_table($db_table, 'table');
369 if (($db == PMA_extract_db_or_table($db_table, 'db'))
370 && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))
375 ////////////////////////////////////////////////////////////////////
376 if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0)
377 ||
(strlen(array_search($db, $server_slave_Ignore_DB)) > 0)
381 foreach ($server_slave_Wild_Ignore_Table as $db_table) {
382 $table_part = PMA_extract_db_or_table($db_table, 'table');
383 if (($db == PMA_extract_db_or_table($db_table))
384 && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))
392 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
394 <input type
="checkbox" name
="selected_tbl[]"
395 value
="<?php echo htmlspecialchars($each_table['TABLE_NAME']); ?>"
396 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
397 <th
><?php
echo $browse_table_label; ?
>
398 <?php
echo (! empty($tracking_icon) ?
$tracking_icon : ''); ?
>
400 <?php
if ($server_slave_status) { ?
><td align
="center"><?php
402 ?
PMA_getImage('s_cancel.png', 'NOT REPLICATED')
405 ?
PMA_getImage('s_success.png', 'REPLICATED')
406 : ''; ?
></td
><?php
} ?
>
407 <td align
="center"><?php
echo $browse_table; ?
></td
>
409 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
410 <?php
echo $titles['Structure']; ?
></a
></td
>
411 <td align
="center"><?php
echo $search_table; ?
></td
>
412 <?php
if (! $db_is_information_schema) { ?
>
413 <td align
="center" class="insert_table">
414 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="ajax"' : ''); ?
> href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
415 <?php
echo $titles['Insert']; ?
></a
></td
>
416 <td align
="center"><?php
echo $empty_table; ?
></td
>
418 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="drop_table_anchor"' : ''); ?
> href
="sql.php?<?php echo $tbl_url_query;
419 ?>&reload=1&purge=1&sql_query=<?php
420 echo urlencode($drop_query); ?>&message_to_show=<?php
421 echo urlencode($drop_message); ?>" >
422 <?php
echo $titles['Drop']; ?
></a
></td
>
423 <?php
} // end if (! $db_is_information_schema)
425 // there is a null value in the ENGINE
426 // - when the table needs to be repaired, or
427 // - when it's a view
428 // so ensure that we'll display "in use" below for a table
429 // that needs to be repaired
430 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
432 $show_superscript = '';
433 if ($table_is_view) {
434 // Drizzle views use FunctionEngine, and the only place where they are available are I_S and D_D
435 // schemas, where we do exact counting
436 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']
437 && $each_table['ENGINE'] != 'FunctionEngine'
439 $row_count_pre = '~';
440 $sum_row_count_pre = '~';
441 $show_superscript = PMA_showHint(
444 __('This view has at least this number of rows. Please refer to %sdocumentation%s.'),
445 '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]',
451 } elseif ($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
452 // InnoDB table: we did not get an accurate row count
453 $row_count_pre = '~';
454 $sum_row_count_pre = '~';
455 $show_superscript = '';
458 <td
class="value tbl_rows"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
459 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
460 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
__('View') : $each_table['ENGINE']); ?
></td
>
461 <?php
if (isset($collation)) { ?
>
462 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
466 <?php
if ($is_show_stats) { ?
>
467 <td
class="value tbl_size"><a
468 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
469 ><?php
echo '<span>' . $formatted_size . '</span> <span class="unit">' . $unit . '</span>'; ?
></a
></td
>
470 <td
class="value tbl_overhead"><?php
echo $overhead; ?
></td
>
472 <?php
} elseif ($table_is_view) { ?
>
473 <td
class="value">-</td
>
474 <td
><?php
echo __('View'); ?
></td
>
476 <?php
if ($is_show_stats) { ?
>
477 <td
class="value">-</td
>
478 <td
class="value">-</td
>
481 <td colspan
="<?php echo ($colspan_for_structure - ($db_is_information_schema ? 5 : 8)) ?>"
483 <?php
echo __('in use'); ?
></td
>
484 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
490 if ($is_show_stats) {
491 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
492 list($overhead_formatted, $overhead_unit)
493 = PMA_formatByteDown($overhead_size, 3, 1);
497 <tbody id
="tbl_summary_row">
499 <th align
="center" nowrap
="nowrap" class="tbl_num">
502 _ngettext('%s table', '%s tables', $num_tables),
503 PMA_formatNumber($num_tables, 0)
508 if ($server_slave_status) {
509 echo ' <th>' . __('Replication') . '</th>' . "\n";
512 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
513 <?php
echo __('Sum'); ?
></th
>
514 <th
class="value tbl_rows"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
516 if (!($cfg['PropertiesNumColumns'] > 1)) {
517 $default_engine = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'storage_engine\';', 0, 1);
518 echo ' <th align="center">' . "\n"
520 . sprintf(__('%s is the default storage engine on this MySQL server.'), $default_engine)
521 . '">' .$default_engine . '</dfn></th>' . "\n";
522 // we got a case where $db_collation was empty
523 echo ' <th align="center">' . "\n";
524 if (! empty($db_collation)) {
526 . PMA_getCollationDescr($db_collation) . ' (' . __('Default') . ')">' . $db_collation
532 if ($is_show_stats) {
534 <th
class="value tbl_size"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
535 <th
class="value tbl_overhead"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
543 <div
class="clearfloat">
545 // Check all tables url
546 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
548 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
549 width
="38" height
="22" alt
="<?php echo __('With selected:'); ?>" />
550 <a href
="<?php echo $checkall_url; ?>&checkall=1"
551 onclick
="if (markAllRows('tablesForm')) return false;">
552 <?php
echo __('Check All'); ?
></a
>
554 <a href
="<?php echo $checkall_url; ?>"
555 onclick
="if (unMarkAllRows('tablesForm')) return false;">
556 <?php
echo __('Uncheck All'); ?
></a
>
557 <?php
if ($overhead_check != '') { ?
>
559 <a href
="#" onclick
="unMarkAllRows('tablesForm');
560 <?php echo $overhead_check; ?> return false;">
561 <?php
echo __('Check tables having overhead'); ?
></a
>
564 <select name
="submit_mult" class="autosubmit" style
="margin: 0 3em 0 3em;">
566 echo ' <option value="' . __('With selected:') . '" selected="selected">'
567 . __('With selected:') . '</option>' . "\n";
568 echo ' <option value="export" >'
569 . __('Export') . '</option>' . "\n";
570 echo ' <option value="print" >'
571 . __('Print view') . '</option>' . "\n";
573 if (!$db_is_information_schema && !$cfg['DisableMultiTableMaintenance']) {
574 echo ' <option value="empty_tbl" >'
575 . __('Empty') . '</option>' . "\n";
576 echo ' <option value="drop_tbl" >'
577 . __('Drop') . '</option>' . "\n";
578 echo ' <option value="check_tbl" >'
579 . __('Check table') . '</option>' . "\n";
581 echo ' <option value="optimize_tbl" >'
582 . __('Optimize table') . '</option>' . "\n";
583 echo ' <option value="repair_tbl" >'
584 . __('Repair table') . '</option>' . "\n";
586 echo ' <option value="analyze_tbl" >'
587 . __('Analyze table') . '</option>' . "\n";
588 echo ' <option value="add_prefix_tbl" >'
589 . __('Add prefix to table') . '</option>' . "\n";
590 echo ' <option value="replace_prefix_tbl" >'
591 . __('Replace table prefix') . '</option>' . "\n";
592 echo ' <option value="copy_tbl_change_prefix" >'
593 . __('Copy table with prefix') . '</option>' . "\n";
597 <script type
="text/javascript">
599 // Fake js to allow the use of the <noscript> tag
603 <input type
="submit" value
="<?php echo __('Go'); ?>" />
605 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
609 // display again the table list navigator
611 $total_num_tables, $pos, $_url_params, 'db_structure.php',
612 'frame_content', $GLOBALS['cfg']['MaxTableList']
621 * Work on the database
624 /* Printable view of a table */
626 echo '<a href="db_printview.php?' . $url_query . '">';
627 echo PMA_getIcon('b_print.png', __('Print view'), true) . '</a>';
629 echo '<a href="./db_datadict.php?' . $url_query . '">';
630 echo PMA_getIcon('b_tblanalyse.png', __('Data Dictionary'), true) . '</a>';
633 if (empty($db_is_information_schema)) {
634 include './libraries/display_create_table.lib.php';
635 } // end if (Create Table dialog)
638 * Displays the footer
640 require './libraries/footer.inc.php';