remove todo, after upgrade PHPExcel
[phpmyadmin/arisferyanto.git] / libraries / db_info.inc.php
blob4f59baa4798cbf72fcbe85c58f29c06003976608
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Gets the list of the table in the current db and informations about these
5 * tables if possible
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()
27 * @uses PMA_isValid()
28 * @uses preg_match()
29 * @uses preg_quote()
30 * @uses uksort()
31 * @uses strnatcasecmp()
32 * @uses count()
33 * @uses addslashes()
34 * @version $Id$
35 * @package phpMyAdmin
37 if (! defined('PHPMYADMIN')) {
38 exit;
41 /**
42 * requirements
44 require_once './libraries/common.inc.php';
46 /**
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'];
58 /**
59 * fills given tooltip arrays
61 * @uses $cfg['ShowTooltipAliasTB']
62 * @uses $GLOBALS['strStatCreateTime']
63 * @uses PMA_localisedDate()
64 * @uses strtotime()
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'];
73 } else {
74 // why?
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'];
82 } else {
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']] .= ', ' . $GLOBALS['strStatCreateTime']
89 . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
92 if (! empty($table['Update_time'])) {
93 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatUpdateTime']
94 . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
97 if (! empty($table['Check_time'])) {
98 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCheckTime']
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
123 $tables = array();
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) . '%"';
128 } else {
129 $tbl_group_sql = '';
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);
163 unset($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'])) {
171 continue;
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');
187 $sot_ready = true;
188 } elseif ($db_info_result) {
189 PMA_DBI_free_result($db_info_result);
191 unset($sot_cache);
193 unset($tmp);
194 } elseif ($db_info_result) {
195 PMA_DBI_free_result($db_info_result);
199 if (! isset($sot_ready)) {
201 // Set some sorting defaults
202 $sort = 'Name';
203 $sort_order = 'ASC';
205 if (isset($_REQUEST['sort'])) {
206 $sortable_name_mappings = array(
207 'table' => 'Name',
208 'records' => 'Rows',
209 'type' => 'Engine',
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);
230 } else {
231 // all tables in db
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);
245 } else {
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;
268 * cleanup
270 unset($each_table, $tbl_group_sql, $db_info_result);
273 * Displays top menu links
275 require './libraries/db_links.inc.php';