Translation update done using Pootle.
[phpmyadmin/crack.git] / db_datadict.php
blob531fbe06fc346cb8caf29d24e01115e5bc369a34
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_row($rowset)) {
62 $table = $row[0];
63 $comments = PMA_getComments($db, $table);
65 echo '<div>' . "\n";
67 echo '<h2>' . $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 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($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 while ($row = PMA_DBI_fetch_assoc($result)) {
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
114 if ($result) {
115 PMA_DBI_free_result($result);
120 * Gets columns properties
122 $result = PMA_DBI_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
123 $fields_cnt = PMA_DBI_num_rows($result);
125 if (PMA_MYSQL_INT_VERSION < 50025) {
126 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
127 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
128 // and SHOW CREATE TABLE says NOT NULL
129 // http://bugs.mysql.com/20910.
131 $show_create_table = PMA_DBI_fetch_value(
132 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
133 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
140 // an array
141 $res_rel = PMA_getForeigners($db, $table);
143 if (count($res_rel) > 0) {
144 $have_rel = true;
145 } else {
146 $have_rel = false;
148 } else {
149 $have_rel = false;
150 } // end if
154 * Displays the comments of the table if MySQL >= 3.23
156 if (!empty($show_comment)) {
157 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
161 * Displays the table structure
165 <table width="100%" class="print">
166 <tr><th width="50"><?php echo __('Column'); ?></th>
167 <th width="80"><?php echo __('Type'); ?></th>
168 <?php /* <th width="50"><?php echo __('Attributes'); ?></th>*/ ?>
169 <th width="40"><?php echo __('Null'); ?></th>
170 <th width="70"><?php echo __('Default'); ?></th>
171 <?php /* <th width="50"><?php echo __('Extra'); ?></th>*/ ?>
172 <?php
173 if ($have_rel) {
174 echo ' <th>' . __('Links to') . '</th>' . "\n";
176 echo ' <th>' . __('Comments') . '</th>' . "\n";
177 if ($cfgRelation['mimework']) {
178 echo ' <th>MIME</th>' . "\n";
181 </tr>
182 <?php
183 $odd_row = true;
184 while ($row = PMA_DBI_fetch_assoc($result)) {
186 if ($row['Null'] == '') {
187 $row['Null'] = 'NO';
189 $type = $row['Type'];
190 // reformat mysql query output
191 // set or enum types: slashes single quotes inside options
192 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
193 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
194 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
195 $type_nowrap = '';
197 $binary = 0;
198 $unsigned = 0;
199 $zerofill = 0;
200 } else {
201 $binary = stristr($row['Type'], 'binary');
202 $unsigned = stristr($row['Type'], 'unsigned');
203 $zerofill = stristr($row['Type'], 'zerofill');
204 $type_nowrap = ' nowrap="nowrap"';
205 $type = preg_replace('@BINARY@i', '', $type);
206 $type = preg_replace('@ZEROFILL@i', '', $type);
207 $type = preg_replace('@UNSIGNED@i', '', $type);
208 if (empty($type)) {
209 $type = ' ';
212 $attribute = ' ';
213 if ($binary) {
214 $attribute = 'BINARY';
216 if ($unsigned) {
217 $attribute = 'UNSIGNED';
219 if ($zerofill) {
220 $attribute = 'UNSIGNED ZEROFILL';
222 if (! isset($row['Default'])) {
223 if ($row['Null'] != 'NO') {
224 $row['Default'] = '<i>NULL</i>';
226 } else {
227 $row['Default'] = htmlspecialchars($row['Default']);
229 $field_name = htmlspecialchars($row['Field']);
231 if (PMA_MYSQL_INT_VERSION < 50025
232 && ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
233 && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
234 && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
235 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
236 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
237 // the latter.
239 * @todo merge this logic with the one in tbl_structure.php
240 * or move it in a function similar to PMA_DBI_get_columns_full()
241 * but based on SHOW CREATE TABLE because information_schema
242 * cannot be trusted in this case (MySQL bug)
244 $row['Null'] = 'NO';
247 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
248 <td nowrap="nowrap">
249 <?php
250 if (isset($pk_array[$row['Field']])) {
251 echo '<u>' . $field_name . '</u>';
252 } else {
253 echo $field_name;
256 </td>
257 <td<?php echo $type_nowrap; ?> xml:lang="en" dir="ltr"><?php echo $type; ?></td>
258 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $attribute; ?></td>*/ ?>
259 <td><?php echo (($row['Null'] == 'NO') ? __('No') : __('Yes')); ?></td>
260 <td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td>
261 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?>
262 <?php
263 if ($have_rel) {
264 echo ' <td>';
265 if (isset($res_rel[$field_name])) {
266 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
268 echo '</td>' . "\n";
270 echo ' <td>';
271 if (isset($comments[$field_name])) {
272 echo htmlspecialchars($comments[$field_name]);
274 echo '</td>' . "\n";
275 if ($cfgRelation['mimework']) {
276 $mime_map = PMA_getMIME($db, $table, true);
278 echo ' <td>';
279 if (isset($mime_map[$field_name])) {
280 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
282 echo '</td>' . "\n";
285 </tr>
286 <?php
287 } // end while
288 PMA_DBI_free_result($result);
289 $count++;
291 </table>
292 </div>
293 <?php
294 } //ends main while
297 * Displays the footer
300 <script type="text/javascript">
301 //<![CDATA[
302 function printPage()
304 document.getElementById('print').style.visibility = 'hidden';
305 // Do print the page
306 if (typeof(window.print) != 'undefined') {
307 window.print();
309 document.getElementById('print').style.visibility = '';
311 //]]>
312 </script>
313 <?php
314 echo '<br /><br /><input type="button" id="print" value="' . __('Print') . '" onclick="printPage()" />';
316 require './libraries/footer.inc.php';