2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Gets the list of the table in the current db and informations about these
7 * fills tooltip arrays and provides $tables, $num_tables, $is_show_stats
8 * and $db_is_information_schema
10 * speedup view on locked tables
14 if (! defined('PHPMYADMIN')) {
21 require_once './libraries/common.inc.php';
24 * limits for table list
26 if (! isset($_SESSION['tmp_user_values']['table_limit_offset']) ||
$_SESSION['tmp_user_values']['table_limit_offset_db'] != $db) {
27 $_SESSION['tmp_user_values']['table_limit_offset'] = 0;
28 $_SESSION['tmp_user_values']['table_limit_offset_db'] = $db;
30 if (isset($_REQUEST['pos'])) {
31 $_SESSION['tmp_user_values']['table_limit_offset'] = (int) $_REQUEST['pos'];
33 $pos = $_SESSION['tmp_user_values']['table_limit_offset'];
36 * fills given tooltip arrays
38 * @param array $tooltip_truename tooltip data
39 * @param array $tooltip_aliasname tooltip data
40 * @param array $table tabledata
42 function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
44 if (empty($table['Comment'])) {
45 $table['Comment'] = $table['Name'];
48 $table['Comment'] .= ' ';
51 if ($GLOBALS['cfg']['ShowTooltipAliasTB']
52 && $GLOBALS['cfg']['ShowTooltipAliasTB'] != 'nested') {
53 $tooltip_truename[$table['Name']] = $table['Comment'];
54 $tooltip_aliasname[$table['Name']] = $table['Name'];
56 $tooltip_truename[$table['Name']] = $table['Name'];
57 $tooltip_aliasname[$table['Name']] = $table['Comment'];
60 if (isset($table['Create_time']) && !empty($table['Create_time'])) {
61 $tooltip_aliasname[$table['Name']] .= ', ' . __('Creation')
62 . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
65 if (! empty($table['Update_time'])) {
66 $tooltip_aliasname[$table['Name']] .= ', ' . __('Last update')
67 . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
70 if (! empty($table['Check_time'])) {
71 $tooltip_aliasname[$table['Name']] .= ', ' . __('Last check')
72 . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
76 PMA_checkParameters(array('db'));
79 * @global bool whether to display extended stats
81 $is_show_stats = $cfg['ShowStats'];
84 * @global bool whether selected db is information_schema
86 $db_is_information_schema = false;
88 if ($db == 'information_schema') {
89 $is_show_stats = false;
90 $db_is_information_schema = true;
94 * @global array information about tables in db
98 // When used in Nested table group mode, only show tables matching the given groupname
99 if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
100 $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
105 if ($cfg['ShowTooltip']) {
106 $tooltip_truename = array();
107 $tooltip_aliasname = array();
110 // Special speedup for newer MySQL Versions (in 4.0 format changed)
111 if (true === $cfg['SkipLockedTables']) {
112 $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
114 // Blending out tables in use
115 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
116 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
117 // if in use memorize tablename
118 if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
119 $sot_cache[$tmp[0]] = true;
122 PMA_DBI_free_result($db_info_result);
124 if (isset($sot_cache)) {
125 $db_info_result = PMA_DBI_query(
126 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
127 null, PMA_DBI_QUERY_STORE
);
128 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
129 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
130 if (! isset($sot_cache[$tmp[0]])) {
131 $sts_result = PMA_DBI_query(
132 'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
133 . ' LIKE \'' . PMA_sqlAddSlashes($tmp[0], true) . '\';');
134 $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
135 PMA_DBI_free_result($sts_result);
138 if (! isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
139 $sts_tmp['Type'] =& $sts_tmp['Engine'];
142 if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
143 && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
147 if ($cfg['ShowTooltip']) {
148 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
151 $tables[$sts_tmp['Name']] = $sts_tmp;
152 } else { // table in use
153 $tables[$tmp[0]] = array('Name' => $tmp[0]);
156 if ($GLOBALS['cfg']['NaturalOrder']) {
157 uksort($tables, 'strnatcasecmp');
161 } elseif ($db_info_result) {
162 PMA_DBI_free_result($db_info_result);
167 } elseif ($db_info_result) {
168 PMA_DBI_free_result($db_info_result);
172 if (! isset($sot_ready)) {
174 // Set some sorting defaults
178 if (isset($_REQUEST['sort'])) {
179 $sortable_name_mappings = array(
183 'collation' => 'Collation',
184 'size' => 'Data_length',
185 'overhead' => 'Data_free'
188 // Make sure the sort type is implemented
189 if (isset($sortable_name_mappings[$_REQUEST['sort']])) {
190 $sort = $sortable_name_mappings[$_REQUEST['sort']];
191 if ($_REQUEST['sort_order'] == 'DESC') {
192 $sort_order = 'DESC';
197 if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
198 // only tables for selected group
199 $tables = PMA_DBI_get_tables_full($db, $tbl_group, true, null, 0, false, $sort, $sort_order);
200 } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
201 // only tables for selected group,
202 // but grouping is done on comment ...
203 $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment', null, 0, false, $sort, $sort_order);
206 // - get the total number of tables
207 // (needed for proper working of the MaxTableList feature)
208 $tables = PMA_DBI_get_tables($db);
209 $total_num_tables = count($tables);
210 if (isset($sub_part) && $sub_part == '_export') {
211 // (don't fetch only a subset if we are coming from db_export.php,
212 // because I think it's too risky to display only a subset of the
213 // table names when exporting a db)
216 * @todo Page selector for table names?
218 $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false, $sort, $sort_order);
220 // fetch the details for a possible limited subset
221 $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true, $sort, $sort_order);
225 if ($cfg['ShowTooltip']) {
226 foreach ($tables as $each_table) {
227 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
233 * @global int count of tables in db
235 $num_tables = count($tables);
236 // (needed for proper working of the MaxTableList feature)
237 if (! isset($total_num_tables)) {
238 $total_num_tables = $num_tables;
244 unset($each_table, $tbl_group_sql, $db_info_result);
247 * Displays top menu links
248 * If in an Ajax request, we do not need to show this
250 if ($GLOBALS['is_ajax_request'] != true) {
251 require './libraries/db_links.inc.php';