Advisor: don't run 'MyISAM concurrent inserts' on Drizzle
[phpmyadmin.git] / tbl_printview.php
blob24949094aabc62567de9be54385969660f6ab502
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
8 /**
11 require_once './libraries/common.inc.php';
13 require './libraries/tbl_common.php';
15 /**
16 * Gets the variables sent or posted to this script, then displays headers
18 $print_view = true;
19 if (! isset($selected_tbl)) {
20 require_once './libraries/header.inc.php';
23 // Check parameters
25 if (! isset($the_tables) || ! is_array($the_tables)) {
26 $the_tables = array();
29 /**
30 * Gets the relations settings
32 require_once './libraries/transformations.lib.php';
33 require_once './libraries/Index.class.php';
35 $cfgRelation = PMA_getRelationsParam();
37 /**
38 * Defines the url to return to in case of error in a sql statement
40 if (strlen($table)) {
41 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
42 } else {
43 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
47 /**
48 * Selects the database
50 PMA_DBI_select_db($db);
53 /**
54 * Multi-tables printview
56 if (isset($selected_tbl) && is_array($selected_tbl)) {
57 $the_tables = $selected_tbl;
58 } elseif (strlen($table)) {
59 $the_tables[] = $table;
61 $multi_tables = (count($the_tables) > 1);
63 if ($multi_tables) {
64 if (empty($GLOBALS['is_header_sent'])) {
65 require_once './libraries/header.inc.php';
67 $tbl_list = '';
68 foreach ($the_tables as $key => $table) {
69 $tbl_list .= (empty($tbl_list) ? '' : ', ')
70 . PMA_backquote($table);
72 echo '<strong>'. __('Show tables') . ': ' . htmlspecialchars($tbl_list) . '</strong>' . "\n";
73 echo '<hr />' . "\n";
74 } // end if
76 $tables_cnt = count($the_tables);
77 $counter = 0;
79 foreach ($the_tables as $key => $table) {
80 if ($counter + 1 >= $tables_cnt) {
81 $breakstyle = '';
82 } else {
83 $breakstyle = ' style="page-break-after: always;"';
85 $counter++;
86 echo '<div' . $breakstyle . '>' . "\n";
87 echo '<h1>' . htmlspecialchars($table) . '</h1>' . "\n";
89 /**
90 * Gets table informations
92 $showtable = PMA_Table::sGetStatusInfo($db, $table);
93 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
94 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
96 $tbl_is_view = PMA_Table::isView($db, $table);
98 /**
99 * Gets fields properties
101 $columns = PMA_DBI_get_columns($db, $table);
104 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
105 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
106 // and SHOW CREATE TABLE says NOT NULL (tested
107 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
109 $show_create_table = PMA_DBI_fetch_value(
110 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
111 0, 1);
112 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
114 // Check if we can use Relations
115 // Find which tables are related with the current one and write it in
116 // an array
117 $res_rel = PMA_getForeigners($db, $table);
118 $have_rel = (bool) count($res_rel);
121 * Displays the comments of the table if MySQL >= 3.23
123 if (!empty($show_comment)) {
124 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
128 * Displays the table structure
132 <!-- TABLE INFORMATIONS -->
133 <table style="width: 100%;">
134 <thead>
135 <tr>
136 <th><?php echo __('Column'); ?></th>
137 <th><?php echo __('Type'); ?></th>
138 <!--<th><?php echo __('Attributes'); ?></th>-->
139 <th><?php echo __('Null'); ?></th>
140 <th><?php echo __('Default'); ?></th>
141 <!--<th><?php echo __('Extra'); ?></th>-->
142 <?php
143 if ($have_rel) {
144 echo '<th>' . __('Links to') . '</th>' . "\n";
146 echo ' <th>' . __('Comments') . '</th>' . "\n";
147 if ($cfgRelation['mimework']) {
148 echo ' <th>MIME</th>' . "\n";
151 </tr>
152 </thead>
153 <tbody>
154 <?php
155 foreach ($columns as $row) {
156 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
157 $type = $extracted_fieldspec['print_type'];
158 $attribute = $extracted_fieldspec['attribute'];
160 if (! isset($row['Default'])) {
161 if ($row['Null'] != '' && $row['Null'] != 'NO') {
162 $row['Default'] = '<i>NULL</i>';
164 } else {
165 $row['Default'] = htmlspecialchars($row['Default']);
167 $field_name = htmlspecialchars($row['Field']);
169 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
170 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
171 // the latter.
173 * @todo merge this logic with the one in tbl_structure.php
174 * or move it in a function similar to PMA_DBI_get_columns_full()
175 * but based on SHOW CREATE TABLE because information_schema
176 * cannot be trusted in this case (MySQL bug)
178 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']) {
179 $row['Null'] = '';
183 <tr><td>
184 <?php
185 if (isset($pk_array[$row['Field']])) {
186 echo ' <u>' . $field_name . '</u>' . "\n";
187 } else {
188 echo ' ' . $field_name . "\n";
191 </td>
192 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
193 <!--<td><?php echo $attribute; ?></td>-->
194 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes')); ?>&nbsp;</td>
195 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
196 <!--<td><?php echo $row['Extra']; ?>&nbsp;</td>-->
197 <?php
198 if ($have_rel) {
199 echo ' <td>';
200 if (isset($res_rel[$field_name])) {
201 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
203 echo '&nbsp;</td>' . "\n";
205 echo ' <td>';
206 $comments = PMA_getComments($db, $table);
207 if (isset($comments[$field_name])) {
208 echo htmlspecialchars($comments[$field_name]);
210 echo '&nbsp;</td>' . "\n";
211 if ($cfgRelation['mimework']) {
212 $mime_map = PMA_getMIME($db, $table, true);
214 echo ' <td>';
215 if (isset($mime_map[$field_name])) {
216 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
218 echo '&nbsp;</td>' . "\n";
221 </tr>
222 <?php
223 } // end foreach
225 </tbody>
226 </table>
227 <?php
228 if (! $tbl_is_view && strtolower($db) != 'information_schema'
229 && (!PMA_DRIZZLE || strtolower($db) != 'data_dictionary')) {
231 * Displays indexes
233 echo PMA_Index::getView($table, $db, true);
236 * Displays Space usage and row statistics
239 if ($cfg['ShowStats']) {
240 $nonisam = false;
241 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
242 $nonisam = true;
244 if ($nonisam == false) {
245 // Gets some sizes
247 $mergetable = PMA_Table::isMerge($db, $table);
249 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
250 if ($mergetable == false) {
251 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
253 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
254 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
255 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
256 } else {
257 unset($free_size);
258 unset($free_unit);
259 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
261 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
262 if ($num_rows > 0) {
263 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
266 // Displays them
268 <br /><br />
270 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
271 <tr>
273 <!-- Space usage -->
274 <td valign="top">
275 <big><?php echo __('Space usage') . ':'; ?></big>
276 <table width="100%">
277 <tr>
278 <th><?php echo __('Type'); ?></th>
279 <th colspan="2" align="center"><?php echo __('Usage'); ?></th>
280 </tr>
281 <tr>
282 <td style="padding-right: 10px"><?php echo __('Data'); ?></td>
283 <td align="right"><?php echo $data_size; ?></td>
284 <td><?php echo $data_unit; ?></td>
285 </tr>
286 <?php
287 if (isset($index_size)) {
288 echo "\n";
290 <tr>
291 <td style="padding-right: 10px"><?php echo __('Index'); ?></td>
292 <td align="right"><?php echo $index_size; ?></td>
293 <td><?php echo $index_unit; ?></td>
294 </tr>
295 <?php
297 if (isset($free_size)) {
298 echo "\n";
300 <tr style="color: #bb0000">
301 <td style="padding-right: 10px"><?php echo __('Overhead'); ?></td>
302 <td align="right"><?php echo $free_size; ?></td>
303 <td><?php echo $free_unit; ?></td>
304 </tr>
305 <tr>
306 <td style="padding-right: 10px"><?php echo __('Effective'); ?></td>
307 <td align="right"><?php echo $effect_size; ?></td>
308 <td><?php echo $effect_unit; ?></td>
309 </tr>
310 <?php
312 if (isset($tot_size) && $mergetable == false) {
313 echo "\n";
315 <tr>
316 <td style="padding-right: 10px"><?php echo __('Total'); ?></td>
317 <td align="right"><?php echo $tot_size; ?></td>
318 <td><?php echo $tot_unit; ?></td>
319 </tr>
320 <?php
322 echo "\n";
324 </table>
325 </td>
327 <td width="20">&nbsp;</td>
329 <!-- Rows Statistic -->
330 <td valign="top">
331 <big><?php echo __('Row Statistics') . ':'; ?></big>
332 <table width="100%">
333 <tr>
334 <th><?php echo __('Statements'); ?></th>
335 <th align="center"><?php echo __('Value'); ?></th>
336 </tr>
337 <?php
338 if (isset($showtable['Row_format'])) {
340 <tr>
341 <td><?php echo __('Format'); ?></td>
342 <td align="<?php echo $cell_align_left; ?>">
343 <?php
344 if ($showtable['Row_format'] == 'Fixed') {
345 echo __('static');
346 } elseif ($showtable['Row_format'] == 'Dynamic') {
347 echo __('dynamic');
348 } else {
349 echo $showtable['Row_format'];
352 </td>
353 </tr>
354 <?php
356 if (isset($showtable['Rows'])) {
358 <tr>
359 <td><?php echo __('Rows'); ?></td>
360 <td align="right">
361 <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
362 </td>
363 </tr>
364 <?php
366 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
368 <tr>
369 <td><?php echo __('Row length'); ?>&nbsp;&oslash;</td>
370 <td>
371 <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
372 </td>
373 </tr>
374 <?php
376 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
378 <tr>
379 <td><?php echo __('Row size'); ?>&nbsp;&oslash;</td>
380 <td align="right">
381 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
382 </td>
383 </tr>
384 <?php
386 if (isset($showtable['Auto_increment'])) {
388 <tr>
389 <td><?php echo __('Next autoindex'); ?></td>
390 <td align="right">
391 <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
392 </td>
393 </tr>
394 <?php
396 if (isset($showtable['Create_time'])) {
398 <tr>
399 <td><?php echo __('Creation'); ?></td>
400 <td align="right">
401 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
402 </td>
403 </tr>
404 <?php
406 if (isset($showtable['Update_time'])) {
408 <tr>
409 <td><?php echo __('Last update'); ?></td>
410 <td align="right">
411 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
412 </td>
413 </tr>
414 <?php
416 if (isset($showtable['Check_time'])) {
418 <tr>
419 <td><?php echo __('Last check'); ?></td>
420 <td align="right">
421 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
422 </td>
423 </tr>
424 <?php
428 </table>
429 </td>
430 </tr>
431 </table>
433 <?php
434 } // end if ($nonisam == false)
435 } // end if ($cfg['ShowStats'])
437 if ($multi_tables) {
438 unset($num_rows, $show_comment);
439 echo '<hr />' . "\n";
440 } // end if
441 echo '</div>' . "\n";
443 } // end while
446 * Displays the footer
450 <script type="text/javascript">
451 //<![CDATA[
452 function printPage()
454 // Do print the page
455 if (typeof(window.print) != 'undefined') {
456 window.print();
459 //]]>
460 </script>
462 <p class="print_ignore">
463 <input type="button" id="print" value="<?php echo __('Print'); ?>"
464 onclick="printPage()" /></p>
466 <?php
467 require './libraries/footer.inc.php';