Translation update done using Pootle.
[phpmyadmin/dkf.git] / db_datadict.php
blob7af533c94f9388381b4c36a0df34315db0d4c187
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
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 require_once './libraries/header.inc.php';
19 /**
20 * Gets the relations settings
22 require_once './libraries/relation.lib.php';
23 require_once './libraries/transformations.lib.php';
25 $cfgRelation = PMA_getRelationsParam();
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 $rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE);
61 $count = 0;
62 while ($row = PMA_DBI_fetch_assoc($rowset)) {
63 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
64 $table = $row[$myfieldname];
65 $comments = PMA_getComments($db, $table);
67 if ($count != 0) {
68 echo '<div style="page-break-before: always;">' . "\n";
69 } else {
70 echo '<div>' . "\n";
73 echo '<h2>' . $table . '</h2>' . "\n";
75 /**
76 * Gets table informations
78 // The 'show table' statement works correct since 3.23.03
79 $num_rows = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_ROWS');
80 $show_comment = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_COMMENT');
82 /**
83 * Gets table keys and retains them
86 PMA_DBI_select_db($db);
87 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
88 $primary = '';
89 $indexes = array();
90 $lastIndex = '';
91 $indexes_info = array();
92 $indexes_data = array();
93 $pk_array = array(); // will be use to emphasis prim. keys in the table
94 // view
95 while ($row = PMA_DBI_fetch_assoc($result)) {
96 // Backups the list of primary keys
97 if ($row['Key_name'] == 'PRIMARY') {
98 $primary .= $row['Column_name'] . ', ';
99 $pk_array[$row['Column_name']] = 1;
101 // Retains keys informations
102 if ($row['Key_name'] != $lastIndex){
103 $indexes[] = $row['Key_name'];
104 $lastIndex = $row['Key_name'];
106 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
107 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
108 if (isset($row['Cardinality'])) {
109 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
111 // I don't know what does following column mean....
112 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
114 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
116 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
117 if (isset($row['Sub_part'])) {
118 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
121 } // end while
122 if ($result) {
123 PMA_DBI_free_result($result);
128 * Gets columns properties
130 $result = PMA_DBI_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
131 $fields_cnt = PMA_DBI_num_rows($result);
133 if (PMA_MYSQL_INT_VERSION < 50025) {
134 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
135 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
136 // and SHOW CREATE TABLE says NOT NULL
137 // http://bugs.mysql.com/20910.
139 $show_create_table = PMA_DBI_fetch_value(
140 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
141 0, 1);
142 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
145 // Check if we can use Relations (Mike Beck)
146 if (!empty($cfgRelation['relation'])) {
147 // Find which tables are related with the current one and write it in
148 // an array
149 $res_rel = PMA_getForeigners($db, $table);
151 if (count($res_rel) > 0) {
152 $have_rel = TRUE;
153 } else {
154 $have_rel = FALSE;
156 } else {
157 $have_rel = FALSE;
158 } // end if
162 * Displays the comments of the table if MySQL >= 3.23
164 if (!empty($show_comment)) {
165 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
169 * Displays the table structure
173 <table width="100%" class="print">
174 <tr><th width="50"><?php echo __('Column'); ?></th>
175 <th width="80"><?php echo __('Type'); ?></th>
176 <?php /* <th width="50"><?php echo __('Attributes'); ?></th>*/ ?>
177 <th width="40"><?php echo __('Null'); ?></th>
178 <th width="70"><?php echo __('Default'); ?></th>
179 <?php /* <th width="50"><?php echo __('Extra'); ?></th>*/ ?>
180 <?php
181 if ($have_rel) {
182 echo ' <th>' . __('Links to') . '</th>' . "\n";
184 echo ' <th>' . __('Comments') . '</th>' . "\n";
185 if ($cfgRelation['mimework']) {
186 echo ' <th>MIME</th>' . "\n";
189 </tr>
190 <?php
191 $odd_row = true;
192 while ($row = PMA_DBI_fetch_assoc($result)) {
194 if ($row['Null'] == '') {
195 $row['Null'] = 'NO';
197 $type = $row['Type'];
198 // reformat mysql query output
199 // set or enum types: slashes single quotes inside options
200 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
201 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
202 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
203 $type_nowrap = '';
205 $binary = 0;
206 $unsigned = 0;
207 $zerofill = 0;
208 } else {
209 $binary = stristr($row['Type'], 'binary');
210 $unsigned = stristr($row['Type'], 'unsigned');
211 $zerofill = stristr($row['Type'], 'zerofill');
212 $type_nowrap = ' nowrap="nowrap"';
213 $type = preg_replace('@BINARY@i', '', $type);
214 $type = preg_replace('@ZEROFILL@i', '', $type);
215 $type = preg_replace('@UNSIGNED@i', '', $type);
216 if (empty($type)) {
217 $type = ' ';
220 $attribute = ' ';
221 if ($binary) {
222 $attribute = 'BINARY';
224 if ($unsigned) {
225 $attribute = 'UNSIGNED';
227 if ($zerofill) {
228 $attribute = 'UNSIGNED ZEROFILL';
230 if (!isset($row['Default'])) {
231 if ($row['Null'] != 'NO') {
232 $row['Default'] = '<i>NULL</i>';
234 } else {
235 $row['Default'] = htmlspecialchars($row['Default']);
237 $field_name = htmlspecialchars($row['Field']);
239 if (PMA_MYSQL_INT_VERSION < 50025
240 && ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
241 && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
242 && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
243 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
244 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
245 // the latter.
247 * @todo merge this logic with the one in tbl_structure.php
248 * or move it in a function similar to PMA_DBI_get_columns_full()
249 * but based on SHOW CREATE TABLE because information_schema
250 * cannot be trusted in this case (MySQL bug)
252 $row['Null'] = 'NO';
255 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
256 <td nowrap="nowrap">
257 <?php
258 if (isset($pk_array[$row['Field']])) {
259 echo '<u>' . $field_name . '</u>';
260 } else {
261 echo $field_name;
264 </td>
265 <td<?php echo $type_nowrap; ?> xml:lang="en" dir="ltr"><?php echo $type; ?></td>
266 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $attribute; ?></td>*/ ?>
267 <td><?php echo (($row['Null'] == 'NO') ? __('No') : __('Yes')); ?></td>
268 <td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td>
269 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?>
270 <?php
271 if ($have_rel) {
272 echo ' <td>';
273 if (isset($res_rel[$field_name])) {
274 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
276 echo '</td>' . "\n";
278 echo ' <td>';
279 if (isset($comments[$field_name])) {
280 echo htmlspecialchars($comments[$field_name]);
282 echo '</td>' . "\n";
283 if ($cfgRelation['mimework']) {
284 $mime_map = PMA_getMIME($db, $table, true);
286 echo ' <td>';
287 if (isset($mime_map[$field_name])) {
288 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
290 echo '</td>' . "\n";
293 </tr>
294 <?php
295 } // end while
296 PMA_DBI_free_result($result);
297 $count++;
299 </table>
300 </div>
301 <?php
302 } //ends main while
305 * Displays the footer
308 <script type="text/javascript">
309 //<![CDATA[
310 function printPage()
312 document.getElementById('print').style.visibility = 'hidden';
313 // Do print the page
314 if (typeof(window.print) != 'undefined') {
315 window.print();
317 document.getElementById('print').style.visibility = '';
319 //]]>
320 </script>
321 <?php
322 echo '<br /><br /><input type="button" id="print" value="' . __('Print') . '" onclick="printPage()" />';
324 require_once './libraries/footer.inc.php';