Translation update done using Pootle.
[phpmyadmin/dkf.git] / db_datadict.php
blob7666b567ae084f5d8835b4ae017e50dabe6c3774
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 require_once './libraries/header.inc.php';
18 /**
19 * Gets the relations settings
21 $cfgRelation = PMA_getRelationsParam();
23 require_once './libraries/transformations.lib.php';
26 /**
27 * Check parameters
29 PMA_checkParameters(array('db'));
31 /**
32 * Defines the url to return to in case of error in a sql statement
34 if (strlen($table)) {
35 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
36 } else {
37 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
40 if ($cfgRelation['commwork']) {
41 $comment = PMA_getDbComment($db);
43 /**
44 * Displays DB comment
46 if ($comment) {
48 <p> <?php echo __('Database comment: '); ?>
49 <i><?php echo htmlspecialchars($comment); ?></i></p>
50 <?php
51 } // end if
54 /**
55 * Selects the database and gets tables names
57 PMA_DBI_select_db($db);
58 $rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE);
60 $count = 0;
61 while ($row = PMA_DBI_fetch_assoc($rowset)) {
62 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
63 $table = $row[$myfieldname];
64 $comments = PMA_getComments($db, $table);
66 if ($count != 0) {
67 echo '<div style="page-break-before: always;">' . "\n";
68 } else {
69 echo '<div>' . "\n";
72 echo '<h2>' . $table . '</h2>' . "\n";
74 /**
75 * Gets table informations
77 // The 'show table' statement works correct since 3.23.03
78 $num_rows = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_ROWS');
79 $show_comment = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_COMMENT');
81 /**
82 * Gets table keys and retains them
85 PMA_DBI_select_db($db);
86 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
87 $primary = '';
88 $indexes = array();
89 $lastIndex = '';
90 $indexes_info = array();
91 $indexes_data = array();
92 $pk_array = array(); // will be use to emphasis prim. keys in the table
93 // view
94 while ($row = PMA_DBI_fetch_assoc($result)) {
95 // Backups the list of primary keys
96 if ($row['Key_name'] == 'PRIMARY') {
97 $primary .= $row['Column_name'] . ', ';
98 $pk_array[$row['Column_name']] = 1;
100 // Retains keys informations
101 if ($row['Key_name'] != $lastIndex){
102 $indexes[] = $row['Key_name'];
103 $lastIndex = $row['Key_name'];
105 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
106 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
107 if (isset($row['Cardinality'])) {
108 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
110 // I don't know what does following column mean....
111 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
113 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
115 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
116 if (isset($row['Sub_part'])) {
117 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
120 } // end while
121 if ($result) {
122 PMA_DBI_free_result($result);
127 * Gets columns properties
129 $result = PMA_DBI_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
130 $fields_cnt = PMA_DBI_num_rows($result);
132 if (PMA_MYSQL_INT_VERSION < 50025) {
133 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
134 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
135 // and SHOW CREATE TABLE says NOT NULL
136 // http://bugs.mysql.com/20910.
138 $show_create_table = PMA_DBI_fetch_value(
139 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
140 0, 1);
141 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
144 // Check if we can use Relations (Mike Beck)
145 if (!empty($cfgRelation['relation'])) {
146 // Find which tables are related with the current one and write it in
147 // an array
148 $res_rel = PMA_getForeigners($db, $table);
150 if (count($res_rel) > 0) {
151 $have_rel = TRUE;
152 } else {
153 $have_rel = FALSE;
155 } else {
156 $have_rel = FALSE;
157 } // end if
161 * Displays the comments of the table if MySQL >= 3.23
163 if (!empty($show_comment)) {
164 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
168 * Displays the table structure
172 <table width="100%" class="print">
173 <tr><th width="50"><?php echo __('Column'); ?></th>
174 <th width="80"><?php echo __('Type'); ?></th>
175 <?php /* <th width="50"><?php echo __('Attributes'); ?></th>*/ ?>
176 <th width="40"><?php echo __('Null'); ?></th>
177 <th width="70"><?php echo __('Default'); ?></th>
178 <?php /* <th width="50"><?php echo __('Extra'); ?></th>*/ ?>
179 <?php
180 if ($have_rel) {
181 echo ' <th>' . __('Links to') . '</th>' . "\n";
183 echo ' <th>' . __('Comments') . '</th>' . "\n";
184 if ($cfgRelation['mimework']) {
185 echo ' <th>MIME</th>' . "\n";
188 </tr>
189 <?php
190 $odd_row = true;
191 while ($row = PMA_DBI_fetch_assoc($result)) {
193 if ($row['Null'] == '') {
194 $row['Null'] = 'NO';
196 $type = $row['Type'];
197 // reformat mysql query output
198 // set or enum types: slashes single quotes inside options
199 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
200 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
201 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
202 $type_nowrap = '';
204 $binary = 0;
205 $unsigned = 0;
206 $zerofill = 0;
207 } else {
208 $binary = stristr($row['Type'], 'binary');
209 $unsigned = stristr($row['Type'], 'unsigned');
210 $zerofill = stristr($row['Type'], 'zerofill');
211 $type_nowrap = ' nowrap="nowrap"';
212 $type = preg_replace('@BINARY@i', '', $type);
213 $type = preg_replace('@ZEROFILL@i', '', $type);
214 $type = preg_replace('@UNSIGNED@i', '', $type);
215 if (empty($type)) {
216 $type = ' ';
219 $attribute = ' ';
220 if ($binary) {
221 $attribute = 'BINARY';
223 if ($unsigned) {
224 $attribute = 'UNSIGNED';
226 if ($zerofill) {
227 $attribute = 'UNSIGNED ZEROFILL';
229 if (!isset($row['Default'])) {
230 if ($row['Null'] != 'NO') {
231 $row['Default'] = '<i>NULL</i>';
233 } else {
234 $row['Default'] = htmlspecialchars($row['Default']);
236 $field_name = htmlspecialchars($row['Field']);
238 if (PMA_MYSQL_INT_VERSION < 50025
239 && ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
240 && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
241 && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
242 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
243 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
244 // the latter.
246 * @todo merge this logic with the one in tbl_structure.php
247 * or move it in a function similar to PMA_DBI_get_columns_full()
248 * but based on SHOW CREATE TABLE because information_schema
249 * cannot be trusted in this case (MySQL bug)
251 $row['Null'] = 'NO';
254 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
255 <td nowrap="nowrap">
256 <?php
257 if (isset($pk_array[$row['Field']])) {
258 echo '<u>' . $field_name . '</u>';
259 } else {
260 echo $field_name;
263 </td>
264 <td<?php echo $type_nowrap; ?> xml:lang="en" dir="ltr"><?php echo $type; ?></td>
265 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $attribute; ?></td>*/ ?>
266 <td><?php echo (($row['Null'] == 'NO') ? __('No') : __('Yes')); ?></td>
267 <td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td>
268 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?>
269 <?php
270 if ($have_rel) {
271 echo ' <td>';
272 if (isset($res_rel[$field_name])) {
273 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
275 echo '</td>' . "\n";
277 echo ' <td>';
278 if (isset($comments[$field_name])) {
279 echo htmlspecialchars($comments[$field_name]);
281 echo '</td>' . "\n";
282 if ($cfgRelation['mimework']) {
283 $mime_map = PMA_getMIME($db, $table, true);
285 echo ' <td>';
286 if (isset($mime_map[$field_name])) {
287 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
289 echo '</td>' . "\n";
292 </tr>
293 <?php
294 } // end while
295 PMA_DBI_free_result($result);
296 $count++;
298 </table>
299 </div>
300 <?php
301 } //ends main while
304 * Displays the footer
307 <script type="text/javascript">
308 //<![CDATA[
309 function printPage()
311 document.getElementById('print').style.visibility = 'hidden';
312 // Do print the page
313 if (typeof(window.print) != 'undefined') {
314 window.print();
316 document.getElementById('print').style.visibility = '';
318 //]]>
319 </script>
320 <?php
321 echo '<br /><br /><input type="button" id="print" value="' . __('Print') . '" onclick="printPage()" />';
323 require './libraries/footer.inc.php';