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 * staybyte: speedup view on locked tables - 11 June 2001
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()
36 if (! defined('PHPMYADMIN')) {
43 require_once './libraries/common.inc.php';
46 * limits for table list
48 if (! isset($_SESSION['userconf']['table_limit_offset']) ||
$_SESSION['userconf']['table_limit_offset_db'] != $db) {
49 $_SESSION['userconf']['table_limit_offset'] = 0;
50 $_SESSION['userconf']['table_limit_offset_db'] = $db;
52 if (isset($_REQUEST['pos'])) {
53 $_SESSION['userconf']['table_limit_offset'] = (int) $_REQUEST['pos'];
55 $pos = $_SESSION['userconf']['table_limit_offset'];
58 * fills given tooltip arrays
60 * @uses $cfg['ShowTooltipAliasTB']
61 * @uses $GLOBALS['strStatCreateTime']
62 * @uses PMA_localisedDate()
64 * @param array $tooltip_truename tooltip data
65 * @param array $tooltip_aliasname tooltip data
66 * @param array $table tabledata
68 function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
70 if (empty($table['Comment'])) {
71 $table['Comment'] = $table['Name'];
74 $table['Comment'] .= ' ';
77 if ($GLOBALS['cfg']['ShowTooltipAliasTB']
78 && $GLOBALS['cfg']['ShowTooltipAliasTB'] != 'nested') {
79 $tooltip_truename[$table['Name']] = $table['Comment'];
80 $tooltip_aliasname[$table['Name']] = $table['Name'];
82 $tooltip_truename[$table['Name']] = $table['Name'];
83 $tooltip_aliasname[$table['Name']] = $table['Comment'];
86 if (isset($table['Create_time']) && !empty($table['Create_time'])) {
87 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCreateTime']
88 . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
91 if (! empty($table['Update_time'])) {
92 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatUpdateTime']
93 . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
96 if (! empty($table['Check_time'])) {
97 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCheckTime']
98 . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
102 PMA_checkParameters(array('db'));
105 * @global bool whether to display extended stats
107 $is_show_stats = $cfg['ShowStats'];
110 * @global bool whether selected db is information_schema
112 $db_is_information_schema = false;
114 if ($db == 'information_schema') {
115 $is_show_stats = false;
116 $db_is_information_schema = true;
120 * @global array information about tables in db
124 // When used in Nested table group mode, only show tables matching the given groupname
125 if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
126 $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
131 if ($cfg['ShowTooltip']) {
132 $tooltip_truename = array();
133 $tooltip_aliasname = array();
136 // Special speedup for newer MySQL Versions (in 4.0 format changed)
137 if (true === $cfg['SkipLockedTables']) {
138 $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
140 // Blending out tables in use
141 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
142 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
143 // if in use memorize tablename
144 if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
145 $sot_cache[$tmp[0]] = true;
148 PMA_DBI_free_result($db_info_result);
150 if (isset($sot_cache)) {
151 $db_info_result = PMA_DBI_query(
152 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
153 null, PMA_DBI_QUERY_STORE
);
154 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
155 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
156 if (!isset($sot_cache[$tmp[0]])) {
157 $sts_result = PMA_DBI_query(
158 'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
159 . ' LIKE \'' . addslashes($tmp[0]) . '\';');
160 $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
161 PMA_DBI_free_result($sts_result);
164 if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
165 $sts_tmp['Type'] =& $sts_tmp['Engine'];
168 if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
169 && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
173 if ($cfg['ShowTooltip']) {
174 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
177 $tables[$sts_tmp['Name']] = $sts_tmp;
178 } else { // table in use
179 $tables[$tmp[0]] = array('Name' => $tmp[0]);
182 if ($GLOBALS['cfg']['NaturalOrder']) {
183 uksort($tables, 'strnatcasecmp');
187 } elseif ($db_info_result) {
188 PMA_DBI_free_result($db_info_result);
193 } elseif ($db_info_result) {
194 PMA_DBI_free_result($db_info_result);
198 if (! isset($sot_ready)) {
199 if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
200 // only tables for selected group
201 $tables = PMA_DBI_get_tables_full($db, $tbl_group, true);
202 } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
203 // only tables for selected group,
204 // but grouping is done on comment ...
205 $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment');
208 // - get the total number of tables
209 // (needed for proper working of the MaxTableList feature)
210 $tables = PMA_DBI_get_tables($db);
211 $total_num_tables = count($tables);
212 if (isset($sub_part) && $sub_part == '_export') {
213 // (don't fetch only a subset if we are coming from db_export.php,
214 // because I think it's too risky to display only a subset of the
215 // table names when exporting a db)
218 * @todo Page selector for table names?
220 $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false);
222 // fetch the details for a possible limited subset
223 $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true);
227 if ($cfg['ShowTooltip']) {
228 foreach ($tables as $each_table) {
229 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
235 * @global int count of tables in db
237 $num_tables = count($tables);
238 // (needed for proper working of the MaxTableList feature)
239 if (! isset($total_num_tables)) {
240 $total_num_tables = $num_tables;
246 unset($each_table, $tbl_group_sql, $db_info_result);
249 * Displays top menu links
251 require './libraries/db_links.inc.php';