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']) . '" />';
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 . '">'
311 . PMA_getImage('eye.png', __('Tracking is active.'))
313 } elseif (PMA_Tracker
::getVersion($GLOBALS["db"], $truename) > 0) {
314 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query
315 . '&table=' . $truename . '">'
316 . PMA_getImage('eye.png', __('Tracking is not active.'))
322 && $num_tables > $num_columns
323 && ($row_count %
$num_columns) == 0
332 PMA_TableHeader(false, $server_slave_status);
338 if ($server_slave_status) {
339 ////////////////////////////////////////////////////////////////
341 if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
342 ||
(strlen(array_search($db, $server_slave_Do_DB)) > 0)
343 ||
(count($server_slave_Do_DB) == 1 && count($server_slave_Ignore_DB) == 1)
347 foreach ($server_slave_Wild_Do_Table as $db_table) {
348 $table_part = PMA_extract_db_or_table($db_table, 'table');
349 if (($db == PMA_extract_db_or_table($db_table, 'db'))
350 && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))
355 ////////////////////////////////////////////////////////////////////
356 if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0)
357 ||
(strlen(array_search($db, $server_slave_Ignore_DB)) > 0)
361 foreach ($server_slave_Wild_Ignore_Table as $db_table) {
362 $table_part = PMA_extract_db_or_table($db_table, 'table');
363 if (($db == PMA_extract_db_or_table($db_table))
364 && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))
372 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
374 <input type
="checkbox" name
="selected_tbl[]"
375 value
="<?php echo htmlspecialchars($each_table['TABLE_NAME']); ?>"
376 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
377 <th
><?php
echo $browse_table_label; ?
>
378 <?php
echo (! empty($tracking_icon) ?
$tracking_icon : ''); ?
>
380 <?php
if ($server_slave_status) { ?
><td align
="center"><?php
382 ?
PMA_getImage('s_cancel.png', 'NOT REPLICATED')
385 ?
PMA_getImage('s_success.png', 'REPLICATED')
386 : ''; ?
></td
><?php
} ?
>
387 <td align
="center"><?php
echo $browse_table; ?
></td
>
389 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
390 <?php
echo $titles['Structure']; ?
></a
></td
>
391 <td align
="center"><?php
echo $search_table; ?
></td
>
392 <?php
if (! $db_is_information_schema) { ?
>
393 <td align
="center" class="insert_table">
394 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="ajax"' : ''); ?
> href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
395 <?php
echo $titles['Insert']; ?
></a
></td
>
396 <td align
="center"><?php
echo $empty_table; ?
></td
>
398 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="drop_table_anchor"' : ''); ?
> href
="sql.php?<?php echo $tbl_url_query;
399 ?>&reload=1&purge=1&sql_query=<?php
400 echo urlencode($drop_query); ?>&message_to_show=<?php
401 echo urlencode($drop_message); ?>" >
402 <?php
echo $titles['Drop']; ?
></a
></td
>
403 <?php
} // end if (! $db_is_information_schema)
405 // there is a null value in the ENGINE
406 // - when the table needs to be repaired, or
407 // - when it's a view
408 // so ensure that we'll display "in use" below for a table
409 // that needs to be repaired
410 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
412 $show_superscript = '';
413 if ($table_is_view) {
414 // Drizzle views use FunctionEngine, and the only place where they are available are I_S and D_D
415 // schemas, where we do exact counting
416 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']
417 && $each_table['ENGINE'] != 'FunctionEngine'
419 $row_count_pre = '~';
420 $sum_row_count_pre = '~';
421 $show_superscript = PMA_showHint(
424 __('This view has at least this number of rows. Please refer to %sdocumentation%s.'),
425 '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]',
431 } elseif ($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
432 // InnoDB table: we did not get an accurate row count
433 $row_count_pre = '~';
434 $sum_row_count_pre = '~';
435 $show_superscript = '';
438 <td
class="value tbl_rows"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
439 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
440 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
__('View') : $each_table['ENGINE']); ?
></td
>
441 <?php
if (isset($collation)) { ?
>
442 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
446 <?php
if ($is_show_stats) { ?
>
447 <td
class="value tbl_size"><a
448 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
449 ><?php
echo $formatted_size . ' ' . $unit; ?
></a
></td
>
450 <td
class="value"><?php
echo $overhead; ?
></td
>
452 <?php
} elseif ($table_is_view) { ?
>
453 <td
class="value">-</td
>
454 <td
><?php
echo __('View'); ?
></td
>
456 <?php
if ($is_show_stats) { ?
>
457 <td
class="value">-</td
>
458 <td
class="value">-</td
>
461 <td colspan
="<?php echo ($colspan_for_structure - ($db_is_information_schema ? 5 : 8)) ?>"
463 <?php
echo __('in use'); ?
></td
>
464 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
470 if ($is_show_stats) {
471 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
472 list($overhead_formatted, $overhead_unit) =
473 PMA_formatByteDown($overhead_size, 3, 1);
477 <tbody id
="tbl_summary_row">
479 <th align
="center" nowrap
="nowrap">
481 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
482 // (we don't want negative numbers here)
483 if ($num_tables == 0) {
484 $tableReductionCount = 0;
487 _ngettext('%s table', '%s tables', $num_tables - $tableReductionCount),
488 PMA_formatNumber($num_tables - $tableReductionCount, 0)
493 if ($server_slave_status) {
494 echo ' <th>' . __('Replication') . '</th>' . "\n";
497 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
498 <?php
echo __('Sum'); ?
></th
>
499 <th
class="value tbl_rows"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
501 if (!($cfg['PropertiesNumColumns'] > 1)) {
502 $default_engine = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'storage_engine\';', 0, 1);
503 echo ' <th align="center">' . "\n"
505 . sprintf(__('%s is the default storage engine on this MySQL server.'), $default_engine)
506 . '">' .$default_engine . '</dfn></th>' . "\n";
507 // we got a case where $db_collation was empty
508 echo ' <th align="center">' . "\n";
509 if (! empty($db_collation)) {
511 . PMA_getCollationDescr($db_collation) . ' (' . __('Default') . ')">' . $db_collation
517 if ($is_show_stats) {
519 <th
class="value tbl_size"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
520 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
528 <div
class="clearfloat">
530 // Check all tables url
531 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
533 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
534 width
="38" height
="22" alt
="<?php echo __('With selected:'); ?>" />
535 <a href
="<?php echo $checkall_url; ?>&checkall=1"
536 onclick
="if (markAllRows('tablesForm')) return false;">
537 <?php
echo __('Check All'); ?
></a
>
539 <a href
="<?php echo $checkall_url; ?>"
540 onclick
="if (unMarkAllRows('tablesForm')) return false;">
541 <?php
echo __('Uncheck All'); ?
></a
>
542 <?php
if ($overhead_check != '') { ?
>
544 <a href
="#" onclick
="unMarkAllRows('tablesForm');
545 <?php echo $overhead_check; ?> return false;">
546 <?php
echo __('Check tables having overhead'); ?
></a
>
549 <select name
="submit_mult" class="autosubmit" style
="margin: 0 3em 0 3em;">
551 echo ' <option value="' . __('With selected:') . '" selected="selected">'
552 . __('With selected:') . '</option>' . "\n";
553 echo ' <option value="export" >'
554 . __('Export') . '</option>' . "\n";
555 echo ' <option value="print" >'
556 . __('Print view') . '</option>' . "\n";
558 if (!$db_is_information_schema && !$cfg['DisableMultiTableMaintenance']) {
559 echo ' <option value="empty_tbl" >'
560 . __('Empty') . '</option>' . "\n";
561 echo ' <option value="drop_tbl" >'
562 . __('Drop') . '</option>' . "\n";
563 echo ' <option value="check_tbl" >'
564 . __('Check table') . '</option>' . "\n";
566 echo ' <option value="optimize_tbl" >'
567 . __('Optimize table') . '</option>' . "\n";
568 echo ' <option value="repair_tbl" >'
569 . __('Repair table') . '</option>' . "\n";
571 echo ' <option value="analyze_tbl" >'
572 . __('Analyze table') . '</option>' . "\n";
573 echo ' <option value="add_prefix_tbl" >'
574 . __('Add prefix to table') . '</option>' . "\n";
575 echo ' <option value="replace_prefix_tbl" >'
576 . __('Replace table prefix') . '</option>' . "\n";
577 echo ' <option value="copy_tbl_change_prefix" >'
578 . __('Copy table with prefix') . '</option>' . "\n";
582 <script type
="text/javascript">
584 // Fake js to allow the use of the <noscript> tag
588 <input type
="submit" value
="<?php echo __('Go'); ?>" />
590 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
594 // display again the table list navigator
596 $total_num_tables, $pos, $_url_params, 'db_structure.php',
597 'frame_content', $GLOBALS['cfg']['MaxTableList']
606 * Work on the database
609 /* Printable view of a table */
611 echo '<a href="db_printview.php?' . $url_query . '">';
612 echo PMA_getIcon('b_print.png', __('Print view'), true) . '</a>';
614 echo '<a href="./db_datadict.php?' . $url_query . '">';
615 echo PMA_getIcon('b_tblanalyse.png', __('Data Dictionary'), true) . '</a>';
618 if (empty($db_is_information_schema)) {
619 include './libraries/display_create_table.lib.php';
620 } // end if (Create Table dialog)
623 * Displays the footer
625 require './libraries/footer.inc.php';