Better descriptions for Drizzle column types
[phpmyadmin.git] / tbl_structure.php
blob75bbbbaad30930de6c904af0ff43cc1df0d3ed06
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays table structure infos like fields/columns, indexes, size, rows
5 * and allows manipulation of indexes and columns/fields
6 * @package PhpMyAdmin
7 */
9 /**
12 require_once 'libraries/common.inc.php';
13 require_once 'libraries/mysql_charsets.lib.php';
15 $GLOBALS['js_include'][] = 'tbl_structure.js';
16 $GLOBALS['js_include'][] = 'indexes.js';
18 /**
19 * handle multiple field commands if required
21 * submit_mult_*_x comes from IE if <input type="img" ...> is used
23 if (isset($_REQUEST['submit_mult_change_x'])) {
24 $submit_mult = 'change';
25 } elseif (isset($_REQUEST['submit_mult_drop_x'])) {
26 $submit_mult = 'drop';
27 } elseif (isset($_REQUEST['submit_mult_primary_x'])) {
28 $submit_mult = 'primary';
29 } elseif (isset($_REQUEST['submit_mult_index_x'])) {
30 $submit_mult = 'index';
31 } elseif (isset($_REQUEST['submit_mult_unique_x'])) {
32 $submit_mult = 'unique';
33 } elseif (isset($_REQUEST['submit_mult_spatial_x'])) {
34 $submit_mult = 'spatial';
35 } elseif (isset($_REQUEST['submit_mult_fulltext_x'])) {
36 $submit_mult = 'ftext';
37 } elseif (isset($_REQUEST['submit_mult_browse_x'])) {
38 $submit_mult = 'browse';
39 } elseif (isset($_REQUEST['submit_mult'])) {
40 $submit_mult = $_REQUEST['submit_mult'];
41 } elseif (isset($_REQUEST['mult_btn']) && $_REQUEST['mult_btn'] == __('Yes')) {
42 $submit_mult = 'row_delete';
43 if (isset($_REQUEST['selected'])) {
44 $_REQUEST['selected_fld'] = $_REQUEST['selected'];
48 if (! empty($submit_mult) && isset($_REQUEST['selected_fld'])) {
49 $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
50 if ($submit_mult == 'browse') {
51 // browsing the table displaying only selected fields/columns
52 $GLOBALS['active_page'] = 'sql.php';
53 $sql_query = '';
54 foreach ($_REQUEST['selected_fld'] as $idx => $sval) {
55 if ($sql_query == '') {
56 $sql_query .= 'SELECT ' . PMA_backquote($sval);
57 } else {
58 $sql_query .= ', ' . PMA_backquote($sval);
62 // what is this htmlspecialchars() for??
63 //$sql_query .= ' FROM ' . PMA_backquote(htmlspecialchars($table));
64 $sql_query .= ' FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
65 include 'sql.php';
66 exit;
67 } else {
68 // handle multiple field commands
69 // handle confirmation of deleting multiple fields/columns
70 $action = 'tbl_structure.php';
71 include 'libraries/mult_submits.inc.php';
72 //require_once 'libraries/header.inc.php';
73 //require_once 'libraries/tbl_links.inc.php';
75 if (empty($message)) {
76 $message = PMA_Message::success();
81 /**
82 * Gets the relation settings
84 $cfgRelation = PMA_getRelationsParam();
86 /**
87 * Runs common work
89 require_once 'libraries/tbl_common.php';
90 $url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
91 $url_params['goto'] = 'tbl_structure.php';
92 $url_params['back'] = 'tbl_structure.php';
94 /**
95 * Prepares the table structure display
99 /**
100 * Gets tables informations
102 require_once 'libraries/tbl_info.inc.php';
105 * Displays top menu links
107 require_once 'libraries/tbl_links.inc.php';
108 require_once 'libraries/Index.class.php';
110 // 2. Gets table keys and retains them
111 // @todo should be: $server->db($db)->table($table)->primary()
112 $primary = PMA_Index::getPrimary($table, $db);
114 $columns_with_unique_index = array();
115 foreach (PMA_Index::getFromTable($table, $db) as $index) {
116 if ($index->isUnique() && $index->getChoice() == 'UNIQUE') {
117 $columns = $index->getColumns();
118 foreach ($columns as $column_name => $dummy) {
119 $columns_with_unique_index[$column_name] = 1;
123 unset($index, $columns, $column_name, $dummy);
125 // 3. Get fields
126 $fields = (array) PMA_DBI_get_columns($db, $table, null, true);
128 // Get more complete field information
129 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
130 // but later, if the analyser returns more information, it
131 // could be executed for any MySQL version and replace
132 // the info given by SHOW FULL COLUMNS FROM.
134 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
135 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
136 // and SHOW CREATE TABLE says NOT NULL (tested
137 // in MySQL 4.0.25 and 5.0.21, 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
143 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
146 * prepare table infos
148 // action titles (image or string)
149 $titles = array();
150 $titles['Change'] = PMA_getIcon('b_edit.png', __('Change'));
151 $titles['Drop'] = PMA_getIcon('b_drop.png', __('Drop'));
152 $titles['NoDrop'] = PMA_getIcon('b_drop.png', __('Drop'));
153 $titles['Primary'] = PMA_getIcon('b_primary.png', __('Primary'));
154 $titles['Index'] = PMA_getIcon('b_index.png', __('Index'));
155 $titles['Unique'] = PMA_getIcon('b_unique.png', __('Unique'));
156 $titles['Spatial'] = PMA_getIcon('b_spatial.png', __('Spatial'));
157 $titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', __('Fulltext'));
158 $titles['NoPrimary'] = PMA_getIcon('bd_primary.png', __('Primary'));
159 $titles['NoIndex'] = PMA_getIcon('bd_index.png', __('Index'));
160 $titles['NoUnique'] = PMA_getIcon('bd_unique.png', __('Unique'));
161 $titles['NoSpatial'] = PMA_getIcon('bd_spatial.png', __('Spatial'));
162 $titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', __('Fulltext'));
163 $titles['DistinctValues'] = PMA_getIcon('b_browse.png', __('Distinct values'));
165 // hidden action titles (image and string)
166 $hidden_titles = array();
167 $hidden_titles['DistinctValues'] = PMA_getIcon('b_browse.png', __('Distinct values'), true);
168 $hidden_titles['Primary'] = PMA_getIcon('b_primary.png', __('Add primary key'), true);
169 $hidden_titles['NoPrimary'] = PMA_getIcon('bd_primary.png', __('Add primary key'), true);
170 $hidden_titles['Index'] = PMA_getIcon('b_index.png', __('Add index'), true);
171 $hidden_titles['NoIndex'] = PMA_getIcon('bd_index.png', __('Add index'), true);
172 $hidden_titles['Unique'] = PMA_getIcon('b_unique.png', __('Add unique index'), true);
173 $hidden_titles['NoUnique'] = PMA_getIcon('bd_unique.png', __('Add unique index'), true);
174 $hidden_titles['Spatial'] = PMA_getIcon('b_spatial.png', __('Add SPATIAL index'), true);
175 $hidden_titles['NoSpatial'] = PMA_getIcon('bd_spatial.png', __('Add SPATIAL index'), true);
176 $hidden_titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', __('Add FULLTEXT index'), true);
177 $hidden_titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', __('Add FULLTEXT index'), true);
180 * Displays the table structure ('show table' works correct since 3.23.03)
182 /* TABLE INFORMATION */
183 // table header
184 $i = 0;
186 <form method="post" action="tbl_structure.php" name="fieldsForm" id="fieldsForm" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>>
187 <?php echo PMA_generate_common_hidden_inputs($db, $table);
188 echo '<input type="hidden" name="table_type" value=';
189 if ($db_is_information_schema) {
190 echo '"information_schema" />';
191 } else if ($tbl_is_view) {
192 echo '"view" />';
193 } else {
194 echo '"table" />';
195 } ?>
197 <table id="tablestructure" class="data<?php
198 if ($GLOBALS['cfg']['PropertiesIconic'] === true) echo ' PropertiesIconic'; ?>">
199 <thead>
200 <tr>
201 <th></th>
202 <th>#</th>
203 <th><?php echo __('Name'); ?></th>
204 <th><?php echo __('Type'); ?></th>
205 <th><?php echo __('Collation'); ?></th>
206 <th><?php echo __('Attributes'); ?></th>
207 <th><?php echo __('Null'); ?></th>
208 <th><?php echo __('Default'); ?></th>
209 <th><?php echo __('Extra'); ?></th>
210 <?php if ($db_is_information_schema || $tbl_is_view) { ?>
211 <th><?php echo __('View'); ?></th>
212 <?php } else { /* see tbl_structure.js, function moreOptsMenuResize() */ ?>
213 <th colspan="<?php
214 $colspan = 9;
215 if (PMA_DRIZZLE) {
216 $colspan -= 2;
218 if ($GLOBALS['cfg']['PropertiesIconic']) {
219 $colspan--;
221 echo $colspan; ?>" class="action"><?php echo __('Action'); ?></th>
222 <?php } ?>
223 </tr>
224 </thead>
225 <tbody>
227 <?php
228 unset($i);
230 // table body
232 // prepare comments
233 $comments_map = array();
234 $mime_map = array();
236 if ($GLOBALS['cfg']['ShowPropertyComments']) {
237 include_once 'libraries/transformations.lib.php';
239 //$cfgRelation = PMA_getRelationsParam();
241 $comments_map = PMA_getComments($db, $table);
243 if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
244 $mime_map = PMA_getMIME($db, $table, true);
248 $rownum = 0;
249 $columns_list = array();
250 $checked = (!empty($checkall) ? ' checked="checked"' : '');
251 $save_row = array();
252 $odd_row = true;
253 foreach ($fields as $row) {
254 $save_row[] = $row;
255 $rownum++;
256 $columns_list[] = $row['Field'];
258 $type = $row['Type'];
259 $extracted_columnspec = PMA_extractColumnSpec($row['Type']);
261 if ('set' == $extracted_columnspec['type'] || 'enum' == $extracted_columnspec['type']) {
262 $type_nowrap = '';
263 } else {
264 $type_nowrap = ' class="nowrap"';
266 $type = $extracted_columnspec['print_type'];
267 if (empty($type)) {
268 $type = ' ';
271 $field_charset = '';
272 if ($extracted_columnspec['can_contain_collation'] && ! empty($row['Collation'])) {
273 $field_charset = $row['Collation'];
276 // Display basic mimetype [MIME]
277 if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
278 $type_mime = '<br />MIME: ' . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
279 } else {
280 $type_mime = '';
283 $attribute = $extracted_columnspec['attribute'];
285 // MySQL 4.1.2+ TIMESTAMP options
286 // (if on_update_current_timestamp is set, then it's TRUE)
287 if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
288 $attribute = 'on update CURRENT_TIMESTAMP';
291 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
292 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
293 // the latter.
294 if (!empty($analyzed_sql[0]['create_table_fields'][$row['Field']]['type']) && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null']) {
295 $row['Null'] = '';
299 if (! isset($row['Default'])) {
300 if ($row['Null'] == 'YES') {
301 $row['Default'] = '<i>NULL</i>';
303 } else {
304 $row['Default'] = htmlspecialchars($row['Default']);
307 $field_encoded = urlencode($row['Field']);
308 $field_name = htmlspecialchars($row['Field']);
309 $displayed_field_name = $field_name;
311 // underline commented fields and display a hover-title (CSS only)
313 if (isset($comments_map[$row['Field']])) {
314 $displayed_field_name = '<span class="commented_column" title="' . htmlspecialchars($comments_map[$row['Field']]) . '">' . $field_name . '</span>';
317 if ($primary && $primary->hasColumn($field_name)) {
318 $displayed_field_name = '<u>' . $field_name . '</u>';
320 echo "\n";
322 <tr class="<?php echo $odd_row ? 'odd': 'even'; $odd_row = !$odd_row; ?>">
323 <td class="center">
324 <input type="checkbox" name="selected_fld[]" value="<?php echo htmlspecialchars($row['Field']); ?>" id="checkbox_row_<?php echo $rownum; ?>" <?php echo $checked; ?> />
325 </td>
326 <td class="right">
327 <?php echo $rownum; ?>
328 </td>
329 <th class="nowrap"><label for="checkbox_row_<?php echo $rownum; ?>"><?php echo $displayed_field_name; ?></label></th>
330 <td<?php echo $type_nowrap; ?>><bdo dir="ltr" lang="en"><?php echo $extracted_columnspec['displayed_type']; echo $type_mime; ?></bdo></td>
331 <td><?php echo (empty($field_charset) ? '' : '<dfn title="' . PMA_getCollationDescr($field_charset) . '">' . $field_charset . '</dfn>'); ?></td>
332 <td class="column_attribute nowrap"><?php echo $attribute; ?></td>
333 <td><?php echo (($row['Null'] == 'YES') ? __('Yes') : __('No')); ?></td>
334 <td class="nowrap"><?php
335 if (isset($row['Default'])) {
336 if ($extracted_columnspec['type'] == 'bit') {
337 // here, $row['Default'] contains something like b'010'
338 echo PMA_convert_bit_default_value($row['Default']);
339 } else {
340 echo $row['Default'];
342 } else {
343 echo '<i>' . _pgettext('None for default', 'None') . '</i>';
344 } ?></td>
345 <td class="nowrap"><?php echo strtoupper($row['Extra']); ?></td>
346 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
347 <td class="edit center">
348 <a href="tbl_alter.php?<?php echo $url_query; ?>&amp;field=<?php echo $field_encoded; ?>">
349 <?php echo $titles['Change']; ?></a>
350 </td>
351 <td class="drop center">
352 <a <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="drop_column_anchor"' : ''); ?> href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' DROP ' . PMA_backquote($row['Field']) . ';'); ?>&amp;dropped_column=<?php echo urlencode($row['Field']); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('Column %s has been dropped'), htmlspecialchars($row['Field']))); ?>" >
353 <?php echo $titles['Drop']; ?></a>
354 </td>
355 <?php }
356 if (! $tbl_is_view && ! $db_is_information_schema) { ?>
357 <td class="primary replaced_by_more center">
358 <?php
359 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_storage_engine || ($primary && $primary->hasColumn($field_name))) {
360 echo $titles['NoPrimary'] . "\n";
361 $primary_enabled = false;
362 } else {
363 echo "\n";
365 <a class="add_primary_key_anchor" href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ($primary ? ' DROP PRIMARY KEY,' : '') . ' ADD PRIMARY KEY(' . PMA_backquote($row['Field']) . ');'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('A primary key has been added on %s'), htmlspecialchars($row['Field']))); ?>" >
366 <?php echo $titles['Primary']; ?></a>
367 <?php $primary_enabled = true;
369 echo "\n";
371 </td>
372 <td class="unique replaced_by_more center">
373 <?php
374 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_storage_engine || isset($columns_with_unique_index[$field_name])) {
375 echo $titles['NoUnique'] . "\n";
376 $unique_enabled = false;
377 } else {
378 echo "\n";
380 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE(' . PMA_backquote($row['Field']) . ');'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
381 <?php echo $titles['Unique']; ?></a>
382 <?php $unique_enabled = true;
384 echo "\n";
386 </td>
387 <td class="index replaced_by_more center">
388 <?php
389 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_storage_engine) {
390 echo $titles['NoIndex'] . "\n";
391 $index_enabled = false;
392 } else {
393 echo "\n";
395 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX(' . PMA_backquote($row['Field']) . ');'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
396 <?php echo $titles['Index']; ?></a>
397 <?php
398 $index_enabled = true;
400 echo "\n";
402 </td>
403 <?php
404 if (!PMA_DRIZZLE) { ?>
405 <td class="spatial replaced_by_more center">
407 <?php
408 $spatial_types = array(
409 'geometry', 'point', 'linestring', 'polygon', 'multipoint',
410 'multilinestring', 'multipolygon', 'geomtrycollection'
412 if (! in_array($type, $spatial_types) || 'MYISAM' != $tbl_storage_engine) {
413 echo $titles['NoSpatial'] . "\n";
414 $spatial_enabled = false;
415 } else {
416 echo "\n";
418 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD SPATIAL(' . PMA_backquote($row['Field']) . ');'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
419 <?php echo $titles['Spatial']; ?></a>
420 <?php
421 $spatial_enabled = true;
423 echo "\n";
425 </td>
426 <?php
427 if (! empty($tbl_storage_engine) && ($tbl_storage_engine == 'MYISAM' || $tbl_storage_engine == 'ARIA' || $tbl_storage_engine == 'MARIA' || ($tbl_storage_engine == 'INNODB' && PMA_MYSQL_INT_VERSION >= 50604))
428 // FULLTEXT is possible on TEXT, CHAR and VARCHAR
429 && (strpos(' ' . $type, 'text') || strpos(' ' . $type, 'char'))
431 echo "\n";
433 <td class="fulltext replaced_by_more center nowrap">
434 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT(' . PMA_backquote($row['Field']) . ');'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
435 <?php echo $titles['IdxFulltext']; ?></a>
436 <?php $fulltext_enabled = true; ?>
437 </td>
438 <?php
439 } else {
440 echo "\n";
442 <td class="fulltext replaced_by_more center nowrap">
443 <?php echo $titles['NoIdxFulltext'] . "\n"; ?>
444 <?php $fulltext_enabled = false; ?>
445 </td>
446 <?php
448 } // end if... else...
450 <td class="browse replaced_by_more center">
451 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('SELECT COUNT(*) AS ' . PMA_backquote(__('Rows')) . ', ' . PMA_backquote($row['Field']) . ' FROM ' . PMA_backquote($table) . ' GROUP BY ' . PMA_backquote($row['Field']) . ' ORDER BY ' . PMA_backquote($row['Field'])); ?>"> <?php echo $titles['DistinctValues']; ?></a>
452 </td>
453 <?php
454 if ($GLOBALS['cfg']['PropertiesIconic'] !== true && $GLOBALS['cfg']['HideStructureActions'] === true) { ?>
455 <td class="more_opts" id="more_opts<?php echo $rownum; ?>">
456 <?php echo PMA_getImage('more.png', __('Show more actions')); ?> <?php echo __('More'); ?>
457 <div class="structure_actions_dropdown" id="row_<?php echo $rownum; ?>">
458 <div class="<?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'action_primary ' : ''); ?>replace_in_more">
459 <?php
460 if (isset($primary_enabled)) {
461 if ($primary_enabled) { ?>
462 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ($primary ? ' DROP PRIMARY KEY,' : '') . ' ADD PRIMARY KEY(' . PMA_backquote($row['Field']) . ');'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('A primary key has been added on %s'), htmlspecialchars($row['Field']))); ?>">
463 <?php echo $hidden_titles['Primary']; ?>
464 </a>
465 <?php
466 } else {
467 echo $hidden_titles['NoPrimary'];
469 } ?>
470 </div>
471 <div class="action_unique replace_in_more">
472 <?php
473 if (isset($unique_enabled)) {
474 if ($unique_enabled) { ?>
475 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE(' . PMA_backquote($row['Field']) . ');'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
476 <?php echo $hidden_titles['Unique']; ?>
477 </a>
478 <?php
479 } else {
480 echo $hidden_titles['NoUnique'];
482 } ?>
483 </div>
484 <div class="action_index replace_in_more">
485 <?php
486 if (isset($index_enabled)) {
487 if ($index_enabled) { ?>
488 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX(' . PMA_backquote($row['Field']) . ');'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
489 <?php echo $hidden_titles['Index']; ?>
490 </a>
491 <?php
492 } else {
493 echo $hidden_titles['NoIndex'];
495 } ?>
496 </div>
497 <?php if (!PMA_DRIZZLE) { ?>
498 <div class="action_spatial replace_in_more">
499 <?php
500 if (isset($spatial_enabled)) {
501 if ($spatial_enabled) { ?>
502 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD SPATIAL(' . PMA_backquote($row['Field']) . ');'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
503 <?php echo $hidden_titles['Spatial']; ?>
504 </a>
505 <?php
506 } else {
507 echo $hidden_titles['NoSpatial'];
509 } ?>
510 </div>
511 <div class="action_fulltext replace_in_more">
512 <?php
513 if (isset($fulltext_enabled)) {
514 if ($fulltext_enabled) { ?>
515 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT(' . PMA_backquote($row['Field']) . ');'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
516 <?php echo $hidden_titles['IdxFulltext']; ?>
517 </a>
518 <?php
519 } else {
520 echo $hidden_titles['NoIdxFulltext'];
522 } ?>
523 </div>
524 <div class="action_browse replace_in_more">
525 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('SELECT COUNT(*) AS ' . PMA_backquote(__('Rows')) . ', ' . PMA_backquote($row['Field']) . ' FROM ' . PMA_backquote($table) . ' GROUP BY ' . PMA_backquote($row['Field']) . ' ORDER BY ' . PMA_backquote($row['Field'])); ?>&amp;browse_distinct=1">
526 <?php echo $hidden_titles['DistinctValues']; ?>
527 </a>
528 </div>
529 <?php } ?>
530 </div>
531 </td>
532 <?php
533 } // end if (GLOBALS['cfg']['PropertiesIconic'] !== true)
534 } // end if (! $tbl_is_view && ! $db_is_information_schema)
536 </tr>
537 <?php
538 unset($field_charset);
539 } // end foreach
541 echo '</tbody>' . "\n"
542 .'</table>' . "\n";
544 $checkall_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
547 <img class="selectallarrow" src="<?php echo $pmaThemeImage . 'arrow_' . $text_dir . '.png'; ?>"
548 width="38" height="22" alt="<?php echo __('With selected:'); ?>" />
549 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
550 onclick="if (markAllRows('fieldsForm')) return false;">
551 <?php echo __('Check All'); ?></a>
553 <a href="<?php echo $checkall_url; ?>"
554 onclick="if (unMarkAllRows('fieldsForm')) return false;">
555 <?php echo __('Uncheck All'); ?></a>
557 <i><?php echo __('With selected:'); ?></i>
559 <?php
560 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_browse', __('Browse'), 'b_browse.png', 'browse');
562 if (! $tbl_is_view && ! $db_is_information_schema) {
563 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', __('Change'), 'b_edit.png', 'change');
564 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_drop', __('Drop'), 'b_drop.png', 'drop');
565 if ('ARCHIVE' != $tbl_storage_engine) {
566 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_primary', __('Primary'), 'b_primary.png', 'primary');
567 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_unique', __('Unique'), 'b_unique.png', 'unique');
568 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_index', __('Index'), 'b_index.png', 'index');
571 if (! empty($tbl_storage_engine) && $tbl_storage_engine == 'MYISAM') {
572 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_spatial', __('Spatial'), 'b_spatial.png', 'spatial');
574 if (! empty($tbl_storage_engine) && ($tbl_storage_engine == 'MYISAM' || $tbl_storage_engine == 'ARIA' || $tbl_storage_engine == 'MARIA')) {
575 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_fulltext', __('Fulltext'), 'b_ftext.png', 'ftext');
579 </form>
580 <hr />
582 <div id="move_columns_dialog" title="<?php echo __('Move columns'); ?>" style="display: none">
583 <p><?php echo __('Move the columns by dragging them up and down.'); ?></p>
584 <form action="tbl_alter.php">
585 <div>
586 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
587 <ul>
588 <?php
589 foreach ($fields as $row) { ?>
591 <li class="placeholderDrag"><?php echo $field = htmlspecialchars($row['Field']); ?>
592 <input type="hidden" name="move_columns[]" value="<?php echo $field; ?>" /></li>
593 <?php } ?>
595 </ul>
596 </div>
597 </form>
598 </div>
600 <?php
602 * Work on the table
605 if ($tbl_is_view) {
606 $create_view = PMA_DBI_get_definition($db, 'VIEW', $table);
607 $create_view = preg_replace('@^CREATE@', 'ALTER', $create_view);
608 echo PMA_linkOrButton(
609 'tbl_sql.php' . PMA_generate_common_url(
610 $url_params +
611 array(
612 'sql_query' => $create_view,
613 'show_query' => '1',
616 PMA_getIcon('b_edit.png', __('Edit view'), true)
621 <a href="tbl_printview.php?<?php echo $url_query; ?>"><?php
622 echo PMA_getIcon('b_print.png', __('Print view'), true);
623 ?></a>
625 <?php
626 if (! $tbl_is_view && ! $db_is_information_schema) {
628 // if internal relations are available, or foreign keys are supported
629 // ($tbl_storage_engine comes from libraries/tbl_info.inc.php)
630 if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_storage_engine)) {
632 <a href="tbl_relation.php?<?php echo $url_query; ?>"><?php
633 echo PMA_getIcon('b_relations.png', __('Relation view'), true);
634 ?></a>
635 <?php
638 if (!PMA_DRIZZLE) {
640 <a href="sql.php?<?php echo $url_query; ?>&amp;session_max_rows=all&amp;sql_query=<?php echo urlencode('SELECT * FROM ' . PMA_backquote($table) . ' PROCEDURE ANALYSE()'); ?>"><?php
641 echo PMA_getIcon('b_tblanalyse.png', __('Propose table structure'), true);
642 ?></a><?php
643 echo PMA_showMySQLDocu('Extending_MySQL', 'procedure_analyse') . "\n";
646 if (PMA_Tracker::isActive()) {
647 echo '<a href="tbl_tracking.php?' . $url_query . '">';
648 echo PMA_getIcon('eye.png', __('Track table'), true);
649 echo '</a>';
653 <a href="#" id="move_columns_anchor"><?php
654 echo PMA_getIcon('b_move.png', __('Move columns'), true);
655 ?></a>
657 <br />
658 <form method="post" action="tbl_addfield.php" id="addColumns" name="addColumns" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>
659 onsubmit="return checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)">
660 <?php
661 echo PMA_generate_common_hidden_inputs($db, $table);
662 if ($cfg['PropertiesIconic']) {
663 echo PMA_getImage('b_insrow.png', __('Add column'));
665 echo sprintf(__('Add %s column(s)'), '<input type="text" name="num_fields" size="2" maxlength="2" value="1" onfocus="this.select()" />');
667 // I tried displaying the drop-down inside the label but with Firefox
668 // the drop-down was blinking
669 $column_selector = '<select name="after_field" onclick="this.form.field_where[2].checked=true" onchange="this.form.field_where[2].checked=true">';
670 foreach ($columns_list as $one_column_name) {
671 $column_selector .= '<option value="' . htmlspecialchars($one_column_name) . '">' . htmlspecialchars($one_column_name) . '</option>';
673 unset($columns_list, $one_column_name);
674 $column_selector .= '</select>';
676 $choices = array(
677 'last' => __('At End of Table'),
678 'first' => __('At Beginning of Table'),
679 'after' => sprintf(__('After %s'), '')
681 PMA_display_html_radio('field_where', $choices, 'last', false);
682 echo $column_selector;
683 unset($column_selector, $choices);
685 <input type="submit" value="<?php echo __('Go'); ?>" />
686 </form>
687 <iframe class="IE_hack"></iframe>
688 <hr />
689 <div id="index_div" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> >
690 <?php
694 * If there are more than 20 rows, displays browse/select/insert/empty/drop
695 * links again
697 if (count($fields) > 20) {
698 include 'libraries/tbl_links.inc.php';
699 } // end if (count($fields) > 20)
702 * Displays indexes
705 if (! $tbl_is_view && ! $db_is_information_schema && 'ARCHIVE' != $tbl_storage_engine) {
706 PMA_generate_slider_effect('indexes', __('Indexes'));
708 * Display indexes
710 echo PMA_Index::getView($table, $db);
712 <fieldset class="tblFooters" style="text-align: left;">
713 <form action="tbl_indexes.php" method="post">
714 <?php
715 echo PMA_generate_common_hidden_inputs($db, $table);
716 echo sprintf(
717 __('Create an index on &nbsp;%s&nbsp;columns'),
718 '<input type="text" size="2" name="added_fields" value="1" />'
721 <input type="hidden" name="create_index" value="1" />
722 <input class="add_index<?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' ajax' : '');?>" type="submit" value="<?php echo __('Go'); ?>" />
723 </form>
724 </fieldset>
725 </div>
726 </div>
727 <?php
731 * Displays Space usage and row statistics
733 // BEGIN - Calc Table Space
734 // Get valid statistics whatever is the table type
735 if ($cfg['ShowStats']) {
736 echo '<div id="tablestatistics">';
737 if (empty($showtable)) {
738 $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
741 $nonisam = false;
742 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
743 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
744 $nonisam = true;
747 // Gets some sizes
749 $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
751 // this is to display for example 261.2 MiB instead of 268k KiB
752 $max_digits = 3;
753 $decimals = 1;
754 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length'], $max_digits, $decimals);
755 if ($mergetable == false) {
756 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length'], $max_digits, $decimals);
758 // InnoDB returns a huge value in Data_free, do not use it
759 if (! $is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
760 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free'], $max_digits, $decimals);
761 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
762 } else {
763 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
765 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
766 if ($table_info_num_rows > 0) {
767 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
770 // Displays them
771 $odd_row = false;
774 <fieldset>
775 <legend><?php echo __('Information'); ?></legend>
776 <a id="showusage"></a>
777 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
778 <table id="tablespaceusage" class="data">
779 <caption class="tblHeaders"><?php echo __('Space usage'); ?></caption>
780 <thead>
781 <tr>
782 <th><?php echo __('Type'); ?></th>
783 <th colspan="2"><?php echo __('Usage'); ?></th>
784 </tr>
785 </thead>
786 <tbody>
787 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
788 <th class="name"><?php echo __('Data'); ?></th>
789 <td class="value"><?php echo $data_size; ?></td>
790 <td class="unit"><?php echo $data_unit; ?></td>
791 </tr>
792 <?php
793 if (isset($index_size)) {
795 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
796 <th class="name"><?php echo __('Index'); ?></th>
797 <td class="value"><?php echo $index_size; ?></td>
798 <td class="unit"><?php echo $index_unit; ?></td>
799 </tr>
800 <?php
802 if (isset($free_size)) {
804 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?> error">
805 <th class="name"><?php echo __('Overhead'); ?></th>
806 <td class="value"><?php echo $free_size; ?></td>
807 <td class="unit"><?php echo $free_unit; ?></td>
808 </tr>
809 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
810 <th class="name"><?php echo __('Effective'); ?></th>
811 <td class="value"><?php echo $effect_size; ?></td>
812 <td class="unit"><?php echo $effect_unit; ?></td>
813 </tr>
814 <?php
816 if (isset($tot_size) && $mergetable == false) {
818 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
819 <th class="name"><?php echo __('Total'); ?></th>
820 <td class="value"><?php echo $tot_size; ?></td>
821 <td class="unit"><?php echo $tot_unit; ?></td>
822 </tr>
823 <?php
825 // Optimize link if overhead
826 if (isset($free_size) && !PMA_DRIZZLE && ($tbl_storage_engine == 'MYISAM' || $tbl_storage_engine == 'ARIA' || $tbl_storage_engine == 'MARIA' || $tbl_storage_engine == 'BDB')) {
828 <tr class="tblFooters">
829 <td colspan="3" class="center">
830 <a href="sql.php?<?php echo $url_query; ?>&pos=0&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>"><?php
831 echo PMA_getIcon('b_tbloptimize.png', __('Optimize table'));
832 ?></a>
833 </td>
834 </tr>
835 <?php
838 </tbody>
839 </table>
840 <?php
842 $odd_row = false;
844 <table id="tablerowstats" class="data">
845 <caption class="tblHeaders"><?php echo __('Row Statistics'); ?></caption>
846 <thead>
847 <tr>
848 <th><?php echo __('Statements'); ?></th>
849 <th><?php echo __('Value'); ?></th>
850 </tr>
851 </thead>
852 <tbody>
853 <?php
854 if (isset($showtable['Row_format'])) {
856 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
857 <th class="name"><?php echo __('Format'); ?></th>
858 <td class="value"><?php
859 if ($showtable['Row_format'] == 'Fixed') {
860 echo __('static');
861 } elseif ($showtable['Row_format'] == 'Dynamic') {
862 echo __('dynamic');
863 } else {
864 echo $showtable['Row_format'];
866 ?></td>
867 </tr>
868 <?php
870 if (! empty($showtable['Create_options'])) {
872 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
873 <th class="name"><?php echo __('Options'); ?></th>
874 <td class="value"><?php
875 if ($showtable['Create_options'] == 'partitioned') {
876 echo __('partitioned');
877 } else {
878 echo $showtable['Create_options'];
880 ?></td>
881 </tr>
882 <?php
884 if (!empty($tbl_collation)) {
886 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
887 <th class="name"><?php echo __('Collation'); ?></th>
888 <td class="value"><?php
889 echo '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
890 ?></td>
891 </tr>
892 <?php
894 if (!$is_innodb && isset($showtable['Rows'])) {
896 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
897 <th class="name"><?php echo __('Rows'); ?></th>
898 <td class="value"><?php echo PMA_formatNumber($showtable['Rows'], 0); ?></td>
899 </tr>
900 <?php
902 if (!$is_innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
904 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
905 <th class="name"><?php echo __('Row length'); ?> &oslash;</th>
906 <td class="value"><?php echo PMA_formatNumber($showtable['Avg_row_length'], 0); ?></td>
907 </tr>
908 <?php
910 if (!$is_innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
912 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
913 <th class="name"><?php echo __('Row size'); ?> &oslash;</th>
914 <td class="value"><?php echo $avg_size . ' ' . $avg_unit; ?></td>
915 </tr>
916 <?php
918 if (isset($showtable['Auto_increment'])) {
920 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
921 <th class="name"><?php echo __('Next autoindex'); ?></th>
922 <td class="value"><?php echo PMA_formatNumber($showtable['Auto_increment'], 0); ?></td>
923 </tr>
924 <?php
926 if (isset($showtable['Create_time'])) {
928 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
929 <th class="name"><?php echo __('Creation'); ?></th>
930 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Create_time'])); ?></td>
931 </tr>
932 <?php
934 if (isset($showtable['Update_time'])) {
936 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
937 <th class="name"><?php echo __('Last update'); ?></th>
938 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Update_time'])); ?></td>
939 </tr>
940 <?php
942 if (isset($showtable['Check_time'])) {
944 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
945 <th class="name"><?php echo __('Last check'); ?></th>
946 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Check_time'])); ?></td>
947 </tr>
948 <?php
951 </tbody>
952 </table>
953 </fieldset>
954 <!-- close tablestatistics div -->
955 </div>
957 <?php
959 // END - Calc Table Space
961 echo '<div class="clearfloat"></div>' . "\n";
964 * Displays the footer
966 require 'libraries/footer.inc.php';