2.11.3-rc1, 2.11.4-dev
[phpmyadmin/crack.git] / libraries / db_info.inc.php
blob5aa2ee6c33843ebba2d5f9822b9e28f46656a6a7
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 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 * limits for table list
46 if (! isset($_SESSION['table_limit_offset'])) {
47 $_SESSION['table_limit_offset'] = 0;
49 if (isset($_REQUEST['pos'])) {
50 $_SESSION['table_limit_offset'] = (int) $_REQUEST['pos'];
52 $pos = $_SESSION['table_limit_offset'];
54 /**
55 * fills given tooltip arrays
57 * @uses $cfg['ShowTooltipAliasTB']
58 * @uses $GLOBALS['strStatCreateTime']
59 * @uses PMA_localisedDate()
60 * @uses strtotime()
61 * @param array $tooltip_truename tooltip data
62 * @param array $tooltip_aliasname tooltip data
63 * @param array $table tabledata
65 function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
67 if (empty($table['Comment'])) {
68 $table['Comment'] = $table['Name'];
69 } else {
70 // why?
71 $table['Comment'] .= ' ';
74 if ($GLOBALS['cfg']['ShowTooltipAliasTB']
75 && $GLOBALS['cfg']['ShowTooltipAliasTB'] != 'nested') {
76 $tooltip_truename[$table['Name']] = $table['Comment'];
77 $tooltip_aliasname[$table['Name']] = $table['Name'];
78 } else {
79 $tooltip_truename[$table['Name']] = $table['Name'];
80 $tooltip_aliasname[$table['Name']] = $table['Comment'];
83 if (isset($table['Create_time']) && !empty($table['Create_time'])) {
84 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCreateTime']
85 . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
88 if (! empty($table['Update_time'])) {
89 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatUpdateTime']
90 . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
93 if (! empty($table['Check_time'])) {
94 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCheckTime']
95 . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
99 PMA_checkParameters(array('db'));
102 * @global bool whether to display extended stats
104 $is_show_stats = $cfg['ShowStats'];
107 * @global bool whether selected db is information_schema
109 $db_is_information_schema = false;
111 if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') {
112 $is_show_stats = false;
113 $db_is_information_schema = true;
117 * @global array information about tables in db
119 $tables = array();
121 // When used in Nested table group mode, only show tables matching the given groupname
122 if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
123 $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
124 } else {
125 $tbl_group_sql = '';
128 if ($cfg['ShowTooltip']) {
129 $tooltip_truename = array();
130 $tooltip_aliasname = array();
133 // Special speedup for newer MySQL Versions (in 4.0 format changed)
134 if (true === $cfg['SkipLockedTables']) {
135 $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
137 // Blending out tables in use
138 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
139 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
140 // if in use memorize tablename
141 if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
142 $sot_cache[$tmp[0]] = true;
145 PMA_DBI_free_result($db_info_result);
147 if (isset($sot_cache)) {
148 $db_info_result = PMA_DBI_query(
149 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
150 null, PMA_DBI_QUERY_STORE);
151 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
152 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
153 if (!isset($sot_cache[$tmp[0]])) {
154 $sts_result = PMA_DBI_query(
155 'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
156 . ' LIKE \'' . addslashes($tmp[0]) . '\';');
157 $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
158 PMA_DBI_free_result($sts_result);
159 unset($sts_result);
161 if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
162 $sts_tmp['Type'] =& $sts_tmp['Engine'];
165 if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
166 && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
167 continue;
170 if ($cfg['ShowTooltip']) {
171 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
174 $tables[$sts_tmp['Name']] = $sts_tmp;
175 } else { // table in use
176 $tables[$tmp[0]] = array('Name' => $tmp[0]);
179 if ($GLOBALS['cfg']['NaturalOrder']) {
180 uksort($tables, 'strnatcasecmp');
183 $sot_ready = true;
184 } elseif ($db_info_result) {
185 PMA_DBI_free_result($db_info_result);
187 unset($sot_cache);
189 unset($tmp);
190 } elseif ($db_info_result) {
191 PMA_DBI_free_result($db_info_result);
195 if (! isset($sot_ready)) {
196 if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
197 // only tables for selected group
198 $tables = PMA_DBI_get_tables_full($db, $tbl_group, true);
199 } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
200 // only tables for selected group,
201 // but grouping is done on comment ...
202 $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment');
203 } else {
204 // all tables in db
205 // - get the total number of tables
206 $tables = PMA_DBI_get_tables($db);
207 $total_num_tables = count($tables);
208 if (isset($sub_part) && $sub_part == '_export') {
209 // (don't fetch only a subset if we are coming from db_export.php,
210 // because I think it's too risky to display only a subset of the
211 // table names when exporting a db)
214 * @todo Page selector for table names?
216 $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false);
217 } else {
218 // fetch the details for a possible limited subset
219 $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true);
223 if ($cfg['ShowTooltip']) {
224 foreach ($tables as $each_table) {
225 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
231 * @global int count of tables in db
233 $num_tables = count($tables);
234 if (! isset($total_num_tables)) {
235 $total_num_tables = $num_tables;
239 * cleanup
241 unset($each_table, $tbl_group_sql, $db_info_result);
244 * Displays top menu links
246 require './libraries/db_links.inc.php';