2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Renders data dictionary
10 * Gets the variables sent or posted to this script, then displays headers
12 require_once 'libraries/common.inc.php';
14 if (! isset($selected_tbl)) {
15 include 'libraries/db_common.inc.php';
16 include 'libraries/db_info.inc.php';
19 $response = PMA_Response
::getInstance();
20 $header = $response->getHeader();
21 $header->enablePrintView();
24 * Gets the relations settings
26 $cfgRelation = PMA_getRelationsParam();
28 require_once 'libraries/transformations.lib.php';
29 require_once 'libraries/Index.class.php';
34 PMA_Util
::checkParameters(array('db'));
37 * Defines the url to return to in case of error in a sql statement
40 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
42 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
45 if ($cfgRelation['commwork']) {
46 $comment = PMA_getDbComment($db);
52 echo '<p>' . __('Database comment: ')
53 . '<i>' . htmlspecialchars($comment) . '</i></p>';
58 * Selects the database and gets tables names
60 $GLOBALS['dbi']->selectDb($db);
61 $tables = $GLOBALS['dbi']->getTables($db);
64 foreach ($tables as $table) {
65 $comments = PMA_getComments($db, $table);
69 echo '<h2>' . htmlspecialchars($table) . '</h2>' . "\n";
72 * Gets table informations
74 $show_comment = PMA_Table
::sGetStatusInfo($db, $table, 'TABLE_COMMENT');
77 * Gets table keys and retains them
80 $GLOBALS['dbi']->selectDb($db);
81 $indexes = $GLOBALS['dbi']->getTableIndexes($db, $table);
85 $indexes_info = array();
86 $indexes_data = array();
87 $pk_array = array(); // will be use to emphasis prim. keys in the table
89 foreach ($indexes as $row) {
90 // Backups the list of primary keys
91 if ($row['Key_name'] == 'PRIMARY') {
92 $primary .= $row['Column_name'] . ', ';
93 $pk_array[$row['Column_name']] = 1;
95 // Retains keys informations
96 if ($row['Key_name'] != $lastIndex) {
97 $indexes[] = $row['Key_name'];
98 $lastIndex = $row['Key_name'];
100 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
101 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
102 if (isset($row['Cardinality'])) {
103 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
105 // I don't know what does following column mean....
106 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
108 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
110 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
111 if (isset($row['Sub_part'])) {
112 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
118 * Gets columns properties
120 $columns = $GLOBALS['dbi']->getColumns($db, $table);
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 = $GLOBALS['dbi']->fetchValue(
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
141 $res_rel = PMA_getForeigners($db, $table);
143 if (count($res_rel) > 0) {
154 * Displays the comments of the table if MySQL >= 3.23
156 if (!empty($show_comment)) {
157 echo __('Table comments:') . ' ';
158 echo htmlspecialchars($show_comment) . '<br /><br />';
162 * Displays the table structure
165 echo '<table width="100%" class="print">';
166 echo '<tr><th width="50">' . __('Column') . '</th>';
167 echo '<th width="80">' . __('Type') . '</th>';
168 echo '<th width="40">' . __('Null') . '</th>';
169 echo '<th width="70">' . __('Default') . '</th>';
171 echo ' <th>' . __('Links to') . '</th>' . "\n";
173 echo ' <th>' . __('Comments') . '</th>' . "\n";
174 if ($cfgRelation['mimework']) {
175 echo ' <th>MIME</th>' . "\n";
179 foreach ($columns as $row) {
181 if ($row['Null'] == '') {
184 $extracted_columnspec
185 = PMA_Util
::extractColumnSpec($row['Type']);
187 // reformat mysql query output
188 // set or enum types: slashes single quotes inside options
189 if ('set' == $extracted_columnspec['type']
190 ||
'enum' == $extracted_columnspec['type']
195 $type_nowrap = ' class="nowrap"';
197 $type = htmlspecialchars($extracted_columnspec['print_type']);
198 $attribute = $extracted_columnspec['attribute'];
199 if (! isset($row['Default'])) {
200 if ($row['Null'] != 'NO') {
201 $row['Default'] = '<i>NULL</i>';
204 $row['Default'] = htmlspecialchars($row['Default']);
206 $column_name = $row['Field'];
208 if (PMA_MYSQL_INT_VERSION
< 50025
209 && ! empty($analyzed_sql[0]['create_table_fields'][$column_name]['type'])
210 && $analyzed_sql[0]['create_table_fields'][$column_name]['type'] == 'TIMESTAMP'
211 && $analyzed_sql[0]['create_table_fields'][$column_name]['timestamp_not_null']
213 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as
214 // having the NULL attribute, but SHOW CREATE TABLE says the
215 // contrary. Believe the latter.
217 * @todo merge this logic with the one in tbl_structure.php
218 * or move it in a function similar to $GLOBALS['dbi']->getColumnsFull()
219 * but based on SHOW CREATE TABLE because information_schema
220 * cannot be trusted in this case (MySQL bug)
225 echo $odd_row ?
'odd' : 'even'; $odd_row = ! $odd_row;
227 echo '<td class="nowrap">';
229 if (isset($pk_array[$row['Field']])) {
230 echo '<u>' . htmlspecialchars($column_name) . '</u>';
232 echo htmlspecialchars($column_name);
235 echo '<td' . $type_nowrap . ' lang="en" dir="ltr">' . $type . '</td>';
237 echo (($row['Null'] == 'NO') ?
__('No') : __('Yes'));
239 echo '<td class="nowrap">';
240 if (isset($row['Default'])) {
241 echo $row['Default'];
247 if (isset($res_rel[$column_name])) {
248 echo htmlspecialchars(
249 $res_rel[$column_name]['foreign_table']
251 . $res_rel[$column_name]['foreign_field']
257 if (isset($comments[$column_name])) {
258 echo htmlspecialchars($comments[$column_name]);
261 if ($cfgRelation['mimework']) {
262 $mime_map = PMA_getMIME($db, $table, true);
265 if (isset($mime_map[$column_name])) {
266 echo htmlspecialchars(
267 str_replace('_', '/', $mime_map[$column_name]['mimetype'])
276 // display indexes information
277 if (count(PMA_Index
::getFromTable($table, $db)) > 0) {
278 echo PMA_Index
::getView($table, $db, true);
284 * Displays the footer
286 echo PMA_Util
::getButton();