2 /* vim: set expandtab sw=4 ts=4 sts=4: */
12 require_once 'libraries/common.inc.php';
14 $response = PMA_Response
::getInstance();
15 $response->getHeader()->enablePrintView();
17 require 'libraries/tbl_common.inc.php';
21 if (! isset($the_tables) ||
! is_array($the_tables)) {
22 $the_tables = array();
26 * Gets the relations settings
28 require_once 'libraries/transformations.lib.php';
29 require_once 'libraries/Index.class.php';
31 $cfgRelation = PMA_getRelationsParam();
34 * Defines the url to return to in case of error in a sql statement
37 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
39 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
44 * Selects the database
46 PMA_DBI_select_db($db);
50 * Multi-tables printview
52 if (isset($selected_tbl) && is_array($selected_tbl)) {
53 $the_tables = $selected_tbl;
54 } elseif (strlen($table)) {
55 $the_tables[] = $table;
57 $multi_tables = (count($the_tables) > 1);
61 foreach ($the_tables as $key => $table) {
62 $tbl_list .= (empty($tbl_list) ?
'' : ', ')
63 . PMA_Util
::backquote($table);
65 echo '<strong>'. __('Showing tables') . ': '
66 . htmlspecialchars($tbl_list) . '</strong>' . "\n";
70 $tables_cnt = count($the_tables);
73 foreach ($the_tables as $key => $table) {
74 if ($counter +
1 >= $tables_cnt) {
77 $breakstyle = ' style="page-break-after: always;"';
80 echo '<div' . $breakstyle . '>' . "\n";
81 echo '<h1>' . htmlspecialchars($table) . '</h1>' . "\n";
84 * Gets table informations
86 $showtable = PMA_Table
::sGetStatusInfo($db, $table);
87 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
88 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
90 $tbl_is_view = PMA_Table
::isView($db, $table);
93 * Gets fields properties
95 $columns = PMA_DBI_get_columns($db, $table);
98 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
99 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
100 // and SHOW CREATE TABLE says NOT NULL (tested
101 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
103 $show_create_table = PMA_DBI_fetch_value(
104 'SHOW CREATE TABLE ' . PMA_Util
::backquote($db) . '.'
105 . PMA_Util
::backquote($table),
108 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
110 // Check if we can use Relations
111 // Find which tables are related with the current one and write it in
113 $res_rel = PMA_getForeigners($db, $table);
114 $have_rel = (bool) count($res_rel);
117 * Displays the comments of the table if MySQL >= 3.23
119 if (!empty($show_comment)) {
120 echo __('Table comments') . ': '
121 . htmlspecialchars($show_comment) . '<br /><br />';
125 * Displays the table structure
127 echo '<table style="width: 100%;">';
130 echo '<th>' . __('Column') . '</th>';
131 echo '<th>' . __('Type') . '</th>';
132 echo '<th>' . __('Null') . '</th>';
133 echo '<th>' . __('Default') . '</th>';
135 echo '<th>' . __('Links to') . '</th>' . "\n";
137 echo ' <th>' . __('Comments') . '</th>' . "\n";
138 if ($cfgRelation['mimework']) {
139 echo ' <th>MIME</th>' . "\n";
144 foreach ($columns as $row) {
145 $extracted_columnspec = PMA_Util
::extractColumnSpec($row['Type']);
146 $type = $extracted_columnspec['print_type'];
147 $attribute = $extracted_columnspec['attribute'];
149 if (! isset($row['Default'])) {
150 if ($row['Null'] != '' && $row['Null'] != 'NO') {
151 $row['Default'] = '<i>NULL</i>';
154 $row['Default'] = htmlspecialchars($row['Default']);
156 $field_name = htmlspecialchars($row['Field']);
158 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
159 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
162 * @todo merge this logic with the one in tbl_structure.php
163 * or move it in a function similar to PMA_DBI_get_columns_full()
164 * but based on SHOW CREATE TABLE because information_schema
165 * cannot be trusted in this case (MySQL bug)
167 if (! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
168 && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
169 && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']
177 if (isset($pk_array[$row['Field']])) {
178 echo ' <u>' . $field_name . '</u>' . "\n";
180 echo ' ' . $field_name . "\n";
183 echo '<td>' . $type. '<bdo dir="ltr"></bdo></td>';
185 echo (($row['Null'] == '' ||
$row['Null'] == 'NO')
190 if (isset($row['Default'])) {
191 echo $row['Default'];
196 if (isset($res_rel[$field_name])) {
197 echo htmlspecialchars(
198 $res_rel[$field_name]['foreign_table']
199 . ' -> ' . $res_rel[$field_name]['foreign_field']
202 echo ' </td>' . "\n";
205 $comments = PMA_getComments($db, $table);
206 if (isset($comments[$field_name])) {
207 echo htmlspecialchars($comments[$field_name]);
209 echo ' </td>' . "\n";
210 if ($cfgRelation['mimework']) {
211 $mime_map = PMA_getMIME($db, $table, true);
214 if (isset($mime_map[$field_name])) {
215 echo htmlspecialchars(
216 str_replace('_', '/', $mime_map[$field_name]['mimetype'])
219 echo ' </td>' . "\n";
225 if (! $tbl_is_view && !PMA_is_system_schema($db)) {
229 echo PMA_Index
::getView($table, $db, true);
232 * Displays Space usage and row statistics
235 if ($cfg['ShowStats']) {
237 if (isset($showtable['Type'])
238 && ! preg_match('@ISAM|HEAP@i', $showtable['Type'])
242 if ($nonisam == false) {
245 $mergetable = PMA_Table
::isMerge($db, $table);
247 list($data_size, $data_unit) = PMA_Util
::formatByteDown(
248 $showtable['Data_length']
250 if ($mergetable == false) {
251 list($index_size, $index_unit)
252 = PMA_Util
::formatByteDown(
253 $showtable['Index_length']
256 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
257 list($free_size, $free_unit)
258 = PMA_Util
::formatByteDown(
259 $showtable['Data_free']
261 list($effect_size, $effect_unit)
262 = PMA_Util
::formatByteDown(
263 $showtable['Data_length'] +
$showtable['Index_length']
264 - $showtable['Data_free']
269 list($effect_size, $effect_unit)
270 = PMA_Util
::formatByteDown(
271 $showtable['Data_length'] +
$showtable['Index_length']
274 list($tot_size, $tot_unit) = PMA_Util
::formatByteDown(
275 $showtable['Data_length'] +
$showtable['Index_length']
278 list($avg_size, $avg_unit)
279 = PMA_Util
::formatByteDown(
280 ($showtable['Data_length'] +
$showtable['Index_length'])
281 / $showtable['Rows'],
290 echo '<table cellspacing="0" cellpadding="0">';
295 echo '<td class="vtop">';
296 echo '<big>' . __('Space usage') . ':</big>';
297 echo '<table width="100%">';
299 echo '<td style="padding-right: 10px">' . __('Data') . '</td>';
300 echo '<td class="right">' . $data_size . '</td>';
301 echo '<td>' . $data_unit . '</td>';
303 if (isset($index_size)) {
306 echo '<td style="padding-right: 10px">' . __('Index') . '</td>';
307 echo '<td class="right">' . $index_size . '</td>';
308 echo '<td>' . $index_unit. '</td>';
311 if (isset($free_size)) {
313 echo '<tr style="color: #bb0000">';
314 echo '<td style="padding-right: 10px">';
317 echo '<td class="right">' . $free_size . '</td>';
318 echo '<td>' . $free_unit . '</td>';
321 echo '<td style="padding-right: 10px">';
322 echo __('Effective');
324 echo '<td class="right">' . $effect_size . '</td>';
325 echo '<td>' . $effect_unit . '</td>';
328 if (isset($tot_size) && $mergetable == false) {
331 echo '<td style="padding-right: 10px">' . __('Total') . '</td>';
332 echo '<td class="right">' . $tot_size . '</td>';
333 echo '<td>' . $tot_unit . '</td>';
340 echo '<td width="20"> </td>';
344 echo '<td class="vtop">';
345 echo '<big>' . __('Row Statistics') . ':</big>';
346 echo '<table width="100%">';
347 if (isset($showtable['Row_format'])) {
350 echo '<td>' . __('Format') . '</td>';
351 echo '<td class="' . $cell_align_left . '">';
352 if ($showtable['Row_format'] == 'Fixed') {
354 } elseif ($showtable['Row_format'] == 'Dynamic') {
357 echo $showtable['Row_format'];
362 if (isset($showtable['Rows'])) {
365 echo '<td>' . __('Rows') . '</td>';
366 echo '<td class="right">';
367 echo PMA_Util
::formatNumber($showtable['Rows'], 0);
371 if (isset($showtable['Avg_row_length'])
372 && $showtable['Avg_row_length'] > 0
376 echo '<td>' . __('Row length') . ' ø</td>';
378 echo PMA_Util
::formatNumber(
379 $showtable['Avg_row_length'], 0
384 if (isset($showtable['Data_length'])
385 && $showtable['Rows'] > 0
386 && $mergetable == false
390 echo '<td>' . __('Row size') . ' ø</td>';
391 echo '<td class="right">';
392 echo $avg_size . ' ' . $avg_unit;
396 if (isset($showtable['Auto_increment'])) {
399 echo '<td>' . __('Next autoindex'). ' </td>';
400 echo '<td class="right">';
401 echo PMA_Util
::formatNumber(
402 $showtable['Auto_increment'], 0
407 if (isset($showtable['Create_time'])) {
410 echo '<td>' . __('Creation') . '</td>';
411 echo '<td class="right">';
412 echo PMA_Util
::localisedDate(
413 strtotime($showtable['Create_time'])
418 if (isset($showtable['Update_time'])) {
421 echo '<td>' . __('Last update') . '</td>';
422 echo '<td class="right">';
423 echo PMA_Util
::localisedDate(
424 strtotime($showtable['Update_time'])
429 if (isset($showtable['Check_time'])) {
432 echo '<td>' . __('Last check') . '</td>';
433 echo '<td class="right">';
434 echo PMA_Util
::localisedDate(
435 strtotime($showtable['Check_time'])
446 } // end if ($nonisam == false)
447 } // end if ($cfg['ShowStats'])
450 unset($num_rows, $show_comment);
451 echo '<hr />' . "\n";
453 echo '</div>' . "\n";
458 * Displays the footer
460 echo PMA_Util
::getButton();
462 echo "<div id='PMA_disable_floating_menubar'></div>\n";