Translated using Weblate (Traditional Chinese)
[phpmyadmin.git] / db_datadict.php
blob8744aa4a053ac292c610c72c5702b07e793392a3
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
8 /**
9 * Gets the variables sent or posted to this script, then displays headers
11 require_once 'libraries/common.inc.php';
13 if (! isset($selected_tbl)) {
14 include 'libraries/db_common.inc.php';
15 include 'libraries/db_info.inc.php';
18 $response = PMA_Response::getInstance();
19 $header = $response->getHeader();
20 $header->enablePrintView();
22 /**
23 * Gets the relations settings
25 $cfgRelation = PMA_getRelationsParam();
27 require_once 'libraries/transformations.lib.php';
28 require_once 'libraries/Index.class.php';
30 /**
31 * Check parameters
33 PMA_Util::checkParameters(array('db'));
35 /**
36 * Defines the url to return to in case of error in a sql statement
38 if (strlen($table)) {
39 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
40 } else {
41 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
44 if ($cfgRelation['commwork']) {
45 $comment = PMA_getDbComment($db);
47 /**
48 * Displays DB comment
50 if ($comment) {
51 echo '<p>' . __('Database comment: ')
52 . '<i>' . htmlspecialchars($comment) . '</i></p>';
53 } // end if
56 /**
57 * Selects the database and gets tables names
59 PMA_DBI_select_db($db);
60 $tables = PMA_DBI_get_tables($db);
62 $count = 0;
63 foreach ($tables as $table) {
64 $comments = PMA_getComments($db, $table);
66 echo '<div>' . "\n";
68 echo '<h2>' . htmlspecialchars($table) . '</h2>' . "\n";
70 /**
71 * Gets table informations
73 $show_comment = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_COMMENT');
75 /**
76 * Gets table keys and retains them
79 PMA_DBI_select_db($db);
80 $indexes = PMA_DBI_get_table_indexes($db, $table);
81 $primary = '';
82 $indexes = array();
83 $lastIndex = '';
84 $indexes_info = array();
85 $indexes_data = array();
86 $pk_array = array(); // will be use to emphasis prim. keys in the table
87 // view
88 foreach ($indexes as $row) {
89 // Backups the list of primary keys
90 if ($row['Key_name'] == 'PRIMARY') {
91 $primary .= $row['Column_name'] . ', ';
92 $pk_array[$row['Column_name']] = 1;
94 // Retains keys informations
95 if ($row['Key_name'] != $lastIndex) {
96 $indexes[] = $row['Key_name'];
97 $lastIndex = $row['Key_name'];
99 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
100 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
101 if (isset($row['Cardinality'])) {
102 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
104 // I don't know what does following column mean....
105 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
107 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
109 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
110 if (isset($row['Sub_part'])) {
111 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
114 } // end while
117 * Gets columns properties
119 $columns = PMA_DBI_get_columns($db, $table);
120 $fields_cnt = count($columns);
122 if (PMA_MYSQL_INT_VERSION < 50025) {
123 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
124 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
125 // and SHOW CREATE TABLE says NOT NULL
126 // http://bugs.mysql.com/20910.
128 $show_create_table_query = 'SHOW CREATE TABLE '
129 . PMA_Util::backquote($db) . '.'
130 . PMA_Util::backquote($table);
131 $show_create_table = PMA_DBI_fetch_value(
132 $show_create_table_query, 0, 1
134 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
137 // Check if we can use Relations
138 if (!empty($cfgRelation['relation'])) {
139 // Find which tables are related with the current one and write it in
140 // an array
141 $res_rel = PMA_getForeigners($db, $table);
143 if (count($res_rel) > 0) {
144 $have_rel = true;
145 } else {
146 $have_rel = false;
148 } else {
149 $have_rel = false;
150 } // end if
154 * Displays the comments of the table if MySQL >= 3.23
156 if (!empty($show_comment)) {
157 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
161 * Displays the table structure
165 <table width="100%" class="print">
166 <tr><th width="50"><?php echo __('Column'); ?></th>
167 <th width="80"><?php echo __('Type'); ?></th>
168 <?php /* <th width="50"><?php echo __('Attributes'); ?></th>*/ ?>
169 <th width="40"><?php echo __('Null'); ?></th>
170 <th width="70"><?php echo __('Default'); ?></th>
171 <?php /* <th width="50"><?php echo __('Extra'); ?></th>*/ ?>
172 <?php
173 if ($have_rel) {
174 echo ' <th>' . __('Links to') . '</th>' . "\n";
176 echo ' <th>' . __('Comments') . '</th>' . "\n";
177 if ($cfgRelation['mimework']) {
178 echo ' <th>MIME</th>' . "\n";
181 </tr>
182 <?php
183 $odd_row = true;
184 foreach ($columns as $row) {
186 if ($row['Null'] == '') {
187 $row['Null'] = 'NO';
189 $extracted_columnspec
190 = PMA_Util::extractColumnSpec($row['Type']);
192 // reformat mysql query output
193 // set or enum types: slashes single quotes inside options
194 if ('set' == $extracted_columnspec['type'] || 'enum' == $extracted_columnspec['type']) {
195 $type_nowrap = '';
197 } else {
198 $type_nowrap = ' class="nowrap"';
200 $type = htmlspecialchars($extracted_columnspec['print_type']);
201 $attribute = $extracted_columnspec['attribute'];
202 if (! isset($row['Default'])) {
203 if ($row['Null'] != 'NO') {
204 $row['Default'] = '<i>NULL</i>';
206 } else {
207 $row['Default'] = htmlspecialchars($row['Default']);
209 $field_name = $row['Field'];
211 if (PMA_MYSQL_INT_VERSION < 50025
212 && ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
213 && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
214 && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']
216 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
217 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
218 // the latter.
220 * @todo merge this logic with the one in tbl_structure.php
221 * or move it in a function similar to PMA_DBI_get_columns_full()
222 * but based on SHOW CREATE TABLE because information_schema
223 * cannot be trusted in this case (MySQL bug)
225 $row['Null'] = 'NO';
228 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
229 <td class="nowrap">
230 <?php
231 if (isset($pk_array[$row['Field']])) {
232 echo '<u>' . htmlspecialchars($field_name) . '</u>';
233 } else {
234 echo htmlspecialchars($field_name);
237 </td>
238 <td<?php echo $type_nowrap; ?> lang="en" dir="ltr"><?php echo $type; ?></td>
239 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $attribute; ?></td>*/ ?>
240 <td><?php echo (($row['Null'] == 'NO') ? __('No') : __('Yes')); ?></td>
241 <td class="nowrap"><?php
242 if (isset($row['Default'])) {
243 echo $row['Default'];
245 ?></td>
246 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?>
247 <?php
248 if ($have_rel) {
249 echo ' <td>';
250 if (isset($res_rel[$field_name])) {
251 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
253 echo '</td>' . "\n";
255 echo ' <td>';
256 if (isset($comments[$field_name])) {
257 echo htmlspecialchars($comments[$field_name]);
259 echo '</td>' . "\n";
260 if ($cfgRelation['mimework']) {
261 $mime_map = PMA_getMIME($db, $table, true);
263 echo ' <td>';
264 if (isset($mime_map[$field_name])) {
265 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
267 echo '</td>' . "\n";
270 </tr>
271 <?php
272 } // end foreach
273 $count++;
275 </table>
276 <?php
277 // display indexes information
278 if (count(PMA_Index::getFromTable($table, $db)) > 0) {
279 echo PMA_Index::getView($table, $db, true);
282 </div>
283 <?php
284 } //ends main while
287 * Displays the footer
289 echo PMA_Util::getButton();