RFE #1435922 [gui] navigation frame shows listing of databases when none selected
[phpmyadmin/last10db.git] / libraries / db_info.inc.php
blob4cd8cf6abc8a58a95cda84a3188280f5633d9384
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 rovides $tables, $num_tables, $is_show_stats
8 * and $db_is_information_schema
10 * staybyte: speedup view on locked tables - 11 June 2001
12 * @uses PMA_MYSQL_INT_VERSION
13 * @uses $cfg['ShowStats']
14 * @uses $cfg['ShowTooltip']
15 * @uses $cfg['ShowTooltipAliasTB']
16 * @uses $cfg['SkipLockedTables']
17 * @uses $GLOBALS['db']
18 * @uses PMA_fillTooltip()
19 * @uses PMA_checkParameters()
20 * @uses PMA_escape_mysql_wildcards()
21 * @uses PMA_DBI_query()
22 * @uses PMA_backquote()
23 * @uses PMA_DBI_num_rows()
24 * @uses PMA_DBI_fetch_row()
25 * @uses PMA_DBI_fetch_assoc()
26 * @uses PMA_DBI_free_result()
27 * @uses PMA_DBI_get_tables_full()
28 * @uses PMA_isValid()
29 * @uses preg_match()
30 * @uses preg_quote()
31 * @uses uksort()
32 * @uses strnatcasecmp()
33 * @uses count()
34 * @uses addslashes()
35 * @version $Id$
38 /**
39 * requirements
41 require_once './libraries/common.inc.php';
43 /**
44 * fills given tooltip arrays
46 * @uses $cfg['ShowTooltipAliasTB']
47 * @uses $GLOBALS['strStatCreateTime']
48 * @uses PMA_localisedDate()
49 * @uses strtotime()
50 * @param array $tooltip_truename tooltip data
51 * @param array $tooltip_aliasname tooltip data
52 * @param array $table tabledata
54 function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
56 if (empty($table['Comment'])) {
57 $table['Comment'] = $table['Name'];
58 } else {
59 // why?
60 $table['Comment'] .= ' ';
63 if ($GLOBALS['cfg']['ShowTooltipAliasTB']
64 && $GLOBALS['cfg']['ShowTooltipAliasTB'] != 'nested') {
65 $tooltip_truename[$table['Name']] = $table['Comment'];
66 $tooltip_aliasname[$table['Name']] = $table['Name'];
67 } else {
68 $tooltip_truename[$table['Name']] = $table['Name'];
69 $tooltip_aliasname[$table['Name']] = $table['Comment'];
72 if (isset($table['Create_time']) && !empty($table['Create_time'])) {
73 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCreateTime']
74 . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
77 if (! empty($table['Update_time'])) {
78 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatUpdateTime']
79 . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
82 if (! empty($table['Check_time'])) {
83 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCheckTime']
84 . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
88 PMA_checkParameters(array('db'));
90 /**
91 * @global bool whether to display extended stats
93 $is_show_stats = $cfg['ShowStats'];
95 /**
96 * @global bool whether selected db is information_schema
98 $db_is_information_schema = false;
100 if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') {
101 $is_show_stats = false;
102 $db_is_information_schema = true;
106 * @global array information about tables in db
108 $tables = array();
110 // When used in Nested table group mode, only show tables matching the given groupname
111 if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
112 $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
113 } else {
114 $tbl_group_sql = '';
117 if ($cfg['ShowTooltip']) {
118 $tooltip_truename = array();
119 $tooltip_aliasname = array();
122 // Special speedup for newer MySQL Versions (in 4.0 format changed)
123 if (true === $cfg['SkipLockedTables']) {
124 $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
126 // Blending out tables in use
127 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
128 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
129 // if in use memorize tablename
130 if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
131 $sot_cache[$tmp[0]] = true;
134 PMA_DBI_free_result($db_info_result);
136 if (isset($sot_cache)) {
137 $db_info_result = PMA_DBI_query(
138 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
139 null, PMA_DBI_QUERY_STORE);
140 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
141 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
142 if (!isset($sot_cache[$tmp[0]])) {
143 $sts_result = PMA_DBI_query(
144 'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
145 . ' LIKE \'' . addslashes($tmp[0]) . '\';');
146 $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
147 PMA_DBI_free_result($sts_result);
148 unset($sts_result);
150 if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
151 $sts_tmp['Type'] =& $sts_tmp['Engine'];
154 if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
155 && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
156 continue;
159 if ($cfg['ShowTooltip']) {
160 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
163 $tables[$sts_tmp['Name']] = $sts_tmp;
164 } else { // table in use
165 $tables[$tmp[0]] = array('Name' => $tmp[0]);
168 if ($GLOBALS['cfg']['NaturalOrder']) {
169 uksort($tables, 'strnatcasecmp');
172 $sot_ready = true;
173 } elseif ($db_info_result) {
174 PMA_DBI_free_result($db_info_result);
176 unset($sot_cache);
178 unset($tmp);
179 } elseif ($db_info_result) {
180 PMA_DBI_free_result($db_info_result);
184 if (! isset($sot_ready)) {
185 if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
186 // only tables for selected group
187 $tables = PMA_DBI_get_tables_full($db, $tbl_group, true);
188 } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
189 // only tables for selected group,
190 // but grouping is done on comment ...
191 $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment');
192 } else {
193 // all tables in db
194 $tables = PMA_DBI_get_tables_full($db);
197 if ($cfg['ShowTooltip']) {
198 foreach ($tables as $each_table) {
199 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
205 * @global int count of tables in db
207 $num_tables = count($tables);
210 * cleanup
212 unset($each_table, $tbl_group_sql, $db_info_result);
215 * Displays top menu links
217 require './libraries/db_links.inc.php';