2 /* vim: set expandtab sw=4 ts=4 sts=4: */
12 require_once './libraries/common.inc.php';
14 require './libraries/tbl_common.php';
17 * Gets the variables sent or posted to this script, then displays headers
20 if (! isset($selected_tbl)) {
21 require_once './libraries/header.inc.php';
26 if (! isset($the_tables) ||
! is_array($the_tables)) {
27 $the_tables = array();
31 * Gets the relations settings
33 require_once './libraries/relation.lib.php';
34 require_once './libraries/transformations.lib.php';
35 require_once './libraries/Index.class.php';
37 $cfgRelation = PMA_getRelationsParam();
40 * Defines the url to return to in case of error in a sql statement
43 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
45 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
50 * Selects the database
52 PMA_DBI_select_db($db);
56 * Multi-tables printview
58 if (isset($selected_tbl) && is_array($selected_tbl)) {
59 $the_tables = $selected_tbl;
60 } elseif (strlen($table)) {
61 $the_tables[] = $table;
63 $multi_tables = (count($the_tables) > 1);
66 if (empty($GLOBALS['is_header_sent'])) {
67 require_once './libraries/header.inc.php';
70 foreach ($the_tables as $key => $table) {
71 $tbl_list .= (empty($tbl_list) ?
'' : ', ')
72 . PMA_backquote($table);
74 echo '<strong>'. __('Show tables') . ': ' . $tbl_list . '</strong>' . "\n";
78 $tables_cnt = count($the_tables);
81 foreach ($the_tables as $key => $table) {
82 if ($counter +
1 >= $tables_cnt) {
85 $breakstyle = ' style="page-break-after: always;"';
88 echo '<div' . $breakstyle . '>' . "\n";
89 echo '<h1>' . $table . '</h1>' . "\n";
92 * Gets table informations
94 $showtable = PMA_Table
::sGetStatusInfo($db, $table);
95 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
96 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
98 $tbl_is_view = PMA_Table
::isView($db, $table);
101 * Gets fields properties
103 $result = PMA_DBI_query(
104 'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
105 PMA_DBI_QUERY_STORE
);
106 $fields_cnt = PMA_DBI_num_rows($result);
109 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
110 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
111 // and SHOW CREATE TABLE says NOT NULL (tested
112 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
114 $show_create_table = PMA_DBI_fetch_value(
115 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
117 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
119 // Check if we can use Relations (Mike Beck)
120 // Find which tables are related with the current one and write it in
122 $res_rel = PMA_getForeigners($db, $table);
123 $have_rel = (bool) count($res_rel);
126 * Displays the comments of the table if MySQL >= 3.23
128 if (!empty($show_comment)) {
129 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
133 * Displays the table structure
137 <!-- TABLE INFORMATIONS
-->
138 <table style
="width: 100%;">
141 <th
><?php
echo __('Column'); ?
></th
>
142 <th
><?php
echo __('Type'); ?
></th
>
143 <!--<th
><?php
echo __('Attributes'); ?
></th
>-->
144 <th
><?php
echo __('Null'); ?
></th
>
145 <th
><?php
echo __('Default'); ?
></th
>
146 <!--<th
><?php
echo __('Extra'); ?
></th
>-->
149 echo '<th>' . __('Links to') . '</th>' . "\n";
151 echo ' <th>' . __('Comments') . '</th>' . "\n";
152 if ($cfgRelation['mimework']) {
153 echo ' <th>MIME</th>' . "\n";
160 while ($row = PMA_DBI_fetch_assoc($result)) {
161 $type = $row['Type'];
162 // reformat mysql query output
163 // set or enum types: slashes single quotes inside options
164 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
165 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
167 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
173 $type = preg_replace('@BINARY@i', '', $type);
174 $type = preg_replace('@ZEROFILL@i', '', $type);
175 $type = preg_replace('@UNSIGNED@i', '', $type);
180 $binary = stristr($row['Type'], 'binary');
181 $unsigned = stristr($row['Type'], 'unsigned');
182 $zerofill = stristr($row['Type'], 'zerofill');
184 $attribute = ' ';
186 $attribute = 'BINARY';
189 $attribute = 'UNSIGNED';
192 $attribute = 'UNSIGNED ZEROFILL';
194 if (!isset($row['Default'])) {
195 if ($row['Null'] != '' && $row['Null'] != 'NO') {
196 $row['Default'] = '<i>NULL</i>';
199 $row['Default'] = htmlspecialchars($row['Default']);
201 $field_name = htmlspecialchars($row['Field']);
203 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
204 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
207 * @todo merge this logic with the one in tbl_structure.php
208 * or move it in a function similar to PMA_DBI_get_columns_full()
209 * but based on SHOW CREATE TABLE because information_schema
210 * cannot be trusted in this case (MySQL bug)
212 if (!empty($analyzed_sql[0]['create_table_fields'][$field_name]['type']) && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
219 if (isset($pk_array[$row['Field']])) {
220 echo ' <u>' . $field_name . '</u>' . "\n";
222 echo ' ' . $field_name . "\n";
226 <td
><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
227 <!--<td
><?php
echo $attribute; ?
></td
>-->
228 <td
><?php
echo (($row['Null'] == '' ||
$row['Null'] == 'NO') ?
__('No') : __('Yes')); ?
> 
;</td
>
229 <td
><?php
if (isset($row['Default'])) { echo $row['Default']; } ?
> 
;</td
>
230 <!--<td
><?php
echo $row['Extra']; ?
> 
;</td
>-->
234 if (isset($res_rel[$field_name])) {
235 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
237 echo ' </td>' . "\n";
240 $comments = PMA_getComments($db, $table);
241 if (isset($comments[$field_name])) {
242 echo htmlspecialchars($comments[$field_name]);
244 echo ' </td>' . "\n";
245 if ($cfgRelation['mimework']) {
246 $mime_map = PMA_getMIME($db, $table, true);
249 if (isset($mime_map[$field_name])) {
250 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
252 echo ' </td>' . "\n";
258 PMA_DBI_free_result($result);
263 if (! $tbl_is_view && $db != 'information_schema') {
267 echo PMA_Index
::getView($table, $db, true);
270 * Displays Space usage and row statistics
273 if ($cfg['ShowStats']) {
275 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
278 if ($nonisam == false) {
281 $mergetable = PMA_Table
::isMerge($db, $table);
283 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
284 if ($mergetable == false) {
285 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
287 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
288 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
289 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length'] - $showtable['Data_free']);
293 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
295 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
297 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] +
$showtable['Index_length']) / $showtable['Rows'], 6, 1);
304 <table border
="0" cellspacing
="0" cellpadding
="0" class="noborder">
309 <big
><?php
echo __('Space usage') . ':'; ?
></big
>
312 <th
><?php
echo __('Type'); ?
></th
>
313 <th colspan
="2" align
="center"><?php
echo __('Usage'); ?
></th
>
316 <td style
="padding-right: 10px"><?php
echo __('Data'); ?
></td
>
317 <td align
="right"><?php
echo $data_size; ?
></td
>
318 <td
><?php
echo $data_unit; ?
></td
>
321 if (isset($index_size)) {
325 <td style
="padding-right: 10px"><?php
echo __('Index'); ?
></td
>
326 <td align
="right"><?php
echo $index_size; ?
></td
>
327 <td
><?php
echo $index_unit; ?
></td
>
331 if (isset($free_size)) {
334 <tr style
="color: #bb0000">
335 <td style
="padding-right: 10px"><?php
echo __('Overhead'); ?
></td
>
336 <td align
="right"><?php
echo $free_size; ?
></td
>
337 <td
><?php
echo $free_unit; ?
></td
>
340 <td style
="padding-right: 10px"><?php
echo __('Effective'); ?
></td
>
341 <td align
="right"><?php
echo $effect_size; ?
></td
>
342 <td
><?php
echo $effect_unit; ?
></td
>
346 if (isset($tot_size) && $mergetable == false) {
350 <td style
="padding-right: 10px"><?php
echo __('Total'); ?
></td
>
351 <td align
="right"><?php
echo $tot_size; ?
></td
>
352 <td
><?php
echo $tot_unit; ?
></td
>
361 <td width
="20"> 
;</td
>
363 <!-- Rows Statistic
-->
365 <big
><?php
echo __('Row Statistics') . ':'; ?
></big
>
368 <th
><?php
echo __('Statements'); ?
></th
>
369 <th align
="center"><?php
echo __('Value'); ?
></th
>
372 if (isset($showtable['Row_format'])) {
375 <td
><?php
echo ucfirst(__('Format')); ?
></td
>
376 <td align
="<?php echo $cell_align_left; ?>">
378 if ($showtable['Row_format'] == 'Fixed') {
380 } elseif ($showtable['Row_format'] == 'Dynamic') {
383 echo $showtable['Row_format'];
390 if (isset($showtable['Rows'])) {
393 <td
><?php
echo ucfirst(__('Rows')); ?
></td
>
395 <?php
echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?
>
400 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
403 <td
><?php
echo ucfirst(__('Row length')); ?
> 
;ø
;</td
>
405 <?php
echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?
>
410 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
413 <td
><?php
echo ucfirst(__(' Row size ')); ?
> 
;ø
;</td
>
415 <?php
echo $avg_size . ' ' . $avg_unit . "\n"; ?
>
420 if (isset($showtable['Auto_increment'])) {
423 <td
><?php
echo ucfirst(__('Next')); ?
> 
;Autoindex
</td
>
425 <?php
echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?
>
430 if (isset($showtable['Create_time'])) {
433 <td
><?php
echo __('Creation'); ?
></td
>
435 <?php
echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?
>
440 if (isset($showtable['Update_time'])) {
443 <td
><?php
echo __('Last update'); ?
></td
>
445 <?php
echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?
>
450 if (isset($showtable['Check_time'])) {
453 <td
><?php
echo __('Last check'); ?
></td
>
455 <?php
echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?
>
468 } // end if ($nonisam == false)
469 } // end if ($cfg['ShowStats'])
472 unset($num_rows, $show_comment);
473 echo '<hr />' . "\n";
475 echo '</div>' . "\n";
480 * Displays the footer
484 <script type
="text/javascript">
489 if (typeof(window
.print) != 'undefined') {
496 <p
class="print_ignore">
497 <input type
="button" id
="print" value
="<?php echo __('Print'); ?>"
498 onclick
="printPage()" /></p
>
501 require_once './libraries/footer.inc.php';