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
12 * @uses $cfg['ShowStats']
13 * @uses $cfg['ShowTooltip']
14 * @uses $cfg['ShowTooltipAliasTB']
15 * @uses $cfg['SkipLockedTables']
16 * @uses $GLOBALS['db']
17 * @uses PMA_fillTooltip()
18 * @uses PMA_checkParameters()
19 * @uses PMA_escape_mysql_wildcards()
20 * @uses PMA_DBI_query()
21 * @uses PMA_backquote()
22 * @uses PMA_DBI_num_rows()
23 * @uses PMA_DBI_fetch_row()
24 * @uses PMA_DBI_fetch_assoc()
25 * @uses PMA_DBI_free_result()
26 * @uses PMA_DBI_get_tables_full()
31 * @uses strnatcasecmp()
37 if (! defined('PHPMYADMIN')) {
44 require_once './libraries/common.inc.php';
47 * limits for table list
49 if (! isset($_SESSION['tmp_user_values']['table_limit_offset']) ||
$_SESSION['tmp_user_values']['table_limit_offset_db'] != $db) {
50 $_SESSION['tmp_user_values']['table_limit_offset'] = 0;
51 $_SESSION['tmp_user_values']['table_limit_offset_db'] = $db;
53 if (isset($_REQUEST['pos'])) {
54 $_SESSION['tmp_user_values']['table_limit_offset'] = (int) $_REQUEST['pos'];
56 $pos = $_SESSION['tmp_user_values']['table_limit_offset'];
59 * fills given tooltip arrays
61 * @uses $cfg['ShowTooltipAliasTB']
62 * @uses __('Creation')
63 * @uses PMA_localisedDate()
65 * @param array $tooltip_truename tooltip data
66 * @param array $tooltip_aliasname tooltip data
67 * @param array $table tabledata
69 function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
71 if (empty($table['Comment'])) {
72 $table['Comment'] = $table['Name'];
75 $table['Comment'] .= ' ';
78 if ($GLOBALS['cfg']['ShowTooltipAliasTB']
79 && $GLOBALS['cfg']['ShowTooltipAliasTB'] != 'nested') {
80 $tooltip_truename[$table['Name']] = $table['Comment'];
81 $tooltip_aliasname[$table['Name']] = $table['Name'];
83 $tooltip_truename[$table['Name']] = $table['Name'];
84 $tooltip_aliasname[$table['Name']] = $table['Comment'];
87 if (isset($table['Create_time']) && !empty($table['Create_time'])) {
88 $tooltip_aliasname[$table['Name']] .= ', ' . __('Creation')
89 . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
92 if (! empty($table['Update_time'])) {
93 $tooltip_aliasname[$table['Name']] .= ', ' . __('Last update')
94 . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
97 if (! empty($table['Check_time'])) {
98 $tooltip_aliasname[$table['Name']] .= ', ' . __('Last check')
99 . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
103 PMA_checkParameters(array('db'));
106 * @global bool whether to display extended stats
108 $is_show_stats = $cfg['ShowStats'];
111 * @global bool whether selected db is information_schema
113 $db_is_information_schema = false;
115 if ($db == 'information_schema') {
116 $is_show_stats = false;
117 $db_is_information_schema = true;
121 * @global array information about tables in db
125 // When used in Nested table group mode, only show tables matching the given groupname
126 if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
127 $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
132 if ($cfg['ShowTooltip']) {
133 $tooltip_truename = array();
134 $tooltip_aliasname = array();
137 // Special speedup for newer MySQL Versions (in 4.0 format changed)
138 if (true === $cfg['SkipLockedTables']) {
139 $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
141 // Blending out tables in use
142 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
143 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
144 // if in use memorize tablename
145 if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
146 $sot_cache[$tmp[0]] = true;
149 PMA_DBI_free_result($db_info_result);
151 if (isset($sot_cache)) {
152 $db_info_result = PMA_DBI_query(
153 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
154 null, PMA_DBI_QUERY_STORE
);
155 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
156 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
157 if (!isset($sot_cache[$tmp[0]])) {
158 $sts_result = PMA_DBI_query(
159 'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
160 . ' LIKE \'' . addslashes($tmp[0]) . '\';');
161 $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
162 PMA_DBI_free_result($sts_result);
165 if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
166 $sts_tmp['Type'] =& $sts_tmp['Engine'];
169 if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
170 && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
174 if ($cfg['ShowTooltip']) {
175 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
178 $tables[$sts_tmp['Name']] = $sts_tmp;
179 } else { // table in use
180 $tables[$tmp[0]] = array('Name' => $tmp[0]);
183 if ($GLOBALS['cfg']['NaturalOrder']) {
184 uksort($tables, 'strnatcasecmp');
188 } elseif ($db_info_result) {
189 PMA_DBI_free_result($db_info_result);
194 } elseif ($db_info_result) {
195 PMA_DBI_free_result($db_info_result);
199 if (! isset($sot_ready)) {
201 // Set some sorting defaults
205 if (isset($_REQUEST['sort'])) {
206 $sortable_name_mappings = array(
210 'collation' => 'Collation',
211 'size' => 'Data_length',
212 'overhead' => 'Data_free'
215 // Make sure the sort type is implemented
216 if ($sort = $sortable_name_mappings[$_REQUEST['sort']]) {
217 if ($_REQUEST['sort_order'] == 'DESC') {
218 $sort_order = 'DESC';
223 if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
224 // only tables for selected group
225 $tables = PMA_DBI_get_tables_full($db, $tbl_group, true, null, 0, false, $sort, $sort_order);
226 } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
227 // only tables for selected group,
228 // but grouping is done on comment ...
229 $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment', null, 0, false, $sort, $sort_order);
232 // - get the total number of tables
233 // (needed for proper working of the MaxTableList feature)
234 $tables = PMA_DBI_get_tables($db);
235 $total_num_tables = count($tables);
236 if (isset($sub_part) && $sub_part == '_export') {
237 // (don't fetch only a subset if we are coming from db_export.php,
238 // because I think it's too risky to display only a subset of the
239 // table names when exporting a db)
242 * @todo Page selector for table names?
244 $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false, $sort, $sort_order);
246 // fetch the details for a possible limited subset
247 $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true, $sort, $sort_order);
251 if ($cfg['ShowTooltip']) {
252 foreach ($tables as $each_table) {
253 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
259 * @global int count of tables in db
261 $num_tables = count($tables);
262 // (needed for proper working of the MaxTableList feature)
263 if (! isset($total_num_tables)) {
264 $total_num_tables = $num_tables;
270 unset($each_table, $tbl_group_sql, $db_info_result);
273 * Displays top menu links
275 require './libraries/db_links.inc.php';