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.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']) . '" />';
272 if ($each_table['TABLE_ROWS'] > 0 ||
$table_is_view) {
273 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $titles['Browse'] . '</a>';
274 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
275 $browse_table_label = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $truename . '</a>';
277 $browse_table = $titles['NoBrowse'];
278 $search_table = $titles['NoSearch'];
279 $browse_table_label = '<a href="tbl_structure.php?' . $tbl_url_query . '">' . $truename . '</a>';
282 if (! $db_is_information_schema) {
283 if (! empty($each_table['TABLE_ROWS'])) {
284 $empty_table = '<a ';
285 if ($GLOBALS['cfg']['AjaxEnable']) {
286 $empty_table .= 'class="truncate_table_anchor"';
288 $empty_table .= ' href="sql.php?' . $tbl_url_query
290 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
291 . '&message_to_show='
292 . urlencode(sprintf(__('Table %s has been emptied'), htmlspecialchars($each_table['TABLE_NAME'])))
293 .'">' . $titles['Empty'] . '</a>';
295 $empty_table = $titles['NoEmpty'];
297 $drop_query = 'DROP '
298 . ($table_is_view ?
'VIEW' : 'TABLE')
299 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
300 $drop_message = sprintf(
301 $table_is_view ?
__('View %s has been dropped') : __('Table %s has been dropped'),
302 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']))
307 if (PMA_Tracker
::isActive()) {
308 if (PMA_Tracker
::isTracked($GLOBALS["db"], $truename)) {
309 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query
310 . '&table=' . $truename . '"><img class="icon ic_eye" src="themes/dot.gif" alt="'
311 . __('Tracking is active.') . '" title="' . __('Tracking is active.') . '" /></a>';
312 } elseif (PMA_Tracker
::getVersion($GLOBALS["db"], $truename) > 0) {
313 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query
314 . '&table=' . $truename . '"><img class="icon ic_eye" src="themes/dot.gif" alt="'
315 . __('Tracking is not active.') . '" title="' . __('Tracking is not active.') . '" /></a>';
320 && $num_tables > $num_columns
321 && ($row_count %
$num_columns) == 0
330 PMA_TableHeader(false, $server_slave_status);
336 if ($server_slave_status) {
337 ////////////////////////////////////////////////////////////////
339 if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
340 ||
(strlen(array_search($db, $server_slave_Do_DB)) > 0)
341 ||
(count($server_slave_Do_DB) == 1 && count($server_slave_Ignore_DB) == 1)
345 foreach ($server_slave_Wild_Do_Table as $db_table) {
346 $table_part = PMA_extract_db_or_table($db_table, 'table');
347 if (($db == PMA_extract_db_or_table($db_table, 'db'))
348 && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))
353 ////////////////////////////////////////////////////////////////////
354 if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0)
355 ||
(strlen(array_search($db, $server_slave_Ignore_DB)) > 0)
359 foreach ($server_slave_Wild_Ignore_Table as $db_table) {
360 $table_part = PMA_extract_db_or_table($db_table, 'table');
361 if (($db == PMA_extract_db_or_table($db_table))
362 && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))
370 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
372 <input type
="checkbox" name
="selected_tbl[]"
373 value
="<?php echo htmlspecialchars($each_table['TABLE_NAME']); ?>"
374 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
375 <th
><?php
echo $browse_table_label; ?
>
376 <?php
echo (! empty($tracking_icon) ?
$tracking_icon : ''); ?
>
378 <?php
if ($server_slave_status) { ?
><td align
="center"><?php
380 ?
' <img class="icon ic_s_cancel" src="themes/dot.gif" alt="NOT REPLICATED" />'
383 ?
' <img class="icon ic_s_success" src="themes/dot.gif" alt="REPLICATED" />'
384 : ''; ?
></td
><?php
} ?
>
385 <td align
="center"><?php
echo $browse_table; ?
></td
>
387 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
388 <?php
echo $titles['Structure']; ?
></a
></td
>
389 <td align
="center"><?php
echo $search_table; ?
></td
>
390 <?php
if (! $db_is_information_schema) { ?
>
391 <td align
="center" class="insert_table">
392 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="ajax"' : ''); ?
> href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
393 <?php
echo $titles['Insert']; ?
></a
></td
>
394 <td align
="center"><?php
echo $empty_table; ?
></td
>
396 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="drop_table_anchor"' : ''); ?
> href
="sql.php?<?php echo $tbl_url_query;
397 ?>&reload=1&purge=1&sql_query=<?php
398 echo urlencode($drop_query); ?>&message_to_show=<?php
399 echo urlencode($drop_message); ?>" >
400 <?php
echo $titles['Drop']; ?
></a
></td
>
401 <?php
} // end if (! $db_is_information_schema)
403 // there is a null value in the ENGINE
404 // - when the table needs to be repaired, or
405 // - when it's a view
406 // so ensure that we'll display "in use" below for a table
407 // that needs to be repaired
408 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
410 $show_superscript = '';
411 if ($table_is_view) {
412 // Drizzle views use FunctionEngine, and the only place where they are available are I_S and D_D
413 // schemas, where we do exact counting
414 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']
415 && $each_table['ENGINE'] != 'FunctionEngine'
417 $row_count_pre = '~';
418 $sum_row_count_pre = '~';
419 $show_superscript = PMA_showHint(
422 __('This view has at least this number of rows. Please refer to %sdocumentation%s.'),
423 '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]',
429 } elseif ($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
430 // InnoDB table: we did not get an accurate row count
431 $row_count_pre = '~';
432 $sum_row_count_pre = '~';
433 $show_superscript = '';
436 <td
class="value tbl_rows"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
437 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
438 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
__('View') : $each_table['ENGINE']); ?
></td
>
439 <?php
if (isset($collation)) { ?
>
440 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
444 <?php
if ($is_show_stats) { ?
>
445 <td
class="value tbl_size"><a
446 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
447 ><?php
echo $formatted_size . ' ' . $unit; ?
></a
></td
>
448 <td
class="value"><?php
echo $overhead; ?
></td
>
450 <?php
} elseif ($table_is_view) { ?
>
451 <td
class="value">-</td
>
452 <td
><?php
echo __('View'); ?
></td
>
454 <?php
if ($is_show_stats) { ?
>
455 <td
class="value">-</td
>
456 <td
class="value">-</td
>
459 <td colspan
="<?php echo ($colspan_for_structure - ($db_is_information_schema ? 5 : 8)) ?>"
461 <?php
echo __('in use'); ?
></td
>
462 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
468 if ($is_show_stats) {
469 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
470 list($overhead_formatted, $overhead_unit) =
471 PMA_formatByteDown($overhead_size, 3, 1);
475 <tbody id
="tbl_summary_row">
477 <th align
="center" nowrap
="nowrap">
479 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
480 // (we don't want negative numbers here)
481 if ($num_tables == 0) {
482 $tableReductionCount = 0;
485 _ngettext('%s table', '%s tables', $num_tables - $tableReductionCount),
486 PMA_formatNumber($num_tables - $tableReductionCount, 0)
491 if ($server_slave_status) {
492 echo ' <th>' . __('Replication') . '</th>' . "\n";
495 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
496 <?php
echo __('Sum'); ?
></th
>
497 <th
class="value tbl_rows"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
499 if (!($cfg['PropertiesNumColumns'] > 1)) {
500 $default_engine = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'storage_engine\';', 0, 1);
501 echo ' <th align="center">' . "\n"
503 . sprintf(__('%s is the default storage engine on this MySQL server.'), $default_engine)
504 . '">' .$default_engine . '</dfn></th>' . "\n";
505 // we got a case where $db_collation was empty
506 echo ' <th align="center">' . "\n";
507 if (! empty($db_collation)) {
509 . PMA_getCollationDescr($db_collation) . ' (' . __('Default') . ')">' . $db_collation
515 if ($is_show_stats) {
517 <th
class="value tbl_size"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
518 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
526 <div
class="clearfloat">
528 // Check all tables url
529 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
531 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
532 width
="38" height
="22" alt
="<?php echo __('With selected:'); ?>" />
533 <a href
="<?php echo $checkall_url; ?>&checkall=1"
534 onclick
="if (markAllRows('tablesForm')) return false;">
535 <?php
echo __('Check All'); ?
></a
>
537 <a href
="<?php echo $checkall_url; ?>"
538 onclick
="if (unMarkAllRows('tablesForm')) return false;">
539 <?php
echo __('Uncheck All'); ?
></a
>
540 <?php
if ($overhead_check != '') { ?
>
542 <a href
="#" onclick
="unMarkAllRows('tablesForm');
543 <?php echo $overhead_check; ?> return false;">
544 <?php
echo __('Check tables having overhead'); ?
></a
>
547 <select name
="submit_mult" class="autosubmit" style
="margin: 0 3em 0 3em;">
549 echo ' <option value="' . __('With selected:') . '" selected="selected">'
550 . __('With selected:') . '</option>' . "\n";
551 echo ' <option value="export" >'
552 . __('Export') . '</option>' . "\n";
553 echo ' <option value="print" >'
554 . __('Print view') . '</option>' . "\n";
556 if (!$db_is_information_schema && !$cfg['DisableMultiTableMaintenance']) {
557 echo ' <option value="empty_tbl" >'
558 . __('Empty') . '</option>' . "\n";
559 echo ' <option value="drop_tbl" >'
560 . __('Drop') . '</option>' . "\n";
561 echo ' <option value="check_tbl" >'
562 . __('Check table') . '</option>' . "\n";
564 echo ' <option value="optimize_tbl" >'
565 . __('Optimize table') . '</option>' . "\n";
566 echo ' <option value="repair_tbl" >'
567 . __('Repair table') . '</option>' . "\n";
569 echo ' <option value="analyze_tbl" >'
570 . __('Analyze table') . '</option>' . "\n";
571 echo ' <option value="add_prefix_tbl" >'
572 . __('Add prefix to table') . '</option>' . "\n";
573 echo ' <option value="replace_prefix_tbl" >'
574 . __('Replace table prefix') . '</option>' . "\n";
575 echo ' <option value="copy_tbl_change_prefix" >'
576 . __('Copy table with prefix') . '</option>' . "\n";
580 <script type
="text/javascript">
582 // Fake js to allow the use of the <noscript> tag
586 <input type
="submit" value
="<?php echo __('Go'); ?>" />
588 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
592 // display again the table list navigator
594 $total_num_tables, $pos, $_url_params, 'db_structure.php',
595 'frame_content', $GLOBALS['cfg']['MaxTableList']
604 * Work on the database
607 /* Printable view of a table */
609 echo '<a href="db_printview.php?' . $url_query . '">';
610 if ($cfg['PropertiesIconic']) {
611 echo '<img class="icon ic_b_print" src="themes/dot.gif" alt="" />';
613 echo __('Print view') . '</a> ';
615 echo '<a href="./db_datadict.php?' . $url_query . '">';
616 if ($cfg['PropertiesIconic']) {
617 echo '<img class="icon ic_b_tblanalyse" src="themes/dot.gif" alt="" />';
619 echo __('Data Dictionary') . '</a>';
622 if (empty($db_is_information_schema)) {
623 include './libraries/display_create_table.lib.php';
624 } // end if (Create Table dialog)
627 * Displays the footer
629 require './libraries/footer.inc.php';