Merge branch 'QA_3_4'
[phpmyadmin/last10db.git] / db_datadict.php
blobe9d18fdf1eab8f08df5b53f736b6e479c24f02b8
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 echo '<div>' . "\n";
68 echo '<h2>' . $table . '</h2>' . "\n";
70 /**
71 * Gets table informations
73 $show_comment = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_COMMENT');
75 /**
76 * Gets table keys and retains them
79 PMA_DBI_select_db($db);
80 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
81 $primary = '';
82 $indexes = array();
83 $lastIndex = '';
84 $indexes_info = array();
85 $indexes_data = array();
86 $pk_array = array(); // will be use to emphasis prim. keys in the table
87 // view
88 while ($row = PMA_DBI_fetch_assoc($result)) {
89 // Backups the list of primary keys
90 if ($row['Key_name'] == 'PRIMARY') {
91 $primary .= $row['Column_name'] . ', ';
92 $pk_array[$row['Column_name']] = 1;
94 // Retains keys informations
95 if ($row['Key_name'] != $lastIndex){
96 $indexes[] = $row['Key_name'];
97 $lastIndex = $row['Key_name'];
99 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
100 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
101 if (isset($row['Cardinality'])) {
102 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
104 // I don't know what does following column mean....
105 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
107 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
109 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
110 if (isset($row['Sub_part'])) {
111 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
114 } // end while
115 if ($result) {
116 PMA_DBI_free_result($result);
121 * Gets columns properties
123 $result = PMA_DBI_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
124 $fields_cnt = PMA_DBI_num_rows($result);
126 if (PMA_MYSQL_INT_VERSION < 50025) {
127 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
128 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
129 // and SHOW CREATE TABLE says NOT NULL
130 // http://bugs.mysql.com/20910.
132 $show_create_table = PMA_DBI_fetch_value(
133 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
134 0, 1);
135 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
138 // Check if we can use Relations (Mike Beck)
139 if (!empty($cfgRelation['relation'])) {
140 // Find which tables are related with the current one and write it in
141 // an array
142 $res_rel = PMA_getForeigners($db, $table);
144 if (count($res_rel) > 0) {
145 $have_rel = TRUE;
146 } else {
147 $have_rel = FALSE;
149 } else {
150 $have_rel = FALSE;
151 } // end if
155 * Displays the comments of the table if MySQL >= 3.23
157 if (!empty($show_comment)) {
158 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
162 * Displays the table structure
166 <table width="100%" class="print">
167 <tr><th width="50"><?php echo __('Column'); ?></th>
168 <th width="80"><?php echo __('Type'); ?></th>
169 <?php /* <th width="50"><?php echo __('Attributes'); ?></th>*/ ?>
170 <th width="40"><?php echo __('Null'); ?></th>
171 <th width="70"><?php echo __('Default'); ?></th>
172 <?php /* <th width="50"><?php echo __('Extra'); ?></th>*/ ?>
173 <?php
174 if ($have_rel) {
175 echo ' <th>' . __('Links to') . '</th>' . "\n";
177 echo ' <th>' . __('Comments') . '</th>' . "\n";
178 if ($cfgRelation['mimework']) {
179 echo ' <th>MIME</th>' . "\n";
182 </tr>
183 <?php
184 $odd_row = true;
185 while ($row = PMA_DBI_fetch_assoc($result)) {
187 if ($row['Null'] == '') {
188 $row['Null'] = 'NO';
190 $type = $row['Type'];
191 // reformat mysql query output
192 // set or enum types: slashes single quotes inside options
193 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
194 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
195 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
196 $type_nowrap = '';
198 $binary = 0;
199 $unsigned = 0;
200 $zerofill = 0;
201 } else {
202 $binary = stristr($row['Type'], 'binary');
203 $unsigned = stristr($row['Type'], 'unsigned');
204 $zerofill = stristr($row['Type'], 'zerofill');
205 $type_nowrap = ' nowrap="nowrap"';
206 $type = preg_replace('@BINARY@i', '', $type);
207 $type = preg_replace('@ZEROFILL@i', '', $type);
208 $type = preg_replace('@UNSIGNED@i', '', $type);
209 if (empty($type)) {
210 $type = ' ';
213 $attribute = ' ';
214 if ($binary) {
215 $attribute = 'BINARY';
217 if ($unsigned) {
218 $attribute = 'UNSIGNED';
220 if ($zerofill) {
221 $attribute = 'UNSIGNED ZEROFILL';
223 if (! isset($row['Default'])) {
224 if ($row['Null'] != 'NO') {
225 $row['Default'] = '<i>NULL</i>';
227 } else {
228 $row['Default'] = htmlspecialchars($row['Default']);
230 $field_name = htmlspecialchars($row['Field']);
232 if (PMA_MYSQL_INT_VERSION < 50025
233 && ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
234 && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
235 && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
236 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
237 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
238 // the latter.
240 * @todo merge this logic with the one in tbl_structure.php
241 * or move it in a function similar to PMA_DBI_get_columns_full()
242 * but based on SHOW CREATE TABLE because information_schema
243 * cannot be trusted in this case (MySQL bug)
245 $row['Null'] = 'NO';
248 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
249 <td nowrap="nowrap">
250 <?php
251 if (isset($pk_array[$row['Field']])) {
252 echo '<u>' . $field_name . '</u>';
253 } else {
254 echo $field_name;
257 </td>
258 <td<?php echo $type_nowrap; ?> xml:lang="en" dir="ltr"><?php echo $type; ?></td>
259 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $attribute; ?></td>*/ ?>
260 <td><?php echo (($row['Null'] == 'NO') ? __('No') : __('Yes')); ?></td>
261 <td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td>
262 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?>
263 <?php
264 if ($have_rel) {
265 echo ' <td>';
266 if (isset($res_rel[$field_name])) {
267 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
269 echo '</td>' . "\n";
271 echo ' <td>';
272 if (isset($comments[$field_name])) {
273 echo htmlspecialchars($comments[$field_name]);
275 echo '</td>' . "\n";
276 if ($cfgRelation['mimework']) {
277 $mime_map = PMA_getMIME($db, $table, true);
279 echo ' <td>';
280 if (isset($mime_map[$field_name])) {
281 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
283 echo '</td>' . "\n";
286 </tr>
287 <?php
288 } // end while
289 PMA_DBI_free_result($result);
290 $count++;
292 </table>
293 </div>
294 <?php
295 } //ends main while
298 * Displays the footer
301 <script type="text/javascript">
302 //<![CDATA[
303 function printPage()
305 document.getElementById('print').style.visibility = 'hidden';
306 // Do print the page
307 if (typeof(window.print) != 'undefined') {
308 window.print();
310 document.getElementById('print').style.visibility = '';
312 //]]>
313 </script>
314 <?php
315 echo '<br /><br /><input type="button" id="print" value="' . __('Print') . '" onclick="printPage()" />';
317 require './libraries/footer.inc.php';