diff --git a/libraries/Index.class.php b/libraries/Index.class.php new file mode 100644 index 000000000..879b9e39a --- /dev/null +++ b/libraries/Index.class.php @@ -0,0 +1,517 @@ +set() + * @param array $params + */ + public function __construct($params = array()) + { + $this->set($params); + } + + /** + * returns an array with all indexes from the given table + * + * @uses PMA_Index::_loadIndexes() + * @uses PMA_Index::$_registry + * @param string $table + * @param string $database + * @return array + */ + static public function getFromTable($table, $database) + { + PMA_Index::_loadIndexes($table, $database); + + if (isset(PMA_Index::$_registry[$database][$table])) { + return PMA_Index::$_registry[$database][$table]; + } else { + return array(); + } + } + + /** + * return primary if set, false otherwise + * + * @uses PMA_Index::_loadIndexes() + * @uses PMA_Index::$_registry + * @param string $table + * @param string $database + * @return mixed primary index or false if no one exists + */ + static public function getPrimary($table, $database) + { + PMA_Index::_loadIndexes($table, $database); + + if (isset(PMA_Index::$_registry[$database][$table]['PRIMARY'])) { + return PMA_Index::$_registry[$database][$table]['PRIMARY']; + } else { + return false; + } + } + + /** + * Load index data for table + * + * @uses PMA_Index::$_registry + * @uses PMA_DBI_fetch_result() + * @uses PMA_backquote() + * @uses PMA_Index + * @uses PMA_Index->addColumn() + * @param string $table + * @param string $database + * @return boolean + */ + static protected function _loadIndexes($table, $database) + { + if (isset(PMA_Index::$_registry[$database][$table])) { + return true; + } + + $_raw_indexes = PMA_DBI_fetch_result('SHOW INDEX FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table)); + foreach ($_raw_indexes as $_each_index) { + if (! isset(PMA_Index::$_registry[$database][$table][$_each_index['Key_name']])) { + $key = new PMA_Index($_each_index); + PMA_Index::$_registry[$database][$table][$_each_index['Key_name']] = $key; + } else { + $key = PMA_Index::$_registry[$database][$table][$_each_index['Key_name']]; + } + + $key->addColumn($_each_index); + } + + return true; + } + + /** + * Add column to index + * + * @uses $this->_columns + * @uses PMA_Index_Column + * @param array $params column params + */ + public function addColumn($params) + { + $this->_columns[$params['Column_name']] = new PMA_Index_Column($params); + } + + /** + * Returns true if $column indexed in this index + * + * @uses $this->_columns + * @param string $column + * @return boolean + */ + public function hasColumn($column) + { + return isset($this->_columns[$column]); + } + + public function set($params) + { + if (isset($params['Column_name'])) { + $this->_database = $params['Column_name']; + } + if (isset($params['Table'])) { + $this->_table = $params['Table']; + } + if (isset($params['Key_name'])) { + $this->_name = $params['Key_name']; + } + if (isset($params['Index_type'])) { + $this->_type = $params['Index_type']; + } + if (isset($params['Comment'])) { + $this->_remarks = $params['Comment']; + } + if (isset($params['Index_comment'])) { + $this->_comment = $params['Index_comment']; + } + if (isset($params['Non_unique'])) { + $this->_non_unique = $params['Non_unique']; + } + if (isset($params['Packed'])) { + $this->_packed = $params['Packed']; + } + } + + public function getColumnCount() + { + return count($this->_columns); + } + + public function getComment() + { + return $this->_comment; + } + + public function getRemarks() + { + return $this->_remarks; + } + + public function getComments() + { + $comments = $this->getRemarks(); + if (strlen($comments)) { + $comments .= "\n"; + } + $comments .= $this->getComment(); + + return $comments; + } + + public function getType() + { + return $this->_type; + } + + public function getPacked() + { + return $this->_packed; + } + + public function isPacked($as_text = false) + { + if ($as_text) { + $r = array( + '0' => $GLOBALS['strNo'], + '1' => $GLOBALS['strYes'], + ); + } else { + $r = array( + '0' => false, + '1' => true, + ); + } + + if (null === $this->_packed) { + return $r[0]; + } + + return $this->_packed; + } + + public function getNonUnique() + { + return $this->_non_unique; + } + + public function isUnique($as_text = false) + { + if ($as_text) { + $r = array( + '0' => $GLOBALS['strYes'], + '1' => $GLOBALS['strNo'], + ); + } else { + $r = array( + '0' => true, + '1' => false, + ); + } + + return $r[$this->_non_unique]; + } + + public function getName() + { + return $this->_name; + } + + public function getColumns() + { + return $this->_columns; + } + + /** + * Show index data + * + * @param string $table The tablename + * @param array $indexes_info Referenced info array + * @param array $indexes_data Referenced data array + * @param boolean $print_mode + * @access public + * @return array Index collection array + * @author Garvin Hicking (pma@supergarv.de) + */ + static public function getView($table, $db, $print_mode = false) + { + $indexes = PMA_Index::getFromTable($table, $db); + + if (count($indexes) < 1) { + return PMA_Message::warning('strNoIndex')->getDisplay(); + } + + $r = ''; + + $r .= '

' . $GLOBALS['strIndexes'] . ': '; + $r .= PMA_showMySQLDocu('optimization', 'optimizing-database-structure'); + $r .= '

'; + $r .= ''; + $r .= ''; + $r .= ''; + if (! $print_mode) { + $r .= ''; + } + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + + $odd_row = true; + foreach ($indexes as $index) { + $row_span = ' rowspan="' . $index->getColumnCount() . '" '; + + $r .= ''; + + if (! $print_mode) { + $this_params = $GLOBALS['url_params']; + $this_params['index'] = $index->getName(); + $r .= '' . "\n"; + + $this_params = $GLOBALS['url_params']; + if ($index->getName() == 'PRIMARY') { + $this_params['sql_query'] = 'ALTER TABLE ' . PMA_backquote($table) . ' DROP PRIMARY KEY'; + $this_params['zero_rows'] = $GLOBALS['strPrimaryKeyHasBeenDropped']; + $js_msg = PMA_jsFormat('ALTER TABLE ' . $table . ' DROP PRIMARY KEY'); + } else { + $this_params['sql_query'] = 'ALTER TABLE ' . PMA_backquote($table) . ' DROP INDEX ' . PMA_backquote($index->getName()); + $this_params['zero_rows'] = sprintf($GLOBALS['strIndexHasBeenDropped'], $index->getName()); + $js_msg = PMA_jsFormat('ALTER TABLE ' . $table . ' DROP INDEX ' . $index->getName()); + } + + $r .= '' . "\n"; + } + + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + + foreach ($index->getColumns() as $column) { + if ($column->getSeqInIndex() > 1) { + $r .= ''; + } + $r .= ''; + $r .= ''; + $r .= ''; + $r .= ''; + + if ($column->getSeqInIndex() == 1) { + $r .= ''; + } + $r .= ''; + } // end foreach $index['Sequences'] + + $odd_row = ! $odd_row; + } // end while + $r .= ''; + $r .= '
' . $GLOBALS['strAction'] . '' . $GLOBALS['strKeyname'] . '' . $GLOBALS['strType'] . '' . $GLOBALS['strUnique'] . '' . $GLOBALS['strPacked'] . '' . $GLOBALS['strField'] . '' . $GLOBALS['strCardinality'] . '' . $GLOBALS['strCollation'] . '' . $GLOBALS['strNull'] . '' . $GLOBALS['strComment'] . '
' + . ' ' . PMA_getIcon('b_edit.png', $GLOBALS['strEdit']) . '' + . '' + . ' ' + . PMA_getIcon('b_drop.png', $GLOBALS['strDrop']) . '' + . '' . htmlspecialchars($index->getName()) . '' . htmlspecialchars($index->getType()) . '' . $index->isUnique(true) . '' . $index->isPacked(true) . '
' . htmlspecialchars($column->getName()); + if ($column->getSubPart()) { + $r .= ' (' . $column->getSubPart() . ')'; + } + $r .= '' . htmlspecialchars($column->getCardinality()) . '' . htmlspecialchars($column->getCollation()) . '' . htmlspecialchars($column->getNull()) . '' + . htmlspecialchars($index->getComments()) . '
'; + + if (! $print_mode) { + //$r .= PMA_check_indexes($ret_keys); + } + + return $r; + } +} + +class PMA_Index_Column +{ + /** + * @var string The column name + */ + protected $_name = ''; + + /** + * @var integer The column sequence number in the index, starting with 1. + */ + protected $_seq_in_index = 1; + + /** + * @var string How the column is sorted in the index. “A” (Ascending) or NULL (Not sorted) + */ + protected $_collation = null; + + /** + * The number of indexed characters if the column is only partly indexed, + * NULL if the entire column is indexed. + * + * @var integer + */ + protected $_sub_part = null; + + /** + * Contains YES if the column may contain NULL. + * If not, the column contains NO. + * + * @var string + */ + protected $_null = ''; + + /** + * An estimate of the number of unique values in the index. This is updated + * by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on + * statistics stored as integers, so the value is not necessarily exact even + * for small tables. The higher the cardinality, the greater the chance that + * MySQL uses the index when doing joins. + * + * @var integer + */ + protected $_cardinality = 0; + + public function __construct($params = array()) + { + $this->set($params); + } + + public function set($params) + { + if (isset($params['Column_name'])) { + $this->_name = $params['Column_name']; + } + if (isset($params['Seq_in_index'])) { + $this->_seq_in_index = $params['Seq_in_index']; + } + if (isset($params['Collation'])) { + $this->_collation = $params['Collation']; + } + if (isset($params['Cardinality'])) { + $this->_cardinality = $params['Cardinality']; + } + if (isset($params['Sub_part'])) { + $this->_sub_part = $params['Sub_part']; + } + if (isset($params['Null'])) { + $this->_null = $params['Null']; + } + } + + public function getName() + { + return $this->_name; + } + + public function getCollation() + { + return $this->_collation; + } + + public function getCardinality() + { + return $this->_cardinality; + } + + public function getNull() + { + return $this->_null; + } + + public function getSeqInIndex() + { + return $this->_seq_in_index; + } + + public function getSubPart() + { + return $this->_sub_part; + } +} +?> \ No newline at end of file diff --git a/libraries/tbl_indexes.lib.php b/libraries/tbl_indexes.lib.php index 27ce9cd5d..d08bb6d22 100644 --- a/libraries/tbl_indexes.lib.php +++ b/libraries/tbl_indexes.lib.php @@ -131,13 +131,12 @@ function PMA_check_indexes($idx_collection) * @param array Referenced Array of indexes * @param array Referenced return array * @param array Referenced return array - * @param array Referenced return array * * @access public * @return boolean void * @author Garvin Hicking (pma@supergarv.de) */ -function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_data) +function PMA_extract_indexes(&$ret_keys, &$indexes_info, &$indexes_data) { if (! is_array($ret_keys)) { return false; @@ -175,120 +174,4 @@ function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_da return true; } -/** - * Show index data and prepare returned collection array for index - * key checks. - * - * @param string $table The tablename - * @param array $indexes Referenced Array of indexes - * @param array $indexes_info Referenced info array - * @param array $indexes_data Referenced data array - * @param boolean $display_html Output HTML code, or just return collection array? - * @param boolean $print_mode - * @access public - * @return array Index collection array - * @author Garvin Hicking (pma@supergarv.de) - */ -function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, - $display_html = true, $print_mode = false) -{ - $idx_collection = array(); - $odd_row = true; - foreach ($indexes as $index_name) { - if ($display_html) { - $row_span = ' rowspan="' . count($indexes_info[$index_name]['Sequences']) . '" '; - - echo ' ' . "\n"; - echo ' ' . "\n" - . ' ' . htmlspecialchars($index_name) . "\n" - . ' ' . "\n"; - } - - if ($indexes_info[$index_name]['Index_type'] == 'FULLTEXT') { - $index_type = 'FULLTEXT'; - } elseif ($index_name == 'PRIMARY') { - $index_type = 'PRIMARY'; - } elseif ($indexes_info[$index_name]['Non_unique'] == '0') { - $index_type = 'UNIQUE'; - } else { - $index_type = 'INDEX'; - } - - if ($display_html) { - echo ' ' . "\n" - . ' ' . $index_type . '' . "\n"; - - echo ' ' . "\n" - . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $GLOBALS['strNone']) . ' ' . "\n" - . ' ' . "\n"; - - if (!$print_mode) { - echo ' ' . "\n" - . ' ' . $GLOBALS['edit_link_text'] . '' . "\n" - . ' ' . "\n"; - - if ($index_name == 'PRIMARY') { - $local_query = urlencode('ALTER TABLE ' . PMA_backquote($table) . ' DROP PRIMARY KEY'); - $js_msg = 'ALTER TABLE ' . PMA_jsFormat($table) . ' DROP PRIMARY KEY'; - $zero_rows = urlencode($GLOBALS['strPrimaryKeyHasBeenDropped']); - } else { - $local_query = urlencode('ALTER TABLE ' . PMA_backquote($table) . ' DROP INDEX ' . PMA_backquote($index_name)); - $js_msg = 'ALTER TABLE ' . PMA_jsFormat($table) . ' DROP INDEX ' . PMA_jsFormat($index_name); - $zero_rows = urlencode(sprintf($GLOBALS['strIndexHasBeenDropped'], htmlspecialchars($index_name))); - } - - echo ' ' . "\n" - . ' ' . $GLOBALS['drop_link_text'] . '' . "\n" - . ' ' . "\n"; - } - } - - foreach ($indexes_info[$index_name]['Sequences'] AS $row_no => $seq_index) { - $col_name = $indexes_data[$index_name][$seq_index]['Column_name']; - if ($row_no == 0) { - if (isset($idx_collection[$index_type][$col_name])) { - $idx_collection[$index_type][$col_name]++; - } else { - $idx_collection[$index_type][$col_name] = 1; - } - - if (isset($idx_collection['ALL'][$col_name])) { - $idx_collection['ALL'][$col_name]++; - } else { - $idx_collection['ALL'][$col_name] = 1; - } - } - - if ($display_html) { - if ($row_no > 0) { - echo ' ' . "\n"; - } - - if (isset($indexes_data[$index_name][$seq_index]['Sub_part']) - && strlen($indexes_data[$index_name][$seq_index]['Sub_part'])) { - echo ' ' . $col_name . '' . "\n"; - echo ' ' . "\n" - . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n" - . ' ' . "\n"; - echo ' ' . "\n"; - } else { - echo ' ' . "\n" - . ' ' . htmlspecialchars($col_name) . "\n" - . ' ' . "\n"; - echo ' ' . "\n"; - } - } - } // end foreach $indexes_info[$index_name]['Sequences'] - - $odd_row = ! $odd_row; - } // end while - - return $idx_collection; -} - ?> diff --git a/pmd_common.php b/pmd_common.php index 23f285512..cf20ab49e 100644 --- a/pmd_common.php +++ b/pmd_common.php @@ -205,8 +205,8 @@ function get_pk_or_unique_keys() $ret_keys = PMA_get_indexes($GLOBALS['PMD']['TABLE_NAME_SMALL'][$I]); if (! empty($ret_keys)) { // reset those as the function uses them by reference - $indexes = $indexes_info = $indexes_data = array(); - PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data); + $indexes_info = $indexes_data = array(); + PMA_extract_indexes($ret_keys, $indexes_info, $indexes_data); // for now, take into account only the first index segment foreach ($indexes_data as $key_name => $one_index) { $column_name = $one_index[1]['Column_name']; @@ -242,8 +242,8 @@ function get_all_keys() $ret_keys = PMA_get_indexes($GLOBALS['PMD']['TABLE_NAME_SMALL'][$I]); if (! empty($ret_keys)) { // reset those as the function uses them by reference - $indexes = $indexes_info = $indexes_data = array(); - PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data); + $indexes_info = $indexes_data = array(); + PMA_extract_indexes($ret_keys, $indexes_info, $indexes_data); // for now, take into account only the first index segment foreach ($indexes_data as $one_index) { $column_name = $one_index[1]['Column_name']; diff --git a/tbl_indexes.php b/tbl_indexes.php index 4b2fbae35..f0cc49b3c 100644 --- a/tbl_indexes.php +++ b/tbl_indexes.php @@ -1,7 +1,7 @@ back to the welcome page - if (strlen($db)) { - $is_db = PMA_DBI_select_db($db); +// Not a valid db name -> back to the welcome page +if (strlen($db)) { + $is_db = PMA_DBI_select_db($db); +} +if (!strlen($db) || !$is_db) { + $uri_params = array('reload' => '1'); + if (isset($message)) { + $uri_params['message'] = $message; } - if (!strlen($db) || !$is_db) { - $uri_params = array('reload' => '1'); - if (isset($message)) { - $uri_params['message'] = $message; - } - PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'main.php' - . PMA_generate_common_url($uri_params, '&')); - exit; - } - // Not a valid table name -> back to the default db sub-page - if (strlen($table)) { - $is_table = PMA_DBI_query('SHOW TABLES LIKE \'' - . PMA_sqlAddslashes($table, TRUE) . '\'', null, PMA_DBI_QUERY_STORE); - } - if (! strlen($table) - || !($is_table && PMA_DBI_num_rows($is_table))) { - $uri_params = array('reload' => '1', 'db' => $db); - if (isset($message)) { - $uri_params['message'] = $message; - } - PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] - . $cfg['DefaultTabDatabase'] - . PMA_generate_common_url($uri_params, '&')); - exit; - } elseif (isset($is_table)) { - PMA_DBI_free_result($is_table); + PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'main.php' + . PMA_generate_common_url($uri_params, '&')); + exit; +} +// Not a valid table name -> back to the default db sub-page +if (strlen($table)) { + $is_table = PMA_DBI_query('SHOW TABLES LIKE \'' + . PMA_sqlAddslashes($table, TRUE) . '\'', null, PMA_DBI_QUERY_STORE); +} +if (! strlen($table) + || !($is_table && PMA_DBI_num_rows($is_table))) { + $uri_params = array('reload' => '1', 'db' => $db); + if (isset($message)) { + $uri_params['message'] = $message; } + PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] + . $cfg['DefaultTabDatabase'] + . PMA_generate_common_url($uri_params, '&')); + exit; +} elseif (isset($is_table)) { + PMA_DBI_free_result($is_table); +} - // Displays headers (if needed) - $GLOBALS['js_include'][] = 'functions.js'; - $GLOBALS['js_include'][] = 'indexes.js'; - require_once './libraries/header.inc.php'; -} // end if +// Displays headers (if needed) +$GLOBALS['js_include'][] = 'functions.js'; +$GLOBALS['js_include'][] = 'indexes.js'; +require_once './libraries/header.inc.php'; /** * Gets fields and indexes informations */ -if (!defined('PMA_IDX_INCLUDED')) { - $err_url_0 = 'db_sql.php?' . PMA_generate_common_url($db); -} +$err_url_0 = 'db_sql.php?' . PMA_generate_common_url($db); // Gets table keys and store them in arrays -$indexes = array(); $indexes_info = array(); $indexes_data = array(); -// keys had already been grabbed in "tbl_sql.php" -if (!defined('PMA_IDX_INCLUDED')) { - $ret_keys = PMA_get_indexes($table, $err_url_0); -} +$ret_keys = PMA_get_indexes($table, $err_url_0); -PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data); +PMA_extract_indexes($ret_keys, $indexes_info, $indexes_data); + +$indexes = PMA_Index::getFromTable($table, $db); // Get fields and stores their name/type // fields had already been grabbed in "tbl_sql.php" -if (!defined('PMA_IDX_INCLUDED')) { - $fields_rs = PMA_DBI_query('SHOW FIELDS FROM ' - . PMA_backquote($table) . ';'); - $save_row = array(); - while ($row = PMA_DBI_fetch_assoc($fields_rs)) { - $save_row[] = $row; - } +$fields_rs = PMA_DBI_query('SHOW FIELDS FROM ' + . PMA_backquote($table) . ';'); +$save_row = array(); +while ($row = PMA_DBI_fetch_assoc($fields_rs)) { + $save_row[] = $row; } $fields_names = array(); @@ -109,9 +102,7 @@ if ($fields_rs) { * Do run the query to build the new index and moves back to * "tbl_sql.php" */ -if (!defined('PMA_IDX_INCLUDED') - && (isset($index) && isset($do_save_data))) { - +if (isset($index) && isset($do_save_data)) { $err_url = 'tbl_indexes.php?' . PMA_generate_common_url($db, $table); if (empty($old_index)) { $err_url .= '&create_index=1&idx_num_fields=' . $idx_num_fields; @@ -188,8 +179,7 @@ if (!defined('PMA_IDX_INCLUDED') /** * Edits an index or defines a new one */ -elseif (!defined('PMA_IDX_INCLUDED') - && (isset($index) || isset($create_index))) { +elseif (isset($index) || isset($create_index)) { // Prepares the form values if (!isset($index)) { @@ -256,8 +246,9 @@ elseif (!defined('PMA_IDX_INCLUDED')
- - ' . "\n"; } @@ -380,97 +371,11 @@ PMA_Message::warning('strPrimaryKeyWarning')->display();
- -
- - - 0) { - $edit_link_text = ''; - $drop_link_text = ''; - - if ($cfg['PropertiesIconic'] === true || $cfg['PropertiesIconic'] === 'both') { - $edit_link_text = '' . $strEdit . ''; - $drop_link_text = '' . $strDrop . ''; - } - if ($cfg['PropertiesIconic'] === false || $cfg['PropertiesIconic'] === 'both') { - $edit_link_text .= $strEdit; - $drop_link_text .= $strDrop; - } - if ($cfg['PropertiesIconic'] === 'both') { - $edit_link_text = '' . $edit_link_text . ''; - $drop_link_text = '' . $drop_link_text . ''; - } - ?> - - - - - - - - - - - ' - .'' . "\n"; - } - ?> - - - -
- - -
'; - PMA_Message::warning('strNoIndex')->display(); - echo '
- '); ?> - -
-
- diff --git a/tbl_printview.php b/tbl_printview.php index a4518b631..be3553202 100644 --- a/tbl_printview.php +++ b/tbl_printview.php @@ -32,6 +32,7 @@ if (! isset($the_tables) || ! is_array($the_tables)) { require_once './libraries/relation.lib.php'; require_once './libraries/transformations.lib.php'; require_once './libraries/tbl_indexes.lib.php'; +require_once './libraries/Index.class.php'; $cfgRelation = PMA_getRelationsParam(); @@ -101,14 +102,6 @@ foreach ($the_tables as $key => $table) { $tbl_is_view = PMA_Table::isView($db, $table); - // Gets table keys and store them in arrays - $indexes = array(); - $indexes_info = array(); - $indexes_data = array(); - $ret_keys = PMA_get_indexes($table, $err_url_0); - - PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data); - /** * Gets fields properties */ @@ -281,41 +274,12 @@ foreach ($the_tables as $key => $table) { ?> - 0) { - echo "\n"; - ?> -

- - - - - - - - - - - -
- $table) { } // end if ($cfg['ShowStats']) } if ($multi_tables) { - unset($ret_keys, $num_rows, $show_comment); + unset($num_rows, $show_comment); echo '
' . "\n"; } // end if echo '' . "\n"; diff --git a/tbl_structure.php b/tbl_structure.php index 282ce4bf1..64648756e 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -87,6 +87,8 @@ $cfgRelation = PMA_getRelationsParam(); */ require_once './libraries/tbl_common.php'; $url_query .= '&goto=tbl_structure.php&back=tbl_structure.php'; +$url_params['goto'] = 'tbl_structure.php'; +$url_params['back'] = 'tbl_structure.php'; /** * Prepares the table structure display @@ -102,26 +104,18 @@ require_once './libraries/tbl_info.inc.php'; * Displays top menu links */ require_once './libraries/tbl_links.inc.php'; +require_once './libraries/Index.class.php'; // 2. Gets table keys and retains them -$result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ';'); -$primary = ''; -$ret_keys = array(); -$pk_array = array(); // will be use to emphasis prim. keys in the table view -while ($row = PMA_DBI_fetch_assoc($result)) { - $ret_keys[] = $row; - // Backups the list of primary keys - if ($row['Key_name'] == 'PRIMARY') { - $primary .= $row['Column_name'] . ', '; - $pk_array[$row['Column_name']] = 1; - } -} // end while -PMA_DBI_free_result($result); +// @todo should be: $server->db($db)->table($table)->primary() +$primary = PMA_Index::getPrimary($table, $db); + // 3. Get fields $fields_rs = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); $fields_cnt = PMA_DBI_num_rows($fields_rs); + // Get more complete field information // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options // but later, if the analyser returns more information, it @@ -327,7 +321,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { $field_name = '' . $field_name . ''; } - if (isset($pk_array[$row['Field']])) { + if ($primary && $primary->hasColumn($field_name)) { $field_name = '' . $field_name . ''; } echo "\n"; @@ -364,8 +358,8 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { } else { echo "\n"; ?> - + 20) { require './libraries/tbl_links.inc.php'; } // end if ($fields_cnt > 20) -echo "\n\n"; /** * Displays indexes */ -PMA_generate_slider_effect('tablestatistics', $strDetails); -echo '
' . "\n"; +PMA_generate_slider_effect('tablestatistics_indexes', $strDetails); +echo '
' . "\n"; if (! $tbl_is_view && ! $db_is_information_schema) { - define('PMA_IDX_INCLUDED', 1); - require './tbl_indexes.php'; + /** + * Display indexes + */ + echo PMA_Index::getView($table, $db); + ?> +
+
+
+ '); + ?> + +
+
+
+ ' . "\n"; /** * Displays Space usage and row statistics @@ -769,6 +786,7 @@ require './libraries/tbl_triggers.lib.php'; echo '
' . "\n"; echo '
' . "\n"; +echo '
' . "\n"; /** * Displays the footer