More concise descriptions for MySQL column types
[phpmyadmin.git] / db_datadict.php
blob578242fa1363a1eb003e4e3c4b088d1d4b87a37e
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';
19 /**
20 * Gets the relations settings
22 $cfgRelation = PMA_getRelationsParam();
24 require_once 'libraries/transformations.lib.php';
25 require_once 'libraries/Index.class.php';
27 /**
28 * Check parameters
30 PMA_checkParameters(array('db'));
32 /**
33 * Defines the url to return to in case of error in a sql statement
35 if (strlen($table)) {
36 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
37 } else {
38 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
41 if ($cfgRelation['commwork']) {
42 $comment = PMA_getDbComment($db);
44 /**
45 * Displays DB comment
47 if ($comment) {
49 <p> <?php echo __('Database comment: '); ?>
50 <i><?php echo htmlspecialchars($comment); ?></i></p>
51 <?php
52 } // end if
55 /**
56 * Selects the database and gets tables names
58 PMA_DBI_select_db($db);
59 $tables = PMA_DBI_get_tables($db);
61 $count = 0;
62 foreach ($tables as $table) {
63 $comments = PMA_getComments($db, $table);
65 echo '<div>' . "\n";
67 echo '<h2>' . htmlspecialchars($table) . '</h2>' . "\n";
69 /**
70 * Gets table informations
72 $show_comment = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_COMMENT');
74 /**
75 * Gets table keys and retains them
78 PMA_DBI_select_db($db);
79 $indexes = PMA_DBI_get_table_indexes($db, $table);
80 $primary = '';
81 $indexes = array();
82 $lastIndex = '';
83 $indexes_info = array();
84 $indexes_data = array();
85 $pk_array = array(); // will be use to emphasis prim. keys in the table
86 // view
87 foreach ($indexes as $row) {
88 // Backups the list of primary keys
89 if ($row['Key_name'] == 'PRIMARY') {
90 $primary .= $row['Column_name'] . ', ';
91 $pk_array[$row['Column_name']] = 1;
93 // Retains keys informations
94 if ($row['Key_name'] != $lastIndex) {
95 $indexes[] = $row['Key_name'];
96 $lastIndex = $row['Key_name'];
98 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
99 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
100 if (isset($row['Cardinality'])) {
101 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
103 // I don't know what does following column mean....
104 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
106 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
108 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
109 if (isset($row['Sub_part'])) {
110 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
113 } // end while
116 * Gets columns properties
118 $columns = PMA_DBI_get_columns($db, $table);
119 $fields_cnt = count($columns);
121 if (PMA_MYSQL_INT_VERSION < 50025) {
122 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
123 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
124 // and SHOW CREATE TABLE says NOT NULL
125 // http://bugs.mysql.com/20910.
127 $show_create_table = PMA_DBI_fetch_value(
128 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
129 0, 1
131 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
134 // Check if we can use Relations
135 if (!empty($cfgRelation['relation'])) {
136 // Find which tables are related with the current one and write it in
137 // an array
138 $res_rel = PMA_getForeigners($db, $table);
140 if (count($res_rel) > 0) {
141 $have_rel = true;
142 } else {
143 $have_rel = false;
145 } else {
146 $have_rel = false;
147 } // end if
151 * Displays the comments of the table if MySQL >= 3.23
153 if (!empty($show_comment)) {
154 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
158 * Displays the table structure
162 <table width="100%" class="print">
163 <tr><th width="50"><?php echo __('Column'); ?></th>
164 <th width="80"><?php echo __('Type'); ?></th>
165 <?php /* <th width="50"><?php echo __('Attributes'); ?></th>*/ ?>
166 <th width="40"><?php echo __('Null'); ?></th>
167 <th width="70"><?php echo __('Default'); ?></th>
168 <?php /* <th width="50"><?php echo __('Extra'); ?></th>*/ ?>
169 <?php
170 if ($have_rel) {
171 echo ' <th>' . __('Links to') . '</th>' . "\n";
173 echo ' <th>' . __('Comments') . '</th>' . "\n";
174 if ($cfgRelation['mimework']) {
175 echo ' <th>MIME</th>' . "\n";
178 </tr>
179 <?php
180 $odd_row = true;
181 foreach ($columns as $row) {
183 if ($row['Null'] == '') {
184 $row['Null'] = 'NO';
186 $extracted_columnspec = PMA_extractColumnSpec($row['Type']);
187 // reformat mysql query output
188 // set or enum types: slashes single quotes inside options
189 if ('set' == $extracted_columnspec['type'] || 'enum' == $extracted_columnspec['type']) {
190 $type_nowrap = '';
192 } else {
193 $type_nowrap = ' class="nowrap"';
195 $type = htmlspecialchars($extracted_columnspec['print_type']);
196 $attribute = $extracted_columnspec['attribute'];
197 if (! isset($row['Default'])) {
198 if ($row['Null'] != 'NO') {
199 $row['Default'] = '<i>NULL</i>';
201 } else {
202 $row['Default'] = htmlspecialchars($row['Default']);
204 $field_name = $row['Field'];
206 if (PMA_MYSQL_INT_VERSION < 50025
207 && ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
208 && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
209 && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']
211 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
212 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
213 // the latter.
215 * @todo merge this logic with the one in tbl_structure.php
216 * or move it in a function similar to PMA_DBI_get_columns_full()
217 * but based on SHOW CREATE TABLE because information_schema
218 * cannot be trusted in this case (MySQL bug)
220 $row['Null'] = 'NO';
223 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
224 <td class="nowrap">
225 <?php
226 if (isset($pk_array[$row['Field']])) {
227 echo '<u>' . htmlspecialchars($field_name) . '</u>';
228 } else {
229 echo htmlspecialchars($field_name);
232 </td>
233 <td<?php echo $type_nowrap; ?> lang="en" dir="ltr"><?php echo $type; ?></td>
234 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $attribute; ?></td>*/ ?>
235 <td><?php echo (($row['Null'] == 'NO') ? __('No') : __('Yes')); ?></td>
236 <td class="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td>
237 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?>
238 <?php
239 if ($have_rel) {
240 echo ' <td>';
241 if (isset($res_rel[$field_name])) {
242 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
244 echo '</td>' . "\n";
246 echo ' <td>';
247 if (isset($comments[$field_name])) {
248 echo htmlspecialchars($comments[$field_name]);
250 echo '</td>' . "\n";
251 if ($cfgRelation['mimework']) {
252 $mime_map = PMA_getMIME($db, $table, true);
254 echo ' <td>';
255 if (isset($mime_map[$field_name])) {
256 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
258 echo '</td>' . "\n";
261 </tr>
262 <?php
263 } // end foreach
264 $count++;
266 </table>
267 <?php
268 // display indexes information
269 if (count(PMA_Index::getFromTable($table, $db)) > 0){
270 echo PMA_Index::getView($table, $db, true);
273 </div>
274 <?php
275 } //ends main while
278 * Displays the footer
280 PMA_printButton();
282 require 'libraries/footer.inc.php';