Translated using Weblate (Polish)
[phpmyadmin.git] / db_datadict.php
blobf08a5c4779caee665570278c60fc5e81bc9576bb
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Renders data dictionary
6 * @package PhpMyAdmin
7 */
9 /**
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();
23 /**
24 * Gets the relations settings
26 $cfgRelation = PMA_getRelationsParam();
28 require_once 'libraries/transformations.lib.php';
29 require_once 'libraries/Index.class.php';
31 /**
32 * Check parameters
34 PMA_Util::checkParameters(array('db'));
36 /**
37 * Defines the url to return to in case of error in a sql statement
39 if (strlen($table)) {
40 $err_url = 'tbl_sql.php?' . PMA_URL_getCommon($db, $table);
41 } else {
42 $err_url = 'db_sql.php?' . PMA_URL_getCommon($db);
45 if ($cfgRelation['commwork']) {
46 $comment = PMA_getDbComment($db);
48 /**
49 * Displays DB comment
51 if ($comment) {
52 echo '<p>' . __('Database comment: ')
53 . '<i>' . htmlspecialchars($comment) . '</i></p>';
54 } // end if
57 /**
58 * Selects the database and gets tables names
60 $GLOBALS['dbi']->selectDb($db);
61 $tables = $GLOBALS['dbi']->getTables($db);
63 $count = 0;
64 foreach ($tables as $table) {
65 $comments = PMA_getComments($db, $table);
67 echo '<div>' . "\n";
69 echo '<h2>' . htmlspecialchars($table) . '</h2>' . "\n";
71 /**
72 * Gets table informations
74 $show_comment = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_COMMENT');
76 /**
77 * Gets table keys and retains them
80 $GLOBALS['dbi']->selectDb($db);
81 $indexes = $GLOBALS['dbi']->getTableIndexes($db, $table);
82 $primary = '';
83 $indexes = array();
84 $lastIndex = '';
85 $indexes_info = array();
86 $indexes_data = array();
87 $pk_array = array(); // will be use to emphasis prim. keys in the table
88 // view
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']
111 = $row['Column_name'];
112 if (isset($row['Sub_part'])) {
113 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part']
114 = $row['Sub_part'];
117 } // end while
120 * Gets columns properties
122 $columns = $GLOBALS['dbi']->getColumns($db, $table);
124 if (PMA_MYSQL_INT_VERSION < 50025) {
125 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
126 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
127 // and SHOW CREATE TABLE says NOT NULL
128 // http://bugs.mysql.com/20910.
130 $show_create_table_query = 'SHOW CREATE TABLE '
131 . PMA_Util::backquote($db) . '.'
132 . PMA_Util::backquote($table);
133 $show_create_table = $GLOBALS['dbi']->fetchValue(
134 $show_create_table_query, 0, 1
136 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
139 // Check if we can use Relations
140 if (!empty($cfgRelation['relation'])) {
141 // Find which tables are related with the current one and write it in
142 // an array
143 $res_rel = PMA_getForeigners($db, $table);
145 if (count($res_rel) > 0) {
146 $have_rel = true;
147 } else {
148 $have_rel = false;
150 } else {
151 $have_rel = false;
152 } // end if
156 * Displays the comments of the table if MySQL >= 3.23
158 if (!empty($show_comment)) {
159 echo __('Table comments:') . ' ';
160 echo htmlspecialchars($show_comment) . '<br /><br />';
164 * Displays the table structure
167 echo '<table width="100%" class="print">';
168 echo '<tr><th width="50">' . __('Column') . '</th>';
169 echo '<th width="80">' . __('Type') . '</th>';
170 echo '<th width="40">' . __('Null') . '</th>';
171 echo '<th width="70">' . __('Default') . '</th>';
172 if ($have_rel) {
173 echo ' <th>' . __('Links to') . '</th>' . "\n";
175 echo ' <th>' . __('Comments') . '</th>' . "\n";
176 if ($cfgRelation['mimework']) {
177 echo ' <th>MIME</th>' . "\n";
179 echo '</tr>';
180 $odd_row = true;
181 foreach ($columns as $row) {
183 if ($row['Null'] == '') {
184 $row['Null'] = 'NO';
186 $extracted_columnspec
187 = PMA_Util::extractColumnSpec($row['Type']);
189 // reformat mysql query output
190 // set or enum types: slashes single quotes inside options
191 if ('set' == $extracted_columnspec['type']
192 || 'enum' == $extracted_columnspec['type']
194 $type_nowrap = '';
196 } else {
197 $type_nowrap = ' class="nowrap"';
199 $type = htmlspecialchars($extracted_columnspec['print_type']);
200 $attribute = $extracted_columnspec['attribute'];
201 if (! isset($row['Default'])) {
202 if ($row['Null'] != 'NO') {
203 $row['Default'] = '<i>NULL</i>';
205 } else {
206 $row['Default'] = htmlspecialchars($row['Default']);
208 $column_name = $row['Field'];
210 $tmp_column = $analyzed_sql[0]['create_table_fields'][$column_name];
211 if (PMA_MYSQL_INT_VERSION < 50025
212 && ! empty($tmp_column['type'])
213 && $tmp_column['type'] == 'TIMESTAMP'
214 && $tmp_column['timestamp_not_null']
216 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as
217 // having the NULL attribute, but SHOW CREATE TABLE says the
218 // contrary. Believe the latter.
220 * @todo merge this logic with the one in tbl_structure.php
221 * or move it in a function similar to $GLOBALS['dbi']->getColumnsFull()
222 * but based on SHOW CREATE TABLE because information_schema
223 * cannot be trusted in this case (MySQL bug)
225 $row['Null'] = 'NO';
227 echo '<tr class="';
228 echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row;
229 echo '">';
230 echo '<td class="nowrap">';
232 if (isset($pk_array[$row['Field']])) {
233 echo '<u>' . htmlspecialchars($column_name) . '</u>';
234 } else {
235 echo htmlspecialchars($column_name);
237 echo '</td>';
238 echo '<td' . $type_nowrap . ' lang="en" dir="ltr">' . $type . '</td>';
239 echo '<td>';
240 echo (($row['Null'] == 'NO') ? __('No') : __('Yes'));
241 echo '</td>';
242 echo '<td class="nowrap">';
243 if (isset($row['Default'])) {
244 echo $row['Default'];
246 echo '</td>';
248 if ($have_rel) {
249 echo ' <td>';
250 if (isset($res_rel[$column_name])) {
251 echo htmlspecialchars(
252 $res_rel[$column_name]['foreign_table']
253 . ' -> '
254 . $res_rel[$column_name]['foreign_field']
257 echo '</td>' . "\n";
259 echo ' <td>';
260 if (isset($comments[$column_name])) {
261 echo htmlspecialchars($comments[$column_name]);
263 echo '</td>' . "\n";
264 if ($cfgRelation['mimework']) {
265 $mime_map = PMA_getMIME($db, $table, true);
267 echo ' <td>';
268 if (isset($mime_map[$column_name])) {
269 echo htmlspecialchars(
270 str_replace('_', '/', $mime_map[$column_name]['mimetype'])
273 echo '</td>' . "\n";
275 echo '</tr>';
276 } // end foreach
277 $count++;
278 echo '</table>';
279 // display indexes information
280 if (count(PMA_Index::getFromTable($table, $db)) > 0) {
281 echo PMA_Index::getView($table, $db, true);
283 echo '</div>';
284 } //ends main while
287 * Displays the footer
289 echo PMA_Util::getButton();