Better descriptions for Drizzle column types
[phpmyadmin.git] / tbl_printview.php
blob60fc66f29232bee1483b3f5ffaa1ab07529e73cf
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 include_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 include_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>'. __('Showing 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
113 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
115 // Check if we can use Relations
116 // Find which tables are related with the current one and write it in
117 // an array
118 $res_rel = PMA_getForeigners($db, $table);
119 $have_rel = (bool) count($res_rel);
122 * Displays the comments of the table if MySQL >= 3.23
124 if (!empty($show_comment)) {
125 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
129 * Displays the table structure
133 <!-- TABLE INFORMATIONS -->
134 <table style="width: 100%;">
135 <thead>
136 <tr>
137 <th><?php echo __('Column'); ?></th>
138 <th><?php echo __('Type'); ?></th>
139 <th><?php echo __('Null'); ?></th>
140 <th><?php echo __('Default'); ?></th>
141 <?php
142 if ($have_rel) {
143 echo '<th>' . __('Links to') . '</th>' . "\n";
145 echo ' <th>' . __('Comments') . '</th>' . "\n";
146 if ($cfgRelation['mimework']) {
147 echo ' <th>MIME</th>' . "\n";
150 </tr>
151 </thead>
152 <tbody>
153 <?php
154 foreach ($columns as $row) {
155 $extracted_columnspec = PMA_extractColumnSpec($row['Type']);
156 $type = $extracted_columnspec['print_type'];
157 $attribute = $extracted_columnspec['attribute'];
159 if (! isset($row['Default'])) {
160 if ($row['Null'] != '' && $row['Null'] != 'NO') {
161 $row['Default'] = '<i>NULL</i>';
163 } else {
164 $row['Default'] = htmlspecialchars($row['Default']);
166 $field_name = htmlspecialchars($row['Field']);
168 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
169 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
170 // the latter.
172 * @todo merge this logic with the one in tbl_structure.php
173 * or move it in a function similar to PMA_DBI_get_columns_full()
174 * but based on SHOW CREATE TABLE because information_schema
175 * cannot be trusted in this case (MySQL bug)
177 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']) {
178 $row['Null'] = '';
181 echo '<tr><td>';
183 if (isset($pk_array[$row['Field']])) {
184 echo ' <u>' . $field_name . '</u>' . "\n";
185 } else {
186 echo ' ' . $field_name . "\n";
189 </td>
190 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
191 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes')); ?>&nbsp;</td>
192 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
193 <?php
194 if ($have_rel) {
195 echo ' <td>';
196 if (isset($res_rel[$field_name])) {
197 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
199 echo '&nbsp;</td>' . "\n";
201 echo ' <td>';
202 $comments = PMA_getComments($db, $table);
203 if (isset($comments[$field_name])) {
204 echo htmlspecialchars($comments[$field_name]);
206 echo '&nbsp;</td>' . "\n";
207 if ($cfgRelation['mimework']) {
208 $mime_map = PMA_getMIME($db, $table, true);
210 echo ' <td>';
211 if (isset($mime_map[$field_name])) {
212 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
214 echo '&nbsp;</td>' . "\n";
217 </tr>
218 <?php
219 } // end foreach
221 </tbody>
222 </table>
223 <?php
224 if (! $tbl_is_view && !PMA_is_system_schema($db)) {
226 * Displays indexes
228 echo PMA_Index::getView($table, $db, true);
231 * Displays Space usage and row statistics
234 if ($cfg['ShowStats']) {
235 $nonisam = false;
236 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
237 $nonisam = true;
239 if ($nonisam == false) {
240 // Gets some sizes
242 $mergetable = PMA_Table::isMerge($db, $table);
244 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
245 if ($mergetable == false) {
246 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
248 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
249 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
250 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
251 } else {
252 unset($free_size);
253 unset($free_unit);
254 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
256 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
257 if ($num_rows > 0) {
258 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
261 // Displays them
263 <br /><br />
265 <table cellspacing="0" cellpadding="0">
266 <tr>
268 <!-- Space usage -->
269 <td class="vtop">
270 <big><?php echo __('Space usage') . ':'; ?></big>
271 <table width="100%">
272 <tr>
273 <th><?php echo __('Type'); ?></th>
274 <th colspan="2" class="center"><?php echo __('Usage'); ?></th>
275 </tr>
276 <tr>
277 <td style="padding-right: 10px"><?php echo __('Data'); ?></td>
278 <td class="right"><?php echo $data_size; ?></td>
279 <td><?php echo $data_unit; ?></td>
280 </tr>
281 <?php
282 if (isset($index_size)) {
283 echo "\n";
285 <tr>
286 <td style="padding-right: 10px"><?php echo __('Index'); ?></td>
287 <td class="right"><?php echo $index_size; ?></td>
288 <td><?php echo $index_unit; ?></td>
289 </tr>
290 <?php
292 if (isset($free_size)) {
293 echo "\n";
295 <tr style="color: #bb0000">
296 <td style="padding-right: 10px"><?php echo __('Overhead'); ?></td>
297 <td class="right"><?php echo $free_size; ?></td>
298 <td><?php echo $free_unit; ?></td>
299 </tr>
300 <tr>
301 <td style="padding-right: 10px"><?php echo __('Effective'); ?></td>
302 <td class="right"><?php echo $effect_size; ?></td>
303 <td><?php echo $effect_unit; ?></td>
304 </tr>
305 <?php
307 if (isset($tot_size) && $mergetable == false) {
308 echo "\n";
310 <tr>
311 <td style="padding-right: 10px"><?php echo __('Total'); ?></td>
312 <td class="right"><?php echo $tot_size; ?></td>
313 <td><?php echo $tot_unit; ?></td>
314 </tr>
315 <?php
317 echo "\n";
319 </table>
320 </td>
322 <td width="20">&nbsp;</td>
324 <!-- Rows Statistic -->
325 <td class="vtop">
326 <big><?php echo __('Row Statistics') . ':'; ?></big>
327 <table width="100%">
328 <tr>
329 <th><?php echo __('Statements'); ?></th>
330 <th class="center"><?php echo __('Value'); ?></th>
331 </tr>
332 <?php
333 if (isset($showtable['Row_format'])) {
335 <tr>
336 <td><?php echo __('Format'); ?></td>
337 <td class="<?php echo $cell_align_left; ?>">
338 <?php
339 if ($showtable['Row_format'] == 'Fixed') {
340 echo __('static');
341 } elseif ($showtable['Row_format'] == 'Dynamic') {
342 echo __('dynamic');
343 } else {
344 echo $showtable['Row_format'];
347 </td>
348 </tr>
349 <?php
351 if (isset($showtable['Rows'])) {
353 <tr>
354 <td><?php echo __('Rows'); ?></td>
355 <td class="right">
356 <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
357 </td>
358 </tr>
359 <?php
361 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
363 <tr>
364 <td><?php echo __('Row length'); ?>&nbsp;&oslash;</td>
365 <td>
366 <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
367 </td>
368 </tr>
369 <?php
371 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
373 <tr>
374 <td><?php echo __('Row size'); ?>&nbsp;&oslash;</td>
375 <td class="right">
376 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
377 </td>
378 </tr>
379 <?php
381 if (isset($showtable['Auto_increment'])) {
383 <tr>
384 <td><?php echo __('Next autoindex'); ?></td>
385 <td class="right">
386 <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
387 </td>
388 </tr>
389 <?php
391 if (isset($showtable['Create_time'])) {
393 <tr>
394 <td><?php echo __('Creation'); ?></td>
395 <td class="right">
396 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
397 </td>
398 </tr>
399 <?php
401 if (isset($showtable['Update_time'])) {
403 <tr>
404 <td><?php echo __('Last update'); ?></td>
405 <td class="right">
406 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
407 </td>
408 </tr>
409 <?php
411 if (isset($showtable['Check_time'])) {
413 <tr>
414 <td><?php echo __('Last check'); ?></td>
415 <td class="right">
416 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
417 </td>
418 </tr>
419 <?php
423 </table>
424 </td>
425 </tr>
426 </table>
428 <?php
429 } // end if ($nonisam == false)
430 } // end if ($cfg['ShowStats'])
432 if ($multi_tables) {
433 unset($num_rows, $show_comment);
434 echo '<hr />' . "\n";
435 } // end if
436 echo '</div>' . "\n";
438 } // end while
441 * Displays the footer
443 PMA_printButton();
445 echo "<div id='PMA_disable_floating_menubar'></div>\n";
447 require 'libraries/footer.inc.php';